123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <?php
- ###
- # @name Admin Access
- # @copyright 2015 by Tobias Reich
- ###
- if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
- if (!defined('LYCHEE_ACCESS_ADMIN')) exit('Error: You are not allowed to access this area!');
- class Admin extends Access {
- public function check($fn) {
- switch ($fn) {
- # Album functions
- case 'Album::getAll': $this->getAlbums(); break;
- case 'Album::get': $this->getAlbum(); break;
- case 'Album::add': $this->addAlbum(); break;
- case 'Album::setTitle': $this->setAlbumTitle(); break;
- case 'Album::setDescription': $this->setAlbumDescription(); break;
- case 'Album::setPublic': $this->setAlbumPublic(); break;
- case 'Album::delete': $this->deleteAlbum(); break;
- case 'Album::merge': $this->mergeAlbums(); break;
- # Photo functions
- case 'Photo::get': $this->getPhoto(); break;
- case 'Photo::setTitle': $this->setPhotoTitle(); break;
- case 'Photo::setDescription': $this->setPhotoDescription(); break;
- case 'Photo::setStar': $this->setPhotoStar(); break;
- case 'Photo::setPublic': $this->setPhotoPublic(); break;
- case 'Photo::setAlbum': $this->setPhotoAlbum(); break;
- case 'Photo::setTags': $this->setPhotoTags(); break;
- case 'Photo::duplicate': $this->duplicatePhoto(); break;
- case 'Photo::delete': $this->deletePhoto(); break;
- # Add functions
- case 'Photo::add': $this->upload(); break;
- case 'Import::url': $this->importUrl(); break;
- case 'Import::server': $this->importServer(); break;
- # Search functions
- case 'search': $this->search(); break;
- # Session functions
- case 'Session::init': $this->init(); break;
- case 'Session::login': $this->login(); break;
- case 'Session::logout': $this->logout(); break;
- # Settings functions
- case 'Settings::setLogin': $this->setLogin(); break;
- case 'Settings::setSorting': $this->setSorting(); break;
- case 'Settings::setDropboxKey': $this->setDropboxKey(); break;
- # $_GET functions
- case 'Album::getArchive': $this->getAlbumArchive(); break;
- case 'Photo::getArchive': $this->getPhotoArchive(); break;
- # Error
- default: exit('Error: Function not found! Please check the spelling of the called function.');
- return false; break;
- }
- return true;
- }
- # Album functions
- private function getAlbums() {
- $album = new Album($this->database, $this->plugins, $this->settings, null);
- echo json_encode($album->getAll(false));
- }
- private function getAlbum() {
- Module::dependencies(isset($_POST['albumID']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
- echo json_encode($album->get());
- }
- private function addAlbum() {
- Module::dependencies(isset($_POST['title']));
- $album = new Album($this->database, $this->plugins, $this->settings, null);
- echo $album->add($_POST['title']);
- }
- private function setAlbumTitle() {
- Module::dependencies(isset($_POST['albumIDs'], $_POST['title']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
- echo $album->setTitle($_POST['title']);
- }
- private function setAlbumDescription() {
- Module::dependencies(isset($_POST['albumID'], $_POST['description']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
- echo $album->setDescription($_POST['description']);
- }
- private function setAlbumPublic() {
- Module::dependencies(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
- echo $album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']);
- }
- private function deleteAlbum() {
- Module::dependencies(isset($_POST['albumIDs']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
- echo $album->delete();
- }
- private function mergeAlbums() {
- Module::dependencies(isset($_POST['albumIDs']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
- echo $album->merge();
- }
- # Photo functions
- private function getPhoto() {
- Module::dependencies(isset($_POST['photoID'], $_POST['albumID']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
- echo json_encode($photo->get($_POST['albumID']));
- }
- private function setPhotoTitle() {
- Module::dependencies(isset($_POST['photoIDs'], $_POST['title']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
- echo $photo->setTitle($_POST['title']);
- }
- private function setPhotoDescription() {
- Module::dependencies(isset($_POST['photoID'], $_POST['description']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
- echo $photo->setDescription($_POST['description']);
- }
- private function setPhotoStar() {
- Module::dependencies(isset($_POST['photoIDs']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
- echo $photo->setStar();
- }
- private function setPhotoPublic() {
- Module::dependencies(isset($_POST['photoID']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
- echo $photo->setPublic();
- }
- private function setPhotoAlbum() {
- Module::dependencies(isset($_POST['photoIDs'], $_POST['albumID']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
- echo $photo->setAlbum($_POST['albumID']);
- }
- private function setPhotoTags() {
- Module::dependencies(isset($_POST['photoIDs'], $_POST['tags']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
- echo $photo->setTags($_POST['tags']);
- }
- private function duplicatePhoto() {
- Module::dependencies(isset($_POST['photoIDs']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
- echo $photo->duplicate();
- }
- private function deletePhoto() {
- Module::dependencies(isset($_POST['photoIDs']));
- $photo = new Photo($this->database, $this->plugins, null, $_POST['photoIDs']);
- echo $photo->delete();
- }
- # Add functions
- private function upload() {
- Module::dependencies(isset($_FILES, $_POST['albumID'], $_POST['tags']));
- $photo = new Photo($this->database, $this->plugins, $this->settings, null);
- echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']);
- }
- private function importUrl() {
- Module::dependencies(isset($_POST['url'], $_POST['albumID']));
- $import = new Import($this->database, $this->plugins, $this->settings);
- echo $import->url($_POST['url'], $_POST['albumID']);
- }
- private function importServer() {
- Module::dependencies(isset($_POST['albumID'], $_POST['path']));
- $import = new Import($this->database, $this->plugins, $this->settings);
- echo $import->server($_POST['path'], $_POST['albumID']);
- }
- # Search function
- private function search() {
- Module::dependencies(isset($_POST['term']));
- echo json_encode(search($this->database, $this->settings, $_POST['term']));
- }
- # Session functions
- private function init() {
- global $dbName;
- $session = new Session($this->plugins, $this->settings);
- echo json_encode($session->init($this->database, $dbName, false));
- }
- private function login() {
- Module::dependencies(isset($_POST['user'], $_POST['password']));
- $session = new Session($this->plugins, $this->settings);
- echo $session->login($_POST['user'], $_POST['password']);
- }
- private function logout() {
- $session = new Session($this->plugins, $this->settings);
- echo $session->logout();
- }
- # Settings functions
- private function setLogin() {
- Module::dependencies(isset($_POST['username'], $_POST['password']));
- if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
- $this->settings = new Settings($this->database);
- echo $this->settings->setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
- }
- private function setSorting() {
- Module::dependencies(isset($_POST['typeAlbums'], $_POST['orderAlbums'], $_POST['typePhotos'], $_POST['orderPhotos']));
- $this->settings = new Settings($this->database);
- $sA = $this->settings->setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']);
- $sP = $this->settings->setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']);
- if ($sA===true&&$sP===true) echo true;
- else echo false;
- }
- private function setDropboxKey() {
- Module::dependencies(isset($_POST['key']));
- $this->settings = new Settings($this->database);
- echo $this->settings->setDropboxKey($_POST['key']);
- }
- # Get functions
- private function getAlbumArchive() {
- Module::dependencies(isset($_GET['albumID']));
- $album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
- $album->getArchive();
- }
- private function getPhotoArchive() {
- Module::dependencies(isset($_GET['photoID']));
- $photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
- $photo->getArchive();
- }
- }
|