2014-04-30 08:56:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
###
|
|
|
|
# @name Guest Access (Public Mode)
|
2015-02-01 21:08:37 +00:00
|
|
|
# @copyright 2015 by Tobias Reich
|
2014-04-30 08:56:04 +00:00
|
|
|
###
|
|
|
|
|
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
if (!defined('LYCHEE_ACCESS_GUEST')) exit('Error: You are not allowed to access this area!');
|
|
|
|
|
|
|
|
class Guest extends Access {
|
|
|
|
|
|
|
|
public function check($fn) {
|
|
|
|
|
|
|
|
switch ($fn) {
|
|
|
|
|
|
|
|
# Album functions
|
2015-02-02 22:36:33 +00:00
|
|
|
case 'Album::getAll': $this->getAlbums(); break;
|
|
|
|
case 'Album::get': $this->getAlbum(); break;
|
|
|
|
case 'Album::getPublic': $this->checkAlbumAccess(); break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Photo functions
|
2015-02-02 22:36:33 +00:00
|
|
|
case 'Photo::get': $this->getPhoto(); break;
|
2014-04-30 08:56:04 +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-04-30 08:56:04 +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-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Error
|
2014-04-30 09:09:28 +00:00
|
|
|
default: exit('Error: Function not found! Please check the spelling of the called function.');
|
|
|
|
return false; break;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Album functions
|
|
|
|
|
|
|
|
private function getAlbums() {
|
|
|
|
|
|
|
|
$album = new Album($this->database, $this->plugins, $this->settings, null);
|
|
|
|
echo json_encode($album->getAll(true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAlbum() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['albumID'], $_POST['password']));
|
|
|
|
$album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
|
|
|
|
|
|
|
|
if ($album->getPublic()) {
|
|
|
|
|
|
|
|
# Album public
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
|
|
|
|
else echo 'Warning: Wrong password!';
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Album private
|
|
|
|
echo 'Warning: Album private!';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function checkAlbumAccess() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['albumID'], $_POST['password']));
|
|
|
|
$album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
|
|
|
|
|
|
|
|
if ($album->getPublic()) {
|
|
|
|
|
|
|
|
# Album public
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($album->checkPassword($_POST['password'])) echo true;
|
|
|
|
else echo false;
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Album private
|
|
|
|
echo false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Photo functions
|
|
|
|
|
|
|
|
private function getPhoto() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['photoID'], $_POST['albumID'], $_POST['password']));
|
|
|
|
$photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
|
|
|
|
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($photo->getPublic($_POST['password'])) echo json_encode($photo->get($_POST['albumID']));
|
|
|
|
else echo 'Warning: Wrong password!';
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Session functions
|
|
|
|
|
|
|
|
private function init() {
|
|
|
|
|
|
|
|
global $dbName;
|
|
|
|
|
|
|
|
$session = new Session($this->plugins, $this->settings);
|
|
|
|
echo json_encode($session->init($this->database, $dbName, true, $_POST['version']));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function login() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_POST['user'], $_POST['password']));
|
|
|
|
$session = new Session($this->plugins, $this->settings);
|
|
|
|
echo $session->login($_POST['user'], $_POST['password']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-14 19:44:08 +00:00
|
|
|
private function logout() {
|
|
|
|
|
|
|
|
$session = new Session($this->plugins, $this->settings);
|
|
|
|
echo $session->logout();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-30 08:56:04 +00:00
|
|
|
# $_GET functions
|
|
|
|
|
|
|
|
private function getAlbumArchive() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_GET['albumID'], $_GET['password']));
|
|
|
|
$album = new Album($this->database, $this->plugins, $this->settings, $_GET['albumID']);
|
|
|
|
|
2014-08-17 18:22:46 +00:00
|
|
|
if ($album->getPublic()&&$album->getDownloadable()) {
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
# Album Public
|
2015-02-16 19:27:27 +00:00
|
|
|
if ($album->checkPassword($_GET['password'])) $album->getArchive();
|
|
|
|
else exit('Warning: Wrong password!');
|
2014-04-30 08:56:04 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Album Private
|
|
|
|
exit('Warning: Album private or not downloadable!');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPhotoArchive() {
|
|
|
|
|
|
|
|
Module::dependencies(isset($_GET['photoID'], $_GET['password']));
|
|
|
|
$photo = new Photo($this->database, $this->plugins, null, $_GET['photoID']);
|
|
|
|
|
|
|
|
# Photo Download
|
|
|
|
if ($photo->getPublic($_GET['password'])) {
|
|
|
|
|
|
|
|
# Photo Public
|
|
|
|
$photo->getArchive();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# Photo Private
|
|
|
|
exit('Warning: Photo private or not downloadable!');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|