lychee/php/Access/Admin.php

344 lines
8.8 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\Albums;
use Lychee\Modules\Import;
use Lychee\Modules\Photo;
2016-02-07 13:32:46 +00:00
use Lychee\Modules\Response;
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
// Albums functions
case 'Albums::get': self::getAlbumsAction(); break;
// Album functions
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;
// 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;
// Add functions
case 'Photo::add': self::uploadAction(); break;
case 'Import::url': self::importUrlAction(); break;
case 'Import::server': self::importServerAction(); break;
// Search functions
case 'search': self::searchAction(); break;
// Session functions
case 'Session::init': self::initAction(); break;
case 'Session::login': self::loginAction(); break;
case 'Session::logout': self::logoutAction(); break;
// Settings functions
case 'Settings::setLogin': self::setLoginAction(); break;
case 'Settings::setSorting': self::setSortingAction(); break;
case 'Settings::setDropboxKey': self::setDropboxKeyAction(); break;
// $_GET functions
case 'Album::getArchive': self::getAlbumArchiveAction(); break;
case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
self::fnNotFound();
2014-04-30 08:54:53 +00:00
2014-04-28 09:23:18 +00:00
}
2014-02-09 18:21:55 +00:00
// Albums functions
2014-02-09 18:21:55 +00:00
private static function getAlbumsAction() {
2014-02-09 18:21:55 +00:00
$albums = new Albums();
Response::json($albums->get(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
// Album functions
private static function getAlbumAction() {
Validator::required(isset($_POST['albumID']), __METHOD__);
2014-02-09 18:21:55 +00:00
$album = new Album($_POST['albumID']);
2016-02-07 13:32:46 +00:00
Response::json($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);
Response::json($album->add($_POST['title']), JSON_NUMERIC_CHECK);
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']);
2016-02-13 22:38:04 +00:00
Response::json($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']);
2016-02-13 22:38:04 +00:00
Response::json($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']);
2016-02-13 22:38:04 +00:00
Response::json($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']);
2016-02-13 22:38:04 +00:00
Response::json($album->delete());
2014-04-28 09:23:18 +00:00
}
private static function mergeAlbumsAction() {
2015-05-05 20:06:54 +00:00
2016-01-30 22:23:58 +00:00
Validator::required(isset($_POST['albumIDs']), __METHOD__);
$album = new Album($_POST['albumIDs']);
2016-02-13 22:38:04 +00:00
Response::json($album->merge());
2015-05-05 20:06:54 +00:00
}
// Photo functions
2014-04-28 09:23:18 +00:00
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']);
2016-02-07 13:32:46 +00:00
Response::json($photo->get($_POST['albumID']));
2014-04-28 09:23:18 +00:00
}
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']);
2016-02-13 22:38:04 +00:00
Response::json($photo->setTitle($_POST['title']));
2014-04-28 09:23:18 +00:00
}
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']);
2016-02-13 22:38:04 +00:00
Response::json($photo->setDescription($_POST['description']));
2014-04-28 09:23:18 +00:00
}
private static function setPhotoStarAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoIDs']);
2016-02-13 22:38:04 +00:00
Response::json($photo->setStar());
2014-04-28 09:23:18 +00:00
}
private static function setPhotoPublicAction() {
Validator::required(isset($_POST['photoID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo($_POST['photoID']);
2016-02-13 22:38:04 +00:00
Response::json($photo->setPublic());
2014-04-28 09:23:18 +00:00
}
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']);
2016-02-13 22:38:04 +00:00
Response::json($photo->setAlbum($_POST['albumID']));
2014-04-28 09:23:18 +00:00
}
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']);
2016-02-13 22:38:04 +00:00
Response::json($photo->setTags($_POST['tags']));
2014-04-28 09:23:18 +00:00
}
private static function duplicatePhotoAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);
$photo = new Photo($_POST['photoIDs']);
2016-02-13 22:38:04 +00:00
Response::json($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']);
2016-02-13 22:38:04 +00:00
Response::json($photo->delete());
2014-04-28 09:23:18 +00:00
}
// Add functions
2014-04-28 09:23:18 +00:00
private static function uploadAction() {
2016-02-13 22:38:04 +00:00
Validator::required(isset($_FILES, $_POST['albumID']), __METHOD__);
2014-04-28 09:23:18 +00:00
$photo = new Photo(null);
Response::json($photo->add($_FILES, $_POST['albumID']), JSON_NUMERIC_CHECK);
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();
2016-02-13 22:38:04 +00:00
Response::json($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();
2016-03-24 20:29:09 +00:00
Response::json($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
2016-02-07 13:32:46 +00:00
Response::json(search($_POST['term']));
2014-04-28 09:23:18 +00:00
}
// Session functions
2014-04-28 09:23:18 +00:00
private static function initAction() {
2014-04-28 09:23:18 +00:00
$session = new Session();
2016-02-07 13:32:46 +00:00
Response::json($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();
2016-02-13 22:38:04 +00:00
Response::json($session->login($_POST['user'], $_POST['password']));
2014-04-28 09:23:18 +00:00
}
private static function logoutAction() {
2014-04-28 09:23:18 +00:00
$session = new Session();
2016-02-13 22:38:04 +00:00
Response::json($session->logout());
2014-04-28 09:23:18 +00:00
}
// Settings functions
2014-04-28 09:23:18 +00:00
private static function setLoginAction() {
Validator::required(isset($_POST['username'], $_POST['password']), __METHOD__);
2014-04-28 09:23:18 +00:00
if (isset($_POST['oldPassword'])===false) $_POST['oldPassword'] = '';
2016-02-13 22:38:04 +00:00
Response::json(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
2016-02-13 22:38:04 +00:00
if ($sA===true&&$sP===true) Response::json(true);
else Response::json(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
2016-02-13 22:38:04 +00:00
Response::json(Settings::setDropboxKey($_POST['key']));
2014-04-28 09:23:18 +00:00
}
// Get functions
2014-04-28 09:23:18 +00:00
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();
}
2016-01-31 14:53:44 +00:00
}
?>