admin.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. switch ($_POST['function']) {
  10. // Album Functions
  11. case 'getAlbums': $album = new Album($database, $plugins, $settings, null);
  12. echo json_encode($album->getAll(false));
  13. break;
  14. case 'getAlbum': if (!isset($_POST['albumID'])) exit();
  15. $album = new Album($database, $plugins, $settings, $_POST['albumID']);
  16. echo json_encode($album->get());
  17. break;
  18. case 'addAlbum': if (!isset($_POST['title'])) exit();
  19. $album = new Album($database, $plugins, $settings, null);
  20. echo $album->add($_POST['title']);
  21. break;
  22. case 'setAlbumTitle': if (!isset($_POST['albumIDs'], $_POST['title'])) exit();
  23. $album = new Album($database, $plugins, $settings, $_POST['albumIDs']);
  24. echo $album->setTitle($_POST['title']);
  25. break;
  26. case 'setAlbumDescription': if (!isset($_POST['albumID'], $_POST['description'])) exit();
  27. $album = new Album($database, $plugins, $settings, $_POST['albumID']);
  28. echo $album->setDescription($_POST['description']);
  29. break;
  30. case 'setAlbumPublic': if (!isset($_POST['albumID'], $_POST['password'])) exit();
  31. $album = new Album($database, $plugins, $settings, $_POST['albumID']);
  32. echo $album->setPublic($_POST['password']);
  33. break;
  34. case 'setAlbumPassword': if (!isset($_POST['albumID'], $_POST['password'])) exit();
  35. $album = new Album($database, $plugins, $settings, $_POST['albumID']);
  36. echo $album->setPassword($_POST['password']);
  37. break;
  38. case 'deleteAlbum': if (!isset($_POST['albumIDs'])) exit();
  39. $album = new Album($database, $plugins, $settings, $_POST['albumIDs']);
  40. echo $album->delete($_POST['albumIDs']);
  41. break;
  42. // Photo Functions
  43. case 'getPhoto': if (!isset($_POST['photoID'], $_POST['albumID'])) exit();
  44. $photo = new Photo($database, $plugins, null, $_POST['photoID']);
  45. echo json_encode($photo->get($_POST['albumID']));
  46. break;
  47. case 'setPhotoTitle': if (!isset($_POST['photoIDs'], $_POST['title'])) exit();
  48. $photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
  49. echo $photo->setTitle($_POST['title']);
  50. break;
  51. case 'setPhotoDescription': if (!isset($_POST['photoID'], $_POST['description'])) exit();
  52. $photo = new Photo($database, $plugins, null, $_POST['photoID']);
  53. echo $photo->setDescription($_POST['description']);
  54. break;
  55. case 'setPhotoStar': if (!isset($_POST['photoIDs'])) exit();
  56. $photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
  57. echo $photo->setStar();
  58. break;
  59. case 'setPhotoPublic': if (!isset($_POST['photoID'])) exit();
  60. $photo = new Photo($database, $plugins, null, $_POST['photoID']);
  61. echo $photo->setPublic();
  62. break;
  63. case 'setPhotoAlbum': if (!isset($_POST['photoIDs'], $_POST['albumID'])) exit();
  64. $photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
  65. echo $photo->setAlbum($_POST['albumID']);
  66. break;
  67. case 'setPhotoTags': if (!isset($_POST['photoIDs'], $_POST['tags'])) exit();
  68. $photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
  69. echo $photo->setTags($_POST['tags']);
  70. break;
  71. case 'deletePhoto': if (!isset($_POST['photoIDs'])) exit();
  72. $photo = new Photo($database, $plugins, null, $_POST['photoIDs']);
  73. echo $photo->delete();
  74. break;
  75. // Add Functions
  76. case 'upload': if (!isset($_FILES, $_POST['albumID'])) exit();
  77. $photo = new Photo($database, $plugins, $settings, null);
  78. echo $photo->add($_FILES, $_POST['albumID']);
  79. break;
  80. case 'importUrl': if (!isset($_POST['url'], $_POST['albumID'])) exit();
  81. echo Import::url($_POST['url'], $_POST['albumID']);
  82. break;
  83. case 'importServer': if (!isset($_POST['albumID'])) exit();
  84. echo Import::server($_POST['albumID'], null);
  85. break;
  86. // Search Function
  87. case 'search': if (!isset($_POST['term'])) exit();
  88. echo json_encode(search($database, $settings, $_POST['term']));
  89. break;
  90. // Session Function
  91. case 'init': if (!isset($_POST['version'])) exit();
  92. $session = new Session($plugins, $settings);
  93. echo json_encode($session->init($database, $dbName, false, $_POST['version']));
  94. break;
  95. case 'login': if (!isset($_POST['user'], $_POST['password'])) exit();
  96. $session = new Session($plugins, $settings);
  97. echo $session->login($_POST['user'], $_POST['password']);
  98. break;
  99. case 'logout': $session = new Session($plugins, $settings);
  100. echo $session->logout();
  101. break;
  102. // Settings Function
  103. case 'setLogin': if (!isset($_POST['username'], $_POST['password'])) exit();
  104. if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
  105. $settings = new Settings($database);
  106. echo $settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
  107. break;
  108. case 'setSorting': if (!isset($_POST['type'], $_POST['order'])) exit();
  109. $settings = new Settings($database);
  110. echo $settings->setSorting($_POST['type'], $_POST['order']);
  111. break;
  112. case 'setDropboxKey': if (!isset($_POST['key'])) exit();
  113. $settings = new Settings($database);
  114. echo $settings->setDropboxKey($_POST['key']);
  115. break;
  116. // Miscellaneous
  117. default: switch ($_GET['function']) {
  118. case 'getAlbumArchive': if (!isset($_GET['albumID'])) exit();
  119. $album = new Album($database, $plugins, $settings, $_GET['albumID']);
  120. $album->getArchive();
  121. break;
  122. case 'getPhotoArchive': if (!isset($_GET['photoID'])) exit();
  123. $photo = new Photo($database, $plugins, null, $_GET['photoID']);
  124. $photo->getArchive();
  125. break;
  126. default: exit('Error: Function not found! Please check the spelling of the called function.');
  127. break;
  128. }
  129. break;
  130. }
  131. ?>