These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * webtrees: online genealogy |
||
4 | * Copyright (C) 2017 webtrees development team |
||
5 | * This program is free software: you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation, either version 3 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * This program is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU General Public License for more details. |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
15 | */ |
||
16 | namespace Fisharebest\Webtrees; |
||
17 | |||
18 | use Fisharebest\Webtrees\Controller\MediaController; |
||
19 | use Fisharebest\Webtrees\Functions\FunctionsPrint; |
||
20 | |||
21 | /** @global Tree $WT_TREE */ |
||
22 | global $WT_TREE; |
||
0 ignored issues
–
show
|
|||
23 | |||
24 | require 'includes/session.php'; |
||
25 | |||
26 | $record = Media::getInstance(Filter::get('mid', WT_REGEX_XREF), $WT_TREE); |
||
27 | $controller = new MediaController($record); |
||
28 | |||
29 | View Code Duplication | if ($controller->record && $controller->record->canShow()) { |
|
30 | if ($controller->record->isPendingDeletion()) { |
||
31 | if (Auth::isModerator($controller->record->getTree())) { |
||
32 | FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ |
||
33 | 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" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>', '<a href="#" class="alert-link" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||
34 | } elseif (Auth::isEditor($controller->record->getTree())) { |
||
35 | FlashMessages::addMessage(I18N::translate('This media object has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||
36 | } |
||
37 | } elseif ($controller->record->isPendingAddtion()) { |
||
38 | if (Auth::isModerator($controller->record->getTree())) { |
||
39 | FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ |
||
40 | 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" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>', '<a href="#" class="alert-link" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||
41 | } elseif (Auth::isEditor($controller->record->getTree())) { |
||
42 | FlashMessages::addMessage(I18N::translate('This media object has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||
43 | } |
||
44 | } |
||
45 | $controller->pageHeader(); |
||
46 | } else { |
||
47 | FlashMessages::addMessage(I18N::translate('This media object does not exist or you do not have permission to view it.'), 'danger'); |
||
48 | http_response_code(404); |
||
49 | $controller->pageHeader(); |
||
50 | |||
51 | return; |
||
52 | } |
||
53 | |||
54 | echo View::make('media-page', [ |
||
55 | 'media' => $controller->record, |
||
56 | 'individuals' => $controller->record->linkedIndividuals('OBJE'), |
||
57 | 'families' => $controller->record->linkedFamilies('OBJE'), |
||
58 | 'sources' => $controller->record->linkedSources('OBJE'), |
||
59 | 'notes' => $controller->record->linkedNotes('OBJE'), |
||
60 | 'facts' => array_filter($controller->getFacts(), function(Fact $fact) { return $fact->getTag() !== 'FILE'; }), |
||
61 | ]); |
||
62 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state