-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalscript.php
596 lines (495 loc) · 16 KB
/
galscript.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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<?php
$fprefix = "";
function load_gal_data($galname, $assoc=false)
{
global $fprefix;
$pics = array();
$galfilename = "./" . $fprefix . $galname . "info.txt";
//echo "loading " . $galfilename . " assoc = " . $assoc;
if (file_exists($galfilename))
{
$galfile = fopen($galfilename, "r");
while(!feof($galfile))
{
$picdesc = trim(fgets($galfile));
if(!feof($galfile) && $picdesc[0]!="#")
{
$item = explode(":", $picdesc, 6);
if($assoc) // make array associative to filename
$pics[$item[0]]=array_slice($item,1);
else // just a normal array
array_push($pics, $item);
}
}
fclose($galfile);
}
return $pics;
}
function fname($filename)
{
$p = strrpos($filename , ".");
if($p === false)
return $filename;
else
return substr($filename, 0, $p);
}
function fext($filename, $defext="jpg")
{
$p = strrpos($filename , ".");
if($p === false)
return $defext;
else
return substr($filename, $p+1);
}
// Gallery data file format:
// filename:width:height:title:description[:buylink]
// (width and heigh ignored for gallery list)
// filename doesn't include the .jpg
// thumbnails set to 80x80
// thumbnail names based on image file name (filename_th.jpg)
//
// A [show]info.txt describes all the galleries ("sets")
// where [show] is the ?show= parameter
// each "filename" for a gallery is a sub-directory
// "filename_th.jpg" in the current directory is the thumbnail for the gallery
// in each sub directory, a galinfo.txt describes the pictures.
// pictures filename.jpg and filename_th.jpg exist in the sub-directory
//
// There is also a top-level file called sectioninfo.txt that lists
// all the sections that can be specified by the show parameter.
// "filename" is the "show" parameter and "title" is the section title.
$ingallery = false;
$curgal = 0;
$numgals = 0;
$numpics = 0;
$picstart = 0;
$curpic = 0;
$gals = array();
$pics = array();
$show = "";
$goodshow = true;
$sections = array();
$wraplinks = true;
$phpname = "gallery.php";
$picsperpage = 9;
$thumbwidth = 80;
$thumbheight = 80;
$indexctr = 0;
function init($_phpname, $_picsperpage, $_thumbwidth, $_thumbheight, $_fprefix="", $_wraplinks=true)
{
global $phpname, $picsperpage, $thumbwidth, $thumbheight;
global $ingallery, $curgal, $numgals, $numpics;
global $picstart, $curpic, $gals, $pics, $wraplinks, $indexctr;
global $show, $goodshow, $sections, $fprefix;
//chdir(dirname(__FILE__)); // do everything relative to the script
$fprefix = $_fprefix;
$phpname = $_phpname;
$picsperpage = $_picsperpage;
$thumbwidth = $_thumbwidth;
$thumbheight = $_thumbheight;
$wraplinks = $_wraplinks;
// load the section info.
$sections = load_gal_data("section", true);
// load the list of galleries
if (array_key_exists("show", $_GET))
{
$show=$_GET["show"];
if(isset($sections[$show]) || array_key_exists("testmode", $_GET) || $show == "video")
{
$gals = load_gal_data($show);
$numgals = sizeof($gals);
}
}
// have we loaded any galleries? if not, pick a random one
if($numgals <= 0)
{
$goodshow = false;
$show = array_rand($sections);
//echo "no section, showing " . $show . " ... ";
$gals = load_gal_data($show);
$numgals = sizeof($gals);
}
// try to access the gallery number specified in the URL
if (array_key_exists("gallery", $_GET))
{
$curgal = (int)$_GET["gallery"];
if( $curgal >=0 && $curgal < $numgals)
$pics = load_gal_data(fname($gals[$curgal][0]) . "/gal");
if(sizeof($pics))
$ingallery = true;
}
// if no gallery specified, or improper gallery, load a random one (for the random pic)
if (!$ingallery)
{
// count the number of pics in each gallery first to weigh the randomizer properly
$totalpics = 0;
for($g=0; $g<$numgals; $g++)
{
$totalpics += sizeof(load_gal_data(fname($gals[$g][0]) . "/gal"));
$galpicindex[$g] = $totalpics;
}
// choose a "dummy" random pic just to get the right gallery
$rndpic = rand(0,$totalpics-1);
//echo "rndpic is " . $rndpic;
// now find the appropriate gallery
for($curgal=0; $curgal<$numgals; $curgal++)
{
//echo " ... gallery " . $curgal . " limit is " . $galpicindex[$curgal];
if($rndpic < $galpicindex[$curgal])
break;
}
$pics = load_gal_data(fname($gals[$curgal][0]) . "/gal");
}
$numpics = sizeof($pics);
// now get the current pic number or a random pic if not in a gallery
if ($ingallery)
{
if(array_key_exists("pic", $_GET))
$curpic = (int)$_GET["pic"];
if($curpic < 0 || $curpic >= $numpics)
$curpic = 0;
}
else
$curpic = rand(0, $numpics-1);
// load the picstart value if it exists
if (array_key_exists("picstart", $_GET))
{
$picstart = (int)$_GET["picstart"];
if ($picstart < 0)
$picstart = 0;
if ($ingallery && $picstart >= $numpics)
$picstart = $numpics - 1;
if (!$ingallery && $picstart >= $numgals)
$picstart = $numgals - 1;
}
else if ($ingallery)
{
$picstart = (int)floor($curpic / $picsperpage)*$picsperpage;
}
$indexctr = $picstart;
}
// returns URL to link to currently displayed picture
function curpiclink()
{
global $phpname, $show, $curgal, $curpic, $picsperpage;
$newpicstart = (int)floor($curpic / $picsperpage)*$picsperpage;
return $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $curpic;
}
function curpicgaltitle()
{
global $gals, $curgal;
return $gals[$curgal][3];
}
function curpicgaldesc()
{
global $gals, $curgal;
return $gals[$curgal][4];
}
// total number of galleries
function galleries()
{
global $numgals;
return $numgals;
}
// current gallery
function curgallery()
{
global $curgal;
return $curgal + 1;
}
// returns $then if in gallery, $else if not
function ifingallery($then, $else)
{
global $ingallery, $goodshow;
if($ingallery && $goodshow)
return $then;
else
return $else;
}
// returns the gallery title string, or the $nogal value
function galtitle($nogal = "")
{
global $ingallery;
if($ingallery)
return curpicgaltitle();
else
return $nogal;
}
function galdesc($nogal = "")
{
global $ingallery;
if($ingallery)
return curpicgaldesc();
else
return $nogal;
}
// returns the section title string, or the $badsec value
function sectitle($badsec = "")
{
global $show, $goodshow, $sections;
if($goodshow)
return $sections[$show][2];
else
return $badsec;
}
function secdesc($badsec = "")
{
global $show, $goodshow, $sections;
if($goodshow)
return $sections[$show][3];
else
return $badsec;
}
function pictitle()
{
global $pics, $curpic;
return $pics[$curpic][3];
}
function picdesc()
{
global $pics, $curpic;
return $pics[$curpic][4];
}
function pichaslink()
{
global $pics, $curpic;
return count($pics[$curpic]) == 6;
}
function piclink()
{
global $pics, $curpic;
return $pics[$curpic][5];
}
// returns a linked image for the index thumbnail, with $imgopt, or $nopic if no pic
function indexthumb($imgopt = "", $nopic = "")
{
global $ingallery, $indexctr, $numpics, $numgals;
global $show, $phpname, $curgal, $picstart, $gals, $pics;
global $thumbwidth, $thumbheight, $goodshow;
global $fprefix;
$val = $nopic;
if(!$goodshow)
return $val;
if ($ingallery && $indexctr < $numpics)
$val= '<a href="' . $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $indexctr . '">' .
'<img src="' . $fprefix . fname($gals[$curgal][0]) . '/' . fname($pics[$indexctr][0]) . '_th.' . fext($pics[$indexctr][0]) . '" ' .
'width="' . $thumbwidth . '" height="' . $thumbheight . '" ' . $imgopt . '></a>';
else if(!$ingallery && $indexctr < $numgals)
$val= '<a href="' . $phpname . '?show=' . $show . '&gallery=' . $indexctr . '">' .
'<img src="' . $fprefix . fname($gals[$indexctr][0]) . '_th.' . fext($gals[$indexctr][0]) . '" ' .
'width="' . $thumbwidth . '" height="' . $thumbheight . '" ' . $imgopt . '></a>';
$indexctr++;
return $val;
}
// returns title of next thumbnail
function indextitle()
{
global $ingallery, $indexctr, $numpics, $numgals;
global $gals, $pics, $goodshow;
if(!$goodshow)
return "";
if ($ingallery && $indexctr < $numpics)
return $pics[$indexctr][3];
else if(!$ingallery && $indexctr < $numgals)
return $gals[$indexctr][3];
}
// if the next index pic is of the current pic, return $then, else return $else
function ifiscurpic($then, $else)
{
global $ingallery, $indexctr, $curpic;
if($ingallery && $indexctr == $curpic)
return $then;
else
return $else;
}
// if the next index pic exists
function ifpicexists($then, $else)
{
global $ingallery, $indexctr, $numpics, $numgals;
if(($ingallery && $indexctr < $numpics) ||
(!$ingallery && $indexctr < $numgals))
return $then;
else
return $else;
}
// total number of pages
function pages()
{
global $ingallery, $numpics, $picsperpage, $numgals;
if($ingallery)
$numitems = $numpics;
else
$numitems = $numgals;
return floor(($numitems - 1) / $picsperpage) + 1;
}
// current page
function curpage()
{
global $picstart, $picsperpage;
return floor($picstart / $picsperpage) + 1;
}
// if there is a "next page"
function ifnextpage($then, $else)
{
global $picstart, $picsperpage, $ingallery, $numpics, $numgals;
global $wraplinks;
if($ingallery)
$numitems = $numpics;
else
$numitems = $numgals;
$nextpicstart = $picstart+$picsperpage;
if(($wraplinks && $numitems > $picsperpage) ||
($nextpicstart < $numitems))
return $then;
else
return $else;
}
function ifprevpage($then, $else)
{
global $picstart, $picsperpage, $ingallery, $numpics, $numgals;
global $wraplinks;
if($ingallery)
$numitems = $numpics;
else
$numitems = $numgals;
$prevpicstart = $picstart-$picsperpage;
if(($wraplinks && $numitems > $picsperpage) ||
($prevpicstart >= 0))
return $then;
else
return $else;
}
function ifnextpic($then, $else)
{
global $curpic, $numpics;
global $wraplinks;
if(($wraplinks && $numpics > 1 ) ||
($curpic+1 < $numpics))
return $then;
else
return $else;
}
function ifprevpic($then, $else)
{
global $curpic, $numpics;
global $wraplinks;
if(($wraplinks && $numpics > 1 ) ||
($curpic-1 >= 0))
return $then;
else
return $else;
}
function ifnextgal($then, $else)
{
global $curgal, $numgals;
global $wraplinks;
if(($wraplinks && $numgals > 1 ) ||
($curgal+1 < $numgals))
return $then;
else
return $else;
}
function ifprevgal($then, $else)
{
global $curgal, $numgals;
global $wraplinks;
if(($wraplinks && $numgals > 1 ) ||
($curgal-1 >= 0))
return $then;
else
return $else;
}
// returns URL for next page link
function nextpagelink()
{
global $picstart, $picsperpage, $ingallery;
global $show, $phpname, $curgal, $curpic, $numpics, $numgals;
$nextpicstart = $picstart+$picsperpage;
if(($ingallery && $nextpicstart >= $numpics) ||
(!$ingallery && $nextpicstart >= $numgals))
$nextpicstart = 0;
if($ingallery)
return $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $curpic .
'&picstart=' . $nextpicstart;
else
return $phpname . '?show=' . $show . '&picstart=' . $nextpicstart;
}
function firstpagelink()
{
global $ingallery;
global $show, $phpname, $curgal, $curpic;
if($ingallery)
return $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $curpic . '&picstart=0';
else
return $phpname . '?show=' . $show . '&picstart=0';
}
function prevpagelink()
{
global $picstart, $picsperpage, $ingallery;
global $show, $phpname, $curgal, $curpic, $numpics, $numgals;
$nextpicstart = $picstart-$picsperpage;
if($nextpicstart < 0)
{
if($ingallery)
$nextpicstart = (int)floor( ($numpics-1) / $picsperpage)*$picsperpage;
else
$nextpicstart = (int)floor( ($numgals-1) / $picsperpage)*$picsperpage;
}
if($ingallery)
return $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $curpic .
'&picstart=' . $nextpicstart;
else
return $phpname . '?show=' . $show . '&picstart=' . $nextpicstart;
}
function nextpiclink()
{
global $show, $phpname, $curgal, $curpic, $numpics, $numgals;
$newpic = $curpic+1;
if($newpic >= $numpics)
$newpic = 0;
return $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $newpic;
}
function prevpiclink()
{
global $show, $phpname, $curgal, $curpic, $numpics;
$newpic = $curpic-1;
if($newpic < 0)
$newpic = $numpics-1;
return $phpname . '?show=' . $show . '&gallery=' . $curgal .
'&pic=' . $newpic;
}
function nextgallink()
{
global $show, $phpname, $curgal, $numgals;
$newgal = $curgal+1;
if($newgal >= $numgals)
$newgal = 0;
return $phpname . '?show=' . $show . '&gallery=' . $newgal;
}
function prevgallink()
{
global $show, $phpname, $curgal, $numgals;
$newgal = $curgal-1;
if($newgal < 0)
$newgal = $numgals-1;
return $phpname . '?show=' . $show . '&gallery=' . $newgal;
}
// returns img tag for the pic, with $imgopt
function thepic($imgopt = "")
{
global $show, $gals, $pics, $curgal, $curpic;
global $fprefix;
if($show == "video") {
return '<iframe width="560" height="315" src="//www.youtube.com/embed/' . $pics[$curpic][1] . '" frameborder="0" allowfullscreen></iframe>';
} else {
return '<img src="' . $fprefix . fname($gals[$curgal][0]) . '/' . fname($pics[$curpic][0]) . '.' . fext($pics[$curpic][0]) . '" ' .
'width="' . $pics[$curpic][1] . '" height="' . $pics[$curpic][2] . '" ' . $imgopt . '>';
}
}
?>