Admin.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. namespace Lychee\Access;
  3. use Lychee\Modules\Album;
  4. use Lychee\Modules\Albums;
  5. use Lychee\Modules\Import;
  6. use Lychee\Modules\Photo;
  7. use Lychee\Modules\Response;
  8. use Lychee\Modules\Session;
  9. use Lychee\Modules\Settings;
  10. use Lychee\Modules\Validator;
  11. final class Admin extends Access {
  12. public static function init($fn) {
  13. switch ($fn) {
  14. // Albums functions
  15. case 'Albums::get': self::getAlbumsAction(); break;
  16. // Album functions
  17. case 'Album::get': self::getAlbumAction(); break;
  18. case 'Album::add': self::addAlbumAction(); break;
  19. case 'Album::setTitle': self::setAlbumTitleAction(); break;
  20. case 'Album::setDescription': self::setAlbumDescriptionAction(); break;
  21. case 'Album::setPublic': self::setAlbumPublicAction(); break;
  22. case 'Album::delete': self::deleteAlbumAction(); break;
  23. case 'Album::merge': self::mergeAlbumsAction(); break;
  24. // Photo functions
  25. case 'Photo::get': self::getPhotoAction(); break;
  26. case 'Photo::setTitle': self::setPhotoTitleAction(); break;
  27. case 'Photo::setDescription': self::setPhotoDescriptionAction(); break;
  28. case 'Photo::setStar': self::setPhotoStarAction(); break;
  29. case 'Photo::setPublic': self::setPhotoPublicAction(); break;
  30. case 'Photo::setAlbum': self::setPhotoAlbumAction(); break;
  31. case 'Photo::setTags': self::setPhotoTagsAction(); break;
  32. case 'Photo::duplicate': self::duplicatePhotoAction(); break;
  33. case 'Photo::delete': self::deletePhotoAction(); break;
  34. // Add functions
  35. case 'Photo::add': self::uploadAction(); break;
  36. case 'Import::url': self::importUrlAction(); break;
  37. case 'Import::server': self::importServerAction(); break;
  38. // Search functions
  39. case 'search': self::searchAction(); break;
  40. // Session functions
  41. case 'Session::init': self::initAction(); break;
  42. case 'Session::login': self::loginAction(); break;
  43. case 'Session::logout': self::logoutAction(); break;
  44. // Settings functions
  45. case 'Settings::setLogin': self::setLoginAction(); break;
  46. case 'Settings::setSorting': self::setSortingAction(); break;
  47. case 'Settings::setDropboxKey': self::setDropboxKeyAction(); break;
  48. // $_GET functions
  49. case 'Album::getArchive': self::getAlbumArchiveAction(); break;
  50. case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
  51. }
  52. self::fnNotFound();
  53. }
  54. // Albums functions
  55. private static function getAlbumsAction() {
  56. $albums = new Albums();
  57. Response::json($albums->get(false));
  58. }
  59. // Album functions
  60. private static function getAlbumAction() {
  61. Validator::required(isset($_POST['albumID']), __METHOD__);
  62. $album = new Album($_POST['albumID']);
  63. Response::json($album->get());
  64. }
  65. private static function addAlbumAction() {
  66. Validator::required(isset($_POST['title']), __METHOD__);
  67. $album = new Album(null);
  68. Response::json($album->add($_POST['title']));
  69. }
  70. private static function setAlbumTitleAction() {
  71. Validator::required(isset($_POST['albumIDs'], $_POST['title']), __METHOD__);
  72. $album = new Album($_POST['albumIDs']);
  73. Response::json($album->setTitle($_POST['title']));
  74. }
  75. private static function setAlbumDescriptionAction() {
  76. Validator::required(isset($_POST['albumID'], $_POST['description']), __METHOD__);
  77. $album = new Album($_POST['albumID']);
  78. Response::json($album->setDescription($_POST['description']));
  79. }
  80. private static function setAlbumPublicAction() {
  81. Validator::required(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']), __METHOD__);
  82. $album = new Album($_POST['albumID']);
  83. Response::json($album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']));
  84. }
  85. private static function deleteAlbumAction() {
  86. Validator::required(isset($_POST['albumIDs']), __METHOD__);
  87. $album = new Album($_POST['albumIDs']);
  88. Response::json($album->delete());
  89. }
  90. private static function mergeAlbumsAction() {
  91. Validator::required(isset($_POST['albumIDs']), __METHOD__);
  92. $album = new Album($_POST['albumIDs']);
  93. Response::json($album->merge());
  94. }
  95. // Photo functions
  96. private static function getPhotoAction() {
  97. Validator::required(isset($_POST['photoID'], $_POST['albumID']), __METHOD__);
  98. $photo = new Photo($_POST['photoID']);
  99. Response::json($photo->get($_POST['albumID']));
  100. }
  101. private static function setPhotoTitleAction() {
  102. Validator::required(isset($_POST['photoIDs'], $_POST['title']), __METHOD__);
  103. $photo = new Photo($_POST['photoIDs']);
  104. Response::json($photo->setTitle($_POST['title']));
  105. }
  106. private static function setPhotoDescriptionAction() {
  107. Validator::required(isset($_POST['photoID'], $_POST['description']), __METHOD__);
  108. $photo = new Photo($_POST['photoID']);
  109. Response::json($photo->setDescription($_POST['description']));
  110. }
  111. private static function setPhotoStarAction() {
  112. Validator::required(isset($_POST['photoIDs']), __METHOD__);
  113. $photo = new Photo($_POST['photoIDs']);
  114. Response::json($photo->setStar());
  115. }
  116. private static function setPhotoPublicAction() {
  117. Validator::required(isset($_POST['photoID']), __METHOD__);
  118. $photo = new Photo($_POST['photoID']);
  119. Response::json($photo->setPublic());
  120. }
  121. private static function setPhotoAlbumAction() {
  122. Validator::required(isset($_POST['photoIDs'], $_POST['albumID']), __METHOD__);
  123. $photo = new Photo($_POST['photoIDs']);
  124. Response::json($photo->setAlbum($_POST['albumID']));
  125. }
  126. private static function setPhotoTagsAction() {
  127. Validator::required(isset($_POST['photoIDs'], $_POST['tags']), __METHOD__);
  128. $photo = new Photo($_POST['photoIDs']);
  129. Response::json($photo->setTags($_POST['tags']));
  130. }
  131. private static function duplicatePhotoAction() {
  132. Validator::required(isset($_POST['photoIDs']), __METHOD__);
  133. $photo = new Photo($_POST['photoIDs']);
  134. Response::json($photo->duplicate());
  135. }
  136. private static function deletePhotoAction() {
  137. Validator::required(isset($_POST['photoIDs']), __METHOD__);
  138. $photo = new Photo($_POST['photoIDs']);
  139. Response::json($photo->delete());
  140. }
  141. // Add functions
  142. private static function uploadAction() {
  143. Validator::required(isset($_FILES, $_POST['albumID']), __METHOD__);
  144. $photo = new Photo(null);
  145. Response::json($photo->add($_FILES, $_POST['albumID']));
  146. }
  147. private static function importUrlAction() {
  148. Validator::required(isset($_POST['url'], $_POST['albumID']), __METHOD__);
  149. $import = new Import();
  150. Response::json($import->url($_POST['url'], $_POST['albumID']));
  151. }
  152. private static function importServerAction() {
  153. Validator::required(isset($_POST['albumID'], $_POST['path']), __METHOD__);
  154. $import = new Import();
  155. echo $import->server($_POST['path'], $_POST['albumID']);
  156. }
  157. // Search functions
  158. private static function searchAction() {
  159. Validator::required(isset($_POST['term']), __METHOD__);
  160. Response::json(search($_POST['term']));
  161. }
  162. // Session functions
  163. private static function initAction() {
  164. $session = new Session();
  165. Response::json($session->init(false));
  166. }
  167. private static function loginAction() {
  168. Validator::required(isset($_POST['user'], $_POST['password']), __METHOD__);
  169. $session = new Session();
  170. Response::json($session->login($_POST['user'], $_POST['password']));
  171. }
  172. private static function logoutAction() {
  173. $session = new Session();
  174. Response::json($session->logout());
  175. }
  176. // Settings functions
  177. private static function setLoginAction() {
  178. Validator::required(isset($_POST['username'], $_POST['password']), __METHOD__);
  179. if (isset($_POST['oldPassword'])===false) $_POST['oldPassword'] = '';
  180. Response::json(Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']));
  181. }
  182. private static function setSortingAction() {
  183. Validator::required(isset($_POST['typeAlbums'], $_POST['orderAlbums'], $_POST['typePhotos'], $_POST['orderPhotos']), __METHOD__);
  184. $sA = Settings::setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']);
  185. $sP = Settings::setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']);
  186. if ($sA===true&&$sP===true) Response::json(true);
  187. else Response::json(false);
  188. }
  189. private static function setDropboxKeyAction() {
  190. Validator::required(isset($_POST['key']), __METHOD__);
  191. Response::json(Settings::setDropboxKey($_POST['key']));
  192. }
  193. // Get functions
  194. private static function getAlbumArchiveAction() {
  195. Validator::required(isset($_GET['albumID']), __METHOD__);
  196. $album = new Album($_GET['albumID']);
  197. $album->getArchive();
  198. }
  199. private static function getPhotoArchiveAction() {
  200. Validator::required(isset($_GET['photoID']), __METHOD__);
  201. $photo = new Photo($_GET['photoID']);
  202. $photo->getArchive();
  203. }
  204. }
  205. ?>