Admin.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. ###
  3. # @name Admin Access
  4. # @copyright 2015 by Tobias Reich
  5. ###
  6. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  7. final class Admin extends Access {
  8. public function check($fn) {
  9. switch ($fn) {
  10. # Album functions
  11. case 'Album::getAll': $this->getAlbums(); break;
  12. case 'Album::get': $this->getAlbum(); break;
  13. case 'Album::add': $this->addAlbum(); break;
  14. case 'Album::setTitle': $this->setAlbumTitle(); break;
  15. case 'Album::setDescription': $this->setAlbumDescription(); break;
  16. case 'Album::setPublic': $this->setAlbumPublic(); break;
  17. case 'Album::delete': $this->deleteAlbum(); break;
  18. case 'Album::merge': $this->mergeAlbums(); break;
  19. # Photo functions
  20. case 'Photo::get': $this->getPhoto(); break;
  21. case 'Photo::setTitle': $this->setPhotoTitle(); break;
  22. case 'Photo::setDescription': $this->setPhotoDescription(); break;
  23. case 'Photo::setStar': $this->setPhotoStar(); break;
  24. case 'Photo::setPublic': $this->setPhotoPublic(); break;
  25. case 'Photo::setAlbum': $this->setPhotoAlbum(); break;
  26. case 'Photo::setTags': $this->setPhotoTags(); break;
  27. case 'Photo::duplicate': $this->duplicatePhoto(); break;
  28. case 'Photo::delete': $this->deletePhoto(); break;
  29. # Add functions
  30. case 'Photo::add': $this->upload(); break;
  31. case 'Import::url': $this->importUrl(); break;
  32. case 'Import::server': $this->importServer(); break;
  33. # Search functions
  34. case 'search': $this->search(); break;
  35. # Session functions
  36. case 'Session::init': $this->init(); break;
  37. case 'Session::login': $this->login(); break;
  38. case 'Session::logout': $this->logout(); break;
  39. # Settings functions
  40. case 'Settings::setLogin': $this->setLogin(); break;
  41. case 'Settings::setSorting': $this->setSorting(); break;
  42. case 'Settings::setDropboxKey': $this->setDropboxKey(); break;
  43. # $_GET functions
  44. case 'Album::getArchive': $this->getAlbumArchive(); break;
  45. case 'Photo::getArchive': $this->getPhotoArchive(); break;
  46. # Error
  47. default: exit('Error: Function not found! Please check the spelling of the called function.');
  48. return false; break;
  49. }
  50. return true;
  51. }
  52. # Album functions
  53. private function getAlbums() {
  54. $album = new Album(null);
  55. echo json_encode($album->getAll(false));
  56. }
  57. private function getAlbum() {
  58. Module::dependencies(isset($_POST['albumID']));
  59. $album = new Album($_POST['albumID']);
  60. echo json_encode($album->get());
  61. }
  62. private function addAlbum() {
  63. Module::dependencies(isset($_POST['title']));
  64. $album = new Album(null);
  65. echo $album->add($_POST['title']);
  66. }
  67. private function setAlbumTitle() {
  68. Module::dependencies(isset($_POST['albumIDs'], $_POST['title']));
  69. $album = new Album($_POST['albumIDs']);
  70. echo $album->setTitle($_POST['title']);
  71. }
  72. private function setAlbumDescription() {
  73. Module::dependencies(isset($_POST['albumID'], $_POST['description']));
  74. $album = new Album($_POST['albumID']);
  75. echo $album->setDescription($_POST['description']);
  76. }
  77. private function setAlbumPublic() {
  78. Module::dependencies(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']));
  79. $album = new Album($_POST['albumID']);
  80. echo $album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']);
  81. }
  82. private function deleteAlbum() {
  83. Module::dependencies(isset($_POST['albumIDs']));
  84. $album = new Album($_POST['albumIDs']);
  85. echo $album->delete();
  86. }
  87. private function mergeAlbums() {
  88. Module::dependencies(isset($_POST['albumIDs']));
  89. $album = new Album($_POST['albumIDs']);
  90. echo $album->merge();
  91. }
  92. # Photo functions
  93. private function getPhoto() {
  94. Module::dependencies(isset($_POST['photoID'], $_POST['albumID']));
  95. $photo = new Photo($_POST['photoID']);
  96. echo json_encode($photo->get($_POST['albumID']));
  97. }
  98. private function setPhotoTitle() {
  99. Module::dependencies(isset($_POST['photoIDs'], $_POST['title']));
  100. $photo = new Photo($_POST['photoIDs']);
  101. echo $photo->setTitle($_POST['title']);
  102. }
  103. private function setPhotoDescription() {
  104. Module::dependencies(isset($_POST['photoID'], $_POST['description']));
  105. $photo = new Photo($_POST['photoID']);
  106. echo $photo->setDescription($_POST['description']);
  107. }
  108. private function setPhotoStar() {
  109. Module::dependencies(isset($_POST['photoIDs']));
  110. $photo = new Photo($_POST['photoIDs']);
  111. echo $photo->setStar();
  112. }
  113. private function setPhotoPublic() {
  114. Module::dependencies(isset($_POST['photoID']));
  115. $photo = new Photo($_POST['photoID']);
  116. echo $photo->setPublic();
  117. }
  118. private function setPhotoAlbum() {
  119. Module::dependencies(isset($_POST['photoIDs'], $_POST['albumID']));
  120. $photo = new Photo($_POST['photoIDs']);
  121. echo $photo->setAlbum($_POST['albumID']);
  122. }
  123. private function setPhotoTags() {
  124. Module::dependencies(isset($_POST['photoIDs'], $_POST['tags']));
  125. $photo = new Photo($_POST['photoIDs']);
  126. echo $photo->setTags($_POST['tags']);
  127. }
  128. private function duplicatePhoto() {
  129. Module::dependencies(isset($_POST['photoIDs']));
  130. $photo = new Photo($_POST['photoIDs']);
  131. echo $photo->duplicate();
  132. }
  133. private function deletePhoto() {
  134. Module::dependencies(isset($_POST['photoIDs']));
  135. $photo = new Photo($_POST['photoIDs']);
  136. echo $photo->delete();
  137. }
  138. # Add functions
  139. private function upload() {
  140. Module::dependencies(isset($_FILES, $_POST['albumID'], $_POST['tags']));
  141. $photo = new Photo(null);
  142. echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']);
  143. }
  144. private function importUrl() {
  145. Module::dependencies(isset($_POST['url'], $_POST['albumID']));
  146. $import = new Import();
  147. echo $import->url($_POST['url'], $_POST['albumID']);
  148. }
  149. private function importServer() {
  150. Module::dependencies(isset($_POST['albumID'], $_POST['path']));
  151. $import = new Import();
  152. echo $import->server($_POST['path'], $_POST['albumID']);
  153. }
  154. # Search function
  155. private function search() {
  156. Module::dependencies(isset($_POST['term']));
  157. echo json_encode(search($_POST['term']));
  158. }
  159. # Session functions
  160. private function init() {
  161. global $dbName;
  162. $session = new Session();
  163. echo json_encode($session->init(false));
  164. }
  165. private function login() {
  166. Module::dependencies(isset($_POST['user'], $_POST['password']));
  167. $session = new Session();
  168. echo $session->login($_POST['user'], $_POST['password']);
  169. }
  170. private function logout() {
  171. $session = new Session();
  172. echo $session->logout();
  173. }
  174. # Settings functions
  175. private function setLogin() {
  176. Module::dependencies(isset($_POST['username'], $_POST['password']));
  177. if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
  178. echo Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
  179. }
  180. private function setSorting() {
  181. Module::dependencies(isset($_POST['typeAlbums'], $_POST['orderAlbums'], $_POST['typePhotos'], $_POST['orderPhotos']));
  182. $sA = Settings::setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']);
  183. $sP = Settings::setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']);
  184. if ($sA===true&&$sP===true) echo true;
  185. else echo false;
  186. }
  187. private function setDropboxKey() {
  188. Module::dependencies(isset($_POST['key']));
  189. echo Settings::setDropboxKey($_POST['key']);
  190. }
  191. # Get functions
  192. private function getAlbumArchive() {
  193. Module::dependencies(isset($_GET['albumID']));
  194. $album = new Album($_GET['albumID']);
  195. $album->getArchive();
  196. }
  197. private function getPhotoArchive() {
  198. Module::dependencies(isset($_GET['photoID']));
  199. $photo = new Photo($_GET['photoID']);
  200. $photo->getArchive();
  201. }
  202. }