Admin.php 8.1 KB

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