photo.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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($photoIDs) {
  54. global $database;
  55. $error = false;
  56. $result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);");
  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($photoIDs, $albumID) {
  67. global $database;
  68. $result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($photoIDs);");
  69. if (!$result) return false;
  70. return true;
  71. }
  72. function setPhotoTitle($photoIDs, $title) {
  73. global $database;
  74. if (strlen($title)>30) return false;
  75. $result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id IN ($photoIDs);");
  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($photoIDs) {
  88. global $database;
  89. $result = $database->query("SELECT * FROM lychee_photos WHERE id IN ($photoIDs);");
  90. while ($row = $result->fetch_object()) {
  91. // Get retina thumb url
  92. $thumbUrl2x = explode(".", $row->thumbUrl);
  93. $thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
  94. // Delete files
  95. if (!unlink('../uploads/big/' . $row->url)) return false;
  96. if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
  97. if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false;
  98. // Delete db entry
  99. $delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;");
  100. if (!$delete) return false;
  101. }
  102. if (!$result) return false;
  103. return true;
  104. }
  105. function isPhotoPublic($photoID, $password) {
  106. global $database;
  107. if (is_numeric($photoID)) {
  108. $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
  109. } else {
  110. $query = "SELECT * FROM lychee_photos WHERE import_name = '../uploads/import/$photoID';";
  111. }
  112. $result = $database->query($query);
  113. $row = $result->fetch_object();
  114. if (!is_numeric($photoID)&&!$row) return true;
  115. if ($row->public==1) return true;
  116. else {
  117. $cAP = checkAlbumPassword($row->album, $password);
  118. $iAP = isAlbumPublic($row->album);
  119. if ($iAP&&$cAP) return true;
  120. else return false;
  121. }
  122. }
  123. function getPhotoArchive($photoID) {
  124. global $database;
  125. $result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
  126. $row = $result->fetch_object();
  127. $extension = array_reverse(explode('.', $row->url));
  128. if ($row->title=='') $row->title = 'Untitled';
  129. header("Content-Type: application/octet-stream");
  130. header("Content-Disposition: attachment; filename=\"$row->title.$extension[0]\"");
  131. header("Content-Length: " . filesize("../uploads/big/$row->url"));
  132. readfile("../uploads/big/$row->url");
  133. return true;
  134. }
  135. ?>