lychee/php/Access/Admin.php

338 lines
8.2 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\Photo;
use Lychee\Modules\Session;
use Lychee\Modules\Settings;
use Lychee\Modules\Validator;
2014-02-09 18:21:55 +00:00
final class Admin extends Access {
2014-02-09 18:21:55 +00:00
public static function init($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
case 'Album::getAll': self::getAlbumsAction(); break;
case 'Album::get': self::getAlbumAction(); break;
case 'Album::add': self::addAlbumAction(); break;
case 'Album::setTitle': self::setAlbumTitleAction(); break;
case 'Album::setDescription': self::setAlbumDescriptionAction(); break;
case 'Album::setPublic': self::setAlbumPublicAction(); break;
case 'Album::delete': self::deleteAlbumAction(); break;
case 'Album::merge': self::mergeAlbumsAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Photo functions
case 'Photo::get': self::getPhotoAction(); break;
case 'Photo::setTitle': self::setPhotoTitleAction(); break;
case 'Photo::setDescription': self::setPhotoDescriptionAction(); break;
case 'Photo::setStar': self::setPhotoStarAction(); break;
case 'Photo::setPublic': self::setPhotoPublicAction(); break;
case 'Photo::setAlbum': self::setPhotoAlbumAction(); break;
case 'Photo::setTags': self::setPhotoTagsAction(); break;
case 'Photo::duplicate': self::duplicatePhotoAction(); break;
case 'Photo::delete': self::deletePhotoAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Add functions
case 'Photo::add': self::uploadAction(); break;
case 'Import::url': self::importUrlAction(); break;
case 'Import::server': self::importServerAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Search functions
case 'search': self::searchAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Session functions
case 'Session::init': self::initAction(); break;
case 'Session::login': self::loginAction(); break;
case 'Session::logout': self::logoutAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Settings functions
case 'Settings::setLogin': self::setLoginAction(); break;
case 'Settings::setSorting': self::setSortingAction(); break;
case 'Settings::setDropboxKey': self::setDropboxKeyAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# $_GET functions
case 'Album::getArchive': self::getAlbumArchiveAction(); break;
case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
2014-02-09 18:21:55 +00:00
2014-04-28 09:23:18 +00:00
# Error
default: self::fnNotFound(); 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
private static function getAlbumsAction() {
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
private static function getAlbumAction() {
Validator::required(isset($_POST['albumID']), __METHOD__);
2014-02-09 18:21:55 +00:00
$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
private static function addAlbumAction() {
Validator::required(isset($_POST['title']), __METHOD__);
2014-02-09 18:21:55 +00:00
$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
private static function setAlbumTitleAction() {
Validator::required(isset($_POST['albumIDs'], $_POST['title']), __METHOD__);
2014-02-09 18:21:55 +00:00
$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
private static function setAlbumDescriptionAction() {
Validator::required(isset($_POST['albumID'], $_POST['description']), __METHOD__);
2014-02-09 18:21:55 +00:00
$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
private static function setAlbumPublicAction() {
Validator::required(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']), __METHOD__);
2014-02-17 16:01:46 +00:00
$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
private static function deleteAlbumAction() {
Validator::required(isset($_POST['albumIDs']), __METHOD__);
2014-04-28 09:23:18 +00:00
$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 static function mergeAlbumsAction() {
2015-05-05 20:06:54 +00:00
Validator::required(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 static function getPhotoAction() {
Validator::required(isset($_POST['photoID'], $_POST['albumID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoID']);
2014-04-28 09:23:18 +00:00
echo json_encode($photo->get($_POST['albumID']));
}
private static function setPhotoTitleAction() {
Validator::required(isset($_POST['photoIDs'], $_POST['title']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setTitle($_POST['title']);
}
private static function setPhotoDescriptionAction() {
Validator::required(isset($_POST['photoID'], $_POST['description']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoID']);
2014-04-28 09:23:18 +00:00
echo $photo->setDescription($_POST['description']);
}
private static function setPhotoStarAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setStar();
}
private static function setPhotoPublicAction() {
Validator::required(isset($_POST['photoID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoID']);
2014-04-28 09:23:18 +00:00
echo $photo->setPublic();
}
private static function setPhotoAlbumAction() {
Validator::required(isset($_POST['photoIDs'], $_POST['albumID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setAlbum($_POST['albumID']);
}
private static function setPhotoTagsAction() {
Validator::required(isset($_POST['photoIDs'], $_POST['tags']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->setTags($_POST['tags']);
}
private static function duplicatePhotoAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);
$photo = new Photo($_POST['photoIDs']);
echo $photo->duplicate();
}
private static function deletePhotoAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoIDs']);
2014-04-28 09:23:18 +00:00
echo $photo->delete();
}
# Add functions
private static function uploadAction() {
Validator::required(isset($_FILES, $_POST['albumID'], $_POST['tags']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo(null);
echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']);
2014-04-28 09:23:18 +00:00
}
private static function importUrlAction() {
Validator::required(isset($_POST['url'], $_POST['albumID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$import = new Import();
echo $import->url($_POST['url'], $_POST['albumID']);
2014-04-28 09:23:18 +00:00
}
private static function importServerAction() {
Validator::required(isset($_POST['albumID'], $_POST['path']), __METHOD__);
2014-04-28 09:23:18 +00:00
$import = new Import();
echo $import->server($_POST['path'], $_POST['albumID']);
2014-04-28 09:23:18 +00:00
}
# Search functions
private static function searchAction() {
2014-04-28 09:23:18 +00:00
Validator::required(isset($_POST['term']), __METHOD__);
2014-04-28 09:23:18 +00:00
echo json_encode(search($_POST['term']));
2014-04-28 09:23:18 +00:00
}
# Session functions
private static function initAction() {
2014-04-28 09:23:18 +00:00
$session = new Session();
echo json_encode($session->init(false));
2014-04-28 09:23:18 +00:00
}
private static function loginAction() {
Validator::required(isset($_POST['user'], $_POST['password']), __METHOD__);
2014-04-28 09:23:18 +00:00
$session = new Session();
2014-04-28 09:23:18 +00:00
echo $session->login($_POST['user'], $_POST['password']);
}
private static function logoutAction() {
2014-04-28 09:23:18 +00:00
$session = new Session();
2014-04-28 09:23:18 +00:00
echo $session->logout();
}
# Settings functions
private static function setLoginAction() {
Validator::required(isset($_POST['username'], $_POST['password']), __METHOD__);
2014-04-28 09:23:18 +00:00
echo Settings::setLogin(@$_POST['oldPassword'], $_POST['username'], $_POST['password']);
2014-04-28 09:23:18 +00:00
}
private static function setSortingAction() {
2014-04-28 09:23:18 +00:00
Validator::required(isset($_POST['typeAlbums'], $_POST['orderAlbums'], $_POST['typePhotos'], $_POST['orderPhotos']), __METHOD__);
2015-05-14 15:20:33 +00:00
$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 static function setDropboxKeyAction() {
Validator::required(isset($_POST['key']), __METHOD__);
2014-04-28 09:23:18 +00:00
echo Settings::setDropboxKey($_POST['key']);
2014-04-28 09:23:18 +00:00
}
# Get functions
private static function getAlbumArchiveAction() {
Validator::required(isset($_GET['albumID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$album = new Album($_GET['albumID']);
2014-04-28 09:23:18 +00:00
$album->getArchive();
}
private static function getPhotoArchiveAction() {
Validator::required(isset($_GET['photoID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_GET['photoID']);
2014-04-28 09:23:18 +00:00
$photo->getArchive();
}
}