forked from fisharebest/webtrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
medialist.php
335 lines (313 loc) · 11.4 KB
/
medialist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2016 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Fisharebest\Webtrees;
/**
* Defined in session.php
*
* @global Tree $WT_TREE
*/
global $WT_TREE;
use Fisharebest\Webtrees\Controller\MediaController;
use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\Functions\FunctionsEdit;
use Fisharebest\Webtrees\Functions\FunctionsPrint;
use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
use Fisharebest\Webtrees\Query\QueryMedia;
define('WT_SCRIPT_NAME', 'medialist.php');
require './includes/session.php';
$controller = new PageController;
$controller
->setPageTitle(I18N::translate('Media objects'))
->pageHeader();
$action = Filter::get('action');
$sortby = Filter::get('sortby', 'file|title', 'title');
if (!Auth::isEditor($WT_TREE)) {
$sortby = 'title';
}
$page = Filter::getInteger('page');
$max = Filter::get('max', '10|20|30|40|50|75|100|125|150|200', '20');
$folder = Filter::get('folder', null, ''); // MySQL needs an empty string, not NULL
$filter = Filter::get('filter', null, ''); // MySQL needs an empty string, not NULL
$columns = Filter::getInteger('columns', 1, 2, 2);
$subdirs = Filter::get('subdirs', 'on');
$form_type = Filter::get('form_type', implode('|', array_keys(GedcomTag::getFileFormTypes())));
$currentdironly = ($subdirs === 'on') ? false : true;
// reset all variables
if ($action === 'reset') {
$sortby = 'title';
$max = '20';
$folder = '';
$columns = '2';
$currentdironly = true;
$filter = '';
$form_type = '';
}
// A list of all subfolders used by this tree
$folders = QueryMedia::folderList();
// A list of all media objects matching the search criteria
$medialist = QueryMedia::mediaList(
$folder,
$currentdironly ? 'exclude' : 'include',
$sortby,
$filter,
$form_type
);
?>
<div id="medialist-page">
<h2><?php echo $controller->getPageTitle(); ?></h2>
<form action="medialist.php" method="get">
<input type="hidden" name="ged" value="<?php echo $WT_TREE->getNameHtml() ?>">
<input type="hidden" name="action" value="filter">
<input type="hidden" name="search" value="yes">
<table class="list_table">
<tbody>
<tr>
<td class="descriptionbox wrap">
<label for="folder">
<?php echo I18N::translate('Folder'); ?>
</label>
</td>
<td class="optionbox wrap">
<?php echo FunctionsEdit::selectEditControl('folder', $folders, null, $folder); ?>
</td>
<?php if (Auth::isEditor($WT_TREE)): ?>
<td class="descriptionbox wrap">
<label for="sortby">
<?php echo I18N::translate('Sort order'); ?>
</label>
</td>
<td class="optionbox wrap">
<select name="sortby" id="sortby">
<option value="title" <?php echo $sortby === 'title' ? 'selected' : ''; ?>>
<?php echo /* I18N: An option in a list-box */ I18N::translate('sort by title'); ?>
</option>
<option value="file" <?php echo $sortby === 'file' ? 'selected' : ''; ?>>
<?php echo /* I18N: An option in a list-box */ I18N::translate('sort by filename'); ?>
</option>
</select>
</td>
<?php else: ?>
<td class="descriptionbox wrap"></td>
<td class="optionbox wrap"></td>
<?php endif; ?>
</tr>
<tr>
<td class="descriptionbox wrap">
<label for="subdirs">
<?php echo /* I18N: Label for check-box */ I18N::translate('Include subfolders'); ?>
</label>
</td>
<td class="optionbox wrap">
<input type="checkbox" id="subdirs" name="subdirs" <?php echo $currentdironly ? '' : 'checked'; ?>>
</td>
<td class="descriptionbox wrap">
<label for="max">
<?php echo I18N::translate('Media objects per page'); ?>
</label>
</td>
<td class="optionbox wrap">
<select name="max" id="max">
<?php
foreach (array('10', '20', '30', '40', '50', '75', '100', '125', '150', '200') as $selectEntry) {
echo '<option value="', $selectEntry, '" ';
if ($selectEntry == $max) {
echo 'selected';
}
echo '>', $selectEntry, '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td class="descriptionbox wrap">
<label for="form-type">
<?php echo I18N::translate('Type'); ?>
</label>
</td>
<td class="optionbox wrap">
<select name="form_type" id="form-type">
<option value=""></option>
<?php foreach (GedcomTag::getFileFormTypes() as $value => $label): ?>
<option value="<?php echo $value; ?>" <?php echo $value === $form_type ? 'selected' : ''; ?>>
<?php echo $label; ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td class="descriptionbox wrap">
<label for="columns">
<?php echo I18N::translate('Columns per page'); ?>
</label>
</td>
<td class="optionbox wrap">
<select name="columns" id="columns">
<?php
foreach (array('1', '2') as $selectEntry) {
echo '<option value="', $selectEntry, '" ';
if ($selectEntry == $columns) {
echo 'selected';
}
echo '>', $selectEntry, '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td class="descriptionbox wrap">
<label for="filter">
<?php echo I18N::translate('Search filters'); ?>
</label>
</td>
<td class="optionbox wrap">
<input type="text" id="filter" name="filter" value="<?php echo Filter::escapeHtml($filter); ?>" size="14" dir="auto">
</td>
<td class="descriptionbox wrap"></td>
<td class="optionbox wrap">
<button type="submit" name="action" value="submit">
<?php echo /* I18N: A button label. */ I18N::translate('search'); ?>
</button>
<button type="submit" name="action" value="reset">
<?php echo /* I18N: A button label. */ I18N::translate('reset'); ?>
</button>
</td>
</tr>
</tbody>
</table>
</form>
<?php
if ($action === 'submit') {
$url = 'medialist.php?action=submit' .
'&ged=' . $WT_TREE->getNameHtml() .
'&folder=' . Filter::escapeUrl($folder) .
'&sortby=' . Filter::escapeUrl($sortby) .
'&subdirs=' . Filter::escapeUrl($subdirs) .
'&filter=' . Filter::escapeUrl($filter) .
'&form_type=' . Filter::escapeUrl($form_type) .
'&columns=' . Filter::escapeUrl($columns) .
'&max=' . Filter::escapeUrl($max);
$count = count($medialist);
$pages = (int) (($count + $max - 1) / $max);
$page = max(min($page, $pages), 1);
if ($page === $pages && $count % $max !== 0) {
// Last page may have fewer than $max pages
$number_on_page = $count % $max;
} else {
$number_on_page = $max;
}
if (I18N::direction() === 'ltr') {
$icons = array('first' => 'ldarrow', 'previous' => 'larrow', 'next' => 'rarrow', 'last' => 'rdarrow');
} else {
$icons = array('first' => 'rdarrow', 'previous' => 'rarrow', 'next' => 'larrow', 'last' => 'ldarrow');
}
echo '<div><p>', I18N::translate('Media objects found'), ' ', $count, '</p>';
if ($count > 0) {
echo '<table class="list_table">';
// Display controls twice - at the top and bottom of the table
foreach (array('thead', 'tfoot') as $tsection) {
echo '<', $tsection, '><tr><td colspan="2">';
echo '<table class="list_table_controls"><tr><td>';
if ($page > 1) {
echo '<a href="', $url, '&page=1" class="icon-', $icons['first'], '"></a>';
echo '<a href="', $url, '&page=', $page - 1, '" class="icon-', $icons['previous'], '"></a>';
}
echo '</td><td>', I18N::translate('Page %s of %s', $page, $pages), '</td><td>';
if ($page < $pages) {
echo '<a href="', $url, '&page=', $page + 1, '" class="icon-', $icons['next'], '"></a>';
echo '<a href="', $url, '&page=', $pages, '" class="icon-', $icons['last'], '"></a>';
}
echo '</td></tr></table>';
echo '</td></tr></', $tsection, '>';
}
echo '<tbody><tr>';
for ($i = 0, $n = 0; $i < $number_on_page; ++$i) {
$mediaobject = $medialist[($page - 1) * $max + $i];
if ($columns === 1) {
echo '<td class="media-col1 list_value_wrap">';
}
if ($columns === 2) {
echo '<td class="media-col2 list_value_wrap">';
}
echo '<table><tr><td class="media-image">';
echo $mediaobject->displayImage();
echo '</td><td class="media-col list_value_wrap">';
if (Auth::isEditor($WT_TREE)) {
echo MediaController::getMediaListMenu($mediaobject);
}
// If sorting by title, highlight the title. If sorting by filename, highlight the filename
if ($sortby === 'title') {
echo '<p><b><a href="', $mediaobject->getHtmlUrl(), '">';
echo $mediaobject->getFullName();
echo '</a></b></p>';
} else {
echo '<p><b><a href="', $mediaobject->getHtmlUrl(), '">';
echo basename($mediaobject->getFilename());
echo '</a></b></p>';
echo GedcomTag::getLabelValue('TITL', $mediaobject->getFullName());
}
// Show file details
if ($mediaobject->isExternal()) {
echo GedcomTag::getLabelValue('URL', $mediaobject->getFilename());
} else {
if ($mediaobject->fileExists()) {
if (Auth::isEditor($WT_TREE)) {
echo GedcomTag::getLabelValue('FILE', $mediaobject->getFilename());
$mediatype = $mediaobject->getMediaType();
if ($mediatype) {
echo GedcomTag::getLabelValue('TYPE', GedcomTag::getFileFormTypeValue($mediatype));
}
}
echo GedcomTag::getLabelValue('FORM', $mediaobject->mimeType());
echo GedcomTag::getLabelValue('__FILE_SIZE__', $mediaobject->getFilesize());
$imgsize = $mediaobject->getImageAttributes();
if ($imgsize['WxH']) {
echo GedcomTag::getLabelValue('__IMAGE_SIZE__', $imgsize['WxH']);
}
} else {
echo '<p class="ui-state-error">', /* I18N: %s is a filename */ I18N::translate('The file “%s” does not exist.', $mediaobject->getFilename()), '</p>';
}
}
echo '<br>';
echo '<div>';
echo FunctionsPrintFacts::printFactSources($mediaobject->getGedcom(), 1);
echo FunctionsPrint::printFactNotes($mediaobject->getGedcom(), 1);
echo '</div>';
foreach ($mediaobject->linkedIndividuals('OBJE') as $individual) {
echo '<a href="' . $individual->getHtmlUrl() . '">' . I18N::translate('View this individual') . ' — ' . $individual->getFullName() . '</a><br>';
}
foreach ($mediaobject->linkedFamilies('OBJE') as $family) {
echo '<a href="' . $family->getHtmlUrl() . '">' . I18N::translate('View this family') . ' — ' . $family->getFullName() . '</a><br>';
}
foreach ($mediaobject->linkedSources('OBJE') as $source) {
echo '<a href="' . $source->getHtmlUrl() . '">' . I18N::translate('View this source') . ' — ' . $source->getFullName() . '</a><br>';
}
echo '</td></tr></table>';
echo '</td>';
if ((++$n) % $columns == 0 && $n < $count) {
echo '</tr><tr>';
}
} // end media loop
// An odd number of media objects in two columns requires an empty cell
if ($columns == 2 && $n % 2 == 1) {
echo '<td></td>';
}
echo '</tr></tbody>';
echo '</table>';
}
echo '</div>';
}
echo '</div>';