Added phpDoc comments
This commit is contained in:
parent
aa00ebc77b
commit
025f6e974b
@ -8,6 +8,9 @@ final class Album {
|
||||
|
||||
private $albumIDs = null;
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function __construct($albumIDs) {
|
||||
|
||||
// Init vars
|
||||
@ -17,6 +20,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer|false ID of the created album.
|
||||
*/
|
||||
public function add($title = 'Untitled') {
|
||||
|
||||
// Call plugins
|
||||
@ -39,6 +45,10 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rurns album-attributes into a front-end friendly format. Note that some attributes remain unchanged.
|
||||
* @return array Returns album-attributes in a normalized structure.
|
||||
*/
|
||||
public static function prepareData(array $data) {
|
||||
|
||||
// This function requires the following album-attributes and turns them
|
||||
@ -72,6 +82,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false Returns an array of photos and album information or false on failure.
|
||||
*/
|
||||
public function get() {
|
||||
|
||||
// Check dependencies
|
||||
@ -117,7 +130,7 @@ final class Album {
|
||||
$photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
$previousPhotoID = '';
|
||||
|
||||
if ($photos===false) Response::error('Could not get photos of album from database!');
|
||||
if ($photos===false) return false;
|
||||
|
||||
while ($photo = $photos->fetch_assoc()) {
|
||||
|
||||
@ -167,6 +180,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false Returns an array of albums or false on failure.
|
||||
*/
|
||||
public function getAll($public = true) {
|
||||
|
||||
// Call plugins
|
||||
@ -189,7 +205,7 @@ final class Album {
|
||||
// Execute query
|
||||
$albums = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($albums===false) Response::error('Could not get albums from database!');
|
||||
if ($albums===false) return false;
|
||||
|
||||
// For each album
|
||||
while ($album = $albums->fetch_assoc()) {
|
||||
@ -205,7 +221,7 @@ final class Album {
|
||||
$query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' ORDER BY star DESC, " . substr(Settings::get()['sortingPhotos'], 9) . " LIMIT 3", array(LYCHEE_TABLE_PHOTOS, $album['id']));
|
||||
$thumbs = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($thumbs===false) Response::error('Could not get thumbs of album from database!');
|
||||
if ($thumbs===false) return false;
|
||||
|
||||
// For each thumb
|
||||
$k = 0;
|
||||
@ -231,6 +247,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false Returns an array of smart albums or false on failure.
|
||||
*/
|
||||
private function getSmartInfo() {
|
||||
|
||||
// Initialize return var
|
||||
@ -249,7 +268,7 @@ final class Album {
|
||||
$unsorted = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
$i = 0;
|
||||
|
||||
if ($unsorted===false) Response::error('Could not get unsorted photos from database!');
|
||||
if ($unsorted===false) return false;
|
||||
|
||||
$return['unsorted'] = array(
|
||||
'thumbs' => array(),
|
||||
@ -271,7 +290,7 @@ final class Album {
|
||||
$starred = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
$i = 0;
|
||||
|
||||
if ($starred===false) Response::error('Could not get starred photos from database!');
|
||||
if ($starred===false) return false;
|
||||
|
||||
$return['starred'] = array(
|
||||
'thumbs' => array(),
|
||||
@ -293,7 +312,7 @@ final class Album {
|
||||
$public = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
$i = 0;
|
||||
|
||||
if ($public===false) Response::error('Could not get public photos from database!');
|
||||
if ($public===false) return false;
|
||||
|
||||
$return['public'] = array(
|
||||
'thumbs' => array(),
|
||||
@ -315,7 +334,7 @@ final class Album {
|
||||
$recent = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
$i = 0;
|
||||
|
||||
if ($recent===false) Response::error('Could not get recent photos from database!');
|
||||
if ($recent===false) return false;
|
||||
|
||||
$return['recent'] = array(
|
||||
'thumbs' => array(),
|
||||
@ -334,6 +353,10 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a download of an album.
|
||||
* @return resource|boolean Sends a ZIP-file or returns false on failure.
|
||||
*/
|
||||
public function getArchive() {
|
||||
|
||||
// Check dependencies
|
||||
@ -373,7 +396,7 @@ final class Album {
|
||||
$query = Database::prepare(Database::get(), "SELECT title FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||
$album = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($album===false) Response::error('Could not get album from database!');
|
||||
if ($album===false) return false;
|
||||
|
||||
// Get album object
|
||||
$album = $album->fetch_object();
|
||||
@ -381,7 +404,7 @@ final class Album {
|
||||
// Photo not found
|
||||
if ($album===null) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
|
||||
Response::error('Could not find specified album!');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set title
|
||||
@ -404,12 +427,12 @@ final class Album {
|
||||
// Execute query
|
||||
$photos = Database::execute(Database::get(), $photos, __METHOD__, __LINE__);
|
||||
|
||||
if ($album===null) Response::error('Could not get photos from database!');
|
||||
if ($album===null) return false;
|
||||
|
||||
// Check if album empty
|
||||
if ($photos->num_rows==0) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not create ZipArchive without images');
|
||||
Response::error('Could not create ZipArchive without images!');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse each path
|
||||
@ -472,6 +495,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setTitle($title = 'Untitled') {
|
||||
|
||||
// Check dependencies
|
||||
@ -492,6 +518,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setDescription($description = '') {
|
||||
|
||||
// Check dependencies
|
||||
@ -512,6 +541,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when the album is public.
|
||||
*/
|
||||
public function getPublic() {
|
||||
|
||||
// Check dependencies
|
||||
@ -539,6 +571,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when the album is downloadable.
|
||||
*/
|
||||
public function getDownloadable() {
|
||||
|
||||
// Check dependencies
|
||||
@ -566,6 +601,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setPublic($public, $password, $visible, $downloadable) {
|
||||
|
||||
// Check dependencies
|
||||
@ -604,6 +642,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
private function setPassword($password) {
|
||||
|
||||
// Check dependencies
|
||||
@ -640,6 +681,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns when album is public.
|
||||
*/
|
||||
public function checkPassword($password) {
|
||||
|
||||
// Check dependencies
|
||||
@ -667,6 +711,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function merge() {
|
||||
|
||||
// Check dependencies
|
||||
@ -702,6 +749,9 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function delete() {
|
||||
|
||||
// Check dependencies
|
||||
|
@ -26,6 +26,9 @@ final class Import {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function url($urls, $albumID = 0) {
|
||||
|
||||
// Call plugins
|
||||
@ -85,6 +88,11 @@ final class Import {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean|string Returns true when successful.
|
||||
* Warning: Folder empty or no readable files to process!
|
||||
* Notice: Import only contained albums!
|
||||
*/
|
||||
public function server($path, $albumID = 0) {
|
||||
|
||||
// Parse path
|
||||
@ -93,7 +101,7 @@ final class Import {
|
||||
|
||||
if (is_dir($path)===false) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')');
|
||||
return 'Error: Given path is not a directory!';
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip folders of Lychee
|
||||
@ -101,7 +109,7 @@ final class Import {
|
||||
$path===LYCHEE_UPLOADS_MEDIUM||($path . '/')===LYCHEE_UPLOADS_MEDIUM||
|
||||
$path===LYCHEE_UPLOADS_THUMB||($path . '/')===LYCHEE_UPLOADS_THUMB) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')');
|
||||
return 'Error: Given path is a reserved path of Lychee!';
|
||||
return false;
|
||||
}
|
||||
|
||||
$error = false;
|
||||
|
@ -21,6 +21,9 @@ final class Photo {
|
||||
'.gif'
|
||||
);
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function __construct($photoIDs) {
|
||||
|
||||
// Init vars
|
||||
@ -251,11 +254,14 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false Returns a subset of a photo when same photo exists or returns false on failure.
|
||||
*/
|
||||
private function exists($checksum, $photoID = null) {
|
||||
|
||||
// Exclude $photoID from select when $photoID is set
|
||||
if (isset($photoID)) $query = Database::prepare(Database::get(), "SELECT id, url, thumbUrl, medium FROM ? WHERE checksum = '?' AND id <> '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $checksum, $photoID));
|
||||
else $query = Database::prepare(Database::get(), "SELECT id, url, thumbUrl, medium FROM ? WHERE checksum = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $checksum));
|
||||
else $query = Database::prepare(Database::get(), "SELECT id, url, thumbUrl, medium FROM ? WHERE checksum = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $checksum));
|
||||
|
||||
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
@ -280,6 +286,9 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
private function createThumb($url, $filename, $type, $width, $height) {
|
||||
|
||||
// Call plugins
|
||||
@ -369,17 +378,18 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a smaller version of a photo when its size is bigger than a preset size.
|
||||
* Photo must be big enough, medium must be activated and Imagick must be installed and activated.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
private function createMedium($url, $filename, $width, $height) {
|
||||
|
||||
// Function creates a smaller version of a photo when its size is bigger than a preset size
|
||||
// Excepts the following:
|
||||
// (string) $url = Path to the photo-file
|
||||
// (string) $filename = Name of the photo-file
|
||||
// (int) $width = Width of the photo
|
||||
// (int) $height = Height of the photo
|
||||
// Returns the following
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Call plugins
|
||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||
@ -446,15 +456,15 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates and flips a photo based on its EXIF orientation.
|
||||
* @return array|false Returns an array with the new orientation, width, height or false on failure.
|
||||
*/
|
||||
public function adjustFile($path, array $info) {
|
||||
|
||||
// Function rotates and flips a photo based on its EXIF orientation
|
||||
// Excepts the following:
|
||||
// (string) $path = Path to the photo-file
|
||||
// (array) $info = ['orientation', 'width', 'height']
|
||||
// Returns the following
|
||||
// (array) $info = ['orientation', 'width', 'height'] = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Call plugins
|
||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||
@ -577,13 +587,14 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rurns photo-attributes into a front-end friendly format. Note that some attributes remain unchanged.
|
||||
* @return array Returns photo-attributes in a normalized structure.
|
||||
*/
|
||||
public static function prepareData(array $data) {
|
||||
|
||||
// Function turns photo-attributes into a front-end friendly format. Note that some attributes remain unchanged.
|
||||
// Excepts the following:
|
||||
// (array) $data = ['id', 'title', 'tags', 'public', 'star', 'album', 'thumbUrl', 'takestamp', 'url']
|
||||
// Returns the following:
|
||||
// (array) $photo
|
||||
|
||||
// Init
|
||||
$photo = null;
|
||||
@ -619,13 +630,13 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false Returns an array with information about the photo or false on failure.
|
||||
*/
|
||||
public function get($albumID) {
|
||||
|
||||
// Functions returns data of a photo
|
||||
// Excepts the following:
|
||||
// (string) $albumID = Album which is currently visible to the user
|
||||
// Returns the following:
|
||||
// (array) $photo
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
@ -637,7 +648,7 @@ final class Photo {
|
||||
$query = Database::prepare(Database::get(), "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $this->photoIDs));
|
||||
$photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($photos===false) Response::error('Could not get photo from database!');
|
||||
if ($photos===false) return false;
|
||||
|
||||
// Get photo object
|
||||
$photo = $photos->fetch_assoc();
|
||||
@ -664,7 +675,7 @@ final class Photo {
|
||||
$query = Database::prepare(Database::get(), "SELECT public FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $photo['album']));
|
||||
$albums = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($albums===false) Response::error('Could not get album of photo from database!');
|
||||
if ($albums===false) return false;
|
||||
|
||||
// Get album object
|
||||
$album = $albums->fetch_assoc();
|
||||
@ -686,6 +697,10 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads and parses information and metadata out of a photo.
|
||||
* @return array Returns an array of photo information and metadata.
|
||||
*/
|
||||
public function getInfo($url) {
|
||||
|
||||
// Functions returns information and metadata of a photo
|
||||
@ -791,13 +806,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a download of a photo.
|
||||
* @return resource|boolean Sends a ZIP-file or returns false on failure.
|
||||
*/
|
||||
public function getArchive() {
|
||||
|
||||
// Functions starts a download of a photo
|
||||
// Returns the following:
|
||||
// (boolean + output) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -808,7 +822,7 @@ final class Photo {
|
||||
$query = Database::prepare(Database::get(), "SELECT title, url FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $this->photoIDs));
|
||||
$photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($photos===false) Response::error('Could not get photo from database!');
|
||||
if ($photos===false) return false;
|
||||
|
||||
// Get photo object
|
||||
$photo = $photos->fetch_object();
|
||||
@ -816,7 +830,7 @@ final class Photo {
|
||||
// Photo not found
|
||||
if ($photo===null) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified photo');
|
||||
Response::error('Could not find specified photo!');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get extension
|
||||
@ -853,15 +867,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title of a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
|
||||
// Functions sets the title of a photo
|
||||
// Excepts the following:
|
||||
// (string) $title = Title with a maximum length of 50 chars
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -880,15 +891,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description of a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setDescription($description) {
|
||||
|
||||
// Functions sets the description of a photo
|
||||
// Excepts the following:
|
||||
// (string) $description = Description with a maximum length of 1000 chars
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -907,13 +915,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the star property of a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setStar() {
|
||||
|
||||
// Functions stars a photo
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -951,14 +958,14 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if photo or parent album is public.
|
||||
* @return integer 0 = Photo private and parent album private
|
||||
* 1 = Album public, but password incorrect
|
||||
* 2 = Photo public or album public and password correct
|
||||
*/
|
||||
public function getPublic($password) {
|
||||
|
||||
// Functions checks if photo or parent album is public
|
||||
// Returns the following:
|
||||
// (int) 0 = Photo private and parent album private
|
||||
// (int) 1 = Album public, but password incorrect
|
||||
// (int) 2 = Photo public or album public and password correct
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -1003,13 +1010,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the public property of a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setPublic() {
|
||||
|
||||
// Functions toggles the public property of a photo
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -1040,13 +1046,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent album of a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
function setAlbum($albumID) {
|
||||
|
||||
// Functions sets the parent album of a photo
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -1065,14 +1070,14 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tags of a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function setTags($tags) {
|
||||
|
||||
// Functions sets the tags of a photo
|
||||
// Excepts the following:
|
||||
// (string) $tags = Comma separated list of tags with a maximum length of 1000 chars
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
@ -1096,13 +1101,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicates a photo.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function duplicate() {
|
||||
|
||||
// Functions duplicates a photo
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
@ -1139,13 +1143,12 @@ final class Photo {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a photo with all its data and files.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function delete() {
|
||||
|
||||
// Functions deletes a photo with all its data and files
|
||||
// Returns the following:
|
||||
// (boolean) true = Success
|
||||
// (boolean) false = Failure
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->photoIDs), __METHOD__);
|
||||
|
||||
|
@ -4,6 +4,10 @@ namespace Lychee\Modules;
|
||||
|
||||
final class Session {
|
||||
|
||||
/**
|
||||
* Reads and returns information about the Lychee installation.
|
||||
* @return array Returns an array with the login status and configuration.
|
||||
*/
|
||||
public function init($public = true) {
|
||||
|
||||
// Call plugins
|
||||
@ -15,11 +19,9 @@ final class Session {
|
||||
// Path to Lychee for the server-import dialog
|
||||
$return['config']['location'] = LYCHEE;
|
||||
|
||||
// Remove username and password from response
|
||||
// Remove sensitive from response
|
||||
unset($return['config']['username']);
|
||||
unset($return['config']['password']);
|
||||
|
||||
// Remove identifier from response
|
||||
unset($return['config']['identifier']);
|
||||
|
||||
// Check if login credentials exist and login if they don't
|
||||
@ -60,6 +62,10 @@ final class Session {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the session values when username and password correct.
|
||||
* @return boolean Returns true when login was successful.
|
||||
*/
|
||||
public function login($username, $password) {
|
||||
|
||||
// Call plugins
|
||||
@ -86,6 +92,10 @@ final class Session {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the session values when no there is no username and password in the database.
|
||||
* @return boolean Returns true when no login was found.
|
||||
*/
|
||||
private function noLogin() {
|
||||
|
||||
// Check if login credentials exist and login if they don't
|
||||
@ -100,14 +110,16 @@ final class Session {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets the session values.
|
||||
* @return boolean Returns true when logout was successful.
|
||||
*/
|
||||
public function logout() {
|
||||
|
||||
// Call plugins
|
||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||
|
||||
$_SESSION['login'] = null;
|
||||
$_SESSION['identifier'] = null;
|
||||
|
||||
session_unset();
|
||||
session_destroy();
|
||||
|
||||
// Call plugins
|
||||
|
@ -6,6 +6,9 @@ final class Settings {
|
||||
|
||||
private static $cache = null;
|
||||
|
||||
/**
|
||||
* @return array Returns the settings of Lychee.
|
||||
*/
|
||||
public static function get() {
|
||||
|
||||
if (self::$cache) return self::$cache;
|
||||
@ -26,6 +29,9 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
private static function set($key, $value, $row = false) {
|
||||
|
||||
if ($row===false) {
|
||||
@ -50,6 +56,11 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username and password when current password is correct.
|
||||
* Exits on error.
|
||||
* @return true Returns true when successful.
|
||||
*/
|
||||
public static function setLogin($oldPassword = '', $username, $password) {
|
||||
|
||||
if ($oldPassword===self::get()['password']||self::get()['password']===crypt($oldPassword, self::get()['password'])) {
|
||||
@ -68,6 +79,10 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new username.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
private static function setUsername($username) {
|
||||
|
||||
// Check dependencies
|
||||
@ -84,6 +99,10 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new username.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
private static function setPassword($password) {
|
||||
|
||||
// Check dependencies
|
||||
@ -99,6 +118,10 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new dropboxKey.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public static function setDropboxKey($dropboxKey) {
|
||||
|
||||
if (strlen($dropboxKey)<1||strlen($dropboxKey)>50) {
|
||||
@ -111,6 +134,10 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new sorting for the photos.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public static function setSortingPhotos($type, $order) {
|
||||
|
||||
$sorting = 'ORDER BY ';
|
||||
@ -125,7 +152,9 @@ final class Settings {
|
||||
case 'type': $sorting .= 'type'; break;
|
||||
case 'star': $sorting .= 'star'; break;
|
||||
case 'takestamp': $sorting .= 'takestamp'; break;
|
||||
default: Response::error('Unknown type for sorting!');
|
||||
default: Log::error(Database::get(), __METHOD__, __LINE__, 'Could not update settings. Unknown type for sorting.');
|
||||
return false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -136,7 +165,9 @@ final class Settings {
|
||||
|
||||
case 'ASC': $sorting .= 'ASC'; break;
|
||||
case 'DESC': $sorting .= 'DESC'; break;
|
||||
default: Response::error('Unknown order for sorting!');
|
||||
default: Log::error(Database::get(), __METHOD__, __LINE__, 'Could not update settings. Unknown order for sorting.');
|
||||
return false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -148,6 +179,10 @@ final class Settings {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new sorting for the albums.
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public static function setSortingAlbums($type, $order) {
|
||||
|
||||
$sorting = 'ORDER BY ';
|
||||
@ -159,7 +194,9 @@ final class Settings {
|
||||
case 'title': $sorting .= 'title'; break;
|
||||
case 'description': $sorting .= 'description'; break;
|
||||
case 'public': $sorting .= 'public'; break;
|
||||
default: Response::error('Unknown type for sorting!');
|
||||
default: Log::error(Database::get(), __METHOD__, __LINE__, 'Could not update settings. Unknown type for sorting.');
|
||||
return false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -170,7 +207,9 @@ final class Settings {
|
||||
|
||||
case 'ASC': $sorting .= 'ASC'; break;
|
||||
case 'DESC': $sorting .= 'DESC'; break;
|
||||
default: Response::error('Unknown order for sorting!');
|
||||
default: Log::error(Database::get(), __METHOD__, __LINE__, 'Could not update settings. Unknown order for sorting.');
|
||||
return false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,9 @@ use Lychee\Modules\Album;
|
||||
use Lychee\Modules\Database;
|
||||
use Lychee\Modules\Photo;
|
||||
|
||||
/**
|
||||
* @return array|false Returns an array with albums and photos.
|
||||
*/
|
||||
function search($term) {
|
||||
|
||||
// Initialize return var
|
||||
|
Loading…
Reference in New Issue
Block a user