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