lychee/php/Access/Admin.php

318 lines
7.5 KiB
PHP
Raw Normal View History

2014-02-09 18:21:55 +00:00
<?php
namespace Lychee\Access;
2014-02-09 18:21:55 +00:00
use Lychee\Modules\Album;
use Lychee\Modules\Import;
use Lychee\Modules\Module;
use Lychee\Modules\Photo;
use Lychee\Modules\Session;
use Lychee\Modules\Settings;
2014-02-09 18:21:55 +00:00
final class Admin implements Access {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
public function check($fn) {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
switch ($fn) {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Album functions
2015-02-02 22:36:33 +00:00
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;
2015-05-05 20:06:54 +00:00
case 'Album::merge': $this->mergeAlbums(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Photo functions
2015-02-02 22:36:33 +00:00
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;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Add functions
2015-02-02 22:36:33 +00:00
case 'Photo::add': $this->upload(); break;
case 'Import::url': $this->importUrl(); break;
case 'Import::server': $this->importServer(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Search functions
2015-02-02 22:36:33 +00:00
case 'search': $this->search(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Session functions
2015-02-02 22:36:33 +00:00
case 'Session::init': $this->init(); break;
case 'Session::login': $this->login(); break;
case 'Session::logout': $this->logout(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Settings functions
2015-02-02 22:36:33 +00:00
case 'Settings::setLogin': $this->setLogin(); break;
case 'Settings::setSorting': $this->setSorting(); break;
case 'Settings::setDropboxKey': $this->setDropboxKey(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# $_GET functions
2015-02-02 22:36:33 +00:00
case 'Album::getArchive': $this->getAlbumArchive(); break;
case 'Photo::getArchive': $this->getPhotoArchive(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Error
2015-02-02 22:36:33 +00:00
default: exit('Error: Function not found! Please check the spelling of the called function.');
return false; break;
2014-02-17 16:01:46 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
2014-04-30 08:54:53 +00:00
return true;
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Album functions
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
private function getAlbums() {
2014-02-09 18:21:55 +00:00
$album = new Album(null);
2014-04-28 09:23:18 +00:00
echo json_encode($album->getAll(false));
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
private function getAlbum() {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
Module::dependencies(isset($_POST['albumID']));
$album = new Album($_POST['albumID']);
2014-04-28 09:23:18 +00:00
echo json_encode($album->get());
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
private function addAlbum() {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
Module::dependencies(isset($_POST['title']));
$album = new Album(null);
2014-04-28 09:23:18 +00:00
echo $album->add($_POST['title']);
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
private function setAlbumTitle() {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
Module::dependencies(isset($_POST['albumIDs'], $_POST['title']));
$album = new Album($_POST['albumIDs']);
2014-04-28 09:23:18 +00:00
echo $album->setTitle($_POST['title']);
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-23 21:42:15 +00:00
2014-04-28 09:23:18 +00:00
private function setAlbumDescription() {
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
Module::dependencies(isset($_POST['albumID'], $_POST['description']));
$album = new Album($_POST['albumID']);
2014-04-28 09:23:18 +00:00
echo $album->setDescription($_POST['description']);
2014-02-17 16:01:46 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-17 16:01:46 +00:00
2014-04-28 09:23:18 +00:00
private function setAlbumPublic() {
2014-02-17 16:01:46 +00:00
Module::dependencies(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']));
$album = new Album($_POST['albumID']);
echo $album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']);
2014-02-17 16:01:46 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
private function deleteAlbum() {
Module::dependencies(isset($_POST['albumIDs']));
$album = new Album($_POST['albumIDs']);
2014-08-29 17:27:09 +00:00
echo $album->delete();
2014-04-28 09:23:18 +00:00
}
private function mergeAlbums() {
2015-05-05 20:06:54 +00:00
Module::dependencies(isset($_POST['albumIDs']));
$album = new Album($_POST['albumIDs']);
echo $album->merge();
2015-05-05 20:06:54 +00:00
}
2014-04-28 09:23:18 +00:00
# Photo functions
private function getPhoto() {
Module::dependencies(isset($_POST['photoID'], $_POST['albumID']));
$photo = new Photo($_POST['photoID']);
2014-04-28 09:23:18 +00:00
echo json_encode($photo->get($_POST['albumID']));
}
private function setPhotoTitle() {
Module::dependencies(isset($_POST['photoIDs'], $_POST['title']));
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setTitle($_POST['title']);
}
private function setPhotoDescription() {
Module::dependencies(isset($_POST['photoID'], $_POST['description']));
$photo = new Photo($_POST['photoID']);
2014-04-28 09:23:18 +00:00
echo $photo->setDescription($_POST['description']);
}
private function setPhotoStar() {
Module::dependencies(isset($_POST['photoIDs']));
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setStar();
}
private function setPhotoPublic() {
Module::dependencies(isset($_POST['photoID']));
$photo = new Photo($_POST['photoID']);
2014-04-28 09:23:18 +00:00
echo $photo->setPublic();
}
private function setPhotoAlbum() {
Module::dependencies(isset($_POST['photoIDs'], $_POST['albumID']));
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setAlbum($_POST['albumID']);
}
private function setPhotoTags() {
Module::dependencies(isset($_POST['photoIDs'], $_POST['tags']));
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setTags($_POST['tags']);
}
private function duplicatePhoto() {
Module::dependencies(isset($_POST['photoIDs']));
$photo = new Photo($_POST['photoIDs']);
echo $photo->duplicate();
}
2014-04-28 09:23:18 +00:00
private function deletePhoto() {
Module::dependencies(isset($_POST['photoIDs']));
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->delete();
}
# Add functions
private function upload() {
Module::dependencies(isset($_FILES, $_POST['albumID'], $_POST['tags']));
$photo = new Photo(null);
echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']);
2014-04-28 09:23:18 +00:00
}
private function importUrl() {
Module::dependencies(isset($_POST['url'], $_POST['albumID']));
$import = new Import();
echo $import->url($_POST['url'], $_POST['albumID']);
2014-04-28 09:23:18 +00:00
}
private function importServer() {
2014-07-23 19:58:41 +00:00
Module::dependencies(isset($_POST['albumID'], $_POST['path']));
$import = new Import();
echo $import->server($_POST['path'], $_POST['albumID']);
2014-04-28 09:23:18 +00:00
}
# Search function
private function search() {
Module::dependencies(isset($_POST['term']));
echo json_encode(search($_POST['term']));
2014-04-28 09:23:18 +00:00
}
# Session functions
private function init() {
global $dbName;
$session = new Session();
echo json_encode($session->init(false));
2014-04-28 09:23:18 +00:00
}
private function login() {
Module::dependencies(isset($_POST['user'], $_POST['password']));
$session = new Session();
2014-04-28 09:23:18 +00:00
echo $session->login($_POST['user'], $_POST['password']);
}
private function logout() {
$session = new Session();
2014-04-28 09:23:18 +00:00
echo $session->logout();
}
# Settings functions
private function setLogin() {
Module::dependencies(isset($_POST['username'], $_POST['password']));
if (!isset($_POST['oldPassword'])) $_POST['oldPassword'] = '';
echo Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
2014-04-28 09:23:18 +00:00
}
private function setSorting() {
2015-05-14 15:20:33 +00:00
Module::dependencies(isset($_POST['typeAlbums'], $_POST['orderAlbums'], $_POST['typePhotos'], $_POST['orderPhotos']));
$sA = Settings::setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']);
$sP = Settings::setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']);
2015-05-14 15:20:33 +00:00
if ($sA===true&&$sP===true) echo true;
else echo false;
2014-04-28 09:23:18 +00:00
}
private function setDropboxKey() {
Module::dependencies(isset($_POST['key']));
echo Settings::setDropboxKey($_POST['key']);
2014-04-28 09:23:18 +00:00
}
# Get functions
private function getAlbumArchive() {
Module::dependencies(isset($_GET['albumID']));
$album = new Album($_GET['albumID']);
2014-04-28 09:23:18 +00:00
$album->getArchive();
}
private function getPhotoArchive() {
Module::dependencies(isset($_GET['photoID']));
$photo = new Photo($_GET['photoID']);
2014-04-28 09:23:18 +00:00
$photo->getArchive();
}
}