photo.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * @name Photo Module
  4. * @author Philipp Maurer
  5. * @author Tobias Reich
  6. * @copyright 2014 by Philipp Maurer, Tobias Reich
  7. */
  8. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  9. function getPhoto($photoID, $albumID) {
  10. global $database;
  11. if (!is_numeric($photoID)) {
  12. $result = $database->query("SELECT COUNT(*) AS quantity FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';");
  13. $row = $result->fetch_object();
  14. if ($row->quantity == 0) {
  15. importPhoto($photoID, 's');
  16. }
  17. if (is_file("../uploads/import/$photoID")) {
  18. importPhoto($photoID, 's');
  19. }
  20. $query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID' ORDER BY ID DESC;";
  21. } else {
  22. $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
  23. }
  24. $result = $database->query($query);
  25. $return = $result->fetch_array();
  26. if ($albumID!='false') {
  27. if ($return['album']!=0) {
  28. $result = $database->query("SELECT public FROM lychee_albums WHERE id = '" . $return['album'] . "';");
  29. $return_album = $result->fetch_array();
  30. if ($return_album['public']=="1") $return['public'] = "2";
  31. }
  32. $return['original_album'] = $return['album'];
  33. $return['album'] = $albumID;
  34. $return['sysdate'] = date('d M. Y', strtotime($return['sysdate']));
  35. if (strlen($return['takedate'])>0) $return['takedate'] = date('d M. Y', strtotime($return['takedate']));
  36. }
  37. unset($return['album_public']);
  38. return $return;
  39. }
  40. function setPhotoPublic($photoID, $url) {
  41. global $database;
  42. $result = $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';");
  43. $row = $result->fetch_object();
  44. if ($row->public == 0){
  45. $public = 1;
  46. } else {
  47. $public = 0;
  48. }
  49. $result = $database->query("UPDATE lychee_photos SET public = '$public' WHERE id = '$photoID';");
  50. if (!$result) return false;
  51. return true;
  52. }
  53. function setPhotoStar($ids) {
  54. global $database;
  55. $error = false;
  56. $result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($ids);");
  57. while ($row = $result->fetch_object()) {
  58. if ($row->star==0) $star = 1;
  59. else $star = 0;
  60. $star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';");
  61. if (!$star) $error = true;
  62. }
  63. if ($error) return false;
  64. return true;
  65. }
  66. function setAlbum($ids, $albumID) {
  67. global $database;
  68. $result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($ids);");
  69. if (!$result) return false;
  70. return true;
  71. }
  72. function setPhotoTitle($photoID, $title) {
  73. global $database;
  74. if (strlen($title)>30) return false;
  75. $result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id = '$photoID';");
  76. if (!$result) return false;
  77. return true;
  78. }
  79. function setPhotoDescription($photoID, $description) {
  80. global $database;
  81. $description = htmlentities($description);
  82. if (strlen($description)>800) return false;
  83. $result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
  84. if (!$result) return false;
  85. return true;
  86. }
  87. function deletePhoto($photoID) {
  88. global $database;
  89. $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
  90. if (!$result) return false;
  91. $row = $result->fetch_object();
  92. $retinaUrl = explode(".", $row->thumbUrl);
  93. $unlink1 = unlink("../uploads/big/".$row->url);
  94. $unlink2 = unlink("../uploads/thumb/".$row->thumbUrl);
  95. $unlink3 = unlink("../uploads/thumb/".$retinaUrl[0].'@2x.'.$retinaUrl[1]);
  96. $result = $database->query("DELETE FROM lychee_photos WHERE id = '$photoID';");
  97. if (!$unlink1 || !$unlink2 || !$unlink3) return false;
  98. if (!$result) return false;
  99. return true;
  100. }
  101. function isPhotoPublic($photoID, $password) {
  102. global $database;
  103. if (is_numeric($photoID)) {
  104. $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
  105. } else {
  106. $query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';";
  107. }
  108. $result = $database->query($query);
  109. $row = $result->fetch_object();
  110. if (!is_numeric($photoID)&&!$row) return true;
  111. if ($row->public==1) return true;
  112. else {
  113. $cAP = checkAlbumPassword($row->album, $password);
  114. $iAP = isAlbumPublic($row->album);
  115. if ($iAP&&$cAP) return true;
  116. else return false;
  117. }
  118. }
  119. function getPhotoArchive($photoID) {
  120. global $database;
  121. $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
  122. $row = $result->fetch_object();
  123. $extension = array_reverse(explode('.', $row->url));
  124. if ($row->title=='') $row->title = 'Untitled';
  125. header("Content-Type: application/octet-stream");
  126. header("Content-Disposition: attachment; filename=\"$row->title.$extension[0]\"");
  127. header("Content-Length: " . filesize("../uploads/big/$row->url"));
  128. readfile("../uploads/big/$row->url");
  129. return true;
  130. }
  131. ?>