Admin.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.');
  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']));
  80. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  81. echo $album->setPublic($_POST['password']);
  82. }
  83. private function setAlbumPassword() {
  84. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  85. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
  86. echo $album->setPassword($_POST['password']);
  87. }
  88. private function deleteAlbum() {
  89. Module::dependencies(isset($_POST['albumIDs']));
  90. $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
  91. echo $album->delete($_POST['albumIDs']);
  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 deletePhoto() {
  130. Module::dependencies(isset($_POST['photoIDs']));
  131. $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
  132. echo $photo->delete();
  133. }
  134. # Add functions
  135. private function upload() {
  136. Module::dependencies(isset($_FILES, $_POST['albumID']));
  137. $photo = new Photo($this->database, $this->plugins, $this->settings, null);
  138. echo $photo->add($_FILES, $_POST['albumID']);
  139. }
  140. private function importUrl() {
  141. Module::dependencies(isset($_POST['url'], $_POST['albumID']));
  142. echo Import::url($_POST['url'], $_POST['albumID']);
  143. }
  144. private function importServer() {
  145. Module::dependencies(isset($_POST['albumID']));
  146. echo Import::server($_POST['albumID'], null);
  147. }
  148. # Search function
  149. private function search() {
  150. Module::dependencies(isset($_POST['term']));
  151. echo json_encode(search($this->database, $this->settings, $_POST['term']));
  152. }
  153. # Session functions
  154. private function init() {
  155. global $dbName;
  156. Module::dependencies(isset($_POST['version']));
  157. $session = new Session($this->plugins, $this->settings);
  158. echo json_encode($session->init($this->database, $dbName, false, $_POST['version']));
  159. }
  160. private function login() {
  161. Module::dependencies(isset($_POST['user'], $_POST['password']));
  162. $session = new Session($this->plugins, $this->settings);
  163. echo $session->login($_POST['user'], $_POST['password']);
  164. }
  165. private function logout() {
  166. $session = new Session($this->plugins, $this->settings);
  167. echo $session->logout();
  168. }
  169. # Settings functions
  170. private function setLogin() {
  171. Module::dependencies(isset($_POST['username'], $_POST['password']));
  172. if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
  173. $this->settings = new Settings($this->database);
  174. echo $this->settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
  175. }
  176. private function setSorting() {
  177. Module::dependencies(isset($_POST['type'], $_POST['order']));
  178. $this->settings = new Settings($this->database);
  179. echo $this->settings->setSorting($_POST['type'], $_POST['order']);
  180. }
  181. private function setDropboxKey() {
  182. Module::dependencies(isset($_POST['key']));
  183. $this->settings = new Settings($this->database);
  184. echo $this->settings->setDropboxKey($_POST['key']);
  185. }
  186. # Get functions
  187. private function getAlbumArchive() {
  188. Module::dependencies(isset($_GET['albumID']));
  189. $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
  190. $album->getArchive();
  191. }
  192. private function getPhotoArchive() {
  193. Module::dependencies(isset($_GET['photoID']));
  194. $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
  195. $photo->getArchive();
  196. }
  197. }