PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/new/photogallery/photogallery.php

https://gitlab.com/cherian/xmec
PHP | 349 lines | 226 code | 57 blank | 66 comment | 36 complexity | 9ca078fed1f61f38bec1943cbf5a6ccd MD5 | raw file
  1. <?php
  2. /*
  3. Script by Tuomas Airaksinen <tuomas.airaksinen@tuma.stc.cx>
  4. and Maarten den Braber <mdb@twister.cx>
  5. Ideas from imgconvert.sh by Garrett LeSage <garrett@linux.com>
  6. Published under GNU General Public Licence (GPL)
  7. You should get whole license information in COPYING
  8. file distributed with this file. For more information
  9. see http://www.gnu.org */
  10. $version = "v1.1.5";
  11. /*
  12. See http://tuma.stc.cx/gallery.php for more info
  13. */
  14. require("photogallery-config.php");
  15. require("compare.php");
  16. # we make an array which contains list of images (-> sorting)
  17. $othumbdir = dir($thumbdir);
  18. $pictures = array();
  19. while($entry = $othumbdir->read())
  20. {
  21. if(is_file("$thumbdir/$entry") && is_readable("$thumbdir/$entry"))
  22. {
  23. array_push($pictures, array("name" => $entry,
  24. "date" => filemtime("$thumbdir/$entry"),
  25. "size" => filesize("$thumbdir/$entry")));
  26. }
  27. }
  28. $othumbdir->close();
  29. #then we can sort information as ordered
  30. if(! $sort)
  31. $sort = "name";
  32. usort($pictures, $sort . "_cmp");
  33. if (! $included )
  34. {
  35. echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
  36. echo "<HTML><HEAD><TITLE>Photogallery</TITLE></HEAD><BODY>\n";
  37. }
  38. if (! $number)
  39. $number = $defnumber;
  40. if (! $pagenum)
  41. $pagenum = 1;
  42. /* Some helper functions */
  43. function get_pictinfo($picture)
  44. {
  45. global $infofile;
  46. # Read the infofile
  47. $fp=fopen($infofile,"r");
  48. $contents=fread($fp, filesize($infofile));
  49. fclose($fp);
  50. $start = strpos($contents,$picture) + strlen($picture);
  51. $tmpstr = substr($contents,$start,strlen($contents));
  52. $stop = strpos($tmpstr, "\n");
  53. $pictinfo = substr($contents,$start,$stop);
  54. return $pictinfo;
  55. }
  56. /*function num2picture($num)
  57. {
  58. global $thumbdir;
  59. $othumbdir = dir($thumbdir);
  60. for($count=0; $count<=($num+1); $count++)
  61. {
  62. $entry=$othumbdir->read();
  63. }
  64. $othumbdir->close;
  65. return $entry;
  66. }
  67. function picture2num($picture)
  68. {
  69. global $thumbdir;
  70. $count = 0;
  71. $othumbdir = dir($thumbdir);
  72. while($entry=$othumbdir->read())
  73. {
  74. $count++;
  75. if($entry == $picture)
  76. break;
  77. }
  78. $othumbdir->close;
  79. return $count - 2; // we don't count . and .. (which are first)
  80. }
  81. */
  82. function num2picture($num)
  83. {
  84. global $pictures;
  85. reset($pictures);
  86. $num--;
  87. for($count=0; $count<=($num); $count++)
  88. {
  89. list(, $entry) = each($pictures);
  90. }
  91. return $entry["name"];
  92. }
  93. function picture2num($picture)
  94. {
  95. global $pictures;
  96. reset($pictures);
  97. $count = 0;
  98. foreach($pictures as $entry)
  99. {
  100. $count++;
  101. if($entry["name"] == $picture)
  102. break;
  103. }
  104. return $count;
  105. }
  106. /*echo "picture2num(0,1,2)" . picture2num(num2picture(1)) . picture2num(num2picture(2)) . picture2num(num2picture(3)) . "\n";
  107. echo "num2picture(0,1,2)" . num2picture(1) . num2picture(2)
  108. . num2picture(3) . "\n";*/
  109. /* -- Gallery function ---------------------------------------------------- */
  110. function thumbnails()
  111. {
  112. global $number, $pagenum, $languages, $thumbdir_links, $imgdir_links, $thumbdir,
  113. $imgdir, $othumbdir, $oimgdir, $thisfile, $help, $backtogallery, $header, $lang,
  114. $tablestart, $lines_in_row, $pagestr, $included, $pictures,
  115. $clickmestr;
  116. # Define the next and previous pages
  117. $prev = $pagenum - 1;
  118. $next = $pagenum + 1;
  119. # Pages start with 0, but we start with 1 so substract 1
  120. // $pagenum--;
  121. # Define when a new page starts
  122. $start = ($pagenum - 1) * $number + 1;
  123. $stop = $start + $number;
  124. // echo "DEBUG: number: $number, start: $start, stop: $stop\n total: " . ($stop - $start) . "\n";
  125. # Print language selector
  126. if (! $included )
  127. {
  128. echo "<CENTER>Choose language: ";
  129. foreach($languages as $this)
  130. {
  131. if ($lang == $this["short"])
  132. echo "[" . $this["full"] . "]";
  133. else
  134. echo "<A HREF=\"$thisfile?lang=" . $this["short"] .
  135. "&action=gallery&pagenum=$pagenum\">[" . $this["full"] . "]</A> ";
  136. }
  137. echo "</CENTER>";
  138. echo "<H1>" . $header[$lang] . " - " . $pagestr[$lang] . " $pagenum</H1>\n";
  139. echo $help[$lang] . "<BR>\n\n";
  140. }
  141. $total = 0;
  142. echo "<BR><CENTER><H2>" . $clickmestr[$lang] . "</H2></CENTER>";
  143. # Loop through all the images in the directory
  144. foreach($pictures as $this)
  145. {
  146. $entry = $this["name"];
  147. $total++;
  148. if(is_file("$thumbdir/$entry") && is_readable("$thumbdir/$entry"))
  149. {
  150. $count = picture2num($entry);
  151. /*
  152. echo " DEBUG: count: $count start: $start, stop: $stop, tulos: " .
  153. ($count < $stop && $count >= $start) . "\n";
  154. */
  155. if($count < $stop && $count >= $start)
  156. {
  157. $newline = $count - $start;
  158. $countloop++;
  159. if ($newline == 0 || $countloop == $lines_in_row)
  160. {
  161. $countloop=0;
  162. if ($newline < ($lines_in_row - 1))
  163. {
  164. echo "$tablestart\n";
  165. }
  166. else
  167. {
  168. echo "</TR><TR>\n";
  169. }
  170. }
  171. echo "<TD><P ALIGN=\"center\">";
  172. echo "<B>$count. </B><SMALL>" . get_pictinfo($entry) . "</SMALL><BR>";
  173. # echo "$imgdir/$entry\n";
  174. if(is_file("$imgdir/$entry"))
  175. {
  176. echo "<A HREF=\"" . $thisfile . "?action=full&picture=$entry&lang=$lang\">" .
  177. "<IMG BORDER=1 SRC=\"$thumbdir_links/$entry\"></A>";
  178. echo "<BR></TD>\n";
  179. }
  180. else
  181. {
  182. echo "<IMG BORDER=1 SRC=\"$thumbdir_links/$entry\">";
  183. echo "<BR></TD>\n";
  184. }
  185. $count++;
  186. }
  187. }
  188. }
  189. echo "</TD></TR></TABLE>\n";
  190. $gallery_prev = "<A HREF=\"$thisfile?action=gallery&pagenum=$prev&number=$number&lang=$lang\">" .
  191. "[&lt;&lt;]</A>";
  192. $gallery_next = "<A HREF=\"$thisfile?action=gallery&pagenum=$next&number=$number&lang=$lang\">" .
  193. "[&gt;&gt;]</A>";
  194. $totalpages = ceil($total / $number);
  195. $gallery_pages = 1;
  196. while ( $totalpages >= $gallery_pages )
  197. {
  198. if ($gallery_pages == $pagenum)
  199. $gallery_number = "$gallery_number$gallery_pages&nbsp;&nbsp;\n";
  200. else
  201. $gallery_number = "$gallery_number<A HREF=\"$thisfile?action=gallery&pagenum="
  202. . "$gallery_pages&number=$number&lang=$lang\">$gallery_pages</A>&nbsp;&nbsp;\n";
  203. $gallery_pages++;
  204. }
  205. if ( $pagenum == 1 )
  206. {
  207. $gallery_prev = "[&lt;&lt;]";
  208. }
  209. if ( $pagenum == $totalpages )
  210. {
  211. $gallery_next = "[&gt;&gt;]";
  212. }
  213. echo "\n<P>\n\n";
  214. echo "$gallery_prev\n&nbsp;&nbsp;&nbsp;\n\n";
  215. echo "<B>" . $pagestr[$lang] . ":</B>\n\n&nbsp;$gallery_number\n";
  216. echo "&nbsp;&nbsp;&nbsp;\n$gallery_next\n";
  217. }
  218. /* -- Show full size picture -------------------------------------- */
  219. function fullsize()
  220. {
  221. global $picture, $infofile, $languages, $thumbdir, $imgdir,
  222. $thumbdir_links, $imgdir_links, $othumbdir,
  223. $oimgdir, $thisfile, $help, $backtogallery, $lang,
  224. $tablestart,$number, $included;
  225. # Find previous and next
  226. $current = picture2num($picture);
  227. $count = picture2num("dontfindme.xyz") - 2 ;
  228. $prev = num2picture($current - 1);
  229. $next = num2picture($current + 1);
  230. $pagenum = ceil($current / $number);
  231. echo "<CENTER><H1><B>$current.</B> " . get_pictinfo($picture) . "</H1>\n";
  232. $thumb_prev = "<A HREF=\"$thisfile?action=full&picture=$prev&lang=$lang\">" .
  233. "[&lt;&lt;]</a>&nbsp;&nbsp;&nbsp;";
  234. $thumb_index = "<A HREF=\"$thisfile?action=gallery&number=$number&pagenum=$pagenum&lang=$lang\">"
  235. . "<B>" . $backtogallery[$lang] . "</B></A>";
  236. $thumb_next = "&nbsp;&nbsp;&nbsp;<A HREF=\" $thisfile?action=full&picture=$next&lang=$lang\">"
  237. . "[&gt;&gt;]</A>\n";
  238. if ($current == 1)
  239. {
  240. $thumb_prev = "[&lt;&lt;]&nbsp;&nbsp;&nbsp;";
  241. }
  242. if ($next == "")
  243. {
  244. $thumb_next = "&nbsp;&nbsp&nbsp;[&gt;&gt;]";
  245. }
  246. $browsestr = "$thumb_prev $thumb_index $thumb_next";
  247. echo "<P>$browsestr<BR><BR>\n";
  248. if(is_file("$imgdir/$picture"))
  249. echo "<IMG BORDER=1 SRC=\"$imgdir_links/$picture\"><BR>\n";
  250. else
  251. {
  252. user_error("[no fullsized-image for this image, showing thumbnail instead]", E_USER_WARNING);
  253. echo "<IMG BORDER=1 SRC=\"$thumbdir_links/$picture\"><BR>\n";
  254. }
  255. echo "<P>$browsestr\n";
  256. }
  257. /* -- Switches ------------------------------------------------------------ */
  258. function gallery()
  259. {
  260. global $version, $action, $oimgdir, $othumbdir, $imgdir_links,
  261. $thumbdir_links, $imgdir, $thumbdir;
  262. $othumbdir = dir($thumbdir);
  263. $oimgdir = dir($imgdir);
  264. switch($action)
  265. {
  266. case "gallery" :
  267. thumbnails();
  268. break;
  269. case "full" :
  270. fullsize();
  271. break;
  272. default :
  273. thumbnails();
  274. break;
  275. }
  276. echo "<BR><BR><SMALL>Generated by " .
  277. "<A HREF=\"http://tuma.stc.cx/gallery.php\">photogallery script</A> $version.</SMALL></CENTER>";
  278. $othumbdir->close();
  279. $oimgdir->close();
  280. }
  281. if(! $included)
  282. {
  283. gallery();
  284. echo "</BODY></HTML>";
  285. }
  286. ?>