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