Admin.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 'deleteAlbum': $this->deleteAlbum(); break;
  20. # Photo functions
  21. case 'getPhoto': $this->getPhoto(); break;
  22. case 'setPhotoTitle': $this->setPhotoTitle(); break;
  23. case 'setPhotoDescription': $this->setPhotoDescription(); break;
  24. case 'setPhotoStar': $this->setPhotoStar(); break;
  25. case 'setPhotoPublic': $this->setPhotoPublic(); break;
  26. case 'setPhotoAlbum': $this->setPhotoAlbum(); break;
  27. case 'setPhotoTags': $this->setPhotoTags(); break;
  28. case 'deletePhoto': $this->deletePhoto(); break;
  29. # Add functions
  30. case 'upload': $this->upload(); break;
  31. case 'importUrl': $this->importUrl(); break;
  32. case 'importServer': $this->importServer(); break;
  33. # Search functions
  34. case 'search': $this->search(); break;
  35. # Session functions
  36. case 'init': $this->init(); break;
  37. case 'login': $this->login(); break;
  38. case 'logout': $this->logout(); break;
  39. # Settings functions
  40. case 'setLogin': $this->setLogin(); break;
  41. case 'setSorting': $this->setSorting(); break;
  42. case 'setDropboxKey': $this->setDropboxKey(); break;
  43. # $_GET functions
  44. case 'getAlbumArchive': $this->getAlbumArchive(); break;
  45. case 'getPhotoArchive': $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']));
  79. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  80. echo $album->setPublic($_POST['password'], $_POST['visible']);
  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($_POST['albumIDs']);
  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 deletePhoto() {
  124. Module::dependencies(isset($_POST['photoIDs']));
  125. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  126. echo $photo->delete();
  127. }
  128. # Add functions
  129. private function upload() {
  130. Module::dependencies(isset($_FILES, $_POST['albumID']));
  131. $photo = new Photo($this->database, $this->plugins, $this->settings, null);
  132. echo $photo->add($_FILES, $_POST['albumID']);
  133. }
  134. private function importUrl() {
  135. Module::dependencies(isset($_POST['url'], $_POST['albumID']));
  136. echo Import::url($_POST['url'], $_POST['albumID']);
  137. }
  138. private function importServer() {
  139. Module::dependencies(isset($_POST['albumID']));
  140. echo Import::server($_POST['albumID'], null);
  141. }
  142. # Search function
  143. private function search() {
  144. Module::dependencies(isset($_POST['term']));
  145. echo json_encode(search($this->database, $this->settings, $_POST['term']));
  146. }
  147. # Session functions
  148. private function init() {
  149. global $dbName;
  150. Module::dependencies(isset($_POST['version']));
  151. $session = new Session($this->plugins, $this->settings);
  152. echo json_encode($session->init($this->database, $dbName, false, $_POST['version']));
  153. }
  154. private function login() {
  155. Module::dependencies(isset($_POST['user'], $_POST['password']));
  156. $session = new Session($this->plugins, $this->settings);
  157. echo $session->login($_POST['user'], $_POST['password']);
  158. }
  159. private function logout() {
  160. $session = new Session($this->plugins, $this->settings);
  161. echo $session->logout();
  162. }
  163. # Settings functions
  164. private function setLogin() {
  165. Module::dependencies(isset($_POST['username'], $_POST['password']));
  166. if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
  167. $this->settings = new Settings($this->database);
  168. echo $this->settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
  169. }
  170. private function setSorting() {
  171. Module::dependencies(isset($_POST['type'], $_POST['order']));
  172. $this->settings = new Settings($this->database);
  173. echo $this->settings->setSorting($_POST['type'], $_POST['order']);
  174. }
  175. private function setDropboxKey() {
  176. Module::dependencies(isset($_POST['key']));
  177. $this->settings = new Settings($this->database);
  178. echo $this->settings->setDropboxKey($_POST['key']);
  179. }
  180. # Get functions
  181. private function getAlbumArchive() {
  182. Module::dependencies(isset($_GET['albumID']));
  183. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  184. $album->getArchive();
  185. }
  186. private function getPhotoArchive() {
  187. Module::dependencies(isset($_GET['photoID']));
  188. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  189. $photo->getArchive();
  190. }
  191. }