index.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. session_start();
  3. $toplevelDir = "pictures/";
  4. $dir = $toplevelDir;
  5. $maxCount = 30;
  6. $offset = 0;
  7. $count = 0;
  8. // load blacklist
  9. $blacklist = array();
  10. $blacklistFilename = "blacklist.txt";
  11. $blacklistHandle = fopen($blacklistFilename, "r");
  12. if ($blacklistHandle) {
  13. $blacklistContent = fread($blacklistHandle, filesize($blacklistFilename));
  14. fclose($blacklistHandle);
  15. $blacklist = explode("\n", $blacklistContent);
  16. }
  17. if (isset($_GET["offset"]))
  18. $offset = $_GET["offset"];
  19. if (isset($_GET["getDir"]))
  20. $dir = $_GET["getDir"];
  21. elseif (isset($_SESSION["indexDir"]))
  22. $dir = $_SESSION["indexDir"];
  23. $_SESSION["indexDir"] = $dir;
  24. if (strpos($dir, $toplevelDir) !== 0)
  25. $dir = $toplevelDir;
  26. else {
  27. $dir = str_replace("..", "", $dir);
  28. $dir = str_replace("//", "/", $dir);
  29. }
  30. $folders = array();
  31. $files = array();
  32. // Open a known directory, and proceed to read its contents
  33. if (is_dir($dir)) {
  34. if ($dh = scandir($dir)) {
  35. for ($i = 0; $i < count($dh); ++$i) {
  36. $file = $dh[$i];
  37. if ($file == "." || $file == "..")
  38. continue;
  39. if (is_dir($dir . $file))
  40. $folders[] = $file;
  41. else {
  42. if (!in_array($dir.$file, $blacklist)) {
  43. if (count($files) < $maxCount && $count >= $offset)
  44. $files[] = $file;
  45. ++$count;
  46. }
  47. }
  48. }
  49. }
  50. }
  51. function createthumb($name, $filename, $new_w, $new_h)
  52. {
  53. $system = explode('.', $name);
  54. if (preg_match('/jpg|jpeg/', $system[1])) {
  55. $src_img = imagecreatefromjpeg($name);
  56. }
  57. if (preg_match('/png/', $system[1])) {
  58. $src_img = imagecreatefrompng($name);
  59. }
  60. if (!$src_img) {
  61. link("icons/image.png", $filename);
  62. return;
  63. }
  64. $old_w = imageSX($src_img);
  65. $old_h = imageSY($src_img);
  66. $old_x = 0;
  67. $old_y = 0;
  68. if ($old_w > $old_h) {
  69. $old_x = ($old_w - $old_h) / 2.0;
  70. $old_w = $old_h;
  71. }
  72. if ($old_w < $old_h) {
  73. $old_y = ($old_h - $old_w) / 2.0;
  74. $old_h = $old_w;
  75. }
  76. $dst_img=ImageCreateTrueColor($new_w, $new_h);
  77. imagecopyresampled($dst_img, $src_img, 0, 0, $old_x, $old_y, $new_w, $new_h, $old_w, $old_h);
  78. if (preg_match("/png/",$system[1])) {
  79. imagepng($dst_img, $filename, 90);
  80. } else {
  81. imagejpeg($dst_img, $filename, 90);
  82. }
  83. imagedestroy($dst_img);
  84. imagedestroy($src_img);
  85. }
  86. ?>
  87. <html>
  88. <head>
  89. <title>Gallery</title>
  90. <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
  91. <link rel='stylesheet' id='googlefonts-css' href='http://fonts.googleapis.com/css?family=Norican%7CAlegreya%3A400italic%2C700italic%2C400%2C700%7CStint+Ultra+Condensed&#038;ver=3.3.2' type='text/css' media='all' />
  92. <link rel="stylesheet" type="text/css" href="style.css">
  93. <script language="JavaScript">
  94. var request = false;
  95. function lightroomToggle(id, filename) {
  96. if (document.getElementById(id).name == "add")
  97. lightroomAction("add", id, filename);
  98. else
  99. lightroomAction("remove", id, filename);
  100. }
  101. function lightroomAction(action, id, filename) {
  102. if (window.XMLHttpRequest)
  103. request = new XMLHttpRequest();
  104. if (!request) {
  105. alert("Could not create XMLHttpRequest.");
  106. return false;
  107. } else {
  108. request.open('post', "lightroom_api.php", true);
  109. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  110. request.send('file=' + encodeURIComponent(filename) + '&action='+action);
  111. request.onreadystatechange = function() {
  112. if (request.readyState == 4) {
  113. if (request.status != 200) {
  114. alert("Request finished with error: " + request.status);
  115. } else {
  116. if (request.responseText == "success") {
  117. if (action == "add") {
  118. document.getElementById(id).name = "remove";
  119. document.getElementById(id).src = "icons/remove.png";
  120. } else {
  121. document.getElementById(id).name = "add";
  122. document.getElementById(id).src = "icons/add.png";
  123. }
  124. }
  125. else
  126. alert(request.responseText);
  127. }
  128. }
  129. };
  130. }
  131. }
  132. function lightroomZipClean() {
  133. if (window.XMLHttpRequest)
  134. request = new XMLHttpRequest();
  135. if (!request) {
  136. return false;
  137. } else {
  138. request.open('post', "lightroom_api.php", true);
  139. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  140. request.send('action=zipClean');
  141. request.onreadystatechange = function() { };
  142. }
  143. }
  144. </script>
  145. </head>
  146. <body bgcolor="#000000" onload="lightroomZipClean();">
  147. <img class="backgroundImage" src="icons/darkwood.jpg"/>
  148. <center><div class="caption">Hochzeit</div></center>
  149. <?php
  150. if ($dir != $toplevelDir) {
  151. $dirUp = trim($dir, "/");
  152. $dirUp = substr($dirUp, 0, strrpos($dirUp, "/"));
  153. echo "<div class=\"backLabel\"><a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?getDir=".$dirUp."/\">Zur&uuml;ck</a></div>";
  154. }
  155. ?>
  156. <div style="position: fixed; top: 20px; right: 20px;"><a href="lightroom.php"><img src="icons/lightroom.png"></a></div>
  157. <table class="grid">
  158. <?php
  159. // Folder
  160. echo "<tr>";
  161. for($i = 0; $i < count($folders); $i++) {
  162. if ($i%3 == 0)
  163. echo "</tr><tr>";
  164. echo "<td class=\"gridCell\">";
  165. echo "<a href=\"".$_SERVER['PHP_SELF']."?getDir=".$dir.$folders[$i]."/\">";
  166. echo "<img src=\"icons/album.png\" class=\"gridIcon\"><div class=\"gridLabel\">".$folders[$i]."</div>";
  167. echo "</a>";
  168. echo "</td>";
  169. }
  170. echo "</tr>";
  171. $sessionLightroomFiles = array();
  172. if (isset($_SESSION["lightroomFiles"]))
  173. $sessionLightroomFiles = $_SESSION["lightroomFiles"];
  174. // Files
  175. echo "<tr>";
  176. for($i = 0; $i < count($files); $i++) {
  177. if ($i%3 == 0)
  178. echo "</tr><tr>";
  179. echo "<td class=\"gridCell\" onMouseover=\"document.getElementById('lightRoomButton".$i."').style.visibility = 'visible';\" onMouseout=\"document.getElementById('lightRoomButton".$i."').style.visibility = 'hidden';\">";
  180. echo "<a href=\"JavaScript: startSlideShow(".$i.");\">";
  181. $thumbnail = "thumbnails/".md5($dir.$files[$i])."jpg";
  182. if (!file_exists($thumbnail))
  183. createthumb($dir . $files[$i], $thumbnail, 250, 250);
  184. echo "<div class=\"gridIconShadow\">";
  185. echo "<img src=\"".$thumbnail."\" class=\"gridIcon\">";
  186. echo "</div>";
  187. //echo "<div class=\"gridLabel\">".$files[$i]."</div>";
  188. echo "</a>";
  189. echo "<div id=\"lightRoomButton".$i."\" class=\"lightroomAddButton\"><a href=\"JavaScript: lightroomToggle('lightRoomButtonIcon".$i."', '".$dir.$files[$i]."');\"><img id=\"lightRoomButtonIcon".$i."\" ";
  190. if (in_array($dir.$files[$i], $sessionLightroomFiles))
  191. echo "name=\"remove\" src=\"icons/remove.png\"";
  192. else
  193. echo "name=\"add\" src=\"icons/add.png\"";
  194. echo " width=\"32\" height=\"32\"/></a></div>";
  195. echo "</td>";
  196. }
  197. echo "</tr>";
  198. ?>
  199. </table>
  200. <center>
  201. <?php
  202. if ($offset > 0) {
  203. $tmp = $offset - $maxCount;
  204. if ($tmp < 0)
  205. $tmp = 0;
  206. echo "<a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?getDir=".$dir."/&offset=".$tmp."\">&lt;</a>";
  207. }
  208. if (($count > $offset + $maxCount) || ($offset > 0))
  209. echo "<font class=\"gridLabel\">&nbsp; - &nbsp;</font>";
  210. if ($count > $offset + $maxCount)
  211. echo "<a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?getDir=".$dir."/&offset=".($offset + $maxCount)."\">&gt;</a>";
  212. ?>
  213. </center>
  214. <div id="slideShow" class="slideShow">
  215. <script language="JavaScript">
  216. var files = new Array();
  217. <?php
  218. for($i = 0; $i < count($files); $i++) {
  219. echo "files.push(\"".$dir.$files[$i]."\")\n";
  220. }
  221. ?>
  222. var slideShowIndex = 0;
  223. function startSlideShow(index) {
  224. var elem = document.getElementById('slideShowItem');
  225. elem.src = "";
  226. slideShowIndex = index;
  227. elem.src = files[slideShowIndex];
  228. resizeToMax();
  229. document.getElementById('slideShow').style.visibility = "visible";
  230. }
  231. function stopSlideShow() {
  232. var elem = document.getElementById('slideShowItem');
  233. document.getElementById('slideShow').style.visibility = "hidden";
  234. elem.src = "";
  235. }
  236. function next() {
  237. var elem = document.getElementById('slideShowItem');
  238. if (slideShowIndex >= files.length-1)
  239. slideShowIndex = 0;
  240. else
  241. slideShowIndex += 1;
  242. elem.src = files[slideShowIndex];
  243. resizeToMax();
  244. }
  245. function previous() {
  246. var elem = document.getElementById('slideShowItem');
  247. if (slideShowIndex <= 0)
  248. slideShowIndex = files.length-1;
  249. else
  250. slideShowIndex -= 1;
  251. elem.src = files[slideShowIndex];
  252. resizeToMax();
  253. }
  254. function resizeToMax(){
  255. myImage = new Image()
  256. var img = document.getElementById('slideShowItem');
  257. myImage.src = img.src;
  258. if(myImage.width / document.body.clientWidth > myImage.height / document.body.clientHeight) {
  259. img.style.width = "95%";
  260. } else {
  261. img.style.height = "95%";
  262. }
  263. }
  264. </script>
  265. <div id="slideShowItemContainer"><img id="slideShowItem" class="slideShowItem" src=""/></div>
  266. <table style="position: absolute; left: 0px; top: 0px;" width="100%" height="100%">
  267. <tr>
  268. <td class="slideShowPreviousButton" onClick="javascript: previous();">&nbsp;</td>
  269. <td class="slideShowCloseButton" onClick="javascript: stopSlideShow();">&nbsp;</td>
  270. <td class="slideShowNextButton" onClick="javascript: next();">&nbsp;</td>
  271. </tr>
  272. </table>
  273. </div>
  274. </body>
  275. </html>