lightroom.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. session_start();
  3. $maxCount = 30;
  4. $offset = 0;
  5. $count = 0;
  6. if (isset($_SESSION["lightroomFiles"])) {
  7. if (isset($_GET["offset"]))
  8. $offset = $_GET["offset"];
  9. $files = array();
  10. for ($i = 0; $i < count($_SESSION["lightroomFiles"]); ++$i) {
  11. if (count($files) < $maxCount && $count >= $offset) {
  12. $files[] = $_SESSION["lightroomFiles"][$i];
  13. }
  14. ++$count;
  15. }
  16. }
  17. function createthumb($name, $filename, $new_w, $new_h)
  18. {
  19. $system = explode('.', $name);
  20. if (preg_match('/jpg|jpeg/', $system[1])) {
  21. $src_img = imagecreatefromjpeg($name);
  22. }
  23. if (preg_match('/png/', $system[1])) {
  24. $src_img = imagecreatefrompng($name);
  25. }
  26. if (!$src_img) {
  27. link("icons/image.png", $filename);
  28. return;
  29. }
  30. $old_w = imageSX($src_img);
  31. $old_h = imageSY($src_img);
  32. $old_x = 0;
  33. $old_y = 0;
  34. if ($old_w > $old_h) {
  35. $old_x = ($old_w - $old_h) / 2.0;
  36. $old_w = $old_h;
  37. }
  38. if ($old_w < $old_h) {
  39. $old_y = ($old_h - $old_w) / 2.0;
  40. $old_h = $old_w;
  41. }
  42. $dst_img=ImageCreateTrueColor($new_w, $new_h);
  43. imagecopyresampled($dst_img, $src_img, 0, 0, $old_x, $old_y, $new_w, $new_h, $old_w, $old_h);
  44. if (preg_match("/png/",$system[1])) {
  45. imagepng($dst_img, $filename, 90);
  46. } else {
  47. imagejpeg($dst_img, $filename, 90);
  48. }
  49. imagedestroy($dst_img);
  50. imagedestroy($src_img);
  51. }
  52. ?>
  53. <html>
  54. <head>
  55. <title>Gallery</title>
  56. <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
  57. <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' />
  58. <link rel="stylesheet" type="text/css" href="style.css">
  59. <script language="JavaScript">
  60. var request = false;
  61. function lightroomRemoveItem(filename) {
  62. if (window.XMLHttpRequest)
  63. request = new XMLHttpRequest();
  64. if (!request) {
  65. alert("Could not create XMLHttpRequest.");
  66. return false;
  67. } else {
  68. request.open('post', "lightroom_api.php", true);
  69. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  70. request.send('file=' + encodeURIComponent(filename) + '&action=remove');
  71. request.onreadystatechange = function() {
  72. if (request.readyState == 4) {
  73. if (request.status != 200) {
  74. alert("Request finished with error: " + request.status);
  75. } else {
  76. if (request.responseText == "success")
  77. location.replace("lightroom.php?offset=<?php echo $offset; ?>");
  78. else
  79. alert(request.responseText);
  80. }
  81. }
  82. };
  83. }
  84. }
  85. function lightroomZip() {
  86. if (window.XMLHttpRequest)
  87. request = new XMLHttpRequest();
  88. if (!request) {
  89. alert("Could not create XMLHttpRequest.");
  90. return false;
  91. } else {
  92. document.getElementById("loadingIndicator").style.visibility = "visible";
  93. request.open('post', "lightroom_api.php", true);
  94. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  95. request.send('action=zip');
  96. request.onreadystatechange = function() {
  97. if (request.readyState == 4) {
  98. if (request.status != 200) {
  99. alert("Request finished with error: " + request.status);
  100. } else {
  101. if (request.responseText.search("success") == 0) {
  102. var zipfile = request.responseText.split(":")[1];
  103. if (zipfile != "")
  104. window.location.href = zipfile;
  105. } else {
  106. alert(request.responseText);
  107. }
  108. document.getElementById("loadingIndicator").style.visibility = "hidden";
  109. }
  110. }
  111. };
  112. }
  113. }
  114. </script>
  115. </head>
  116. <body bgcolor="#000000">
  117. <img class="backgroundImage" src="icons/darkwood.jpg"/>
  118. <center><div class="caption">Lightroom</div></center>
  119. <div style="position: fixed; top: 20px; left: 20px;"><a class="gridLabel" href="index.php">Zur&uuml;ck</a></div>
  120. <div style="position: fixed; top: 20px; right: 20px;"><a href="JavaScript: lightroomZip();"><img src="icons/zip.png"></a></div>
  121. <div id="loadingIndicator" style="position: fixed; top: 20px; right: 27px; visibility: hidden;"><img src="icons/ajax-loader.gif"></div>
  122. <table class="grid">
  123. <?php
  124. if (isset($files)) {
  125. // Files
  126. echo "<tr>";
  127. for($i = 0; $i < count($files); $i++) {
  128. if ($i%3 == 0)
  129. echo "</tr><tr>";
  130. echo "<td class=\"gridCell\" onMouseover=\"document.getElementById('lightRoomButton".$i."').style.visibility = 'visible';\" onMouseout=\"document.getElementById('lightRoomButton".$i."').style.visibility = 'hidden';\">";
  131. $thumbnail = "thumbnails/".md5($files[$i])."jpg";
  132. if (!file_exists($thumbnail))
  133. createthumb($files[$i], $thumbnail, 250, 250);
  134. echo "<div class=\"gridIconShadow\">";
  135. echo "<img src=\"".$thumbnail."\" class=\"gridIcon\">";
  136. echo "</div>";
  137. echo "<div id=\"lightRoomButton".$i."\" class=\"lightroomAddButton\"><a href=\"JavaScript: lightroomRemoveItem('".$files[$i]."');\"><img src=\"icons/remove.png\" width=\"32\" height=\"32\"/></a></div>";
  138. echo "</td>";
  139. }
  140. echo "</tr>";
  141. }
  142. ?>
  143. </table>
  144. <center>
  145. <?php
  146. if ($offset > 0) {
  147. $tmp = $offset - $maxCount;
  148. if ($tmp < 0)
  149. $tmp = 0;
  150. echo "<a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?offset=".$tmp."\">&lt;</a>";
  151. }
  152. if (($count > $offset + $maxCount) || ($offset > 0))
  153. echo "<font class=\"gridLabel\">&nbsp; - &nbsp;</font>";
  154. if ($count > $offset + $maxCount)
  155. echo "<a class=\"gridLabel\" href=\"".$_SERVER['PHP_SELF']."?offset=".($offset + $maxCount)."\">&gt;</a>";
  156. ?>
  157. </center>
  158. </body>
  159. </html>