Admin.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!');
  8. class Admin extends Access {
  9. public function check($fn) {
  10. switch ($fn) {
  11. # Album functions
  12. case 'Album::getAll': $this->getAlbums(); break;
  13. case 'Album::get': $this->getAlbum(); break;
  14. case 'Album::add': $this->addAlbum(); break;
  15. case 'Album::setTitle': $this->setAlbumTitle(); break;
  16. case 'Album::setDescription': $this->setAlbumDescription(); break;
  17. case 'Album::setPublic': $this->setAlbumPublic(); break;
  18. case 'Album::delete': $this->deleteAlbum(); 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($this->database, $this->plugins, $this->settings, null);
  55. echo json_encode($album->getAll(false));
  56. }
  57. private function getAlbum() {
  58. Module::dependencies(isset($_POST['albumID']));
  59. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  60. echo json_encode($album->get());
  61. }
  62. private function addAlbum() {
  63. Module::dependencies(isset($_POST['title']));
  64. $album = new Album($this->database, $this->plugins, $this->settings, null);
  65. echo $album->add($_POST['title']);
  66. }
  67. private function setAlbumTitle() {
  68. Module::dependencies(isset($_POST['albumIDs'], $_POST['title']));
  69. $album = new Album($this->database, $this->plugins, $this->settings, $_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($this->database, $this->plugins, $this->settings, $_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($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  80. echo $album->setPublic($_POST['password'], $_POST['visible'], $_POST['downloadable']);
  81. }
  82. private function deleteAlbum() {
  83. Module::dependencies(isset($_POST['albumIDs']));
  84. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
  85. echo $album->delete();
  86. }
  87. # Photo functions
  88. private function getPhoto() {
  89. Module::dependencies(isset($_POST['photoID'], $_POST['albumID']));
  90. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
  91. echo json_encode($photo->get($_POST['albumID']));
  92. }
  93. private function setPhotoTitle() {
  94. Module::dependencies(isset($_POST['photoIDs'], $_POST['title']));
  95. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  96. echo $photo->setTitle($_POST['title']);
  97. }
  98. private function setPhotoDescription() {
  99. Module::dependencies(isset($_POST['photoID'], $_POST['description']));
  100. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
  101. echo $photo->setDescription($_POST['description']);
  102. }
  103. private function setPhotoStar() {
  104. Module::dependencies(isset($_POST['photoIDs']));
  105. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  106. echo $photo->setStar();
  107. }
  108. private function setPhotoPublic() {
  109. Module::dependencies(isset($_POST['photoID']));
  110. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
  111. echo $photo->setPublic();
  112. }
  113. private function setPhotoAlbum() {
  114. Module::dependencies(isset($_POST['photoIDs'], $_POST['albumID']));
  115. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  116. echo $photo->setAlbum($_POST['albumID']);
  117. }
  118. private function setPhotoTags() {
  119. Module::dependencies(isset($_POST['photoIDs'], $_POST['tags']));
  120. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  121. echo $photo->setTags($_POST['tags']);
  122. }
  123. private function duplicatePhoto() {
  124. Module::dependencies(isset($_POST['photoIDs']));
  125. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  126. echo $photo->duplicate();
  127. }
  128. private function deletePhoto() {
  129. Module::dependencies(isset($_POST['photoIDs']));
  130. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  131. echo $photo->delete();
  132. }
  133. # Add functions
  134. private function upload() {
  135. Module::dependencies(isset($_FILES, $_POST['albumID'], $_POST['tags']));
  136. $photo = new Photo($this->database, $this->plugins, $this->settings, null);
  137. echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']);
  138. }
  139. private function importUrl() {
  140. Module::dependencies(isset($_POST['url'], $_POST['albumID']));
  141. echo Import::url($_POST['url'], $_POST['albumID']);
  142. }
  143. private function importServer() {
  144. Module::dependencies(isset($_POST['albumID'], $_POST['path']));
  145. echo Import::server($_POST['albumID'], $_POST['path']);
  146. }
  147. # Search function
  148. private function search() {
  149. Module::dependencies(isset($_POST['term']));
  150. echo json_encode(search($this->database, $this->settings, $_POST['term']));
  151. }
  152. # Session functions
  153. private function init() {
  154. global $dbName;
  155. Module::dependencies(isset($_POST['version']));
  156. $session = new Session($this->plugins, $this->settings);
  157. echo json_encode($session->init($this->database, $dbName, false, $_POST['version']));
  158. }
  159. private function login() {
  160. Module::dependencies(isset($_POST['user'], $_POST['password']));
  161. $session = new Session($this->plugins, $this->settings);
  162. echo $session->login($_POST['user'], $_POST['password']);
  163. }
  164. private function logout() {
  165. $session = new Session($this->plugins, $this->settings);
  166. echo $session->logout();
  167. }
  168. # Settings functions
  169. private function setLogin() {
  170. Module::dependencies(isset($_POST['username'], $_POST['password']));
  171. if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
  172. $this->settings = new Settings($this->database);
  173. echo $this->settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
  174. }
  175. private function setSorting() {
  176. Module::dependencies(isset($_POST['type'], $_POST['order']));
  177. $this->settings = new Settings($this->database);
  178. echo $this->settings->setSorting($_POST['type'], $_POST['order']);
  179. }
  180. private function setDropboxKey() {
  181. Module::dependencies(isset($_POST['key']));
  182. $this->settings = new Settings($this->database);
  183. echo $this->settings->setDropboxKey($_POST['key']);
  184. }
  185. # Get functions
  186. private function getAlbumArchive() {
  187. Module::dependencies(isset($_GET['albumID']));
  188. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  189. $album->getArchive();
  190. }
  191. private function getPhotoArchive() {
  192. Module::dependencies(isset($_GET['photoID']));
  193. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  194. $photo->getArchive();
  195. }
  196. }