Guest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace Lychee\Access;
  3. use Lychee\Modules\Album;
  4. use Lychee\Modules\Module;
  5. use Lychee\Modules\Photo;
  6. use Lychee\Modules\Session;
  7. final class Guest implements Access {
  8. public function check($fn) {
  9. switch ($fn) {
  10. # Album functions
  11. case 'Album::getAll': $this->getAlbums(); break;
  12. case 'Album::get': $this->getAlbum(); break;
  13. case 'Album::getPublic': $this->checkAlbumAccess(); break;
  14. # Photo functions
  15. case 'Photo::get': $this->getPhoto(); break;
  16. # Session functions
  17. case 'Session::init': $this->init(); break;
  18. case 'Session::login': $this->login(); break;
  19. case 'Session::logout': $this->logout(); break;
  20. # $_GET functions
  21. case 'Album::getArchive': $this->getAlbumArchive(); break;
  22. case 'Photo::getArchive': $this->getPhotoArchive(); break;
  23. # Error
  24. default: exit('Error: Function not found! Please check the spelling of the called function.');
  25. break;
  26. }
  27. return true;
  28. }
  29. # Album functions
  30. private function getAlbums() {
  31. $album = new Album(null);
  32. echo json_encode($album->getAll(true));
  33. }
  34. private function getAlbum() {
  35. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  36. $album = new Album($_POST['albumID']);
  37. if ($album->getPublic()) {
  38. # Album public
  39. if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
  40. else echo 'Warning: Wrong password!';
  41. } else {
  42. # Album private
  43. echo 'Warning: Album private!';
  44. }
  45. }
  46. private function checkAlbumAccess() {
  47. Module::dependencies(isset($_POST['albumID'], $_POST['password']));
  48. $album = new Album($_POST['albumID']);
  49. if ($album->getPublic()) {
  50. # Album public
  51. if ($album->checkPassword($_POST['password'])) echo true;
  52. else echo false;
  53. } else {
  54. # Album private
  55. echo false;
  56. }
  57. }
  58. # Photo functions
  59. private function getPhoto() {
  60. Module::dependencies(isset($_POST['photoID'], $_POST['albumID'], $_POST['password']));
  61. $photo = new Photo($_POST['photoID']);
  62. $pgP = $photo->getPublic($_POST['password']);
  63. if ($pgP===2) echo json_encode($photo->get($_POST['albumID']));
  64. else if ($pgP===1) echo 'Warning: Wrong password!';
  65. else if ($pgP===0) echo 'Warning: Photo private!';
  66. }
  67. # Session functions
  68. private function init() {
  69. global $dbName;
  70. $session = new Session();
  71. echo json_encode($session->init(true));
  72. }
  73. private function login() {
  74. Module::dependencies(isset($_POST['user'], $_POST['password']));
  75. $session = new Session();
  76. echo $session->login($_POST['user'], $_POST['password']);
  77. }
  78. private function logout() {
  79. $session = new Session();
  80. echo $session->logout();
  81. }
  82. # $_GET functions
  83. private function getAlbumArchive() {
  84. Module::dependencies(isset($_GET['albumID'], $_GET['password']));
  85. $album = new Album($_GET['albumID']);
  86. if ($album->getPublic()&&$album->getDownloadable()) {
  87. # Album Public
  88. if ($album->checkPassword($_GET['password'])) $album->getArchive();
  89. else exit('Warning: Wrong password!');
  90. } else {
  91. # Album Private
  92. exit('Warning: Album private or not downloadable!');
  93. }
  94. }
  95. private function getPhotoArchive() {
  96. Module::dependencies(isset($_GET['photoID'], $_GET['password']));
  97. $photo = new Photo($_GET['photoID']);
  98. $pgP = $photo->getPublic($_GET['password']);
  99. # Photo Download
  100. if ($pgP===2) {
  101. # Photo Public
  102. $photo->getArchive();
  103. } else {
  104. # Photo Private
  105. exit('Warning: Photo private or password incorrect!');
  106. }
  107. }
  108. }
  109. ?>