xref: /webtrees/resources/views/media-page-details.phtml (revision b3679361640bf9d3bb5424fb15815c51cf0c1513)
1<?php
2
3use Fisharebest\Webtrees\Auth;
4use Fisharebest\Webtrees\Fact;
5use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
6use Fisharebest\Webtrees\Http\RequestHandlers\DeleteFact;
7use Fisharebest\Webtrees\Http\RequestHandlers\EditMediaFileModal;
8use Fisharebest\Webtrees\I18N;
9use Fisharebest\Webtrees\Media;
10use Fisharebest\Webtrees\Registry;
11use Fisharebest\Webtrees\Tree;
12use Illuminate\Support\Collection;
13use League\Flysystem\FilesystemOperator;
14
15/**
16 * @var Collection           $clipboard_facts
17 * @var FilesystemOperator   $data_filesystem
18 * @var Media                $record
19 * @var Tree                 $tree
20 */
21
22?>
23
24<table class="table wt-facts-table">
25    <?php foreach ($record->mediaFiles() as $media_file) : ?>
26        <tr class="<?= $media_file->isPendingAddition() ? 'wt-new' : '' ?><?= $media_file->isPendingDeletion() ? 'wt-old' : '' ?>">
27            <th scope="row">
28                <?= I18N::translate('Media file') ?>
29                <?php if ($record->canEdit()) : ?>
30                    <div class="editfacts nowrap">
31                        <a class="btn btn-link" href="#" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="<?= route(EditMediaFileModal::class, ['tree' => $record->tree()->name(), 'xref' => $record->xref(), 'fact_id' => $media_file->factId()]) ?>" title="<?= I18N::translate('Edit') ?>">
32                            <?= view('icons/edit') ?>
33                            <span class="visually-hidden">
34                            <?= I18N::translate('Edit') ?>
35                        </span>
36                        </a>
37
38                        <?php if (count($record->mediaFiles()) > 1) : ?>
39                            <a class="btn btn-link" href="#" data-wt-confirm="<?= I18N::translate('Are you sure you want to delete this fact?') ?>" data-wt-post-url="<?= e(route(DeleteFact::class, ['tree' => $record->tree()->name(), 'xref' => $record->xref(), 'fact_id' => $media_file->factId()])) ?>" title="<?= I18N::translate('Delete') ?>">
40                                <?= view('icons/delete') ?>
41                                <span class="visually-hidden">
42                            <?= I18N::translate('Delete') ?>
43                        </span>
44                            </a>
45
46                        <?php endif ?>
47                    </div>
48                <?php endif ?>
49            </th>
50            <td class="d-flex justify-content-between">
51                <div>
52                    <?php if ($media_file->isExternal()) : ?>
53                        <?= Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $record->tree()) ?>
54                    <?php elseif (Auth::isEditor($record->tree())) :?>
55                        <?php if (!$media_file->fileExists($data_filesystem)) : ?>
56                            <p class="alert alert-danger">
57                                <?= I18N::translate('The file “%s” does not exist.', e($media_file->filename())) ?>
58                            </p>
59                        <?php endif ?>
60                        <?= Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $record->tree()) ?>
61                    <?php endif ?>
62
63                    <?= Registry::elementFactory()->make('OBJE:FILE:TITL')->labelValue($media_file->title(), $record->tree()) ?>
64                    <?= Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->labelValue($media_file->type(), $record->tree()) ?>
65                    <?= Registry::elementFactory()->make('OBJE:FILE:FORM')->labelValue($media_file->format(), $record->tree()) ?>
66                </div>
67
68                <div>
69                    <?php if (!$media_file->isExternal()) : ?>
70                        <?php if (explode('/', $media_file->mimeType())[0] === 'audio') : ?>
71                        <audio controls>
72                            <source src="<?= e($media_file->downloadUrl('inline')) ?>" type="<?= $media_file->mimeType() ?>">
73                        </audio>
74                        <?php elseif (explode('/', $media_file->mimeType())[0] === 'video') : ?>
75                            <video controls width="300">
76                                <source src="<?= e($media_file->downloadUrl('inline')) ?>" type="<?= $media_file->mimeType() ?>">
77                            </video>
78                        <?php else : ?>
79                            <?= $media_file->displayImage(200, 150, 'contain', []) ?>
80                        <?php endif ?>
81                        <?php if ($record->tree()->getPreference('SHOW_MEDIA_DOWNLOAD') >= Auth::accessLevel($record->tree()) && $media_file->fileExists($data_filesystem)) : ?>
82                            <br>
83                            <a href="<?= e($media_file->downloadUrl('attachment')) ?>">
84                                <?= I18N::translate('Download file') ?>
85                            </a>
86                        <?php endif ?>
87                    <?php endif ?>
88                </div>
89            </td>
90        </tr>
91    <?php endforeach ?>
92
93    <?php foreach ($record->facts()->filter(fn (Fact $fact): bool => $fact->tag() !== 'OBJE:FILE') as $fact) : ?>
94        <?php FunctionsPrintFacts::printFact($fact, $record) ?>
95    <?php endforeach ?>
96</table>
97