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 | /** |
||||
19 | * Defined in session.php |
||||
20 | * |
||||
21 | * @global Tree $WT_TREE |
||||
22 | */ |
||||
23 | global $WT_TREE; |
||||
24 | |||||
25 | use Fisharebest\Webtrees\Controller\MediaController; |
||||
26 | use Fisharebest\Webtrees\Functions\FunctionsPrint; |
||||
27 | use Fisharebest\Webtrees\Functions\FunctionsPrintFacts; |
||||
28 | use Fisharebest\Webtrees\Functions\FunctionsPrintLists; |
||||
29 | |||||
30 | define('WT_SCRIPT_NAME', 'mediaviewer.php'); |
||||
31 | require './includes/session.php'; |
||||
32 | |||||
33 | $record = Media::getInstance(Filter::get('mid', WT_REGEX_XREF), $WT_TREE); |
||||
34 | $controller = new MediaController($record); |
||||
35 | |||||
36 | if ($controller->record && $controller->record->canShow()) { |
||||
37 | if ($controller->record->isPendingDeletion()) { |
||||
38 | if (Auth::isModerator($controller->record->getTree())) { |
||||
39 | FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate( |
||||
40 | 'This media object has been deleted. You should review the deletion and then %1$s or %2$s it.', |
||||
41 | '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>', |
||||
42 | '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>' |
||||
43 | ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||||
44 | } elseif (Auth::isEditor($controller->record->getTree())) { |
||||
45 | 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'); |
||||
46 | } |
||||
47 | } elseif ($controller->record->isPendingAddtion()) { |
||||
48 | if (Auth::isModerator($controller->record->getTree())) { |
||||
49 | FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate( |
||||
50 | 'This media object has been edited. You should review the changes and then %1$s or %2$s them.', |
||||
51 | '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>', |
||||
52 | '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>' |
||||
53 | ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||||
54 | } elseif (Auth::isEditor($controller->record->getTree())) { |
||||
55 | FlashMessages::addMessage(I18N::translate('This media object has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning'); |
||||
56 | } |
||||
57 | } |
||||
58 | $controller->pageHeader(); |
||||
59 | } else { |
||||
60 | FlashMessages::addMessage(I18N::translate('This media object does not exist or you do not have permission to view it.'), 'danger'); |
||||
61 | http_response_code(404); |
||||
62 | $controller->pageHeader(); |
||||
63 | |||||
64 | return; |
||||
65 | } |
||||
66 | |||||
67 | $controller->addInlineJavascript(' |
||||
68 | jQuery("#media-tabs") |
||||
69 | .tabs({ |
||||
70 | create: function(e, ui){ |
||||
71 | jQuery(e.target).css("visibility", "visible"); // prevent FOUC |
||||
72 | } |
||||
73 | }); |
||||
74 | '); |
||||
75 | |||||
76 | $linked_fam = $controller->record->linkedFamilies('OBJE'); |
||||
77 | $linked_indi = $controller->record->linkedIndividuals('OBJE'); |
||||
78 | $linked_note = $controller->record->linkedNotes('OBJE'); |
||||
79 | $linked_obje = array(); |
||||
80 | $linked_sour = $controller->record->linkedSources('OBJE'); |
||||
81 | $linked_repo = $controller->record->linkedRepositories('OBJE'); |
||||
82 | |||||
83 | $facts = $controller->getFacts(); |
||||
84 | |||||
85 | ?> |
||||
86 | <div id="media-details"> |
||||
87 | <h2> |
||||
88 | <?php echo $controller->record->getFullName() ?> |
||||
89 | </h2> |
||||
90 | <div id="media-tabs"> |
||||
91 | <ul> |
||||
92 | <li> |
||||
93 | <a href="#media-edit"> |
||||
94 | <?php echo I18N::translate('Details') ?> |
||||
95 | </a> |
||||
96 | </li> |
||||
97 | <?php if ($linked_indi): ?> |
||||
0 ignored issues
–
show
|
|||||
98 | <li> |
||||
99 | <a href="#linked-individuals"> |
||||
100 | <?php echo I18N::translate('Individuals') ?> |
||||
101 | </a> |
||||
102 | </li> |
||||
103 | <?php endif; ?> |
||||
104 | <?php if ($linked_fam): ?> |
||||
0 ignored issues
–
show
The expression
$linked_fam of type Fisharebest\Webtrees\Family[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
105 | <li> |
||||
106 | <a href="#linked-families"> |
||||
107 | <?php echo I18N::translate('Families') ?> |
||||
108 | </a> |
||||
109 | </li> |
||||
110 | <?php endif; ?> |
||||
111 | <?php if ($linked_obje): ?> |
||||
0 ignored issues
–
show
The expression
$linked_obje of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
112 | <li> |
||||
113 | <a href="#linked-media"> |
||||
114 | <?php echo I18N::translate('Media objects') ?> |
||||
115 | </a> |
||||
116 | </li> |
||||
117 | <?php endif; ?> |
||||
118 | <?php if ($linked_sour): ?> |
||||
0 ignored issues
–
show
The expression
$linked_sour of type Fisharebest\Webtrees\Source[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
119 | <li> |
||||
120 | <a href="#linked-sources"><?php echo I18N::translate('Sources') ?></a> |
||||
121 | </li> |
||||
122 | <?php endif; ?> |
||||
123 | <?php if ($linked_note): ?> |
||||
0 ignored issues
–
show
The expression
$linked_note of type Fisharebest\Webtrees\Note[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
124 | <li> |
||||
125 | <a href="#linked-notes"><?php echo I18N::translate('Notes') ?></a> |
||||
126 | </li> |
||||
127 | <?php endif; ?> |
||||
128 | </ul> |
||||
129 | |||||
130 | <div id="media-edit"> |
||||
131 | <table class="facts_table"> |
||||
132 | <tr> |
||||
133 | <td style="text-align:center; width:150px;"> |
||||
134 | <?php |
||||
135 | // When we have a pending edit, $controller->record shows the *old* data. |
||||
136 | // As a temporary kludge, fetch a "normal" version of the record - which includes pending changes |
||||
137 | // Perhaps check both, and use RED/BLUE boxes. |
||||
138 | $tmp = Media::getInstance($controller->record->getXref(), $WT_TREE); |
||||
139 | echo $tmp->displayImage(); |
||||
140 | if (!$tmp->isExternal()) { |
||||
0 ignored issues
–
show
The method
isExternal() does not exist on Fisharebest\Webtrees\Individual .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
141 | if ($tmp->fileExists('main')) { |
||||
0 ignored issues
–
show
The method
fileExists() does not exist on Fisharebest\Webtrees\Individual .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
142 | if ($WT_TREE->getPreference('SHOW_MEDIA_DOWNLOAD') >= Auth::accessLevel($WT_TREE)) { |
||||
143 | echo '<p><a href="' . $tmp->getHtmlUrlDirect('main', true) . '">' . I18N::translate('Download file') . '</a></p>'; |
||||
0 ignored issues
–
show
The method
getHtmlUrlDirect() does not exist on Fisharebest\Webtrees\Individual . Did you maybe mean getHtmlUrl() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
144 | } |
||||
145 | } else { |
||||
146 | echo '<p class="ui-state-error">' . I18N::translate('The file “%s” does not exist.', $tmp->getFilename()) . '</p>'; |
||||
0 ignored issues
–
show
The method
getFilename() does not exist on Fisharebest\Webtrees\Individual .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
147 | } |
||||
148 | } |
||||
149 | ?> |
||||
150 | </td> |
||||
151 | <td> |
||||
152 | <table class="facts_table"> |
||||
153 | <?php |
||||
154 | foreach ($facts as $fact) { |
||||
155 | FunctionsPrintFacts::printFact($fact, $controller->record); |
||||
156 | } |
||||
157 | ?> |
||||
158 | </table> |
||||
159 | </td> |
||||
160 | </tr> |
||||
161 | </table> |
||||
162 | </div> |
||||
163 | |||||
164 | <?php if ($linked_indi): ?> |
||||
0 ignored issues
–
show
The expression
$linked_indi of type Fisharebest\Webtrees\Individual[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
165 | <div id="linked-individuals"> |
||||
166 | <?php echo FunctionsPrintLists::individualTable($linked_indi) ?> |
||||
167 | </div> |
||||
168 | <?php endif; ?> |
||||
169 | |||||
170 | <?php if ($linked_fam): ?> |
||||
0 ignored issues
–
show
The expression
$linked_fam of type Fisharebest\Webtrees\Family[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
171 | <div id="linked-families"> |
||||
172 | <?php echo FunctionsPrintLists::familyTable($linked_fam) ?> |
||||
173 | </div> |
||||
174 | <?php endif; ?> |
||||
175 | |||||
176 | <?php if ($linked_obje): ?> |
||||
0 ignored issues
–
show
The expression
$linked_obje of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
177 | <div id="linked-media"> |
||||
178 | <?php echo FunctionsPrintLists::mediaTable($linked_obje) ?> |
||||
179 | </div> |
||||
180 | <?php endif; ?> |
||||
181 | |||||
182 | <?php if ($linked_sour): ?> |
||||
0 ignored issues
–
show
The expression
$linked_sour of type Fisharebest\Webtrees\Source[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
183 | <div id="linked-sources"> |
||||
184 | <?php echo FunctionsPrintLists::sourceTable($linked_sour) ?> |
||||
185 | </div> |
||||
186 | <?php endif; ?> |
||||
187 | |||||
188 | <?php if ($linked_note): ?> |
||||
0 ignored issues
–
show
The expression
$linked_note of type Fisharebest\Webtrees\Note[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
189 | <div id="linked-notes"> |
||||
190 | <?php echo FunctionsPrintLists::noteTable($linked_note) ?> |
||||
191 | </div> |
||||
192 | <?php endif; ?> |
||||
193 | </div> |
||||
194 | </div> |
||||
195 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.