admin.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 (count($files) < $maxCount && $count >= $offset && !in_array($dir.$file, $blacklist))
  43. $files[] = $file;
  44. ++$count;
  45. }
  46. }
  47. }
  48. }
  49. function createthumb($name, $filename, $new_w, $new_h)
  50. {
  51. $system = explode('.', $name);
  52. if (preg_match('/jpg|jpeg/', $system[1])) {
  53. $src_img = imagecreatefromjpeg($name);
  54. }
  55. if (preg_match('/png/', $system[1])) {
  56. $src_img = imagecreatefrompng($name);
  57. }
  58. if (!$src_img) {
  59. link("icons/image.png", $filename);
  60. return;
  61. }
  62. $old_w = imageSX($src_img);
  63. $old_h = imageSY($src_img);
  64. $old_x = 0;
  65. $old_y = 0;
  66. if ($old_w > $old_h) {
  67. $old_x = ($old_w - $old_h) / 2.0;
  68. $old_w = $old_h;
  69. }
  70. if ($old_w < $old_h) {
  71. $old_y = ($old_h - $old_w) / 2.0;
  72. $old_h = $old_w;
  73. }
  74. $dst_img=ImageCreateTrueColor($new_w, $new_h);
  75. imagecopyresampled($dst_img, $src_img, 0, 0, $old_x, $old_y, $new_w, $new_h, $old_w, $old_h);
  76. if (preg_match("/png/",$system[1])) {
  77. imagepng($dst_img, $filename, 90);
  78. } else {
  79. imagejpeg($dst_img, $filename, 90);
  80. }
  81. imagedestroy($dst_img);
  82. imagedestroy($src_img);
  83. }
  84. ?>
  85. <html>
  86. <head>
  87. <title>Gallery</title>
  88. <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
  89. <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' />
  90. <link rel="stylesheet" type="text/css" href="style.css">
  91. <script language="JavaScript">
  92. var request = false;
  93. function sortOut(filename) {
  94. if (window.XMLHttpRequest)
  95. request = new XMLHttpRequest();
  96. if (!request) {
  97. alert("Could not create XMLHttpRequest.");
  98. return false;
  99. } else {
  100. request.open('post', "lightroom_api.php", true);
  101. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  102. request.send('file=' + encodeURIComponent(filename) + '&action=sortOut');
  103. request.onreadystatechange = function() {
  104. if (request.readyState == 4) {
  105. if (request.status != 200) {
  106. alert("Request finished with error: " + request.status);
  107. } else {
  108. if (request.responseText == "success")
  109. location.replace("admin.php?getDir=<?php echo $dir; ?>&offset=<?php echo $offset; ?>");
  110. else
  111. alert(request.responseText);
  112. }
  113. }
  114. };
  115. }
  116. }
  117. function lightroomZipClean() {
  118. if (window.XMLHttpRequest)
  119. request = new XMLHttpRequest();
  120. if (!request) {
  121. return false;
  122. } else {
  123. request.open('post', "lightroom_api.php", true);
  124. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  125. request.send('action=zipClean');
  126. request.onreadystatechange = function() { };
  127. }
  128. }
  129. </script>
  130. </head>
  131. <body bgcolor="#000000">
  132. <img class="backgroundImage" src="icons/darkwood.jpg"/>
  133. <center><div class="caption">Hochzeit - Admin</div></center>
  134. <?php
  135. if ($dir != $toplevelDir) {
  136. $dirUp = trim($dir, "/");
  137. $dirUp = substr($dirUp, 0, strrpos($dirUp, "/"));
  138. echo "<div class=\"backLabel\"><a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?getDir=".$dirUp."/\">Zur&uuml;ck</a></div>";
  139. }
  140. ?>
  141. <table class="grid">
  142. <?php
  143. // Folder
  144. echo "<tr>";
  145. for($i = 0; $i < count($folders); $i++) {
  146. if ($i%3 == 0)
  147. echo "</tr><tr>";
  148. echo "<td class=\"gridCell\">";
  149. echo "<a href=\"".$_SERVER['PHP_SELF']."?getDir=".$dir.$folders[$i]."/\">";
  150. echo "<img src=\"icons/album.png\" class=\"gridIcon\"><div class=\"gridLabel\">".$folders[$i]."</div>";
  151. echo "</a>";
  152. echo "</td>";
  153. }
  154. echo "</tr>";
  155. $sessionLightroomFiles = array();
  156. if (isset($_SESSION["lightroomFiles"]))
  157. $sessionLightroomFiles = $_SESSION["lightroomFiles"];
  158. // Files
  159. echo "<tr>";
  160. for($i = 0; $i < count($files); $i++) {
  161. if ($i%3 == 0)
  162. echo "</tr><tr>";
  163. echo "<td class=\"gridCell\">";
  164. $thumbnail = "thumbnails/".md5($dir.$files[$i])."jpg";
  165. if (!file_exists($thumbnail))
  166. createthumb($dir . $files[$i], $thumbnail, 250, 250);
  167. echo "<div class=\"gridIconShadow\">";
  168. echo "<img src=\"".$thumbnail."\" class=\"gridIcon\">";
  169. echo "</div>";
  170. echo "<div id=\"lightRoomButton".$i."\" class=\"sortOutButton\"><a href=\"JavaScript: sortOut('".$dir.$files[$i]."');\"><img id=\"lightRoomButtonIcon".$i."\" name=\"remove\" src=\"icons/remove.png\" width=\"32\" height=\"32\"/></a></div>";
  171. echo "</td>";
  172. }
  173. echo "</tr>";
  174. ?>
  175. </table>
  176. <center>
  177. <?php
  178. if ($offset > 0) {
  179. $tmp = $offset - $maxCount;
  180. if ($tmp < 0)
  181. $tmp = 0;
  182. echo "<a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?getDir=".$dir."/&offset=".$tmp."\">&lt;</a>";
  183. }
  184. if (($count > $offset + $maxCount) || ($offset > 0))
  185. echo "<font class=\"gridLabel\">&nbsp; - &nbsp;</font>";
  186. if ($count > $offset + $maxCount)
  187. echo "<a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?getDir=".$dir."/&offset=".($offset + $maxCount)."\">&gt;</a>";
  188. ?>
  189. </center>
  190. </body>
  191. </html>