Admin.php 8.8 KB

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