aboutsummaryrefslogtreecommitdiff
path: root/www/index.php
blob: f32d3b384ec8d8d7944646bb0ecc296c2fd9b875 (plain)
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
<?php
# uncomment this to check for uninitialized variables etc.:
# error_reporting (E_ALL);

#language support
require_once ("lib/lib.l10n.php");

if (file_exists("inc/config.inc.php")) {
  require_once("inc/config.inc.php");
} else {
  die('Please copy inc/config.dist.inc.php to inc/config.inc.php and edit according to your needs.');
}

require_once("inc/www.class.inc.php");
require_once("inc/funkce.inc.php");
//session_name("navstevnik");
//session_register("page");

#set the language translation
l10n::set("$root/l10n/".$sclang."/main.lang");
l10n::set("$root/l10n/".$sclang."/date.lang");




# always get sorted directory entries
$adr = new SortDir("$gallery_dir");

# get variables passed in from the URL:
$galerie='';
if (isset($_GET['galerie'])) $galerie=$_GET["galerie"];
if (isset($_GET['gallery'])) $galerie=$_GET["gallery"];
$galerie = preg_replace('/\//', '', $galerie);
if (isset($_GET["thumbsize"])) $thumbsize=$_GET["thumbsize"];
$snimek = 0;
if (isset($_GET["snimek"])) $snimek=$_GET["snimek"];
if (isset($_GET["photo"])) $snimek=$_GET["photo"];
$snimek = intval($snimek);
$y='';
if (isset($_GET['y'])) $y=$_GET["y"];
$cmnt='';
if (isset($_GET["cmnt"])) $cmnt=$_GET["cmnt"];
$show_thumbs='';
if (isset($_GET["show_thumbs"])) $show_thumbs=$_GET["show_thumbs"];

$page = new C_www;
//default colors

if (!is_dir("$gallery_dir/$galerie/thumbs")) {
  $galerie = "";
}

//read interesting stuff from info.txt
if ($galerie) { 
	readInfo("$root/$gallery_dir/$galerie/info.txt", $galerie);
//check for restricted access
	if ($galerielogin[$galerie]) {
			 access_check($galerielogin[$galerie],$galeriepw[$galerie],$galerie);
	}
}

$page->process_comment_form();

//START RENDERING


$page->header("Photos");
require("inc/header.inc.php");

// folder > tree
//print "<div class=\"navigation\"><a href=\"$ThisScript\">" . $scnamegallery . "</a>";
print "<div class=\"navigation\"><a href=\"./\">" . $scnamegallery . "</a>";

#############################
# 	Overall Gallery Index		#
#############################
if (!$galerie) {
   # finish off navigation bar
   print "</div>\n\n<!-- listing galleries-->\n\n";  
	 # I've nuked date.txt to replace it with a more generic info.txt
   # It optionally supplies i18n name, camera model, author and date
	 # TODO: imgconv script support
   while ($file = $adr->Read()) {
      // checking for inc is only really needed when gallery_dir == $root
      // hopefully not many galleries will be named inc ;)
      if (is_dir("$gallery_dir/$file") && !preg_match("/\./", $file) && $file!="inc") { 
         // Use date file for gallery date if avaliable
				 // info.txt format described in README
         readInfo("$root/$gallery_dir/$file/info.txt", $file);
         
      }
   }

	 if (!isset($galeriemonth)) $galeriemonth = array();
   if (!isset($galerieday)) $galerieday = array();
	 //sort within month depending on $sortinmonth
	 if ($sortinmonth) {
		 //alphabetically
		 ksort($galeriemonth);
		 reset($galeriemonth);
	 } else {//by date
		 arsort($galerieday);
		 reset($galerieday);
	 }


	 $thisyear = 0;
	 if (!$yearto) $yearto = date("Y");
   for ($i = $yearto; $i >= $yearsince; $i--) {
      for ($thismonth=12; $thismonth>0; $thismonth--) { // go year by year, month by month
																												// down
				 foreach ($galerieday as $foldername => $day) { //using $galerieday (for when sorted)
						if ($galeriemonth["$foldername"] == $thismonth && 
							      $galerieyear["$foldername"] == $i) { //such Y/M exists

								$galerieyearordered["$foldername"]=$galerieyear["$foldername"];
								$galeriemonthordered["$foldername"]=$galeriemonth["$foldername"];
						}
				 }
      }
   }


	 $months = array(__('January'), __('February'), __('March'), __('April'), __('May'), __('June'), __('July'), __('August'),
	 __('September'), __('October'), __('November'), __('December'));
	 $one_out = false;
	 foreach ($galerieyearordered as $foldername => $year) {
		  $one_out = true;
			if (@$thisyear!=$year) { #if the year is not equal to the current year
				 #This is the first year
				 if (@$thisyear) { print "   </div>\n</div>\n";}// end last year if this is 
																				 // not the first one
				 #This is a new year
				 unset($thismonth);
				 print "<div class=\"year\"><h3>$year</h3>\n";
				 print "";
			}
			$month=$galeriemonth["$foldername"];
			# now months
			if (@$thismonth!=$month) {
				 #first one
				 if (@$thismonth) { print "   </div>\n"; } // end of last month if
																							// this is not the first one
				 #new month
				 $monthindex = $month - 1;
				 $monthname = $months[$monthindex];
				 print "   <div class=\"month\"><h4>$monthname</h4>\n";
			}
			#galleries within month	
			if ($galerielogin[$foldername]) {
				print "      <p class=\"restricted\"><a ";
			} else {
				print "      <p><a ";
			}
			if (@$galeriename[$foldername]) {
				print " href=\"$ThisScript?galerie=$foldername\">";
				print $galeriename[$foldername];
				print "</a>";
			} else {
				print " href=\"$ThisScript?galerie=$foldername\">$foldername</a>";
			}
			if (@$galeriedesc[$foldername]) {
				print "<span class=\"desc\">" . $galeriedesc[$foldername];
				print "</span>\n";
			}
			if (@$galerieauthor[$foldername]) {
				print "<span class=\"author\">by&nbsp;" . $galerieauthor[$foldername];
				print "</span>\n";
			}
			if (@$galerieday[$foldername]) {
				print "<span class=\"date\">";
				print "$monthname&nbsp;" . $galerieday[$foldername];
				print "</span>\n";
			}
			print "</p>\n";
			$thisyear=$year;
			$thismonth=$month;
	 }
	 if ($one_out) print ("   </div>\n</div>\n\n");
   
##############################
#  Individual Gallery Index  #
##############################
} elseif (!$snimek) {
	 
   # finish off navigation header
	 
   print "\n &gt; ";
	 if ($galeriename[$galerie]) {
		 print $galeriename[$galerie];
	 } else {
		 print $galerie;
	 }
	 print "</div>\n\n";

	 //thumbnails
	 print "<p class=\"bigthumbnails\">\n";
   $path = "$gallery_dir/$galerie/thumbs";
   $imgfiles = new SortDir($path);
   check($galerie); // check for nasty input
   while ($file = $imgfiles->read()) {
      if (is_file("$path/$file") && preg_match("/^img-([0-9]+)\.(png|jpe?g)/i", $file, $x)) {
				 				 
         $thumb = "$gallery_dir/$galerie/thumbs/img-${x[1]}.${x[2]}";
         $imgsize = getimagesize("$root/$thumb");
				 //check for portraits
				 $portrait = "false";
				 $class = "";
				 if($imgsize[0]<100) {
					 //portraits need a special class for styling
					 $class = "portrait";
				 }
				 //check for number of comments per photo
				 if ($comments) { //there probably won't be user comments if it's off
				   $NumOfComments = 0;
					 if (file_exists("$gallery_dir/$galerie/comments/user_${x[1]}.txt")) {
							if ($class) $class .= " ";
							$class .= "hascomments";
							//now let's count'em
							$fh = fopen("$gallery_dir/$galerie/comments/user_${x[1]}.txt","r");
							while (!feof($fh)) {
								$line = fgets($fh);
								if (preg_match("/commententry/i",$line)) $NumOfComments++;
							}
							fclose($fh);
					 }
					 if ($NumOfComments==1) {
						 $NumOfComments = $NumOfComments . " " . __('Comment');
					 } else {
						 $NumOfComments = $NumOfComments . " " . __('Comments');
					 }
				 }
	 if (file_exists("$gallery_dir/$galerie/comments/${x[1]}.txt") &&
		   $title = file_get_contents("$gallery_dir/$galerie/comments/${x[1]}.txt")) {
	     $title = preg_replace("/(\"|\')/","",trim(strip_tags($title)));
       $title = preg_replace("/(.{77}).*/","\\1",$title);
	 } else 
	   $title = "Photo ${x[1]}";

         print "   <a href=\"$ThisScript?galerie=$galerie&amp;photo=${x[1]}\"";
				 print " title=\"$title, $NumOfComments\"";
				 if ($class) print " class=\"$class\"";
				 print ">";
         print "<img ";
         if (isset($thumbsize)) {
            print "width=\"120\" height=\"80\" ";
         } else {
            // scale portraits to 80 height
            if ($portrait) {
							//portrait
               print "width=\"";
               $scaled = round($imgsize[0] / 1.5);
               print $scaled;
               print "\" height=\"${imgsize[0]}\"";
            } else {
							//landscape
               print $imgsize[3]; 
            }
         }
         print " src=\"$thumb\" ";
         print "alt=\"photo No. ${x[1]}\" />";
         print "</a>\n";
      }
   }
   print "</p>\n";

	 //info
	 print "<div id=\"info\">\n";
	 if ($galeriedesc[$galerie]) {
		 print "<p>";
		 print "<span class=\"value\">";
		 print $galeriedesc[$galerie] . "</span></p>\n";
	 }
	 if ($galerieauthor[$galerie]) {
		 print "<p><span class=\"key\">Author: </span>";
		 print "<span class=\"value\">";
		 print $galerieauthor[$galerie] . "</span></p>\n";
	 }
	 print "</div>\n";

   //and links to archived images:
   print "\n<p class=\"archives\">\n";
   if (file_exists("$gallery_dir/$galerie/zip/mq.zip")) {
      print "[ <a href=\"$gallery_dir/$galerie/zip/mq.zip\">" . __('zipped MQ images') . "</a> ] ";
   }
   if (file_exists("$gallery_dir/$galerie/zip/mq.tar.bz2")) {
      print "[ <a href=\"$gallery_dir/$galerie/zip/mq.tar.bz2\">" . __('MQ images tarball') . "</a> ] ";
   }
   if (file_exists("$gallery_dir/$galerie/zip/hq.zip")) {
      print "[ <a href=\"$gallery_dir/$galerie/zip/hq.zip\">" . __('zipped HQ images') . "</a> ]";
   }
   if (file_exists("$gallery_dir/$galerie/zip/hq.tar.bz2")) {
      print "[ <a href=\"$gallery_dir/$galerie/zip/hq.tar.bz2\">" . __('HQ images tarball') . "</a> ]";
   }
   print "</p>";

#######################
# 	Individual Image	#
#######################
} else { //low-res image
   # finish off header
   print "\n &gt; <a href=\"$ThisScript?galerie=$galerie\">";
	 if ($galeriename[$galerie]) {
		 print $galeriename[$galerie];
	 } else {
		 print $galerie;
	 }
	 print "</a>\n &gt; Photo";
   print " $snimek</div>";
   $path = "$gallery_dir/$galerie/thumbs";
   $imgfiles = new SortDir("$path");
   check($galerie);
   $path = "$gallery_dir/$galerie/lq";
   $file = "$path/img-$snimek.jpg";
   if (!file_exists($file)) {
      print __('No such image');
      $page->footer();
      exit;
   }
	 
	 if (!$picture) { //picture may have been created if commentform submitted
	    require_once("$root/inc/photo.class.inc.php");
	    $picture = new C_photo($file, $snimek);
	 }

   // mini thumbnail roll

   if ($show_thumbs) {
      print "\n<!--mini thumbnail roll-->\n<div class=\"thumbroll\">";
      print "<a id=\"minus\" href=\"$ThisScript?galerie=$galerie&amp;photo=$snimek";
      print "\">";
      print "</a>\n";
      print " : \n";
      while ($thumbfile = $imgfiles->read()) {
         if ( preg_match("/^img-([0-9]+)\.(png|jpe?g)/",
             $thumbfile, $x)) {
            $thumb = "$gallery_dir/$galerie/thumbs/img-${x[1]}.${x[2]}";
            print "   <a href=\"$ThisScript?galerie=$galerie&amp;photo=${x[1]}";
            print "&amp;show_thumbs=$show_thumbs\"";
						print " title=" . get_photo_title($galerie, $x[1]) . ">";
            print "<img class=\"thumb\" ";
            // hadess' hack (TM) ;)
            if ($thumbsize) {
                 print " width=\"24\" height=\"16\"";
            } else {
                 $minithumb=getimagesize("$root/$thumb");
                 $w=$minithumb[0]/6;
                 $h=$minithumb[1]/6;
                 print " width=\"$w\" height=\"$h\"";
            }
            print " src=\"$thumb\" ";
            print "alt=\"photo No. ${x[1]}\" />";
            print "</a> \n";
         }
      }
      if (file_exists("$gallery_dir/$galerie/zip/hq.zip")) {
         print "<a id=\"zip\" href=\"$gallery_dir/$galerie/zip/hq.zip\">";
         print "zip<span /></a>";
      }
      if (file_exists("$gallery_dir/$galerie/zip/hq.tar.bz2")) {
         print "<a id=\"zip\" href=\"$gallery_dir/$galerie/zip/hq.tar.bz2\">";
         print "zip<span /></a>";
      }
      print "</div>\n";
   } else {
      // show the popup button
      print "\n<!--mini thumbnail popup-->\n<div class=\"thumbroll\">";
      print "<a id=\"plus\" href=\"$ThisScript?galerie=$galerie&amp;photo=$snimek";
      print "&amp;show_thumbs=yes\"";
			print " title=\"" . __('Show Thumbnail Navigation') . "\">";
      print "</a>\n";
      print "</div>\n";
   }

   /* main image + thumbnail navigation (prev/next) */

   $picture->renderPreview();
   $page->navigation($galerie, $snimek, "prev");
   $page->navigation($galerie, $snimek, "next");
   print "</div>\n"; //end image div



   if (function_exists(exif_read_data)) require("$root/inc/exif.inc.php"); 
	 /* Image comment
	 		really poor naming here, it is caption.
	 */
	 $picture->renderCaption();

 	
	 //show page counter
	 if ($log_access) {
			$picture->renderCounter();
	 }

	 $picture->renderBigSize();

   $page->user_comments($picture->number);
   $page->navigation($galerie, $snimek, null);
}

require("inc/footer.inc.php");
$page->footer();
?>