photo.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. $query = "SELECT * FROM lychee_photos WHERE id = '$photoID';";
  12. $result = $database->query($query);
  13. $return = $result->fetch_array();
  14. if ($albumID!='false') {
  15. if ($return['album']!=0) {
  16. $result = $database->query("SELECT public FROM lychee_albums WHERE id = '" . $return['album'] . "';");
  17. $return_album = $result->fetch_array();
  18. if ($return_album['public']=="1") $return['public'] = "2";
  19. }
  20. $return['original_album'] = $return['album'];
  21. $return['album'] = $albumID;
  22. $return['sysdate'] = date('d M. Y', strtotime($return['sysdate']));
  23. if (strlen($return['takedate'])>0) $return['takedate'] = date('d M. Y', strtotime($return['takedate']));
  24. }
  25. unset($return['album_public']);
  26. return $return;
  27. }
  28. function setPhotoPublic($photoID, $url) {
  29. global $database;
  30. $result = $database->query("SELECT public FROM lychee_photos WHERE id = '$photoID';");
  31. $row = $result->fetch_object();
  32. $public = ($row->public==0 ? 1 : 0);
  33. $result = $database->query("UPDATE lychee_photos SET public = '$public' WHERE id = '$photoID';");
  34. if (!$result) return false;
  35. return true;
  36. }
  37. function setPhotoStar($photoIDs) {
  38. global $database;
  39. $error = false;
  40. $result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($photoIDs);");
  41. while ($row = $result->fetch_object()) {
  42. $star = ($row->star==0 ? 1 : 0);
  43. $star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';");
  44. if (!$star) $error = true;
  45. }
  46. if ($error) return false;
  47. return true;
  48. }
  49. function setPhotoAlbum($photoIDs, $albumID) {
  50. global $database;
  51. $result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($photoIDs);");
  52. if (!$result) return false;
  53. return true;
  54. }
  55. function setPhotoTitle($photoIDs, $title) {
  56. global $database;
  57. if (strlen($title)>50) return false;
  58. $result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id IN ($photoIDs);");
  59. if (!$result) return false;
  60. return true;
  61. }
  62. function setPhotoDescription($photoID, $description) {
  63. global $database;
  64. $description = htmlentities($description);
  65. if (strlen($description)>1000) return false;
  66. $result = $database->query("UPDATE lychee_photos SET description = '$description' WHERE id = '$photoID';");
  67. if (!$result) return false;
  68. return true;
  69. }
  70. function setPhotoTags($photoIDs, $tags) {
  71. global $database;
  72. // Parse tags
  73. $tags = preg_replace('/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/', ',', $tags);
  74. $tags = preg_replace('/,$|^,/', ',', $tags);
  75. if (strlen($tags)>1000) return false;
  76. $result = $database->query("UPDATE lychee_photos SET tags = '$tags' WHERE id IN ($photoIDs);");
  77. if (!$result) return false;
  78. return true;
  79. }
  80. function deletePhoto($photoIDs) {
  81. global $database;
  82. $result = $database->query("SELECT id, url, thumbUrl FROM lychee_photos WHERE id IN ($photoIDs);");
  83. while ($row = $result->fetch_object()) {
  84. // Get retina thumb url
  85. $thumbUrl2x = explode(".", $row->thumbUrl);
  86. $thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
  87. // Delete files
  88. if (!unlink('../uploads/big/' . $row->url)) return false;
  89. if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
  90. if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false;
  91. // Delete db entry
  92. $delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;");
  93. if (!$delete) return false;
  94. }
  95. if (!$result) return false;
  96. return true;
  97. }
  98. function isPhotoPublic($photoID, $password) {
  99. global $database;
  100. $query = "SELECT public, album FROM lychee_photos WHERE id = '$photoID';";
  101. $result = $database->query($query);
  102. $row = $result->fetch_object();
  103. if ($row->public==1) return true;
  104. else {
  105. $cAP = checkAlbumPassword($row->album, $password);
  106. $iAP = isAlbumPublic($row->album);
  107. if ($iAP&&$cAP) return true;
  108. return false;
  109. }
  110. }
  111. function getPhotoArchive($photoID) {
  112. global $database;
  113. $result = $database->query("SELECT title, url FROM lychee_photos WHERE id = '$photoID';");
  114. $row = $result->fetch_object();
  115. $extension = array_reverse(explode('.', $row->url));
  116. if ($row->title=='') $row->title = 'Untitled';
  117. header("Content-Type: application/octet-stream");
  118. header("Content-Disposition: attachment; filename=\"$row->title.$extension[0]\"");
  119. header("Content-Length: " . filesize("../uploads/big/$row->url"));
  120. readfile("../uploads/big/$row->url");
  121. return true;
  122. }
  123. ?>