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.

197 lines
5.9 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 .tags_edit {
  40. width: 180px;
  41. height: 250px;
  42. }
  43. @media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
  44. #imageViewer_sidebar .tags_edit {
  45. width: 80px;
  46. height: 150px;
  47. }
  48. }
  49. #imageViewer_main {
  50. position: fixed;
  51. z-index: 1031;
  52. border:4px solid #ffffff;
  53. border-radius: 4px;
  54. background-color: #ffffff;
  55. -webkit-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  56. -moz-box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  57. box-shadow: 0 1px 10px rgba(0,0,0,0.1);
  58. }
  59. </style>
  60. <div id="image_loader" style="display: none;"></div>
  61. <?if (isset($_MGM['user']) && $_MGM['user']['level']<=2) {?>
  62. <div id="imageViewer_confirmDelete" class="modal hide fade" tabindex="-1" role="dialog">
  63. <div class="modal-header">
  64. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  65. <h3>Delete Image</h3>
  66. </div>
  67. <div class="modal-body">
  68. <p>You are about to delete an image from the database.</p>
  69. <p>Are you sure you wish to do this?</p>
  70. </div>
  71. <div class="modal-footer">
  72. <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
  73. <button class="btn btn-danger" data-dismiss="modal" id="imageViewer_confirmDelete_yes">Yes</button>
  74. </div>
  75. </div>
  76. <?}?>
  77. <div id="imageViewer_sidebar">
  78. <?if (isset($_MGM['user'])) {?>
  79. <textarea class="tags_edit"></textarea>
  80. <button type="button" class="btn" id="imageViewer_save">Save/Next</button>
  81. <?if ($_MGM['user']['level']<=2) {?>
  82. <br /><br /><button type="button" class="btn btn-danger" id="imageViewer_delete">Delete/Next</button>
  83. <?}?>
  84. <div id="imageViewer_apiloader" style="display: none;"></div>
  85. <?}?>
  86. </div>
  87. <div id="imageViewer_main"></div>
  88. <script type="text/javascript">
  89. function loadNext() {
  90. $("#image_loader").load("<?=generateURL("api/tagless")?>/", function(response, status, xhr) {
  91. loadImage($("#image_loader #image"), 0);
  92. });
  93. }
  94. var imageViewing = "";
  95. function repositionImage() {
  96. if (imageViewing=="") {
  97. return;
  98. }
  99. var image = $("#image_loader [hash='"+imageViewing+"']");
  100. var width = image.attr("image_width");
  101. var height = image.attr("image_height");
  102. var spaceWidth = ($(window).width()-$("#imageViewer_sidebar").width())-20;
  103. var spaceHeight = ($(window).height()-$(".navbar").height())-20;
  104. var newWidth = width;
  105. var newHeight = height;
  106. if (width>spaceWidth || height>spaceHeight) {
  107. var widthFactor = spaceWidth/width;
  108. var heightFactor = spaceHeight/height;
  109. var scaleFactor = 1;
  110. if (widthFactor<heightFactor)
  111. scaleFactor = widthFactor;
  112. else
  113. scaleFactor = heightFactor;
  114. newWidth = Math.round(width*scaleFactor);
  115. newHeight = Math.round(height*scaleFactor);
  116. }
  117. $("imageViewer_main img").css({width: newWidth, height: newHeight});
  118. $("#imageViewer_main").css({top: (((spaceHeight-newHeight)/2)+$(".navbar").height())+5, right: ((spaceWidth-newWidth)/2)+5, width: newWidth, height: newHeight});
  119. }
  120. function loadImage(image) {
  121. imageViewing = image.attr("hash");
  122. $("#imageViewer_main").html("<a href=\""+image.attr("original")+"\" target=\"blank\"><img src=\""+image.attr("original")+"\" /></a>");
  123. repositionImage();
  124. var tagsEdit = "";
  125. var tags = image.attr("tags").split(" ");
  126. for (var i=0; i<tags.length; i++) {
  127. var tag = tags[i].replace(/_/g, " ");
  128. tagsEdit += tag+"\n";
  129. }
  130. <?if (isset($_MGM['user'])) {?>
  131. $("#imageViewer_sidebar .tags_edit").val(tagsEdit);
  132. <?}?>
  133. <?if (isset($_MGM['user'])) {?>
  134. $("#imageViewer_sidebar .tags_edit").focus();
  135. <?}?>
  136. }
  137. $(document).ready(function() {
  138. $("#imageViewer_sidebar").css({top: $(".navbar").height()});
  139. $(window).resize(function() {
  140. repositionImage();
  141. $("#imageViewer_sidebar").css({top: $(".navbar").height()});
  142. });
  143. <?if (isset($_MGM['user'])) {?>
  144. $("#imageViewer_save").click(function() {
  145. if (imageViewing=="") {
  146. return;
  147. }
  148. var tagsToSave = "";
  149. var tags = $("#imageViewer_sidebar .tags_edit").val().split("\n");
  150. for (var i=0; i<tags.length; i++) {
  151. var tag = tags[i].replace(/\s/g, "_");
  152. if (tag=="") {
  153. continue;
  154. }
  155. if (tagsToSave!="") {
  156. tagsToSave += " ";
  157. }
  158. tagsToSave += tag;
  159. }
  160. $("#imageViewer_apiloader").load("<?=generateURL("api/save_tags")?>/", {hash: imageViewing, tags: tagsToSave}, function() {
  161. loadNext();
  162. });
  163. });
  164. <?if ($_MGM['user']['level']<=2) {?>
  165. $("#imageViewer_delete").click(function() {
  166. if (imageViewing=="") {
  167. return;
  168. }
  169. $("#imageViewer_confirmDelete").modal();
  170. });
  171. $("#imageViewer_confirmDelete_yes").click(function() {
  172. $("#imageViewer_apiloader").load("<?=generateURL("api/delete")?>/", {hash: imageViewing}, function() {
  173. loadNext();
  174. });
  175. });
  176. <?}?>
  177. <?}?>
  178. loadNext();
  179. });
  180. </script>
  181. <?
  182. require_once("footer.php");
  183. exit();
  184. ?>