xref: /webtrees/resources/views/media-page.phtml (revision 9320815f1ce8e5a76b792d0fc59d7ba088fe3793)
1<?php
2
3use Fisharebest\Webtrees\Auth;
4use Fisharebest\Webtrees\Fact;
5use Fisharebest\Webtrees\Family;
6use Fisharebest\Webtrees\Functions\FunctionsPrint;
7use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
8use Fisharebest\Webtrees\Http\RequestHandlers\AddMediaFileModal;
9use Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
10use Fisharebest\Webtrees\Http\RequestHandlers\DeleteFact;
11use Fisharebest\Webtrees\Http\RequestHandlers\EditMediaFileModal;
12use Fisharebest\Webtrees\Http\RequestHandlers\PendingChangesAcceptRecord;
13use Fisharebest\Webtrees\Http\RequestHandlers\PendingChangesRejectRecord;
14use Fisharebest\Webtrees\I18N;
15use Fisharebest\Webtrees\Individual;
16use Fisharebest\Webtrees\Media;
17use Fisharebest\Webtrees\Note;
18use Fisharebest\Webtrees\Registry;
19use Fisharebest\Webtrees\Source;
20use Fisharebest\Webtrees\Tree;
21use Illuminate\Support\Collection;
22use League\Flysystem\FilesystemInterface;
23
24/**
25 * @var Collection<Fact>       $clipboard_facts
26 * @var FilesystemInterface    $data_filesystem
27 * @var Collection<Fact>       $facts
28 * @var Collection<Family>     $families
29 * @var Collection<Individual> $individuals
30 * @var Media                  $media
31 * @var Collection<Note>       $notes
32 * @var Collection<Source>     $sources
33 * @var Tree                   $tree
34 */
35?>
36
37<?php if ($media->isPendingDeletion()) : ?>
38    <?php if (Auth::isModerator($media->tree())) : ?>
39        <?= view('components/alert-warning-dismissible', ['alert' => /* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate('This media object has been deleted. You should review the deletion and then %1$s or %2$s it.', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesAcceptRecord::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref()])) . '">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesRejectRecord::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref()])) . '">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>') . ' ' . view('help/link', ['topic' => 'pending_changes'])]) ?>
40    <?php elseif (Auth::isEditor($media->tree())) : ?>
41        <?= view('components/alert-warning-dismissible', ['alert' => I18N::translate('This media object has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . view('help/link', ['topic' => 'pending_changes'])]) ?>
42    <?php endif ?>
43<?php elseif ($media->isPendingAddition()) : ?>
44    <?php if (Auth::isModerator($media->tree())) : ?>
45        <?= view('components/alert-warning-dismissible', ['alert' => /* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate('This media object has been edited. You should review the changes and then %1$s or %2$s them.', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesAcceptRecord::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref()])) . '">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>', '<a href="#" class="alert-link" data-post-url="' . e(route(PendingChangesRejectRecord::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref()])) . '">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>') . ' ' . view('help/link', ['topic' => 'pending_changes'])]) ?>
46    <?php elseif (Auth::isEditor($media->tree())) : ?>
47        <?= view('components/alert-warning-dismissible', ['alert' => I18N::translate('This media object has been edited. The changes need to be reviewed by a moderator.') . ' ' . view('help/link', ['topic' => 'pending_changes'])]) ?>
48    <?php endif ?>
49<?php endif ?>
50
51<div class="d-flex mb-4">
52    <h2 class="wt-page-title mx-auto">
53        <?= $media->fullName() ?>
54    </h2>
55    <?php if ($media->canEdit()) : ?>
56        <?= view('media-page-menu', ['record' => $media]) ?>
57    <?php endif ?>
58</div>
59
60<div class="wt-page-content">
61    <ul class="nav nav-tabs" role="tablist">
62        <li class="nav-item" role="presentation">
63            <a class="nav-link active" data-toggle="tab" role="tab" href="#details">
64                <?= I18N::translate('Details') ?>
65            </a>
66        </li>
67
68        <li class="nav-item" role="presentation">
69            <a class="nav-link<?= $individuals->isEmpty() ? ' text-muted' : '' ?>" data-toggle="tab" role="tab" href="#individuals">
70                <?= I18N::translate('Individuals') ?>
71                <?= view('components/badge', ['count' => $individuals->count()]) ?>
72            </a>
73        </li>
74
75        <li class="nav-item" role="presentation">
76            <a class="nav-link<?= $families->isEmpty() ? ' text-muted' : '' ?>" data-toggle="tab" role="tab" href="#families">
77                <?= I18N::translate('Families') ?>
78                <?= view('components/badge', ['count' => $families->count()]) ?>
79            </a>
80        </li>
81
82        <li class="nav-item" role="presentation">
83            <a class="nav-link<?= $sources->isEmpty() ? ' text-muted' : '' ?>" data-toggle="tab" role="tab" href="#sources">
84                <?= I18N::translate('Sources') ?>
85                <?= view('components/badge', ['count' => $sources->count()]) ?>
86            </a>
87        </li>
88
89        <li class="nav-item" role="presentation">
90            <a class="nav-link<?= $notes->isEmpty() ? ' text-muted' : '' ?>" data-toggle="tab" role="tab" href="#notes">
91                <?= I18N::translate('Notes') ?>
92                <?= view('components/badge', ['count' => $notes->count()]) ?>
93            </a>
94        </li>
95    </ul>
96
97    <div class="tab-content mt-4">
98        <div class="tab-pane active fade show" role="tabpanel" id="details">
99            <table class="table wt-facts-table">
100                <?php foreach ($media->mediaFiles() as $media_file) : ?>
101                    <tr class="<?= $media_file->isPendingAddition() ? 'wt-new' : '' ?> <?= $media_file->isPendingDeletion() ? 'wt-old' : '' ?>">
102                        <th scope="row">
103                            <?= I18N::translate('Media file') ?>
104                            <?php if ($media->canEdit()) : ?>
105                                <div class="editfacts nowrap">
106                                    <a class="btn btn-link" href="#" data-toggle="modal" data-backdrop="static" data-target="#wt-ajax-modal" data-href="<?= route(EditMediaFileModal::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref(), 'fact_id' => $media_file->factId()]) ?>" title="<?= I18N::translate('Edit') ?>">
107                                        <?= view('icons/edit') ?>
108                                        <span class="sr-only">
109                                        <?= I18N::translate('Edit') ?>
110                                    </span>
111                                    </a>
112
113                                    <?php if (count($media->mediaFiles()) > 1) : ?>
114                                        <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' => $media->tree()->name(), 'xref' => $media->xref(), 'fact_id' => $media_file->factId()])) ?>" title="<?= I18N::translate('Delete') ?>">
115                                            <?= view('icons/delete') ?>
116                                            <span class="sr-only">
117                                        <?= I18N::translate('Delete') ?>
118                                    </span>
119                                        </a>
120
121                                    <?php endif ?>
122                                </div>
123                            <?php endif ?>
124                        </th>
125                        <td class="d-flex justify-content-between">
126                            <div>
127                                <?php if ($media_file->isExternal()) : ?>
128                                    <?= Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media->tree()) ?>
129                                <?php elseif (Auth::isEditor($media->tree())) :?>
130                                    <?php if (!$media_file->fileExists($data_filesystem)) : ?>
131                                        <p class="alert alert-danger">
132                                            <?= I18N::translate('The file “%s” does not exist.', e($media_file->filename())) ?>
133                                        </p>
134                                    <?php endif ?>
135                                    <?= Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media->tree()) ?>
136                                <?php endif ?>
137
138                                <?= Registry::elementFactory()->make('OBJE:FILE:TITL')->labelValue($media_file->title(), $media->tree()) ?>
139                                <?= Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->labelValue($media_file->type(), $media->tree()) ?>
140                                <?= Registry::elementFactory()->make('OBJE:FILE:FORM')->labelValue($media_file->format(), $media->tree()) ?>
141                            </div>
142
143                            <div>
144                                <?php if (!$media_file->isExternal()) : ?>
145                                    <?php if (explode('/', $media_file->mimeType())[0] === 'audio') : ?>
146                                    <audio controls>
147                                        <source src="<?= e($media_file->downloadUrl('inline')) ?>" type="<?= $media_file->mimeType() ?>">
148                                    </audio>
149                                    <?php elseif (explode('/', $media_file->mimeType())[0] === 'video') : ?>
150                                        <video controls width="300">
151                                            <source src="<?= e($media_file->downloadUrl('inline')) ?>" type="<?= $media_file->mimeType() ?>">
152                                        </video>
153                                    <?php else : ?>
154                                        <?= $media_file->displayImage(200, 150, 'contain', []) ?>
155                                    <?php endif ?>
156                                    <?php if ($media->tree()->getPreference('SHOW_MEDIA_DOWNLOAD') >= Auth::accessLevel($media->tree()) && $media_file->fileExists($data_filesystem)) : ?>
157                                        <br>
158                                        <a href="<?= e($media_file->downloadUrl('attachment')) ?>">
159                                            <?= I18N::translate('Download file') ?>
160                                        </a>
161                                    <?php endif ?>
162                                <?php endif ?>
163                            </div>
164                        </td>
165                    </tr>
166                <?php endforeach ?>
167                <?php foreach ($facts as $fact) : ?>
168                    <?php FunctionsPrintFacts::printFact($fact, $media) ?>
169                <?php endforeach ?>
170                <?php if ($media->canEdit()) : ?>
171                    <?= view('edit/paste-fact-row', ['record' => $media, 'facts' => $clipboard_facts]) ?>
172
173                    <?php FunctionsPrint::printAddNewFact($media, $facts, Media::RECORD_TYPE) ?>
174                    <tr>
175                        <th>
176                            <?= I18N::translate('Source') ?>
177                        </th>
178                        <td>
179                            <a href="<?= e(route(AddNewFact::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref(), 'fact' => 'SOUR'])) ?>">
180                                <?= I18N::translate('Add a source citation') ?>
181                            </a>
182                        </td>
183                    </tr>
184                    <tr>
185                        <th scope="row">
186                            <?= I18N::translate('Shared note') ?>
187                        </th>
188                        <td>
189                            <a href="<?= e(route(AddNewFact::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref(), 'fact' => 'SHARED_NOTE'])) ?>">
190                                <?= I18N::translate('Add a shared note') ?>
191                            </a>
192                        </td>
193                    </tr>
194                    <tr>
195                        <th scope="row">
196                            <?= I18N::translate('Restriction') ?>
197                        </th>
198                        <td>
199                            <a href="<?= e(route(AddNewFact::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref(), 'fact' => 'RESN'])) ?>">
200                                <?= I18N::translate('Add a restriction') ?>
201                            </a>
202                        </td>
203                    </tr>
204                    <tr>
205                        <th scope="row">
206                            <?= I18N::translate('Media file') ?>
207                        </th>
208                        <td>
209                            <a href="#" data-href="<?= e(route(AddMediaFileModal::class, ['tree' => $media->tree()->name(), 'xref' => $media->xref()])) ?>" data-target="#wt-ajax-modal" data-toggle="modal" data-backdrop="static">
210                                <?= I18N::translate('Add a media file') ?>
211                            </a>
212                        </td>
213                    </tr>
214                <?php endif ?>
215            </table>
216        </div>
217
218        <div class="tab-pane fade" role="tabpanel" id="individuals">
219            <?= view('lists/individuals-table', ['individuals' => $individuals, 'sosa' => false, 'tree' => $tree]) ?>
220        </div>
221
222        <div class="tab-pane fade" role="tabpanel" id="families">
223            <?= view('lists/families-table', ['families' => $families, 'tree' => $tree]) ?>
224        </div>
225
226        <div class="tab-pane fade" role="tabpanel" id="sources">
227            <?= view('lists/sources-table', ['sources' => $sources, 'tree' => $tree]) ?>
228        </div>
229
230        <div class="tab-pane fade" role="tabpanel" id="notes">
231            <?= view('lists/notes-table', ['notes' => $notes, 'tree' => $tree]) ?>
232        </div>
233    </div>
234</div>
235
236<?= view('modals/ajax') ?>
237