xref: /webtrees/resources/views/media-page-details.phtml (revision e6f6dba568a1cd33f69043304bcc868958be978a)
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;
14
15/**
16 * @var Collection $clipboard_facts
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() && !$media_file->isPendingDeletion()) : ?>
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()) : ?>
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()) : ?>
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