forked from fisharebest/webtrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
medialist.php
367 lines (351 loc) · 16.1 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
// Displays a list of the media objects
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved.
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
define('WT_SCRIPT_NAME', 'medialist.php');
require './includes/session.php';
require_once WT_ROOT.'includes/functions/functions_edit.php';
require_once WT_ROOT.'includes/functions/functions_print_facts.php';
$controller = new WT_Controller_Page();
$controller->setPageTitle(WT_I18N::translate('Media objects'));
$search = WT_Filter::get('search');
$sortby = WT_Filter::get('sortby', 'file|title', 'title');
if (!WT_USER_CAN_EDIT && !WT_USER_CAN_ACCEPT) {
$sortby='title';
}
$start = WT_Filter::getInteger('start');
$max = WT_Filter::get('max', '10|20|30|40|50|75|100|125|150|200', '20');
$folder = WT_Filter::get('folder', null, ''); // MySQL needs an empty string, not NULL
$reset = WT_Filter::get('reset');
$apply_filter = WT_Filter::get('apply_filter');
$filter = WT_Filter::get('filter', null, ''); // MySQL needs an empty string, not NULL
$columns = WT_Filter::getInteger('columns', 1, 2, 2);
$subdirs = WT_Filter::get('subdirs');
$currentdironly = ($subdirs=='on') ? false : true;
// reset all variables
if ($reset == 'Reset') {
$sortby = 'title';
$max = '20';
$folder = '';
$columns = '2';
$currentdironly = true;
$filter = '';
}
// A list of all subfolders used by this tree
$folders = WT_Query_Media::folderList();
// A list of all media objects matching the search criteria
$medialist = WT_Query_Media::mediaList(
$folder,
$currentdironly ? 'exclude' : 'include',
$sortby,
$filter
);
$controller->pageHeader();
?>
<div id="medialist-page"><h2><?php echo $controller->getPageTitle(); ?></h2>
<form action="medialist.php" method="get">
<input type="hidden" name="action" value="filter">
<input type="hidden" name="search" value="yes">
<table class="list_table width75">
<tr>
<td class="descriptionbox wrap width25">
<?php echo WT_I18N::translate('Folder'); ?>
</td>
<td class="optionbox wrap width25">
<?php echo select_edit_control('folder', $folders, null, $folder); ?>
</td>
<?php
if (WT_USER_CAN_EDIT || WT_USER_CAN_ACCEPT) {
echo '<td class="descriptionbox wrap width25">';
echo WT_I18N::translate('Sort order');
echo '</td><td class="optionbox wrap width25">';
echo '<select name="sortby">';
echo '<option value="title" ', ($sortby=='title') ? 'selected="selected"' : '', '>';
echo /* I18N: An option in a list-box */ WT_I18N::translate('sort by title');
echo '</option>';
echo '<option value="file" ', ($sortby=='file') ? 'selected="selected"' : '' , '>';
echo /* I18N: An option in a list-box */ WT_I18N::translate('sort by filename');
echo '</option>';
echo '</select>';
echo '</td>';
} else {
echo '<td class="descriptionbox wrap width25"> </td>';
echo '<td class="optionbox wrap width25"> </td>';
}
?>
</tr>
<tr>
<td class="descriptionbox wrap width25">
<?php echo /* I18N: Label for check-box */ WT_I18N::translate('Include subfolders'); ?>
</td>
<td class="optionbox wrap width25">
<input type="checkbox" id="subdirs" name="subdirs" <?php if (!$currentdironly) { ?>checked="checked"<?php } ?>>
</td>
<td class="descriptionbox wrap width25">
<?php echo WT_I18N::translate('Media objects per page'); ?>
</td>
<td class="optionbox wrap width25">
<select name="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="selected"';
echo '>', $selectEntry, '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td class="descriptionbox wrap width25">
<?php echo WT_I18N::translate('Search filters'); ?>
</td>
<td class="optionbox wrap width25">
<input id="filter" name="filter" value="<?php echo $filter; ?>" size="14" dir="auto">
</td>
<td class="descriptionbox wrap width25">
<?php echo WT_I18N::translate('Columns per page'); ?>
</td>
<td class="optionbox wrap width25">
<select name="columns">
<?php
foreach (array('1', '2') as $selectEntry) {
echo '<option value="', $selectEntry, '"';
if ($selectEntry==$columns) echo ' selected="selected"';
echo '>', $selectEntry, '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td class="descriptionbox wrap width25">
</td>
<td class="optionbox wrap width25">
<input type="submit" name="apply_filter" value="<?php echo WT_I18N::translate('Search'); ?>">
<input type="submit" name="reset" value="<?php echo WT_I18N::translate('Reset'); ?>">
</td>
<td class="descriptionbox wrap width25"> </td>
<td class="optionbox wrap width25"> </td>
</tr>
</table>
</form>
<?php
if ($search) {
if (!empty($medialist)) {
// Count the number of items in the medialist
$ct=count($medialist);
$start = 0;
if (isset($_GET['start'])) $start = $_GET['start'];
$count = $max;
if ($start+$count > $ct) $count = $ct-$start;
} else {
$ct = '0';
}
echo '<div align="center">', WT_I18N::translate('Media Objects found'), ' ', $ct, ' <br><br>';
if ($ct>0) {
$currentPage = ((int) ($start / $max)) + 1;
$lastPage = (int) (($ct + $max - 1) / $max);
echo '<table class="list_table">';
// echo page back, page number, page forward controls
echo '<tr><td colspan="2">';
echo '<table class="list_table_controls">';
echo '<tr>';
echo '<td>';
if ($TEXT_DIRECTION=='ltr') {
if ($ct>$max) {
if ($currentPage > 1) {
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=0&max=', $max, '" class="icon-ldarrow"></a>';
}
if ($start>0) {
$newstart = $start-$max;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&;columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-larrow"></a>';
}
}
} else {
if ($ct>$max) {
if ($currentPage < $lastPage) {
$lastStart = ((int) ($ct / $max)) * $max;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $lastStart, '&max=', $max, '" class="icon-rdarrow"></a>';
}
if ($start+$max < $ct) {
$newstart = $start+$count;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-rarrow"></a>';
}
}
}
echo '</td>';
echo '<td>', WT_I18N::translate('Page %s of %s', $currentPage, $lastPage), '</td>';
echo '<td>';
if ($TEXT_DIRECTION=='ltr') {
if ($ct>$max) {
if ($start+$max < $ct) {
$newstart = $start+$count;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '"class="icon-rarrow"></a>';
}
if ($currentPage < $lastPage) {
$lastStart = ((int) ($ct / $max)) * $max;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $lastStart, '&max=', $max, '" class="icon-rdarrow"></a>';
}
}
} else {
if ($ct>$max) {
if ($start>0) {
$newstart = $start-$max;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-larrow"></a>';
}
if ($currentPage > 1) {
$lastStart = ((int) ($ct / $max)) * $max;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=0&max=', $max, '" class="icon-ldarrow"></a>';
}
}
}
echo '</td>';
echo '</tr></table></td></tr>';
echo '<tr>';
for ($i=$start, $n=0; $i<$start+$count; ++$i) {
$mediaobject = $medialist[$i];
if ($columns == '1') echo '<td class="list_value_wrap" width="80%">';
if ($columns == '2') echo '<td class="list_value_wrap" width="50%">';
echo '<table><tr><td valign="top" style="white-space:normal;">';
echo $mediaobject->displayImage();
echo '</td><td class="list_value_wrap" style="border:none;" width="100%">';
if (WT_USER_CAN_EDIT) {
echo WT_Controller_Media::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 WT_Gedcom_Tag::getLabelValue('TITL', $mediaobject->getFullName());
}
// Show file details
if ($mediaobject->isExternal()) {
echo WT_Gedcom_Tag::getLabelValue('URL', $mediaobject->getFilename());
} else {
if ($mediaobject->fileExists()) {
if (WT_USER_CAN_EDIT || WT_USER_CAN_ACCEPT) {
echo WT_Gedcom_Tag::getLabelValue('FILE', $mediaobject->getFilename());
}
echo WT_Gedcom_Tag::getLabelValue('FORM', $mediaobject->mimeType());
echo WT_Gedcom_Tag::getLabelValue('__FILE_SIZE__', $mediaobject->getFilesize());
$imgsize = $mediaobject->getImageAttributes();
if ($imgsize['WxH']) {
echo WT_Gedcom_Tag::getLabelValue('__IMAGE_SIZE__', $imgsize['WxH']);
}
} else {
echo '<p class="ui-state-error">', /* I18N: %s is a filename */ WT_I18N::translate('The file “%s” does not exist.', $mediaobject->getFilename()), '</p>';
}
}
echo '<br>';
echo '<div style="white-space: normal; width: 95%;">';
echo print_fact_sources($mediaobject->getGedcom(), 1);
echo print_fact_notes($mediaobject->getGedcom(), 1);
echo '</div>';
foreach ($mediaobject->linkedIndividuals('OBJE') as $individual) {
echo '<a href="' . $individual->getHtmlUrl() . '">' . WT_I18N::translate('View person') . ' — ' . $individual->getFullname().'</a><br>';
}
foreach ($mediaobject->linkedFamilies('OBJE') as $family) {
echo '<a href="' . $family->getHtmlUrl() . '">' . WT_I18N::translate('View family') . ' — ' . $family->getFullname().'</a><br>';
}
foreach ($mediaobject->linkedSources('OBJE') as $source) {
echo '<a href="' . $source->getHtmlUrl() . '">' . WT_I18N::translate('View source') . ' — ' . $source->getFullname().'</a><br>';
}
echo '</td></tr></table>';
echo '</td>';
if ((++$n) % $columns == 0) {
echo '</tr><tr>';
}
} // end media loop
echo '</tr>';
// echo page back, page number, page forward controls
echo '<tr><td colspan="2">';
echo '<table class="list_table width100">';
echo '<tr>';
echo '<td class="width30">';
if ($TEXT_DIRECTION=='ltr') {
if ($ct>$max) {
if ($currentPage > 1) {
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=0&max=', $max, '" class="icon-ldarrow"></a>';
}
if ($start>0) {
$newstart = $start-$max;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-larrow"></a>';
}
}
} else {
if ($ct>$max) {
if ($currentPage < $lastPage) {
$lastStart = ((int) ($ct / $max)) * $max;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $lastStart, '&max=', $max, '" class="icon-rdarrow"></a>';
}
if ($start+$max < $ct) {
$newstart = $start+$count;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-rarrow"></a>';
}
}
}
echo '</td>';
echo '<td align="center">', WT_I18N::translate('Page %s of %s', $currentPage, $lastPage), '</td>';
echo '<td class="width30">';
if ($TEXT_DIRECTION=='ltr') {
if ($ct>$max) {
if ($start+$max < $ct) {
$newstart = $start+$count;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-rarrow"></a>';
}
if ($currentPage < $lastPage) {
$lastStart = ((int) ($ct / $max)) * $max;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $lastStart, '&max=', $max, '" class="icon-rdarrow"></a>';
}
}
} else {
if ($ct>$max) {
if ($start>0) {
$newstart = $start-$max;
if ($start<0) $start = 0;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=', $newstart, '&max=', $max, '" class="icon-larrow"></a>';
}
if ($currentPage > 1) {
$lastStart = ((int) ($ct / $max)) * $max;
echo '<a href="medialist.php?action=no&search=no&folder=', rawurlencode($folder), '&sortby=', $sortby, '&subdirs=', $subdirs, '&filter=', rawurlencode($filter), '&columns=', $columns, '&apply_filter=', $apply_filter, '&start=0&max=', $max, '" class="icon-ldarrow"></a>';
}
}
}
echo '</td>';
echo '</tr></table></td></tr>';
echo '</table><br>';
}
echo '</div>
</div>';
}