/
gallery.php
512 lines (409 loc) · 12.5 KB
/
gallery.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<?php
session_start();
require("set_paths.php");
include_once("caption_functions.php");
$tag1="";
$tag2="";
// Check POST action for write caption
if ( $_POST['action'] == 'write_caption' ){
# if ( ! authorise_user('write_caption') ) continue;
$gallery = $_SESSION['gallery'];
$dirkey = $_SESSION['dirkey'];
$filekey = $_SESSION['filekey'];
include_once("$imagedata/".$_SESSION['gallery']);
write_caption($gallery, $dirkey, $filekey, $_POST['caption']);
header("Location: gallery.php?gallery=$gallery&dirkey=$dirkey&filekey=$filekey&action=display_image&size=700");
exit;
}
# Override session vars with GET vars.
# Not secure - try to hard code each key
foreach ( array_keys($_GET) as $key ) {
$_SESSION[$key] = $_GET[$key];
}
# Secret edit parameter:
if ( isset($_GET['edit']) ){
$_SESSION['edit'] = $_GET['edit'];
}
if ( $_GET['edit'] == "off" ) unset($_SESSION['edit']);
# Image ref parameters
if ( isset($_GET['filekey']) ){
$_SESSION['filekey'] = $_GET['filekey'];
}
elseif ( isset($_POST['filekey']) ){
$_SESSION['filekey'] = $_POST['filekey'];
}
$filekey = $_SESSION['filekey'];
if ( isset($_GET['dirkey']) ){
$_SESSION['dirkey'] = $_GET['dirkey'];
}
elseif ( isset($_POST['dirkey']) ){
$_SESSION['dirkey'] = $_POST['dirkey'];
}
$dirkey = $_SESSION['dirkey'];
unset( $_SESSION['size'] );
unset( $_SESSION['xsize'] );
unset( $_SESSION['ysize'] );
if ( isset($_GET['xsize']) || isset($_GET['ysize']) ) {
// Fixed sizing requested
$xsize = $_GET['xsize'];
$ysize = $_GET['ysize'];
}
elseif ( isset($_GET['size']) ){
// Auto sizing requested
$size = $_GET['size'];
}
if (isset($_GET['gallery'])){
$_SESSION['gallery'] = $_GET['gallery'];
}
elseif (isset($_POST['gallery'])){
$_SESSION['gallery'] = $_POST['gallery'];
}
elseif ( ! isset($_SESSION['gallery'])) {
session_destroy();
header("Location:index.php") ;
}
$gallery=$_SESSION['gallery'] ;
include("$imagedata/$gallery");
$_SESSION['basedir'] = $dirs[$dirkey];
$basedir=$_SESSION['basedir'];
$_GLOBAL['basedir']=$_SESSION['basedir'];
if ( ! isset($default_image) ) {
$default_image="default.jpg" ;
}
if ( isset($_SESSION['action']) ) {
$action = $_SESSION['action'];
$default=false;
}
else {
$action="display_image";
#$_SESSION['size']=450;
$size=450;
$_SESSION['imagefile']="$default_image";
$default=true;
}
// Only display a gallery title if there is an action set - if there is no action set then it should mean we're going to the gallery front page.
if ( ! isset($_GET['action']) ) {
$title = "";
}
elseif ( isset($_SESSION['title']) ) {
$title = $_SESSION['title'];
}
else {
$title = 'Gallery';
}
$title = stripslashes(htmlentities($title, ENT_QUOTES)) ;
if ( isset($_SESSION['selection']) ) {
$selection = $_SESSION['selection'];
}
else {
$selection = "$default_image" ;
}
$gallery_title = stripslashes(htmlentities($gallery_title, ENT_QUOTES)) ;
// Start the html output
write_html_head($gallery_title);
// Start the html body
print <<<EOH
<BODY>
<H1>$gallery_title</H2>
EOH;
if (! $default ){
breadCrumbs($action, $gallery, $dirkey, $title );
}
else {
breadCrumbs("default", $gallery, $dirkey, $title );
}
print <<<EOH
<TABLE>
<TR>
<TD class=list valign=top >
<H2>Galleries</H2>
<ul class="bullet">
EOH;
foreach ( array_keys($titles) as $key ) {
gallery_listing($gallery, $key, $titles[$key]) ;
}
print " </ul>\n";
// End of gallery list
print <<<EOH
</TD>
EOH;
// End of navigation column
// Main Display column/cell
print <<<EOH
<TD class=view >
<H3>$title</H3>
EOH;
if ( $default ) {
// Default front page image
$size = 600 ;
if ( ! isset($caption) || $caption == "" ) $caption = basename($default_image);
echo <<<HTMLEND
<img src="image_resample.php?gallery=$gallery&filekey=default&size=$size" title="$caption" >
HTMLEND;
}
if ( ! $default && $action == "display_image" ) {
display_image_section($gallery, $dirkey, $filekey, $size,$xsize,$ysize);
}
elseif ( ! $default && $action == "edit_caption" ) {
display_image_section($gallery, $dirkey, $filekey, $size,$xsize,$ysize);
}
elseif ( $action == "generate_gallery" ) {
include("generate_gallery.php");
generate_gallery($gallery, $dirkey);
}
unset( $_SESSION['action'] );
html_footer();
/////////////////
function breadCrumbs($action, $gallery, $dirkey, $title ){
// Display the breadcrumb trail, ie the navigation links which
// show the user the way back up the album/gallery tree
// Using span to allow user defined list bullet characters and layout
$bullet = '<span class="crumb_bullet">>></span>';
$herebullet = '<span class="crumb_bullet">: </span>';
print <<<EOH
<div class="crumb_ul" >
<div class="crumb_li">
<a href="logout.php" >
${bullet}Album List </a>
</div>
EOH;
if ( $action != "default" ) {
print <<<EOH
<div class="crumb_li">
<a href="gallery.php?gallery=$gallery" >
${bullet}Album Cover</a>
</div>
EOH;
}
elseif ( $action == "default" ) {
print <<<EOH
<div class="crumb_youarehere">
${herebullet}Album Cover
</div>
EOH;
}
if ( $action != "default" && $action != "generate_gallery" ) {
print <<<EOH
<div class="crumb_li">
<a href="gallery.php?gallery=$gallery&dirkey=$dirkey&action=generate_gallery&title=$title" >
${bullet}Gallery Thumbs </a>
</div>
EOH;
}
elseif ( $action == "generate_gallery" ) {
print <<<EOH
<div class="crumb_youarehere">
${herebullet}Gallery Thumbs
</div>
EOH;
}
if ( $action == "display_image" ){
print <<<EOH
<div class="crumb_youarehere">
${herebullet}Image
</div>
EOH;
}
print <<<EOH
</div>
<br/>
EOH;
}
/////////////////
function gallery_listing($gallery,$dirkey,$title){
$title = stripslashes(htmlentities("$title", ENT_QUOTES)) ;
global $dirs;
$dir = $dirs[$dirkey];
$age = filemtime($dir) ;
if ( filemtime($dir) > time()-(60*60*24*21) )
$new="<span class='new' >*New*</span>";
echo <<<HTMLEND
<li>
<a href="gallery.php?gallery=$gallery&dirkey=$dirkey&action=generate_gallery&title=$title" >
$title $new
</a>
</li>
HTMLEND
;
}
/////////////////
function write_html_head($title) {
echo <<<HTMLEND
<html>
<head>
<title>Gallery: $title</title>
<link REL="stylesheet" HREF="gallery.css" type="text/css"/>
<link REL="stylesheet" HREF="dropdowns.css" type="text/css"/>
<script type="text/javascript" src="dropdowns.js" ></script>
</head>
HTMLEND;
}
///////////////
function display_image_section($gallery, $dirkey, $filekey, $size,$xsize,$ysize){
include("set_paths.php");
include("$imagedata/$gallery");
if ( ! isset($_GLOBAL['filelist']) ){
include_once("generate_filelist.php");
$filelist = generate_filelist($gallery,$dirkey);
}
else {
$filelist=($_GLOBAL['filelist']);
}
$numfiles=count($filelist);
#$imagecache=dirname(__FILE__)."/imagecache";
$basedir = $dirs[$dirkey];
if ( preg_match("/\.(mov|mpg|mpeg|avi|mp4)$/i", $filelist[$filekey]) ){
$type="movie";
}
// Create next image href
#$nexttag = "<span class='nav_inactive' >Next>></span>";
if ( $filekey+1 >= $numfiles){
$nextfile=$filelist[0];
$nextfile="$basedir/$nextfile";
$nexttag="<a class='prevnext_active' href='gallery.php?filekey=0&size=700&action=display_image'>|<<Back to start</a>";
}
else
{
$nextkey=$filekey+1;
$nextfile=$filelist[$nextkey];
$nextfile="$basedir/$nextfile";
$nexttag="<a class='prevnext_active' href='gallery.php?filekey=$nextkey&size=700&action=display_image'>Next>></a>";
}
// Create href to previous image
if ( $filekey == 0 ){
# We are at first image so don't show next link - just inactive.
$prevtag = "<span class='prevnext_inactive' ><<Previous</span>";
} else {
$prevkey=$filekey-1;
$prevfile=$filelist[$prevkey];
$prevfile="$basedir/$prevfile";
$prevtag = "<a class='prevnext_active' href='gallery.php?&filekey=$prevkey&size=700&action=display_image'><<Previous</a>";
}
// Use random number so that browser cache does not mistake this for the same picture each time
$random = rand(1000, 9999) ;
#$imagefile=$_SESSION['imagefile'];
$imagefile="$basedir/".$filelist[$filekey];
$_GLOBAL['caption'] = get_caption($imagefile);
$caption=$_GLOBAL['caption'];
// Menu line
if ($type != "movie" ){
?> <div class="imagenavigate" > <?php
include("resize_menu.php");
print "\n<span id='resize_menu'>\n";
display_resize_menu($filekey);
print "</span>\n";
}
else {
//Display fake resize menu as placeholder
print "\n<ul class='nav' ><li> </li></ul>\n";
}
print <<<EOH
<span class="prevnext" >
$prevtag $nexttag
</span>
EOH;
if ( $_SESSION['edit'] ) print <<<EOH
<span id="edit_caption_link" >
<a href="?gallery=$gallery&action=edit_caption&filekey=$filekey&dirkey=$dirkey&size=$size" >
Edit Caption
</a>
</span>
</div><br/>
EOH;
#if ( $_SESSION['action'] != 'edit_caption' && authorise_user('edit_caption') ){
if ( $_SESSION['action'] != 'edit_caption' ) {
// display caption
print <<<EOH
<br/>
<span id="caption" >$caption</span>
EOH;
print "\n<br/>\n";
}
elseif ( $_SESSION['action'] == 'edit_caption' ) {
// display caption in an editable text box
$filepath = $dirs[$dirkey] ."/". $filelist[$filekey] ;
caption_edit_form($filepath, $gallery, $dirkey, $filekey);
print "<br/>\n";
}
else {
// no edit functions requested, just write the caption
print <<<EOH
<span id="caption" >$caption</span><br/>
EOH;
}
// Display image
if ( preg_match_all("/\.(mov|mpg|mpeg|avi|mp4)$/i", $filelist[$filekey], $matches )){
$mimetype=mime_content_type($dirs[$dirkey]."/".$filelist[$filekey]);
$parts=$matches[0]; $type=$parts[0];
#$filename="$basedir/${filelist[$filekey]}";
#<embed type="video/x-msvideo" src='send_file.php?mode=stream&gallery=$gallery&dirkey=$dirkey&filekey=$filekey' width=640 height=480 >
#<object type="video/avi" data='send_file.php?mode=stream&gallery=$gallery&dirkey=$dirkey&filekey=$filekey' width=640 height=480 >
echo <<<HTMLEND
<span class="center" >This file "$filelist[$filekey]" is a "$mimetype" movie file.<br/>
<a href='send_file.php?mode=stream&gallery=$gallery&dirkey=$dirkey&filekey=$filekey' type='$mimetype' >Click here to play it</a>
<br/>
<a href='send_file.php?mode=attach&gallery=$gallery&dirkey=$dirkey&filekey=$filekey'>
<b>Click here to download it.</b></a></span><br>
HTMLEND;
}
else{
#if ( $_SESSION['size'] == "full" ) {
if ( $size == "full" ) {
$filekey = $_SESSION['filekey'];
$filelist = $_SESSION['filelist'];
$basedir = $_SESSION['basedir'];
$filename = $filelist[$filekey];
$src_imgfile = "$basedir/$filename";
if ( ! isset($caption) || $caption == "" ) $caption = $filename;
echo <<<HTMLEND
<img src="send_file.php?mode=stream&gallery=$gallery&dirkey=$dirkey&filekey=$filekey" title="$caption" >
HTMLEND;
} else {
if ( ! isset($caption) || $caption == "" ) $caption = basename($imagefile);
if ( $size > 10 ) { $urlsize = "size=$size"; }
else { $urlsize = "xsize=$xsize&ysize=$ysize"; }
$filekey = $_SESSION['filekey'];
$dirkey = $_SESSION['dirkey'];
echo <<<HTMLEND
<img src="image_resample.php?gallery=$gallery&dirkey=$dirkey&filekey=$filekey&$urlsize&xxx=$random" title="$caption">
HTMLEND;
}
print "\n\n<br/>\n\n";
show_exif_button();
display_exif( "$basedir/".$filelist[$filekey] );
}
}
////////////////
function display_exif($src_imgfile) {
// Display exif image data
#print "Exif image data:<br/> <code> ". system("exiv2 $src_imgfile") . "</code>";
print "\n\n<span id='exifdata' > Exif image data:<br/>\n<ul>";
exec("exiv2 $src_imgfile", $exifdata);
foreach( $exifdata as $line ){
if ( preg_match("/File name/i", $line ) || ! preg_match("/\w/", $line ) ){
continue;
}
print "\n<li>$line</li>";
}
print "</ul>\n</span>\n";
}
////////////////
function show_exif_button() {
print <<<EOH
<span id="exifbutton" onclick='exifdata.style.display = ( exifdata.style.display == "block" ) ? "none" : "block" ; if (exifdata.style.display == "none" ) { exifexpand.innerHTML = ("+"); } else { exifexpand.innerHTML = ("-");} ' >
<span id="exifexpand" > + </span>
Image data
</span>
EOH;
}
////////////////
function html_footer() {
echo <<<HTMLEND
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
HTMLEND;
}
?>