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