photo.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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($photoID) {
  54. global $database;
  55. $result = $database->query("SELECT star FROM lychee_photos WHERE id = '$photoID';");
  56. $row = $result->fetch_object();
  57. if ($row->star == 0) {
  58. $star = 1;
  59. } else {
  60. $star = 0;
  61. }
  62. $result = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$photoID';");
  63. return true;
  64. }
  65. function setAlbum($photoID, $newAlbum) {
  66. global $database;
  67. $result = $database->query("UPDATE lychee_photos SET album = '$newAlbum' WHERE id = '$photoID';");
  68. if (!$result) return false;
  69. else return true;
  70. }
  71. function setPhotoTitle($photoID, $title) {
  72. global $database;
  73. if (strlen($title)>30) return false;
  74. $result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id = '$photoID';");
  75. if (!$result) return false;
  76. else return true;
  77. }
  78. function setPhotoDescription($photoID, $description) {
  79. global $database;
  80. $description = htmlentities($description);
  81. if (strlen($description)>800) return false;
  82. $result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
  83. if (!$result) return false;
  84. return true;
  85. }
  86. function deletePhoto($photoID) {
  87. global $database;
  88. $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
  89. if (!$result) return false;
  90. $row = $result->fetch_object();
  91. $retinaUrl = explode(".", $row->thumbUrl);
  92. $unlink1 = unlink("../uploads/big/".$row->url);
  93. $unlink2 = unlink("../uploads/thumb/".$row->thumbUrl);
  94. $unlink3 = unlink("../uploads/thumb/".$retinaUrl[0].'@2x.'.$retinaUrl[1]);
  95. $result = $database->query("DELETE FROM lychee_photos WHERE id = '$photoID';");
  96. if (!$unlink1 || !$unlink2 || !$unlink3) return false;
  97. if (!$result) return false;
  98. return true;
  99. }
  100. function isPhotoPublic($photoID, $password) {
  101. global $database;
  102. if (is_numeric($photoID)) {
  103. $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
  104. } else {
  105. $query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';";
  106. }
  107. $result = $database->query($query);
  108. $row = $result->fetch_object();
  109. if (!is_numeric($photoID)&&!$row) return true;
  110. if ($row->public==1) return true;
  111. else {
  112. $cAP = checkAlbumPassword($row->album, $password);
  113. $iAP = isAlbumPublic($row->album);
  114. if ($iAP&&$cAP) return true;
  115. else return false;
  116. }
  117. }
  118. function getPhotoArchive($photoID) {
  119. global $database;
  120. $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
  121. $row = $result->fetch_object();
  122. $extension = array_reverse(explode('.', $row->url));
  123. if ($row->title=='') $row->title = 'Untitled';
  124. header("Content-Type: application/octet-stream");
  125. header("Content-Disposition: attachment; filename=\"$row->title.$extension[0]\"");
  126. header("Content-Length: " . filesize("../uploads/big/$row->url"));
  127. readfile("../uploads/big/$row->url");
  128. return true;
  129. }
  130. ?>