An PHP based Image Database
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
6.6 KiB

  1. <?
  2. //
  3. // Copyright (c) 2013 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
  4. //
  5. // Permission to use, copy, modify, and/or distribute this software for any purpose
  6. // with or without fee is hereby granted, provided that the above copyright notice
  7. // and this permission notice appear in all copies.
  8. //
  9. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  10. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  11. // FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  12. // OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  14. // ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. //
  16. require_once("header.php");
  17. ?>
  18. <style type="text/css">
  19. #imageViewer_sidebar {
  20. opacity: 0.9;
  21. position: fixed;
  22. top: 41px;
  23. bottom: 0;
  24. left: 0;
  25. width: 200px;
  26. z-index: 1032;
  27. overflow: scroll;
  28. padding-top: 8px;
  29. background-color: #ffffff;
  30. -webkit-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  31. -moz-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  32. box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  33. }
  34. @media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
  35. #imageViewer_sidebar {
  36. width: 100px;
  37. }
  38. }
  39. #imageViewer_sidebar .basic_info {
  40. padding-top: 5px;
  41. padding-left: 5px;
  42. padding-right: 5px;
  43. }
  44. #imageViewer_sidebar .tags {
  45. padding-top: 5px;
  46. padding-left: 5px;
  47. padding-right: 5px;
  48. }
  49. #imageViewer_sidebar .tags_edit {
  50. width: 180px;
  51. height: 250px;
  52. }
  53. @media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
  54. #imageViewer_sidebar .tags_edit {
  55. width: 80px;
  56. height: 150px;
  57. }
  58. }
  59. #imageViewer_main {
  60. position: fixed;
  61. z-index: 1031;
  62. border:4px solid #ffffff;
  63. border-radius: 4px;
  64. background-color: #ffffff;
  65. -webkit-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  66. -moz-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  67. box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  68. }
  69. </style>
  70. <div id="image_loader" style="display: none;"></div>
  71. <div id="imageViewer_sidebar">
  72. <div class="basic_info"></div>
  73. <div class="tags"></div>
  74. <?if (isset($_MGM['user'])) {?>
  75. <textarea class="tags_edit hide"></textarea>
  76. <button type="button" class="btn" id="imageViewer_editTags">Edit Tags</button>
  77. <div id="imageViewer_apiloader" style="display: none;"></div>
  78. <?}?>
  79. </div>
  80. <div id="imageViewer_main"></div>
  81. <script type="text/javascript">
  82. function loadNext() {
  83. $("#image_loader").load("<?=generateURL("api/hash/".$_MGM['path'][1])?>/", function(response, status, xhr) {
  84. loadImage($("#image_loader #image"), 0);
  85. });
  86. }
  87. var imageViewing = "";
  88. function repositionImage() {
  89. if (imageViewing=="") {
  90. return;
  91. }
  92. var image = $("#image_loader [hash='"+imageViewing+"']");
  93. var width = image.attr("image_width");
  94. var height = image.attr("image_height");
  95. var spaceWidth = ($(window).width()-$("#imageViewer_sidebar").width())-20;
  96. var spaceHeight = ($(window).height()-$(".navbar").height())-20;
  97. var newWidth = width;
  98. var newHeight = height;
  99. if (width>spaceWidth || height>spaceHeight) {
  100. var widthFactor = spaceWidth/width;
  101. var heightFactor = spaceHeight/height;
  102. var scaleFactor = 1;
  103. if (widthFactor<heightFactor)
  104. scaleFactor = widthFactor;
  105. else
  106. scaleFactor = heightFactor;
  107. newWidth = Math.round(width*scaleFactor);
  108. newHeight = Math.round(height*scaleFactor);
  109. }
  110. $("imageViewer_main img").css({width: newWidth, height: newHeight});
  111. $("#imageViewer_main").css({top: (((spaceHeight-newHeight)/2)+$(".navbar").height())+5, right: ((spaceWidth-newWidth)/2)+5, width: newWidth, height: newHeight});
  112. }
  113. function bytesToSize(bytes) {
  114. var size = bytes;
  115. var type = "Bytes";
  116. if (size>=1024) {
  117. size = size/1024;
  118. type = "KB";
  119. }
  120. if (size>=1024) {
  121. size = size/1024;
  122. type = "MB";
  123. }
  124. if (size>=1024) {
  125. size = size/1024;
  126. type = "GB";
  127. }
  128. return (Math.round(size*100)/100)+" "+type;
  129. }
  130. function loadImage(image) {
  131. imageViewing = image.attr("hash");
  132. $("#imageViewer_main").html("<a href=\""+image.attr("original")+"\" target=\"blank\"><img src=\""+image.attr("original")+"\" /></a>");
  133. repositionImage();
  134. $("#imageViewer_sidebar .basic_info").html("");
  135. $("#imageViewer_sidebar .basic_info").append("<a href=\"<?=generateURL("hash/")?>"+image.attr("hash")+"/\">Image Link</a><br />");
  136. $("#imageViewer_sidebar .basic_info").append("Date: "+date("m/d/y h:i:s A", image.attr("time"))+"<br />");
  137. $("#imageViewer_sidebar .basic_info").append("Size: "+image.attr("image_width")+"x"+image.attr("image_height")+"<br />");
  138. $("#imageViewer_sidebar .basic_info").append("File Size: "+bytesToSize(image.attr("file_size"))+"<br />");
  139. $("#imageViewer_sidebar .tags").html("");
  140. var tagsEdit = "";
  141. var tags = image.attr("tags").split(" ");
  142. for (var i=0; i<tags.length; i++) {
  143. var tag = tags[i].replace(/_/g, " ");
  144. $("#imageViewer_sidebar .tags").append(tag+"<br />");
  145. tagsEdit += tag+"\n";
  146. }
  147. <?if (isset($_MGM['user'])) {?>
  148. $("#imageViewer_sidebar .tags_edit").val(tagsEdit);
  149. <?}?>
  150. <?if (isset($_MGM['user']) && $_MGM['user']['level']>=4) {?>
  151. if (image.attr("user")=="<?=$_MGM['user']['docid']?>") {
  152. $("#imageViewer_editTags").show();
  153. } else {
  154. $("#imageViewer_editTags").hide();
  155. }
  156. <?}?>
  157. }
  158. $(document).ready(function() {
  159. $("#imageViewer_sidebar").css({top: $(".navbar").height()});
  160. $(window).resize(function() {
  161. repositionImage();
  162. $("#imageViewer_sidebar").css({top: $(".navbar").height()});
  163. });
  164. <?if (isset($_MGM['user'])) {?>
  165. $("#imageViewer_editTags").click(function() {
  166. if (imageViewing=="") {
  167. return;
  168. }
  169. if ($(this).text()=="Edit Tags") {
  170. $(this).text("Save Tags");
  171. $("#imageViewer_sidebar .tags").addClass("hide");
  172. $("#imageViewer_sidebar .tags_edit").removeClass("hide");
  173. } else {
  174. $(this).text("Edit Tags");
  175. $("#imageViewer_sidebar .tags").removeClass("hide");
  176. $("#imageViewer_sidebar .tags_edit").addClass("hide");
  177. var tagsToSave = "";
  178. var tags = $("#imageViewer_sidebar .tags_edit").val().split("\n");
  179. for (var i=0; i<tags.length; i++) {
  180. var tag = tags[i].replace(/\s/g, "_");
  181. if (tag=="") {
  182. continue;
  183. }
  184. if (tagsToSave!="") {
  185. tagsToSave += " ";
  186. }
  187. tagsToSave += tag;
  188. }
  189. $("#imageViewer_sidebar .tags").html("");
  190. var tags = tagsToSave.split(" ");
  191. for (var i=0; i<tags.length; i++) {
  192. var tag = tags[i].replace(/_/g, " ");
  193. $("#imageViewer_sidebar .tags").append(tag+"<br />");
  194. }
  195. $("#imageViewer_apiloader").load("<?=generateURL("api/save_tags")?>/", {hash: imageViewing, tags: tagsToSave});
  196. }
  197. });
  198. <?}?>
  199. loadNext();
  200. });
  201. </script>
  202. <?
  203. require_once("footer.php");
  204. exit();
  205. ?>