// for comments and spaces for alignment
This commit is contained in:
parent
b13283e4d4
commit
e89203bcb1
@ -15,7 +15,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
switch ($fn) {
|
switch ($fn) {
|
||||||
|
|
||||||
# Album functions
|
// Album functions
|
||||||
case 'Album::getAll': self::getAlbumsAction(); break;
|
case 'Album::getAll': self::getAlbumsAction(); break;
|
||||||
case 'Album::get': self::getAlbumAction(); break;
|
case 'Album::get': self::getAlbumAction(); break;
|
||||||
case 'Album::add': self::addAlbumAction(); break;
|
case 'Album::add': self::addAlbumAction(); break;
|
||||||
@ -25,7 +25,7 @@ final class Admin extends Access {
|
|||||||
case 'Album::delete': self::deleteAlbumAction(); break;
|
case 'Album::delete': self::deleteAlbumAction(); break;
|
||||||
case 'Album::merge': self::mergeAlbumsAction(); break;
|
case 'Album::merge': self::mergeAlbumsAction(); break;
|
||||||
|
|
||||||
# Photo functions
|
// Photo functions
|
||||||
case 'Photo::get': self::getPhotoAction(); break;
|
case 'Photo::get': self::getPhotoAction(); break;
|
||||||
case 'Photo::setTitle': self::setPhotoTitleAction(); break;
|
case 'Photo::setTitle': self::setPhotoTitleAction(); break;
|
||||||
case 'Photo::setDescription': self::setPhotoDescriptionAction(); break;
|
case 'Photo::setDescription': self::setPhotoDescriptionAction(); break;
|
||||||
@ -36,29 +36,29 @@ final class Admin extends Access {
|
|||||||
case 'Photo::duplicate': self::duplicatePhotoAction(); break;
|
case 'Photo::duplicate': self::duplicatePhotoAction(); break;
|
||||||
case 'Photo::delete': self::deletePhotoAction(); break;
|
case 'Photo::delete': self::deletePhotoAction(); break;
|
||||||
|
|
||||||
# Add functions
|
// Add functions
|
||||||
case 'Photo::add': self::uploadAction(); break;
|
case 'Photo::add': self::uploadAction(); break;
|
||||||
case 'Import::url': self::importUrlAction(); break;
|
case 'Import::url': self::importUrlAction(); break;
|
||||||
case 'Import::server': self::importServerAction(); break;
|
case 'Import::server': self::importServerAction(); break;
|
||||||
|
|
||||||
# Search functions
|
// Search functions
|
||||||
case 'search': self::searchAction(); break;
|
case 'search': self::searchAction(); break;
|
||||||
|
|
||||||
# Session functions
|
// Session functions
|
||||||
case 'Session::init': self::initAction(); break;
|
case 'Session::init': self::initAction(); break;
|
||||||
case 'Session::login': self::loginAction(); break;
|
case 'Session::login': self::loginAction(); break;
|
||||||
case 'Session::logout': self::logoutAction(); break;
|
case 'Session::logout': self::logoutAction(); break;
|
||||||
|
|
||||||
# Settings functions
|
// Settings functions
|
||||||
case 'Settings::setLogin': self::setLoginAction(); break;
|
case 'Settings::setLogin': self::setLoginAction(); break;
|
||||||
case 'Settings::setSorting': self::setSortingAction(); break;
|
case 'Settings::setSorting': self::setSortingAction(); break;
|
||||||
case 'Settings::setDropboxKey': self::setDropboxKeyAction(); break;
|
case 'Settings::setDropboxKey': self::setDropboxKeyAction(); break;
|
||||||
|
|
||||||
# $_GET functions
|
// $_GET functions
|
||||||
case 'Album::getArchive': self::getAlbumArchiveAction(); break;
|
case 'Album::getArchive': self::getAlbumArchiveAction(); break;
|
||||||
case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
|
case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
|
||||||
|
|
||||||
# Error
|
// Error
|
||||||
default: self::fnNotFound(); break;
|
default: self::fnNotFound(); break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Album functions
|
// Album functions
|
||||||
|
|
||||||
private static function getAlbumsAction() {
|
private static function getAlbumsAction() {
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Photo functions
|
// Photo functions
|
||||||
|
|
||||||
private static function getPhotoAction() {
|
private static function getPhotoAction() {
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add functions
|
// Add functions
|
||||||
|
|
||||||
private static function uploadAction() {
|
private static function uploadAction() {
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Search functions
|
// Search functions
|
||||||
|
|
||||||
private static function searchAction() {
|
private static function searchAction() {
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Session functions
|
// Session functions
|
||||||
|
|
||||||
private static function initAction() {
|
private static function initAction() {
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Settings functions
|
// Settings functions
|
||||||
|
|
||||||
private static function setLoginAction() {
|
private static function setLoginAction() {
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ final class Admin extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get functions
|
// Get functions
|
||||||
|
|
||||||
private static function getAlbumArchiveAction() {
|
private static function getAlbumArchiveAction() {
|
||||||
|
|
||||||
|
@ -13,24 +13,24 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
switch ($fn) {
|
switch ($fn) {
|
||||||
|
|
||||||
# Album functions
|
// Album functions
|
||||||
case 'Album::getAll': self::getAlbumsAction(); break;
|
case 'Album::getAll': self::getAlbumsAction(); break;
|
||||||
case 'Album::get': self::getAlbumAction(); break;
|
case 'Album::get': self::getAlbumAction(); break;
|
||||||
case 'Album::getPublic': self::checkAlbumAccessAction(); break;
|
case 'Album::getPublic': self::checkAlbumAccessAction(); break;
|
||||||
|
|
||||||
# Photo functions
|
// Photo functions
|
||||||
case 'Photo::get': self::getPhotoAction(); break;
|
case 'Photo::get': self::getPhotoAction(); break;
|
||||||
|
|
||||||
# Session functions
|
// Session functions
|
||||||
case 'Session::init': self::initAction(); break;
|
case 'Session::init': self::initAction(); break;
|
||||||
case 'Session::login': self::loginAction(); break;
|
case 'Session::login': self::loginAction(); break;
|
||||||
case 'Session::logout': self::logoutAction(); break;
|
case 'Session::logout': self::logoutAction(); break;
|
||||||
|
|
||||||
# $_GET functions
|
// $_GET functions
|
||||||
case 'Album::getArchive': self::getAlbumArchiveAction(); break;
|
case 'Album::getArchive': self::getAlbumArchiveAction(); break;
|
||||||
case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
|
case 'Photo::getArchive': self::getPhotoArchiveAction(); break;
|
||||||
|
|
||||||
# Error
|
// Error
|
||||||
default: self::fnNotFound(); break;
|
default: self::fnNotFound(); break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Album functions
|
// Album functions
|
||||||
|
|
||||||
private static function getAlbumsAction() {
|
private static function getAlbumsAction() {
|
||||||
|
|
||||||
@ -56,13 +56,13 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
if ($album->getPublic()) {
|
if ($album->getPublic()) {
|
||||||
|
|
||||||
# Album public
|
// Album public
|
||||||
if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
|
if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
|
||||||
else echo 'Warning: Wrong password!';
|
else echo 'Warning: Wrong password!';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Album private
|
// Album private
|
||||||
echo 'Warning: Album private!';
|
echo 'Warning: Album private!';
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -77,20 +77,20 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
if ($album->getPublic()) {
|
if ($album->getPublic()) {
|
||||||
|
|
||||||
# Album public
|
// Album public
|
||||||
if ($album->checkPassword($_POST['password'])) echo true;
|
if ($album->checkPassword($_POST['password'])) echo true;
|
||||||
else echo false;
|
else echo false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Album private
|
// Album private
|
||||||
echo false;
|
echo false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Photo functions
|
// Photo functions
|
||||||
|
|
||||||
private static function getPhotoAction() {
|
private static function getPhotoAction() {
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Session functions
|
// Session functions
|
||||||
|
|
||||||
private static function initAction() {
|
private static function initAction() {
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# $_GET functions
|
// $_GET functions
|
||||||
|
|
||||||
private static function getAlbumArchiveAction() {
|
private static function getAlbumArchiveAction() {
|
||||||
|
|
||||||
@ -141,13 +141,13 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
if ($album->getPublic()&&$album->getDownloadable()) {
|
if ($album->getPublic()&&$album->getDownloadable()) {
|
||||||
|
|
||||||
# Album Public
|
// Album Public
|
||||||
if ($album->checkPassword($_GET['password'])) $album->getArchive();
|
if ($album->checkPassword($_GET['password'])) $album->getArchive();
|
||||||
else exit('Warning: Wrong password!');
|
else exit('Warning: Wrong password!');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Album Private
|
// Album Private
|
||||||
exit('Warning: Album private or not downloadable!');
|
exit('Warning: Album private or not downloadable!');
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -162,15 +162,15 @@ final class Guest extends Access {
|
|||||||
|
|
||||||
$pgP = $photo->getPublic($_GET['password']);
|
$pgP = $photo->getPublic($_GET['password']);
|
||||||
|
|
||||||
# Photo Download
|
// Photo Download
|
||||||
if ($pgP===2) {
|
if ($pgP===2) {
|
||||||
|
|
||||||
# Photo Public
|
// Photo Public
|
||||||
$photo->getArchive();
|
$photo->getArchive();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Photo Private
|
// Photo Private
|
||||||
exit('Warning: Photo private or password incorrect!');
|
exit('Warning: Photo private or password incorrect!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ final class Installation extends Access {
|
|||||||
|
|
||||||
case 'Config::create': self::configCreateAction(); break;
|
case 'Config::create': self::configCreateAction(); break;
|
||||||
|
|
||||||
# Error
|
// Error
|
||||||
default: self::initAction(); break;
|
default: self::initAction(); break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ final class Album {
|
|||||||
|
|
||||||
public function __construct($albumIDs) {
|
public function __construct($albumIDs) {
|
||||||
|
|
||||||
# Init vars
|
// Init vars
|
||||||
$this->albumIDs = $albumIDs;
|
$this->albumIDs = $albumIDs;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -17,22 +17,22 @@ final class Album {
|
|||||||
|
|
||||||
public function add($title = 'Untitled') {
|
public function add($title = 'Untitled') {
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Parse
|
// Parse
|
||||||
if (strlen($title)>50) $title = substr($title, 0, 50);
|
if (strlen($title)>50) $title = substr($title, 0, 50);
|
||||||
|
|
||||||
# Properties
|
// Properties
|
||||||
$public = 0;
|
$public = 0;
|
||||||
$visible = 1;
|
$visible = 1;
|
||||||
|
|
||||||
# Database
|
// Database
|
||||||
$sysstamp = time();
|
$sysstamp = time();
|
||||||
$query = Database::prepare(Database::get(), "INSERT INTO ? (title, sysstamp, public, visible) VALUES ('?', '?', '?', '?')", array(LYCHEE_TABLE_ALBUMS, $title, $sysstamp, $public, $visible));
|
$query = Database::prepare(Database::get(), "INSERT INTO ? (title, sysstamp, public, visible) VALUES ('?', '?', '?', '?')", array(LYCHEE_TABLE_ALBUMS, $title, $sysstamp, $public, $visible));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -45,31 +45,31 @@ final class Album {
|
|||||||
|
|
||||||
public static function prepareData(array $data) {
|
public static function prepareData(array $data) {
|
||||||
|
|
||||||
# This function requires the following album-attributes and turns them
|
// This function requires the following album-attributes and turns them
|
||||||
# into a front-end friendly format: id, title, public, sysstamp, password
|
// into a front-end friendly format: id, title, public, sysstamp, password
|
||||||
# Note that some attributes remain unchanged
|
// Note that some attributes remain unchanged
|
||||||
|
|
||||||
# Init
|
// Init
|
||||||
$album = null;
|
$album = null;
|
||||||
|
|
||||||
# Set unchanged attributes
|
// Set unchanged attributes
|
||||||
$album['id'] = $data['id'];
|
$album['id'] = $data['id'];
|
||||||
$album['title'] = $data['title'];
|
$album['title'] = $data['title'];
|
||||||
$album['public'] = $data['public'];
|
$album['public'] = $data['public'];
|
||||||
|
|
||||||
# Additional attributes
|
// Additional attributes
|
||||||
# Only part of $album when available
|
// Only part of $album when available
|
||||||
if (isset($data['description'])) $album['description'] = $data['description'];
|
if (isset($data['description'])) $album['description'] = $data['description'];
|
||||||
if (isset($data['visible'])) $album['visible'] = $data['visible'];
|
if (isset($data['visible'])) $album['visible'] = $data['visible'];
|
||||||
if (isset($data['downloadable'])) $album['downloadable'] = $data['downloadable'];
|
if (isset($data['downloadable'])) $album['downloadable'] = $data['downloadable'];
|
||||||
|
|
||||||
# Parse date
|
// Parse date
|
||||||
$album['sysdate'] = date('F Y', $data['sysstamp']);
|
$album['sysdate'] = date('F Y', $data['sysstamp']);
|
||||||
|
|
||||||
# Parse password
|
// Parse password
|
||||||
$album['password'] = ($data['password']=='' ? '0' : '1');
|
$album['password'] = ($data['password']=='' ? '0' : '1');
|
||||||
|
|
||||||
# Parse thumbs or set default value
|
// Parse thumbs or set default value
|
||||||
$album['thumbs'] = (isset($data['thumbs']) ? explode(',', $data['thumbs']) : array());
|
$album['thumbs'] = (isset($data['thumbs']) ? explode(',', $data['thumbs']) : array());
|
||||||
|
|
||||||
return $album;
|
return $album;
|
||||||
@ -78,32 +78,37 @@ final class Album {
|
|||||||
|
|
||||||
public function get() {
|
public function get() {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Get album information
|
// Get album information
|
||||||
switch ($this->albumIDs) {
|
switch ($this->albumIDs) {
|
||||||
|
|
||||||
case 'f': $return['public'] = '0';
|
case 'f':
|
||||||
|
$return['public'] = '0';
|
||||||
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE star = 1 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE star = 1 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': $return['public'] = '0';
|
case 's':
|
||||||
|
$return['public'] = '0';
|
||||||
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE public = 1 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE public = 1 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r': $return['public'] = '0';
|
case 'r':
|
||||||
|
$return['public'] = '0';
|
||||||
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '0': $return['public'] = '0';
|
case '0':
|
||||||
|
$return['public'] = '0';
|
||||||
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = 0 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = 0 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: $query = Database::prepare(Database::get(), "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
default:
|
||||||
|
$query = Database::prepare(Database::get(), "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
$albums = Database::get()->query($query);
|
$albums = Database::get()->query($query);
|
||||||
$return = $albums->fetch_assoc();
|
$return = $albums->fetch_assoc();
|
||||||
$return = Album::prepareData($return);
|
$return = Album::prepareData($return);
|
||||||
@ -112,35 +117,35 @@ final class Album {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get photos
|
// Get photos
|
||||||
$photos = Database::get()->query($query);
|
$photos = Database::get()->query($query);
|
||||||
$previousPhotoID = '';
|
$previousPhotoID = '';
|
||||||
while ($photo = $photos->fetch_assoc()) {
|
while ($photo = $photos->fetch_assoc()) {
|
||||||
|
|
||||||
# Turn data from the database into a front-end friendly format
|
// Turn data from the database into a front-end friendly format
|
||||||
$photo = Photo::prepareData($photo);
|
$photo = Photo::prepareData($photo);
|
||||||
|
|
||||||
# Set previous and next photoID for navigation purposes
|
// Set previous and next photoID for navigation purposes
|
||||||
$photo['previousPhoto'] = $previousPhotoID;
|
$photo['previousPhoto'] = $previousPhotoID;
|
||||||
$photo['nextPhoto'] = '';
|
$photo['nextPhoto'] = '';
|
||||||
|
|
||||||
# Set current photoID as nextPhoto of previous photo
|
// Set current photoID as nextPhoto of previous photo
|
||||||
if ($previousPhotoID!=='') $return['content'][$previousPhotoID]['nextPhoto'] = $photo['id'];
|
if ($previousPhotoID!=='') $return['content'][$previousPhotoID]['nextPhoto'] = $photo['id'];
|
||||||
$previousPhotoID = $photo['id'];
|
$previousPhotoID = $photo['id'];
|
||||||
|
|
||||||
# Add to return
|
// Add to return
|
||||||
$return['content'][$photo['id']] = $photo;
|
$return['content'][$photo['id']] = $photo;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($photos->num_rows===0) {
|
if ($photos->num_rows===0) {
|
||||||
|
|
||||||
# Album empty
|
// Album empty
|
||||||
$return['content'] = false;
|
$return['content'] = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Enable next and previous for the first and last photo
|
// Enable next and previous for the first and last photo
|
||||||
$lastElement = end($return['content']);
|
$lastElement = end($return['content']);
|
||||||
$lastElementId = $lastElement['id'];
|
$lastElementId = $lastElement['id'];
|
||||||
$firstElement = reset($return['content']);
|
$firstElement = reset($return['content']);
|
||||||
@ -156,7 +161,7 @@ final class Album {
|
|||||||
$return['id'] = $this->albumIDs;
|
$return['id'] = $this->albumIDs;
|
||||||
$return['num'] = $photos->num_rows;
|
$return['num'] = $photos->num_rows;
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
@ -165,45 +170,45 @@ final class Album {
|
|||||||
|
|
||||||
public function getAll($public = true) {
|
public function getAll($public = true) {
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Initialize return var
|
// Initialize return var
|
||||||
$return = array(
|
$return = array(
|
||||||
'smartalbums' => null,
|
'smartalbums' => null,
|
||||||
'albums' => null,
|
'albums' => null,
|
||||||
'num' => 0
|
'num' => 0
|
||||||
);
|
);
|
||||||
|
|
||||||
# Get SmartAlbums
|
// Get SmartAlbums
|
||||||
if ($public===false) $return['smartalbums'] = $this->getSmartInfo();
|
if ($public===false) $return['smartalbums'] = $this->getSmartInfo();
|
||||||
|
|
||||||
# Albums query
|
// Albums query
|
||||||
if ($public===false) $query = Database::prepare(Database::get(), 'SELECT id, title, public, sysstamp, password FROM ? ' . Settings::get()['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS));
|
if ($public===false) $query = Database::prepare(Database::get(), 'SELECT id, title, public, sysstamp, password FROM ? ' . Settings::get()['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS));
|
||||||
else $query = Database::prepare(Database::get(), 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0 ' . Settings::get()['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS));
|
else $query = Database::prepare(Database::get(), 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0 ' . Settings::get()['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS));
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$albums = Database::get()->query($query);
|
$albums = Database::get()->query($query);
|
||||||
if (!$albums) {
|
if (!$albums) {
|
||||||
Log::error(__METHOD__, __LINE__, 'Could not get all albums (' . Database::get()->error . ')');
|
Log::error(__METHOD__, __LINE__, 'Could not get all albums (' . Database::get()->error . ')');
|
||||||
exit('Error: ' . Database::get()->error);
|
exit('Error: ' . Database::get()->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
# For each album
|
// For each album
|
||||||
while ($album = $albums->fetch_assoc()) {
|
while ($album = $albums->fetch_assoc()) {
|
||||||
|
|
||||||
# Turn data from the database into a front-end friendly format
|
// Turn data from the database into a front-end friendly format
|
||||||
$album = Album::prepareData($album);
|
$album = Album::prepareData($album);
|
||||||
|
|
||||||
# Thumbs
|
// Thumbs
|
||||||
if (($public===true&&$album['password']==='0')||
|
if (($public===true&&$album['password']==='0')||
|
||||||
($public===false)) {
|
($public===false)) {
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$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']));
|
$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::get()->query($query);
|
$thumbs = Database::get()->query($query);
|
||||||
|
|
||||||
# For each thumb
|
// For each thumb
|
||||||
$k = 0;
|
$k = 0;
|
||||||
while ($thumb = $thumbs->fetch_object()) {
|
while ($thumb = $thumbs->fetch_object()) {
|
||||||
$album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
|
$album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
|
||||||
@ -212,15 +217,15 @@ final class Album {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add to return
|
// Add to return
|
||||||
$return['albums'][] = $album;
|
$return['albums'][] = $album;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Num of albums
|
// Num of albums
|
||||||
$return['num'] = $albums->num_rows;
|
$return['num'] = $albums->num_rows;
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
@ -229,7 +234,7 @@ final class Album {
|
|||||||
|
|
||||||
private function getSmartInfo() {
|
private function getSmartInfo() {
|
||||||
|
|
||||||
# Initialize return var
|
// Initialize return var
|
||||||
$return = array(
|
$return = array(
|
||||||
'unsorted' => null,
|
'unsorted' => null,
|
||||||
'public' => null,
|
'public' => null,
|
||||||
@ -237,9 +242,9 @@ final class Album {
|
|||||||
'recent' => null
|
'recent' => null
|
||||||
);
|
);
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Unsorted
|
* Unsorted
|
||||||
###
|
*/
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE album = 0 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE album = 0 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
$unsorted = Database::get()->query($query);
|
$unsorted = Database::get()->query($query);
|
||||||
@ -257,9 +262,9 @@ final class Album {
|
|||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Starred
|
* Starred
|
||||||
###
|
*/
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE star = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE star = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
$starred = Database::get()->query($query);
|
$starred = Database::get()->query($query);
|
||||||
@ -277,9 +282,9 @@ final class Album {
|
|||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Public
|
* Public
|
||||||
###
|
*/
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE public = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE public = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
$public = Database::get()->query($query);
|
$public = Database::get()->query($query);
|
||||||
@ -297,9 +302,9 @@ final class Album {
|
|||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Recent
|
* Recent
|
||||||
###
|
*/
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
||||||
$recent = Database::get()->query($query);
|
$recent = Database::get()->query($query);
|
||||||
@ -317,26 +322,26 @@ final class Album {
|
|||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return SmartAlbums
|
// Return SmartAlbums
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArchive() {
|
public function getArchive() {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Illicit chars
|
// Illicit chars
|
||||||
$badChars = array_merge(
|
$badChars = array_merge(
|
||||||
array_map('chr', range(0,31)),
|
array_map('chr', range(0,31)),
|
||||||
array("<", ">", ":", '"', "/", "\\", "|", "?", "*")
|
array("<", ">", ":", '"', "/", "\\", "|", "?", "*")
|
||||||
);
|
);
|
||||||
|
|
||||||
# Photos query
|
// Photos query
|
||||||
switch($this->albumIDs) {
|
switch($this->albumIDs) {
|
||||||
case 's':
|
case 's':
|
||||||
$photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE public = 1', array(LYCHEE_TABLE_PHOTOS));
|
$photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE public = 1', array(LYCHEE_TABLE_PHOTOS));
|
||||||
@ -355,79 +360,79 @@ final class Album {
|
|||||||
$zipTitle = 'Unsorted';
|
$zipTitle = 'Unsorted';
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get title from database when album is not a SmartAlbum
|
// Get title from database when album is not a SmartAlbum
|
||||||
if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) {
|
if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) {
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), "SELECT title FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "SELECT title FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
$album = Database::get()->query($query);
|
$album = Database::get()->query($query);
|
||||||
|
|
||||||
# Error in database query
|
// Error in database query
|
||||||
if (!$album) {
|
if (!$album) {
|
||||||
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch object
|
// Fetch object
|
||||||
$album = $album->fetch_object();
|
$album = $album->fetch_object();
|
||||||
|
|
||||||
# Photo not found
|
// Photo not found
|
||||||
if ($album===null) {
|
if ($album===null) {
|
||||||
Log::error(__METHOD__, __LINE__, 'Album not found. Cannot start download.');
|
Log::error(__METHOD__, __LINE__, 'Album not found. Cannot start download.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set title
|
// Set title
|
||||||
$zipTitle = $album->title;
|
$zipTitle = $album->title;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Escape title
|
// Escape title
|
||||||
$zipTitle = str_replace($badChars, '', $zipTitle);
|
$zipTitle = str_replace($badChars, '', $zipTitle);
|
||||||
|
|
||||||
$filename = LYCHEE_DATA . $zipTitle . '.zip';
|
$filename = LYCHEE_DATA . $zipTitle . '.zip';
|
||||||
|
|
||||||
# Create zip
|
// Create zip
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
||||||
Log::error(__METHOD__, __LINE__, 'Could not create ZipArchive');
|
Log::error(__METHOD__, __LINE__, 'Could not create ZipArchive');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$photos = Database::get()->query($photos);
|
$photos = Database::get()->query($photos);
|
||||||
|
|
||||||
# Check if album empty
|
// Check if album empty
|
||||||
if ($photos->num_rows==0) {
|
if ($photos->num_rows==0) {
|
||||||
Log::error(__METHOD__, __LINE__, 'Could not create ZipArchive without images');
|
Log::error(__METHOD__, __LINE__, 'Could not create ZipArchive without images');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse each path
|
// Parse each path
|
||||||
$files = array();
|
$files = array();
|
||||||
while ($photo = $photos->fetch_object()) {
|
while ($photo = $photos->fetch_object()) {
|
||||||
|
|
||||||
# Parse url
|
// Parse url
|
||||||
$photo->url = LYCHEE_UPLOADS_BIG . $photo->url;
|
$photo->url = LYCHEE_UPLOADS_BIG . $photo->url;
|
||||||
|
|
||||||
# Parse title
|
// Parse title
|
||||||
$photo->title = str_replace($badChars, '', $photo->title);
|
$photo->title = str_replace($badChars, '', $photo->title);
|
||||||
if (!isset($photo->title)||$photo->title==='') $photo->title = 'Untitled';
|
if (!isset($photo->title)||$photo->title==='') $photo->title = 'Untitled';
|
||||||
|
|
||||||
# Check if readable
|
// Check if readable
|
||||||
if (!@is_readable($photo->url)) continue;
|
if (!@is_readable($photo->url)) continue;
|
||||||
|
|
||||||
# Get extension of image
|
// Get extension of image
|
||||||
$extension = getExtension($photo->url);
|
$extension = getExtension($photo->url);
|
||||||
|
|
||||||
# Set title for photo
|
// Set title for photo
|
||||||
$zipFileName = $zipTitle . '/' . $photo->title . $extension;
|
$zipFileName = $zipTitle . '/' . $photo->title . $extension;
|
||||||
|
|
||||||
# Check for duplicates
|
// Check for duplicates
|
||||||
if (!empty($files)) {
|
if (!empty($files)) {
|
||||||
$i = 1;
|
$i = 1;
|
||||||
while (in_array($zipFileName, $files)) {
|
while (in_array($zipFileName, $files)) {
|
||||||
|
|
||||||
# Set new title for photo
|
// Set new title for photo
|
||||||
$zipFileName = $zipTitle . '/' . $photo->title . '-' . $i . $extension;
|
$zipFileName = $zipTitle . '/' . $photo->title . '-' . $i . $extension;
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
@ -435,27 +440,27 @@ final class Album {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add to array
|
// Add to array
|
||||||
$files[] = $zipFileName;
|
$files[] = $zipFileName;
|
||||||
|
|
||||||
# Add photo to zip
|
// Add photo to zip
|
||||||
$zip->addFile($photo->url, $zipFileName);
|
$zip->addFile($photo->url, $zipFileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Finish zip
|
// Finish zip
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
# Send zip
|
// Send zip
|
||||||
header("Content-Type: application/zip");
|
header("Content-Type: application/zip");
|
||||||
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
|
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
|
||||||
header("Content-Length: " . filesize($filename));
|
header("Content-Length: " . filesize($filename));
|
||||||
readfile($filename);
|
readfile($filename);
|
||||||
|
|
||||||
# Delete zip
|
// Delete zip
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -464,17 +469,17 @@ final class Album {
|
|||||||
|
|
||||||
public function setTitle($title = 'Untitled') {
|
public function setTitle($title = 'Untitled') {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET title = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $title, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET title = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $title, $this->albumIDs));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -487,17 +492,17 @@ final class Album {
|
|||||||
|
|
||||||
public function setDescription($description = '') {
|
public function setDescription($description = '') {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET description = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $description, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET description = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $description, $this->albumIDs));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -510,20 +515,20 @@ final class Album {
|
|||||||
|
|
||||||
public function getPublic() {
|
public function getPublic() {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f') return false;
|
if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f') return false;
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "SELECT public FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "SELECT public FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
$albums = Database::get()->query($query);
|
$albums = Database::get()->query($query);
|
||||||
$album = $albums->fetch_object();
|
$album = $albums->fetch_object();
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if ($album->public==1) return true;
|
if ($album->public==1) return true;
|
||||||
@ -533,20 +538,20 @@ final class Album {
|
|||||||
|
|
||||||
public function getDownloadable() {
|
public function getDownloadable() {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f'||$this->albumIDs==='r') return false;
|
if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f'||$this->albumIDs==='r') return false;
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "SELECT downloadable FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "SELECT downloadable FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
$albums = Database::get()->query($query);
|
$albums = Database::get()->query($query);
|
||||||
$album = $albums->fetch_object();
|
$album = $albums->fetch_object();
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if ($album->downloadable==1) return true;
|
if ($album->downloadable==1) return true;
|
||||||
@ -556,18 +561,18 @@ final class Album {
|
|||||||
|
|
||||||
public function setPublic($public, $password, $visible, $downloadable) {
|
public function setPublic($public, $password, $visible, $downloadable) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Convert values
|
// Convert values
|
||||||
$public = ($public==='1' ? 1 : 0);
|
$public = ($public==='1' ? 1 : 0);
|
||||||
$visible = ($visible==='1' ? 1 : 0);
|
$visible = ($visible==='1' ? 1 : 0);
|
||||||
$downloadable = ($downloadable==='1' ? 1 : 0);
|
$downloadable = ($downloadable==='1' ? 1 : 0);
|
||||||
|
|
||||||
# Set public
|
// Set public
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET public = '?', visible = '?', downloadable = '?', password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $public, $visible, $downloadable, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET public = '?', visible = '?', downloadable = '?', password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $public, $visible, $downloadable, $this->albumIDs));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -575,7 +580,7 @@ final class Album {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Reset permissions for photos
|
// Reset permissions for photos
|
||||||
if ($public===1) {
|
if ($public===1) {
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET public = 0 WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET public = 0 WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
@ -585,10 +590,10 @@ final class Album {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
# Set password
|
// Set password
|
||||||
if (isset($password)&&strlen($password)>0) return $this->setPassword($password);
|
if (isset($password)&&strlen($password)>0) return $this->setPassword($password);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -597,33 +602,33 @@ final class Album {
|
|||||||
|
|
||||||
private function setPassword($password) {
|
private function setPassword($password) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
if (strlen($password)>0) {
|
if (strlen($password)>0) {
|
||||||
|
|
||||||
# Get hashed password
|
// Get hashed password
|
||||||
$password = getHashedString($password);
|
$password = getHashedString($password);
|
||||||
|
|
||||||
# Set hashed password
|
// Set hashed password
|
||||||
# Do not prepare $password because it is hashed and save
|
// Do not prepare $password because it is hashed and save
|
||||||
# Preparing (escaping) the password would destroy the hash
|
// Preparing (escaping) the password would destroy the hash
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET password = '$password' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET password = '$password' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Unset password
|
// Unset password
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -636,18 +641,18 @@ final class Album {
|
|||||||
|
|
||||||
public function checkPassword($password) {
|
public function checkPassword($password) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "SELECT password FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "SELECT password FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
$albums = Database::get()->query($query);
|
$albums = Database::get()->query($query);
|
||||||
$album = $albums->fetch_object();
|
$album = $albums->fetch_object();
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if ($album->password=='') return true;
|
if ($album->password=='') return true;
|
||||||
@ -658,16 +663,16 @@ final class Album {
|
|||||||
|
|
||||||
public function merge() {
|
public function merge() {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Convert to array
|
// Convert to array
|
||||||
$albumIDs = explode(',', $this->albumIDs);
|
$albumIDs = explode(',', $this->albumIDs);
|
||||||
|
|
||||||
# Get first albumID
|
// Get first albumID
|
||||||
$albumID = array_splice($albumIDs, 0, 1);
|
$albumID = array_splice($albumIDs, 0, 1);
|
||||||
$albumID = $albumID[0];
|
$albumID = $albumID[0];
|
||||||
|
|
||||||
@ -679,14 +684,14 @@ final class Album {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# $albumIDs contains all IDs without the first albumID
|
// $albumIDs contains all IDs without the first albumID
|
||||||
# Convert to string
|
// Convert to string
|
||||||
$filteredIDs = implode(',', $albumIDs);
|
$filteredIDs = implode(',', $albumIDs);
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $filteredIDs));
|
$query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $filteredIDs));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -699,20 +704,20 @@ final class Album {
|
|||||||
|
|
||||||
public function delete() {
|
public function delete() {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Init vars
|
// Init vars
|
||||||
$error = false;
|
$error = false;
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
||||||
$photos = Database::get()->query($query);
|
$photos = Database::get()->query($query);
|
||||||
|
|
||||||
# For each album delete photo
|
// For each album delete photo
|
||||||
while ($row = $photos->fetch_object()) {
|
while ($row = $photos->fetch_object()) {
|
||||||
|
|
||||||
$photo = new Photo($row->id);
|
$photo = new Photo($row->id);
|
||||||
@ -720,11 +725,11 @@ final class Album {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete albums
|
// Delete albums
|
||||||
$query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
$query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if ($error) return false;
|
if ($error) return false;
|
||||||
|
@ -6,43 +6,37 @@ final class Config {
|
|||||||
|
|
||||||
public static function create($host, $user, $password, $name = 'lychee', $prefix = '') {
|
public static function create($host, $user, $password, $name = 'lychee', $prefix = '') {
|
||||||
|
|
||||||
# Open a new connection to the MySQL server
|
// Open a new connection to the MySQL server
|
||||||
$connection = Database::connect($host, $user, $password);
|
$connection = Database::connect($host, $user, $password);
|
||||||
|
|
||||||
# Check if the connection was successful
|
// Check if the connection was successful
|
||||||
if ($connection===false) return 'Warning: Connection failed!';
|
if ($connection===false) return 'Warning: Connection failed!';
|
||||||
|
|
||||||
# Check if user can create the database before saving the configuration
|
// Check if user can create the database before saving the configuration
|
||||||
if (!Database::createDatabase($connection, $name)) return 'Warning: Creation failed!';
|
if (!Database::createDatabase($connection, $name)) return 'Warning: Creation failed!';
|
||||||
|
|
||||||
# Escape data
|
// Escape data
|
||||||
$host = mysqli_real_escape_string($connection, $host);
|
$host = mysqli_real_escape_string($connection, $host);
|
||||||
$user = mysqli_real_escape_string($connection, $user);
|
$user = mysqli_real_escape_string($connection, $user);
|
||||||
$password = mysqli_real_escape_string($connection, $password);
|
$password = mysqli_real_escape_string($connection, $password);
|
||||||
$name = mysqli_real_escape_string($connection, $name);
|
$name = mysqli_real_escape_string($connection, $name);
|
||||||
$prefix = mysqli_real_escape_string($connection, $prefix);
|
$prefix = mysqli_real_escape_string($connection, $prefix);
|
||||||
|
|
||||||
# Save config.php
|
// Save config.php
|
||||||
$config = "<?php
|
$config = "<?php
|
||||||
|
|
||||||
###
|
|
||||||
# @name Configuration
|
|
||||||
# @author Tobias Reich
|
|
||||||
# @copyright 2015 Tobias Reich
|
|
||||||
###
|
|
||||||
|
|
||||||
if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||||
|
|
||||||
# Database configuration
|
// Database configuration
|
||||||
\$dbHost = '$host'; # Host of the database
|
\$dbHost = '$host'; // Host of the database
|
||||||
\$dbUser = '$user'; # Username of the database
|
\$dbUser = '$user'; // Username of the database
|
||||||
\$dbPassword = '$password'; # Password of the database
|
\$dbPassword = '$password'; // Password of the database
|
||||||
\$dbName = '$name'; # Database name
|
\$dbName = '$name'; // Database name
|
||||||
\$dbTablePrefix = '$prefix'; # Table prefix
|
\$dbTablePrefix = '$prefix'; // Table prefix
|
||||||
|
|
||||||
?>";
|
?>";
|
||||||
|
|
||||||
# Save file
|
// Save file
|
||||||
if (file_put_contents(LYCHEE_CONFIG_FILE, $config)===false) return 'Warning: Could not create file!';
|
if (file_put_contents(LYCHEE_CONFIG_FILE, $config)===false) return 'Warning: Could not create file!';
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,10 +10,10 @@ final class Database {
|
|||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
private static $versions = array(
|
private static $versions = array(
|
||||||
'020700', #2.7.0
|
'020700', // 2.7.0
|
||||||
'030000', #3.0.0
|
'030000', // 3.0.0
|
||||||
'030001', #3.0.1
|
'030001', // 3.0.1
|
||||||
'030003' #3.0.3
|
'030003' // 3.0.3
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function get() {
|
public static function get() {
|
||||||
@ -38,27 +38,27 @@ final class Database {
|
|||||||
|
|
||||||
private function __construct($host, $user, $password, $name = 'lychee', $dbTablePrefix) {
|
private function __construct($host, $user, $password, $name = 'lychee', $dbTablePrefix) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($host, $user, $password, $name), __METHOD__);
|
Validator::required(isset($host, $user, $password, $name), __METHOD__);
|
||||||
|
|
||||||
# Define the table prefix
|
// Define the table prefix
|
||||||
defineTablePrefix($dbTablePrefix);
|
defineTablePrefix($dbTablePrefix);
|
||||||
|
|
||||||
# Open a new connection to the MySQL server
|
// Open a new connection to the MySQL server
|
||||||
$connection = self::connect($host, $user, $password);
|
$connection = self::connect($host, $user, $password);
|
||||||
|
|
||||||
# Check if the connection was successful
|
// Check if the connection was successful
|
||||||
if ($connection===false) exit('Error: ' . $connection->connect_error);
|
if ($connection===false) exit('Error: ' . $connection->connect_error);
|
||||||
|
|
||||||
if (!self::setCharset($connection)) exit('Error: Could not set database charset!');
|
if (!self::setCharset($connection)) exit('Error: Could not set database charset!');
|
||||||
|
|
||||||
# Create database
|
// Create database
|
||||||
if (!self::createDatabase($connection, $name)) exit('Error: Could not create database!');
|
if (!self::createDatabase($connection, $name)) exit('Error: Could not create database!');
|
||||||
|
|
||||||
# Create tables
|
// Create tables
|
||||||
if (!self::createTables($connection)) exit('Error: Could not create tables!');
|
if (!self::createTables($connection)) exit('Error: Could not create tables!');
|
||||||
|
|
||||||
# Update database
|
// Update database
|
||||||
if (!self::update($connection, $name)) exit('Error: Could not update database and tables!');
|
if (!self::update($connection, $name)) exit('Error: Could not update database and tables!');
|
||||||
|
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
@ -67,10 +67,10 @@ final class Database {
|
|||||||
|
|
||||||
public static function connect($host = 'localhost', $user, $password) {
|
public static function connect($host = 'localhost', $user, $password) {
|
||||||
|
|
||||||
# Open a new connection to the MySQL server
|
// Open a new connection to the MySQL server
|
||||||
$connection = new Mysqli($host, $user, $password);
|
$connection = new Mysqli($host, $user, $password);
|
||||||
|
|
||||||
# Check if the connection was successful
|
// Check if the connection was successful
|
||||||
if ($connection->connect_errno) return false;
|
if ($connection->connect_errno) return false;
|
||||||
|
|
||||||
return $connection;
|
return $connection;
|
||||||
@ -79,14 +79,14 @@ final class Database {
|
|||||||
|
|
||||||
private static function setCharset($connection) {
|
private static function setCharset($connection) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($connection), __METHOD__);
|
Validator::required(isset($connection), __METHOD__);
|
||||||
|
|
||||||
# Avoid sql injection on older MySQL versions by using GBK
|
// Avoid sql injection on older MySQL versions by using GBK
|
||||||
if ($connection->server_version<50500) @$connection->set_charset('GBK');
|
if ($connection->server_version<50500) @$connection->set_charset('GBK');
|
||||||
else @$connection->set_charset('utf8');
|
else @$connection->set_charset('utf8');
|
||||||
|
|
||||||
# Set unicode
|
// Set unicode
|
||||||
$connection->query('SET NAMES utf8;');
|
$connection->query('SET NAMES utf8;');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -95,13 +95,13 @@ final class Database {
|
|||||||
|
|
||||||
public static function createDatabase($connection, $name = 'lychee') {
|
public static function createDatabase($connection, $name = 'lychee') {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($connection), __METHOD__);
|
Validator::required(isset($connection), __METHOD__);
|
||||||
|
|
||||||
# Check if database exists
|
// Check if database exists
|
||||||
if ($connection->select_db($name)) return true;
|
if ($connection->select_db($name)) return true;
|
||||||
|
|
||||||
# Create database
|
// Create database
|
||||||
$query = self::prepare($connection, 'CREATE DATABASE IF NOT EXISTS ?', array($name));
|
$query = self::prepare($connection, 'CREATE DATABASE IF NOT EXISTS ?', array($name));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
|
|
||||||
@ -112,34 +112,34 @@ final class Database {
|
|||||||
|
|
||||||
private static function createTables($connection) {
|
private static function createTables($connection) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($connection), __METHOD__);
|
Validator::required(isset($connection), __METHOD__);
|
||||||
|
|
||||||
# Check if tables exist
|
// Check if tables exist
|
||||||
$query = self::prepare($connection, 'SELECT * FROM ?, ?, ?, ? LIMIT 0', array(LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS, LYCHEE_TABLE_SETTINGS, LYCHEE_TABLE_LOG));
|
$query = self::prepare($connection, 'SELECT * FROM ?, ?, ?, ? LIMIT 0', array(LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS, LYCHEE_TABLE_SETTINGS, LYCHEE_TABLE_LOG));
|
||||||
if ($connection->query($query)) return true;
|
if ($connection->query($query)) return true;
|
||||||
|
|
||||||
# Create log
|
// Create log
|
||||||
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_LOG));
|
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_LOG));
|
||||||
if (!$connection->query($exist)) {
|
if (!$connection->query($exist)) {
|
||||||
|
|
||||||
# Read file
|
// Read file
|
||||||
$file = __DIR__ . '/../database/log_table.sql';
|
$file = __DIR__ . '/../database/log_table.sql';
|
||||||
$query = @file_get_contents($file);
|
$query = @file_get_contents($file);
|
||||||
|
|
||||||
if (!isset($query)||$query===false) return false;
|
if (!isset($query)||$query===false) return false;
|
||||||
|
|
||||||
# Create table
|
// Create table
|
||||||
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_LOG));
|
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_LOG));
|
||||||
if (!$connection->query($query)) return false;
|
if (!$connection->query($query)) return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create settings
|
// Create settings
|
||||||
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_SETTINGS));
|
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_SETTINGS));
|
||||||
if (!$connection->query($exist)) {
|
if (!$connection->query($exist)) {
|
||||||
|
|
||||||
# Read file
|
// Read file
|
||||||
$file = __DIR__ . '/../database/settings_table.sql';
|
$file = __DIR__ . '/../database/settings_table.sql';
|
||||||
$query = @file_get_contents($file);
|
$query = @file_get_contents($file);
|
||||||
|
|
||||||
@ -148,14 +148,14 @@ final class Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create table
|
// Create table
|
||||||
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_SETTINGS));
|
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_SETTINGS));
|
||||||
if (!$connection->query($query)) {
|
if (!$connection->query($query)) {
|
||||||
Log::error(__METHOD__, __LINE__, $connection->error);
|
Log::error(__METHOD__, __LINE__, $connection->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read file
|
// Read file
|
||||||
$file = __DIR__ . '/../database/settings_content.sql';
|
$file = __DIR__ . '/../database/settings_content.sql';
|
||||||
$query = @file_get_contents($file);
|
$query = @file_get_contents($file);
|
||||||
|
|
||||||
@ -164,14 +164,14 @@ final class Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add content
|
// Add content
|
||||||
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_SETTINGS));
|
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_SETTINGS));
|
||||||
if (!$connection->query($query)) {
|
if (!$connection->query($query)) {
|
||||||
Log::error(__METHOD__, __LINE__, $connection->error);
|
Log::error(__METHOD__, __LINE__, $connection->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate identifier
|
// Generate identifier
|
||||||
$identifier = md5(microtime(true));
|
$identifier = md5(microtime(true));
|
||||||
$query = self::prepare($connection, "UPDATE `?` SET `value` = '?' WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS, $identifier));
|
$query = self::prepare($connection, "UPDATE `?` SET `value` = '?' WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS, $identifier));
|
||||||
if (!$connection->query($query)) {
|
if (!$connection->query($query)) {
|
||||||
@ -181,11 +181,11 @@ final class Database {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create albums
|
// Create albums
|
||||||
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_ALBUMS));
|
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_ALBUMS));
|
||||||
if (!$connection->query($exist)) {
|
if (!$connection->query($exist)) {
|
||||||
|
|
||||||
# Read file
|
// Read file
|
||||||
$file = __DIR__ . '/../database/albums_table.sql';
|
$file = __DIR__ . '/../database/albums_table.sql';
|
||||||
$query = @file_get_contents($file);
|
$query = @file_get_contents($file);
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ final class Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create table
|
// Create table
|
||||||
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_ALBUMS));
|
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_ALBUMS));
|
||||||
if (!$connection->query($query)) {
|
if (!$connection->query($query)) {
|
||||||
Log::error(__METHOD__, __LINE__, $connection->error);
|
Log::error(__METHOD__, __LINE__, $connection->error);
|
||||||
@ -203,11 +203,11 @@ final class Database {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create photos
|
// Create photos
|
||||||
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_PHOTOS));
|
$exist = self::prepare($connection, 'SELECT * FROM ? LIMIT 0', array(LYCHEE_TABLE_PHOTOS));
|
||||||
if (!$connection->query($exist)) {
|
if (!$connection->query($exist)) {
|
||||||
|
|
||||||
# Read file
|
// Read file
|
||||||
$file = __DIR__ . '/../database/photos_table.sql';
|
$file = __DIR__ . '/../database/photos_table.sql';
|
||||||
$query = @file_get_contents($file);
|
$query = @file_get_contents($file);
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ final class Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create table
|
// Create table
|
||||||
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_PHOTOS));
|
$query = self::prepare($connection, $query, array(LYCHEE_TABLE_PHOTOS));
|
||||||
if (!$connection->query($query)) {
|
if (!$connection->query($query)) {
|
||||||
Log::error(__METHOD__, __LINE__, $connection->error);
|
Log::error(__METHOD__, __LINE__, $connection->error);
|
||||||
@ -231,21 +231,21 @@ final class Database {
|
|||||||
|
|
||||||
private static function update($connection, $dbName) {
|
private static function update($connection, $dbName) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($connection, $dbName), __METHOD__);
|
Validator::required(isset($connection, $dbName), __METHOD__);
|
||||||
|
|
||||||
# Get current version
|
// Get current version
|
||||||
$query = self::prepare($connection, "SELECT * FROM ? WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
|
$query = self::prepare($connection, "SELECT * FROM ? WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$results = $connection->query($query);
|
$results = $connection->query($query);
|
||||||
$current = $results->fetch_object()->value;
|
$current = $results->fetch_object()->value;
|
||||||
|
|
||||||
# For each update
|
// For each update
|
||||||
foreach (self::$versions as $version) {
|
foreach (self::$versions as $version) {
|
||||||
|
|
||||||
# Only update when newer version available
|
// Only update when newer version available
|
||||||
if ($version<=$current) continue;
|
if ($version<=$current) continue;
|
||||||
|
|
||||||
# Load update
|
// Load update
|
||||||
include(__DIR__ . '/../database/update_' . $version . '.php');
|
include(__DIR__ . '/../database/update_' . $version . '.php');
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ final class Database {
|
|||||||
|
|
||||||
public static function setVersion($connection, $version) {
|
public static function setVersion($connection, $version) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($connection), __METHOD__);
|
Validator::required(isset($connection), __METHOD__);
|
||||||
|
|
||||||
$query = self::prepare($connection, "UPDATE ? SET value = '?' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS, $version));
|
$query = self::prepare($connection, "UPDATE ? SET value = '?' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS, $version));
|
||||||
@ -270,13 +270,13 @@ final class Database {
|
|||||||
|
|
||||||
public static function prepare($connection, $query, array $data) {
|
public static function prepare($connection, $query, array $data) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($connection, $query), __METHOD__);
|
Validator::required(isset($connection, $query), __METHOD__);
|
||||||
|
|
||||||
# Count the number of placeholders and compare it with the number of arguments
|
// Count the number of placeholders and compare it with the number of arguments
|
||||||
# If it doesn't match, calculate the difference and skip this number of placeholders before starting the replacement
|
// If it doesn't match, calculate the difference and skip this number of placeholders before starting the replacement
|
||||||
# This avoids problems with placeholders in user-input
|
// This avoids problems with placeholders in user-input
|
||||||
# $skip = Number of placeholders which need to be skipped
|
// $skip = Number of placeholders which need to be skipped
|
||||||
$skip = 0;
|
$skip = 0;
|
||||||
$temp = '';
|
$temp = '';
|
||||||
$num = array(
|
$num = array(
|
||||||
@ -288,44 +288,44 @@ final class Database {
|
|||||||
|
|
||||||
foreach ($data as $value) {
|
foreach ($data as $value) {
|
||||||
|
|
||||||
# Escape
|
// Escape
|
||||||
$value = mysqli_real_escape_string($connection, $value);
|
$value = mysqli_real_escape_string($connection, $value);
|
||||||
|
|
||||||
# Recalculate number of placeholders
|
// Recalculate number of placeholders
|
||||||
$num['placeholder'] = substr_count($query, '?');
|
$num['placeholder'] = substr_count($query, '?');
|
||||||
|
|
||||||
# Calculate number of skips
|
// Calculate number of skips
|
||||||
if ($num['placeholder']>$num['data']) $skip = $num['placeholder'] - $num['data'];
|
if ($num['placeholder']>$num['data']) $skip = $num['placeholder'] - $num['data'];
|
||||||
|
|
||||||
if ($skip>0) {
|
if ($skip>0) {
|
||||||
|
|
||||||
# Need to skip $skip placeholders, because the user input contained placeholders
|
// Need to skip $skip placeholders, because the user input contained placeholders
|
||||||
# Calculate a substring which does not contain the user placeholders
|
// Calculate a substring which does not contain the user placeholders
|
||||||
# 1 or -1 is the length of the placeholder (placeholder = ?)
|
// 1 or -1 is the length of the placeholder (placeholder = ?)
|
||||||
|
|
||||||
$pos = -1;
|
$pos = -1;
|
||||||
for ($i=$skip; $i>0; $i--) $pos = strpos($query, '?', $pos + 1);
|
for ($i=$skip; $i>0; $i--) $pos = strpos($query, '?', $pos + 1);
|
||||||
$pos++;
|
$pos++;
|
||||||
|
|
||||||
$temp = substr($query, 0, $pos); # First part of $query
|
$temp = substr($query, 0, $pos); // First part of $query
|
||||||
$query = substr($query, $pos); # Last part of $query
|
$query = substr($query, $pos); // Last part of $query
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Replace
|
// Replace
|
||||||
$query = preg_replace('/\?/', $value, $query, 1);
|
$query = preg_replace('/\?/', $value, $query, 1);
|
||||||
|
|
||||||
if ($skip>0) {
|
if ($skip>0) {
|
||||||
|
|
||||||
# Reassemble the parts of $query
|
// Reassemble the parts of $query
|
||||||
$query = $temp . $query;
|
$query = $temp . $query;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Reset skip
|
// Reset skip
|
||||||
$skip = 0;
|
$skip = 0;
|
||||||
|
|
||||||
# Decrease number of data elements
|
// Decrease number of data elements
|
||||||
$num['data']--;
|
$num['data']--;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ final class Import {
|
|||||||
|
|
||||||
private function photo($path, $albumID = 0, $description = '', $tags = '') {
|
private function photo($path, $albumID = 0, $description = '', $tags = '') {
|
||||||
|
|
||||||
# No need to validate photo type and extension in this function.
|
// No need to validate photo type and extension in this function.
|
||||||
# $photo->add will take care of it.
|
// $photo->add will take care of it.
|
||||||
|
|
||||||
$info = getimagesize($path);
|
$info = getimagesize($path);
|
||||||
$size = filesize($path);
|
$size = filesize($path);
|
||||||
@ -28,21 +28,21 @@ final class Import {
|
|||||||
|
|
||||||
public function url($urls, $albumID = 0) {
|
public function url($urls, $albumID = 0) {
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
$error = false;
|
$error = false;
|
||||||
|
|
||||||
# Parse URLs
|
// Parse URLs
|
||||||
$urls = str_replace(' ', '%20', $urls);
|
$urls = str_replace(' ', '%20', $urls);
|
||||||
$urls = explode(',', $urls);
|
$urls = explode(',', $urls);
|
||||||
|
|
||||||
foreach ($urls as &$url) {
|
foreach ($urls as &$url) {
|
||||||
|
|
||||||
# Validate photo type and extension even when $this->photo (=> $photo->add) will do the same.
|
// Validate photo type and extension even when $this->photo (=> $photo->add) will do the same.
|
||||||
# This prevents us from downloading invalid photos.
|
// This prevents us from downloading invalid photos.
|
||||||
|
|
||||||
# Verify extension
|
// Verify extension
|
||||||
$extension = getExtension($url);
|
$extension = getExtension($url);
|
||||||
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
|
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
|
||||||
$error = true;
|
$error = true;
|
||||||
@ -50,7 +50,7 @@ final class Import {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify image
|
// Verify image
|
||||||
$type = @exif_imagetype($url);
|
$type = @exif_imagetype($url);
|
||||||
if (!in_array($type, Photo::$validTypes, true)) {
|
if (!in_array($type, Photo::$validTypes, true)) {
|
||||||
$error = true;
|
$error = true;
|
||||||
@ -68,7 +68,7 @@ final class Import {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Import photo
|
// Import photo
|
||||||
if (!$this->photo($tmp_name, $albumID)) {
|
if (!$this->photo($tmp_name, $albumID)) {
|
||||||
$error = true;
|
$error = true;
|
||||||
Log::error(__METHOD__, __LINE__, 'Could not import file: ' . $tmp_name);
|
Log::error(__METHOD__, __LINE__, 'Could not import file: ' . $tmp_name);
|
||||||
@ -77,7 +77,7 @@ final class Import {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
if ($error===false) return true;
|
if ($error===false) return true;
|
||||||
@ -87,7 +87,7 @@ final class Import {
|
|||||||
|
|
||||||
public function server($path, $albumID = 0) {
|
public function server($path, $albumID = 0) {
|
||||||
|
|
||||||
# Parse path
|
// Parse path
|
||||||
if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
|
if (!isset($path)) $path = LYCHEE_UPLOADS_IMPORT;
|
||||||
if (substr($path, -1)==='/') $path = substr($path, 0, -1);
|
if (substr($path, -1)==='/') $path = substr($path, 0, -1);
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ final class Import {
|
|||||||
return 'Error: Given path is not a directory!';
|
return 'Error: Given path is not a directory!';
|
||||||
}
|
}
|
||||||
|
|
||||||
# Skip folders of Lychee
|
// Skip folders of Lychee
|
||||||
if ($path===LYCHEE_UPLOADS_BIG||($path . '/')===LYCHEE_UPLOADS_BIG||
|
if ($path===LYCHEE_UPLOADS_BIG||($path . '/')===LYCHEE_UPLOADS_BIG||
|
||||||
$path===LYCHEE_UPLOADS_MEDIUM||($path . '/')===LYCHEE_UPLOADS_MEDIUM||
|
$path===LYCHEE_UPLOADS_MEDIUM||($path . '/')===LYCHEE_UPLOADS_MEDIUM||
|
||||||
$path===LYCHEE_UPLOADS_THUMB||($path . '/')===LYCHEE_UPLOADS_THUMB) {
|
$path===LYCHEE_UPLOADS_THUMB||($path . '/')===LYCHEE_UPLOADS_THUMB) {
|
||||||
@ -108,18 +108,18 @@ final class Import {
|
|||||||
$contains['photos'] = false;
|
$contains['photos'] = false;
|
||||||
$contains['albums'] = false;
|
$contains['albums'] = false;
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
# Note that updated albumId and path explicitly passed, rather
|
// Note that updated albumId and path explicitly passed, rather
|
||||||
# than using func_get_args() which will only return original ones
|
// than using func_get_args() which will only return original ones
|
||||||
Plugins::get()->activate(__METHOD__, 0, array($albumID, $path));
|
Plugins::get()->activate(__METHOD__, 0, array($albumID, $path));
|
||||||
|
|
||||||
# Get all files
|
// Get all files
|
||||||
$files = glob($path . '/*');
|
$files = glob($path . '/*');
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
||||||
# It is possible to move a file because of directory permissions but
|
// It is possible to move a file because of directory permissions but
|
||||||
# the file may still be unreadable by the user
|
// the file may still be unreadable by the user
|
||||||
if (!is_readable($file)) {
|
if (!is_readable($file)) {
|
||||||
$error = true;
|
$error = true;
|
||||||
Log::error(__METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
|
Log::error(__METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
|
||||||
@ -128,7 +128,7 @@ final class Import {
|
|||||||
|
|
||||||
if (@exif_imagetype($file)!==false) {
|
if (@exif_imagetype($file)!==false) {
|
||||||
|
|
||||||
# Photo
|
// Photo
|
||||||
|
|
||||||
$contains['photos'] = true;
|
$contains['photos'] = true;
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ final class Import {
|
|||||||
|
|
||||||
} else if (is_dir($file)) {
|
} else if (is_dir($file)) {
|
||||||
|
|
||||||
# Folder
|
// Folder
|
||||||
|
|
||||||
$album = new Album(null);
|
$album = new Album(null);
|
||||||
$newAlbumID = $album->add('[Import] ' . basename($file));
|
$newAlbumID = $album->add('[Import] ' . basename($file));
|
||||||
@ -164,12 +164,12 @@ final class Import {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
# Note that updated albumId and path explicitly passed, rather
|
// Note that updated albumId and path explicitly passed, rather
|
||||||
# than using func_get_args() which will only return original ones
|
// than using func_get_args() which will only return original ones
|
||||||
Plugins::get()->activate(__METHOD__, 1, array($albumID, $path));
|
Plugins::get()->activate(__METHOD__, 1, array($albumID, $path));
|
||||||
|
|
||||||
# The following returns will be caught in the front-end
|
// The following returns will be caught in the front-end
|
||||||
if ($contains['photos']===false&&$contains['albums']===false) return 'Warning: Folder empty or no readable files to process!';
|
if ($contains['photos']===false&&$contains['albums']===false) return 'Warning: Folder empty or no readable files to process!';
|
||||||
if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contained albums!';
|
if ($contains['photos']===false&&$contains['albums']===true) return 'Notice: Import only contained albums!';
|
||||||
|
|
||||||
|
@ -24,13 +24,13 @@ final class Log {
|
|||||||
|
|
||||||
private static function text($type, $function, $line, $text = '') {
|
private static function text($type, $function, $line, $text = '') {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($type, $function, $line, $text), __METHOD__);
|
Validator::required(isset($type, $function, $line, $text), __METHOD__);
|
||||||
|
|
||||||
# Get time
|
// Get time
|
||||||
$sysstamp = time();
|
$sysstamp = time();
|
||||||
|
|
||||||
# Save in database
|
// Save in database
|
||||||
$query = Database::prepare(Database::get(), "INSERT INTO ? (time, type, function, line, text) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_LOG, $sysstamp, $type, $function, $line, $text));
|
$query = Database::prepare(Database::get(), "INSERT INTO ? (time, type, function, line, text) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_LOG, $sysstamp, $type, $function, $line, $text));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,7 @@ final class Plugins implements SplSubject {
|
|||||||
|
|
||||||
private function __construct(array $plugins) {
|
private function __construct(array $plugins) {
|
||||||
|
|
||||||
# Load plugins
|
// Load plugins
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
|
|
||||||
if ($plugin==='') continue;
|
if ($plugin==='') continue;
|
||||||
@ -47,7 +47,7 @@ final class Plugins implements SplSubject {
|
|||||||
|
|
||||||
if (!isset($observer)) return false;
|
if (!isset($observer)) return false;
|
||||||
|
|
||||||
# Add observer
|
// Add observer
|
||||||
$this->observers[] = $observer;
|
$this->observers[] = $observer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -58,7 +58,7 @@ final class Plugins implements SplSubject {
|
|||||||
|
|
||||||
if (!isset($observer)) return false;
|
if (!isset($observer)) return false;
|
||||||
|
|
||||||
# Remove observer
|
// Remove observer
|
||||||
$key = array_search($observer, $this->observers, true);
|
$key = array_search($observer, $this->observers, true);
|
||||||
if ($key) unset($this->observers[$key]);
|
if ($key) unset($this->observers[$key]);
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ final class Plugins implements SplSubject {
|
|||||||
|
|
||||||
public function notify() {
|
public function notify() {
|
||||||
|
|
||||||
# Notify each observer
|
// Notify each observer
|
||||||
foreach ($this->observers as $value) $value->update($this);
|
foreach ($this->observers as $value) $value->update($this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -79,15 +79,15 @@ final class Plugins implements SplSubject {
|
|||||||
|
|
||||||
if (!isset($name, $location, $args)) return false;
|
if (!isset($name, $location, $args)) return false;
|
||||||
|
|
||||||
# Parse
|
// Parse
|
||||||
$location = ($location===0 ? 'before' : 'after');
|
$location = ($location===0 ? 'before' : 'after');
|
||||||
$action = $name . ":" . $location;
|
$action = $name . ":" . $location;
|
||||||
|
|
||||||
# Save vars
|
// Save vars
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
|
|
||||||
# Notify observers
|
// Notify observers
|
||||||
$this->notify();
|
$this->notify();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,23 +6,23 @@ final class Session {
|
|||||||
|
|
||||||
public function init($public = true) {
|
public function init($public = true) {
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
# Return settings
|
// Return settings
|
||||||
$return['config'] = Settings::get();
|
$return['config'] = Settings::get();
|
||||||
|
|
||||||
# Path to Lychee for the server-import dialog
|
// Path to Lychee for the server-import dialog
|
||||||
$return['config']['location'] = LYCHEE;
|
$return['config']['location'] = LYCHEE;
|
||||||
|
|
||||||
# Remove username and password from response
|
// Remove username and password from response
|
||||||
unset($return['config']['username']);
|
unset($return['config']['username']);
|
||||||
unset($return['config']['password']);
|
unset($return['config']['password']);
|
||||||
|
|
||||||
# Remove identifier from response
|
// Remove identifier from response
|
||||||
unset($return['config']['identifier']);
|
unset($return['config']['identifier']);
|
||||||
|
|
||||||
# Check if login credentials exist and login if they don't
|
// Check if login credentials exist and login if they don't
|
||||||
if ($this->noLogin()===true) {
|
if ($this->noLogin()===true) {
|
||||||
$public = false;
|
$public = false;
|
||||||
$return['config']['login'] = false;
|
$return['config']['login'] = false;
|
||||||
@ -32,15 +32,15 @@ final class Session {
|
|||||||
|
|
||||||
if ($public===false) {
|
if ($public===false) {
|
||||||
|
|
||||||
# Logged in
|
// Logged in
|
||||||
$return['status'] = LYCHEE_STATUS_LOGGEDIN;
|
$return['status'] = LYCHEE_STATUS_LOGGEDIN;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# Logged out
|
// Logged out
|
||||||
$return['status'] = LYCHEE_STATUS_LOGGEDOUT;
|
$return['status'] = LYCHEE_STATUS_LOGGEDOUT;
|
||||||
|
|
||||||
# Unset unused vars
|
// Unset unused vars
|
||||||
unset($return['config']['skipDuplicates']);
|
unset($return['config']['skipDuplicates']);
|
||||||
unset($return['config']['thumbQuality']);
|
unset($return['config']['thumbQuality']);
|
||||||
unset($return['config']['sortingAlbums']);
|
unset($return['config']['sortingAlbums']);
|
||||||
@ -54,7 +54,7 @@ final class Session {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
@ -63,13 +63,13 @@ final class Session {
|
|||||||
|
|
||||||
public function login($username, $password) {
|
public function login($username, $password) {
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
$username = crypt($username, Settings::get()['username']);
|
$username = crypt($username, Settings::get()['username']);
|
||||||
$password = crypt($password, Settings::get()['password']);
|
$password = crypt($password, Settings::get()['password']);
|
||||||
|
|
||||||
# Check login with crypted hash
|
// Check login with crypted hash
|
||||||
if (Settings::get()['username']===$username&&
|
if (Settings::get()['username']===$username&&
|
||||||
Settings::get()['password']===$password) {
|
Settings::get()['password']===$password) {
|
||||||
$_SESSION['login'] = true;
|
$_SESSION['login'] = true;
|
||||||
@ -77,10 +77,10 @@ final class Session {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
# No login
|
// No login
|
||||||
if ($this->noLogin()===true) return true;
|
if ($this->noLogin()===true) return true;
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -89,7 +89,7 @@ final class Session {
|
|||||||
|
|
||||||
private function noLogin() {
|
private function noLogin() {
|
||||||
|
|
||||||
# Check if login credentials exist and login if they don't
|
// Check if login credentials exist and login if they don't
|
||||||
if (Settings::get()['username']===''&&
|
if (Settings::get()['username']===''&&
|
||||||
Settings::get()['password']==='') {
|
Settings::get()['password']==='') {
|
||||||
$_SESSION['login'] = true;
|
$_SESSION['login'] = true;
|
||||||
@ -103,7 +103,7 @@ final class Session {
|
|||||||
|
|
||||||
public function logout() {
|
public function logout() {
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||||
|
|
||||||
$_SESSION['login'] = null;
|
$_SESSION['login'] = null;
|
||||||
@ -111,7 +111,7 @@ final class Session {
|
|||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
# Call plugins
|
// Call plugins
|
||||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,14 +10,14 @@ final class Settings {
|
|||||||
|
|
||||||
if (self::$cache) return self::$cache;
|
if (self::$cache) return self::$cache;
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
$query = Database::prepare(Database::get(), "SELECT * FROM ?", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare(Database::get(), "SELECT * FROM ?", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$settings = Database::get()->query($query);
|
$settings = Database::get()->query($query);
|
||||||
|
|
||||||
# Add each to return
|
// Add each to return
|
||||||
while ($setting = $settings->fetch_object()) $return[$setting->key] = $setting->value;
|
while ($setting = $settings->fetch_object()) $return[$setting->key] = $setting->value;
|
||||||
|
|
||||||
# Convert plugins to array
|
// Convert plugins to array
|
||||||
$return['plugins'] = explode(';', $return['plugins']);
|
$return['plugins'] = explode(';', $return['plugins']);
|
||||||
|
|
||||||
self::$cache = $return;
|
self::$cache = $return;
|
||||||
@ -34,7 +34,7 @@ final class Settings {
|
|||||||
|
|
||||||
} elseif ($row===true) {
|
} elseif ($row===true) {
|
||||||
|
|
||||||
# Do not prepare $value because it has already been escaped or is a true statement
|
// Do not prepare $value because it has already been escaped or is a true statement
|
||||||
$query = Database::prepare(Database::get(), "UPDATE ? SET value = '$value' WHERE `key` = '?'", array(LYCHEE_TABLE_SETTINGS, $key));
|
$query = Database::prepare(Database::get(), "UPDATE ? SET value = '$value' WHERE `key` = '?'", array(LYCHEE_TABLE_SETTINGS, $key));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -54,10 +54,10 @@ final class Settings {
|
|||||||
|
|
||||||
if ($oldPassword===self::get()['password']||self::get()['password']===crypt($oldPassword, self::get()['password'])) {
|
if ($oldPassword===self::get()['password']||self::get()['password']===crypt($oldPassword, self::get()['password'])) {
|
||||||
|
|
||||||
# Save username
|
// Save username
|
||||||
if (self::setUsername($username)!==true) exit('Error: Updating username failed!');
|
if (self::setUsername($username)!==true) exit('Error: Updating username failed!');
|
||||||
|
|
||||||
# Save password
|
// Save password
|
||||||
if (self::setPassword($password)!==true) exit('Error: Updating password failed!');
|
if (self::setPassword($password)!==true) exit('Error: Updating password failed!');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -70,15 +70,15 @@ final class Settings {
|
|||||||
|
|
||||||
private static function setUsername($username) {
|
private static function setUsername($username) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($username), __METHOD__);
|
Validator::required(isset($username), __METHOD__);
|
||||||
|
|
||||||
# Hash username
|
// Hash username
|
||||||
$username = getHashedString($username);
|
$username = getHashedString($username);
|
||||||
|
|
||||||
# Execute query
|
// Execute query
|
||||||
# Do not prepare $username because it is hashed and save
|
// Do not prepare $username because it is hashed and save
|
||||||
# Preparing (escaping) the username would destroy the hash
|
// Preparing (escaping) the username would destroy the hash
|
||||||
if (self::set('username', $username, true)===false) {
|
if (self::set('username', $username, true)===false) {
|
||||||
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
||||||
return false;
|
return false;
|
||||||
@ -89,14 +89,14 @@ final class Settings {
|
|||||||
|
|
||||||
private static function setPassword($password) {
|
private static function setPassword($password) {
|
||||||
|
|
||||||
# Check dependencies
|
// Check dependencies
|
||||||
Validator::required(isset($password), __METHOD__);
|
Validator::required(isset($password), __METHOD__);
|
||||||
|
|
||||||
# Hash password
|
// Hash password
|
||||||
$password = getHashedString($password);
|
$password = getHashedString($password);
|
||||||
|
|
||||||
# Do not prepare $password because it is hashed and save
|
// Do not prepare $password because it is hashed and save
|
||||||
# Preparing (escaping) the password would destroy the hash
|
// Preparing (escaping) the password would destroy the hash
|
||||||
if (self::set('password', $password, true)===false) {
|
if (self::set('password', $password, true)===false) {
|
||||||
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
||||||
return false;
|
return false;
|
||||||
@ -124,52 +124,34 @@ final class Settings {
|
|||||||
|
|
||||||
$sorting = 'ORDER BY ';
|
$sorting = 'ORDER BY ';
|
||||||
|
|
||||||
# Set row
|
// Set row
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
|
||||||
case 'id': $sorting .= 'id';
|
case 'id': $sorting .= 'id'; break;
|
||||||
break;
|
case 'title': $sorting .= 'title'; break;
|
||||||
|
case 'description': $sorting .= 'description'; break;
|
||||||
case 'title': $sorting .= 'title';
|
case 'public': $sorting .= 'public'; break;
|
||||||
break;
|
case 'type': $sorting .= 'type'; break;
|
||||||
|
case 'star': $sorting .= 'star'; break;
|
||||||
case 'description': $sorting .= 'description';
|
case 'takestamp': $sorting .= 'takestamp'; break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'public': $sorting .= 'public';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'type': $sorting .= 'type';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'star': $sorting .= 'star';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'takestamp': $sorting .= 'takestamp';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: exit('Error: Unknown type for sorting!');
|
default: exit('Error: Unknown type for sorting!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sorting .= ' ';
|
$sorting .= ' ';
|
||||||
|
|
||||||
# Set order
|
// Set order
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
|
|
||||||
case 'ASC': $sorting .= 'ASC';
|
case 'ASC': $sorting .= 'ASC'; break;
|
||||||
break;
|
case 'DESC': $sorting .= 'DESC'; break;
|
||||||
|
|
||||||
case 'DESC': $sorting .= 'DESC';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: exit('Error: Unknown order for sorting!');
|
default: exit('Error: Unknown order for sorting!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Do not prepare $sorting because it is a true statement
|
// Do not prepare $sorting because it is a true statement
|
||||||
# Preparing (escaping) the sorting would destroy it
|
// Preparing (escaping) the sorting would destroy it
|
||||||
# $sorting is save and can't contain user-input
|
// $sorting is save and can't contain user-input
|
||||||
if (self::set('sortingPhotos', $sorting, true)===false) {
|
if (self::set('sortingPhotos', $sorting, true)===false) {
|
||||||
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
||||||
return false;
|
return false;
|
||||||
@ -182,43 +164,31 @@ final class Settings {
|
|||||||
|
|
||||||
$sorting = 'ORDER BY ';
|
$sorting = 'ORDER BY ';
|
||||||
|
|
||||||
# Set row
|
// Set row
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
|
||||||
case 'id': $sorting .= 'id';
|
case 'id': $sorting .= 'id'; break;
|
||||||
break;
|
case 'title': $sorting .= 'title'; break;
|
||||||
|
case 'description': $sorting .= 'description'; break;
|
||||||
case 'title': $sorting .= 'title';
|
case 'public': $sorting .= 'public'; break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'description': $sorting .= 'description';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'public': $sorting .= 'public';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: exit('Error: Unknown type for sorting!');
|
default: exit('Error: Unknown type for sorting!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sorting .= ' ';
|
$sorting .= ' ';
|
||||||
|
|
||||||
# Set order
|
// Set order
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
|
|
||||||
case 'ASC': $sorting .= 'ASC';
|
case 'ASC': $sorting .= 'ASC'; break;
|
||||||
break;
|
case 'DESC': $sorting .= 'DESC'; break;
|
||||||
|
|
||||||
case 'DESC': $sorting .= 'DESC';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: exit('Error: Unknown order for sorting!');
|
default: exit('Error: Unknown order for sorting!');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Do not prepare $sorting because it is a true statement
|
// Do not prepare $sorting because it is a true statement
|
||||||
# Preparing (escaping) the sorting would destroy it
|
// Preparing (escaping) the sorting would destroy it
|
||||||
# $sorting is save and can't contain user-input
|
// $sorting is save and can't contain user-input
|
||||||
if (self::set('sortingAlbums', $sorting, true)===false) {
|
if (self::set('sortingAlbums', $sorting, true)===false) {
|
||||||
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
###
|
/**
|
||||||
# @name Update to version 2.7.0
|
* Update to version 2.7.0
|
||||||
# @copyright 2015 by Tobias Reich
|
*/
|
||||||
###
|
|
||||||
|
|
||||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||||
|
|
||||||
# Add medium to photos
|
// Add medium to photos
|
||||||
$query = Database::prepare($connection, "SELECT `medium` FROM `?` LIMIT 1", array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare($connection, "SELECT `medium` FROM `?` LIMIT 1", array(LYCHEE_TABLE_PHOTOS));
|
||||||
if (!$connection->query($query)) {
|
if (!$connection->query($query)) {
|
||||||
$query = Database::prepare($connection, "ALTER TABLE `?` ADD `medium` TINYINT(1) NOT NULL DEFAULT 0", array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare($connection, "ALTER TABLE `?` ADD `medium` TINYINT(1) NOT NULL DEFAULT 0", array(LYCHEE_TABLE_PHOTOS));
|
||||||
@ -18,14 +17,15 @@ if (!$connection->query($query)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create medium folder
|
// Create medium folder
|
||||||
if (is_dir(LYCHEE_UPLOADS_MEDIUM)===false) {
|
if (is_dir(LYCHEE_UPLOADS_MEDIUM)===false) {
|
||||||
# Only create the folder when it is missing
|
// Only create the folder when it is missing
|
||||||
if (@mkdir(LYCHEE_UPLOADS_MEDIUM)===false)
|
if (@mkdir(LYCHEE_UPLOADS_MEDIUM)===false) {
|
||||||
Log::error('update_020700', __LINE__, 'Could not create medium-folder');
|
Log::error('update_020700', __LINE__, 'Could not create medium-folder');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Add medium to settings
|
// Add medium to settings
|
||||||
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'medium' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'medium' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if ($result->num_rows===0) {
|
if ($result->num_rows===0) {
|
||||||
@ -37,7 +37,7 @@ if ($result->num_rows===0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set version
|
// Set version
|
||||||
if (Database::setVersion($connection, '020700')===false) return false;
|
if (Database::setVersion($connection, '020700')===false) return false;
|
||||||
|
|
||||||
?>
|
?>
|
@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
###
|
/**
|
||||||
# @name Update to version 3.0.0
|
* Update to version 3.0.0
|
||||||
# @copyright 2015 by Tobias Reich
|
*/
|
||||||
###
|
|
||||||
|
|
||||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||||
|
|
||||||
# Remove login
|
// Remove login
|
||||||
# Login now saved as crypt without md5. Legacy code has been removed.
|
// Login now saved as crypt without md5. Legacy code has been removed.
|
||||||
$query = Database::prepare($connection, "UPDATE `?` SET `value` = '' WHERE `key` = 'username' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare($connection, "UPDATE `?` SET `value` = '' WHERE `key` = 'username' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$resetUsername = $connection->query($query);
|
$resetUsername = $connection->query($query);
|
||||||
if (!$resetUsername) {
|
if (!$resetUsername) {
|
||||||
@ -22,8 +21,8 @@ if (!$resetPassword) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make public albums private and reset password
|
// Make public albums private and reset password
|
||||||
# Password now saved as crypt without md5. Legacy code has been removed.
|
// Password now saved as crypt without md5. Legacy code has been removed.
|
||||||
$query = Database::prepare($connection, "UPDATE `?` SET `public` = 0, `password` = NULL", array(LYCHEE_TABLE_ALBUMS));
|
$query = Database::prepare($connection, "UPDATE `?` SET `public` = 0, `password` = NULL", array(LYCHEE_TABLE_ALBUMS));
|
||||||
$resetPublic = $connection->query($query);
|
$resetPublic = $connection->query($query);
|
||||||
if (!$resetPublic) {
|
if (!$resetPublic) {
|
||||||
@ -31,7 +30,7 @@ if (!$resetPublic) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set version
|
// Set version
|
||||||
if (Database::setVersion($connection, '030000')===false) return false;
|
if (Database::setVersion($connection, '030000')===false) return false;
|
||||||
|
|
||||||
?>
|
?>
|
@ -1,13 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
###
|
/**
|
||||||
# @name Update to version 3.0.1
|
* Update to version 3.0.1
|
||||||
# @copyright 2015 by Tobias Reich
|
*/
|
||||||
###
|
|
||||||
|
|
||||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||||
|
|
||||||
# Change length of photo title
|
// Change length of photo title
|
||||||
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_PHOTOS));
|
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_PHOTOS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -15,7 +14,7 @@ if (!$result) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Change length of album title
|
// Change length of album title
|
||||||
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_ALBUMS));
|
$query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `title` `title` VARCHAR( 100 ) NOT NULL DEFAULT ''", array(LYCHEE_TABLE_ALBUMS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -23,7 +22,7 @@ if (!$result) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add album sorting to settings
|
// Add album sorting to settings
|
||||||
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'sortingAlbums' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'sortingAlbums' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if ($result->num_rows===0) {
|
if ($result->num_rows===0) {
|
||||||
@ -35,7 +34,7 @@ if ($result->num_rows===0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Rename sorting to sortingPhotos
|
// Rename sorting to sortingPhotos
|
||||||
$query = Database::prepare($connection, "UPDATE ? SET `key` = 'sortingPhotos' WHERE `key` = 'sorting' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare($connection, "UPDATE ? SET `key` = 'sortingPhotos' WHERE `key` = 'sorting' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@ -43,7 +42,7 @@ if (!$result) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add identifier to settings
|
// Add identifier to settings
|
||||||
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'identifier' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if ($result->num_rows===0) {
|
if ($result->num_rows===0) {
|
||||||
@ -56,7 +55,7 @@ if ($result->num_rows===0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set version
|
// Set version
|
||||||
if (Database::setVersion($connection, '030001')===false) return false;
|
if (Database::setVersion($connection, '030001')===false) return false;
|
||||||
|
|
||||||
?>
|
?>
|
@ -1,13 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
###
|
/**
|
||||||
# @name Update to version 3.0.3
|
* Update to version 3.0.3
|
||||||
# @copyright 2015 by Tobias Reich
|
*/
|
||||||
###
|
|
||||||
|
|
||||||
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
||||||
|
|
||||||
# Add skipDuplicates to settings
|
// Add skipDuplicates to settings
|
||||||
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'skipDuplicates' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'skipDuplicates' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
|
||||||
$result = $connection->query($query);
|
$result = $connection->query($query);
|
||||||
if ($result->num_rows===0) {
|
if ($result->num_rows===0) {
|
||||||
@ -19,7 +18,7 @@ if ($result->num_rows===0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set version
|
// Set version
|
||||||
if (Database::setVersion($connection, '030003')===false) return false;
|
if (Database::setVersion($connection, '030003')===false) return false;
|
||||||
|
|
||||||
?>
|
?>
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
# Define root
|
// Define root
|
||||||
define('LYCHEE', substr(__DIR__, 0, -3));
|
define('LYCHEE', substr(__DIR__, 0, -3));
|
||||||
|
|
||||||
# Define status
|
// Define status
|
||||||
define('LYCHEE_STATUS_NOCONFIG', 0);
|
define('LYCHEE_STATUS_NOCONFIG', 0);
|
||||||
define('LYCHEE_STATUS_LOGGEDOUT', 1);
|
define('LYCHEE_STATUS_LOGGEDOUT', 1);
|
||||||
define('LYCHEE_STATUS_LOGGEDIN', 2);
|
define('LYCHEE_STATUS_LOGGEDIN', 2);
|
||||||
|
|
||||||
# Define dirs
|
// Define dirs
|
||||||
define('LYCHEE_DATA', LYCHEE . 'data/');
|
define('LYCHEE_DATA', LYCHEE . 'data/');
|
||||||
define('LYCHEE_SRC', LYCHEE . 'src/');
|
define('LYCHEE_SRC', LYCHEE . 'src/');
|
||||||
define('LYCHEE_UPLOADS', LYCHEE . 'uploads/');
|
define('LYCHEE_UPLOADS', LYCHEE . 'uploads/');
|
||||||
@ -18,25 +18,25 @@ define('LYCHEE_UPLOADS_THUMB', LYCHEE_UPLOADS . 'thumb/');
|
|||||||
define('LYCHEE_UPLOADS_IMPORT', LYCHEE_UPLOADS . 'import/');
|
define('LYCHEE_UPLOADS_IMPORT', LYCHEE_UPLOADS . 'import/');
|
||||||
define('LYCHEE_PLUGINS', LYCHEE . 'plugins/');
|
define('LYCHEE_PLUGINS', LYCHEE . 'plugins/');
|
||||||
|
|
||||||
# Define files
|
// Define files
|
||||||
define('LYCHEE_CONFIG_FILE', LYCHEE_DATA . 'config.php');
|
define('LYCHEE_CONFIG_FILE', LYCHEE_DATA . 'config.php');
|
||||||
|
|
||||||
# Define urls
|
// Define urls
|
||||||
define('LYCHEE_URL_UPLOADS_BIG', 'uploads/big/');
|
define('LYCHEE_URL_UPLOADS_BIG', 'uploads/big/');
|
||||||
define('LYCHEE_URL_UPLOADS_MEDIUM', 'uploads/medium/');
|
define('LYCHEE_URL_UPLOADS_MEDIUM', 'uploads/medium/');
|
||||||
define('LYCHEE_URL_UPLOADS_THUMB', 'uploads/thumb/');
|
define('LYCHEE_URL_UPLOADS_THUMB', 'uploads/thumb/');
|
||||||
|
|
||||||
function defineTablePrefix($dbTablePrefix = '') {
|
function defineTablePrefix($dbTablePrefix = '') {
|
||||||
|
|
||||||
# This part is wrapped into a function, because it needs to be called
|
// This part is wrapped into a function, because it needs to be called
|
||||||
# after the config-file has been loaded. Other defines are available
|
// after the config-file has been loaded. Other defines are available
|
||||||
# before the config-file has been loaded.
|
// before the config-file has been loaded.
|
||||||
|
|
||||||
# Parse table prefix
|
// Parse table prefix
|
||||||
# Old users do not have the table prefix stored in their config-file
|
// Old users do not have the table prefix stored in their config-file
|
||||||
if ($dbTablePrefix!=='') $dbTablePrefix .= '_';
|
if ($dbTablePrefix!=='') $dbTablePrefix .= '_';
|
||||||
|
|
||||||
# Define tables
|
// Define tables
|
||||||
define('LYCHEE_TABLE_ALBUMS', $dbTablePrefix . 'lychee_albums');
|
define('LYCHEE_TABLE_ALBUMS', $dbTablePrefix . 'lychee_albums');
|
||||||
define('LYCHEE_TABLE_LOG', $dbTablePrefix . 'lychee_log');
|
define('LYCHEE_TABLE_LOG', $dbTablePrefix . 'lychee_log');
|
||||||
define('LYCHEE_TABLE_PHOTOS', $dbTablePrefix . 'lychee_photos');
|
define('LYCHEE_TABLE_PHOTOS', $dbTablePrefix . 'lychee_photos');
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
function fastImageCopyResampled(&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 4) {
|
function fastImageCopyResampled(&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 4) {
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Plug-and-Play fastImageCopyResampled function replaces much slower imagecopyresampled.
|
* Plug-and-Play fastImageCopyResampled function replaces much slower imagecopyresampled.
|
||||||
# Just include this function and change all "imagecopyresampled" references to "fastImageCopyResampled".
|
* Just include this function and change all "imagecopyresampled" references to "fastImageCopyResampled".
|
||||||
# Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
|
* Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
|
||||||
# Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain.
|
* Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain.
|
||||||
#
|
*
|
||||||
# Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5. Must be greater than zero.
|
* Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5. Must be greater than zero.
|
||||||
# Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.
|
* Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.
|
||||||
# 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.
|
* 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.
|
||||||
# 2 = Up to 95 times faster. Images appear a little sharp, some prefer this over a quality of 3.
|
* 2 = Up to 95 times faster. Images appear a little sharp, some prefer this over a quality of 3.
|
||||||
# 3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled, just faster.
|
* 3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled, just faster.
|
||||||
# 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images.
|
* 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images.
|
||||||
# 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.
|
* 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.
|
||||||
###
|
*/
|
||||||
|
|
||||||
if (empty($src_image) || empty($dst_image) || $quality <= 0) { return false; }
|
if (empty($src_image) || empty($dst_image) || $quality <= 0) { return false; }
|
||||||
|
|
||||||
|
@ -2,28 +2,35 @@
|
|||||||
|
|
||||||
function getHashedString($password) {
|
function getHashedString($password) {
|
||||||
|
|
||||||
# Inspired by http://alias.io/2010/01/store-passwords-safely-with-php-and-mysql/
|
// Inspired by http://alias.io/2010/01/store-passwords-safely-with-php-and-mysql/
|
||||||
|
|
||||||
# A higher $cost is more secure but consumes more processing power
|
// A higher $cost is more secure but consumes more processing power
|
||||||
$cost = 10;
|
$cost = 10;
|
||||||
|
|
||||||
# Create a random salt
|
// Create a random salt
|
||||||
if (extension_loaded('openssl')) {
|
if (extension_loaded('openssl')) {
|
||||||
|
|
||||||
$salt = strtr(substr(base64_encode(openssl_random_pseudo_bytes(17)),0,22), '+', '.');
|
$salt = strtr(substr(base64_encode(openssl_random_pseudo_bytes(17)),0,22), '+', '.');
|
||||||
|
|
||||||
} elseif (extension_loaded('mcrypt')) {
|
} elseif (extension_loaded('mcrypt')) {
|
||||||
|
|
||||||
$salt = strtr(substr(base64_encode(mcrypt_create_iv(17, MCRYPT_DEV_URANDOM)),0,22), '+', '.');
|
$salt = strtr(substr(base64_encode(mcrypt_create_iv(17, MCRYPT_DEV_URANDOM)),0,22), '+', '.');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$salt = "";
|
|
||||||
|
$salt = '';
|
||||||
|
|
||||||
for ($i = 0; $i < 22; $i++) {
|
for ($i = 0; $i < 22; $i++) {
|
||||||
$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1);
|
$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Prefix information about the hash so PHP knows how to verify it later.
|
// Prefix information about the hash so PHP knows how to verify it later.
|
||||||
# "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
|
// "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
|
||||||
$salt = sprintf("$2a$%02d$", $cost) . $salt;
|
$salt = sprintf("$2a$%02d$", $cost) . $salt;
|
||||||
|
|
||||||
# Hash the password with the salt
|
// Hash the password with the salt
|
||||||
return crypt($password, $salt);
|
return crypt($password, $salt);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ function hasPermissions($path) {
|
|||||||
|
|
||||||
// Check if the given path is readable and writable
|
// Check if the given path is readable and writable
|
||||||
// Both functions are also verifying that the path exists
|
// Both functions are also verifying that the path exists
|
||||||
if (is_readable($path)===true&&
|
if (is_readable($path)===true&&is_writeable($path)===true) return true;
|
||||||
is_writeable($path)===true) return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -2,18 +2,16 @@
|
|||||||
|
|
||||||
function search($term) {
|
function search($term) {
|
||||||
|
|
||||||
$return['albums'] = '';
|
// Initialize return var
|
||||||
|
|
||||||
# Initialize return var
|
|
||||||
$return = array(
|
$return = array(
|
||||||
'photos' => null,
|
'photos' => null,
|
||||||
'albums' => null,
|
'albums' => null,
|
||||||
'hash' => ''
|
'hash' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Photos
|
* Photos
|
||||||
###
|
*/
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' OR tags LIKE '%?%'", array(LYCHEE_TABLE_PHOTOS, $term, $term, $term));
|
$query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' OR tags LIKE '%?%'", array(LYCHEE_TABLE_PHOTOS, $term, $term, $term));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
@ -25,35 +23,35 @@ function search($term) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Albums
|
* Albums
|
||||||
###
|
*/
|
||||||
|
|
||||||
$query = Database::prepare(Database::get(), "SELECT id, title, public, sysstamp, password FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%'", array(LYCHEE_TABLE_ALBUMS, $term, $term));
|
$query = Database::prepare(Database::get(), "SELECT id, title, public, sysstamp, password FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%'", array(LYCHEE_TABLE_ALBUMS, $term, $term));
|
||||||
$result = Database::get()->query($query);
|
$result = Database::get()->query($query);
|
||||||
|
|
||||||
while($album = $result->fetch_assoc()) {
|
while($album = $result->fetch_assoc()) {
|
||||||
|
|
||||||
# Turn data from the database into a front-end friendly format
|
// Turn data from the database into a front-end friendly format
|
||||||
$album = Album::prepareData($album);
|
$album = Album::prepareData($album);
|
||||||
|
|
||||||
# Thumbs
|
// Thumbs
|
||||||
$query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'] . " LIMIT 0, 3", array(LYCHEE_TABLE_PHOTOS, $album['id']));
|
$query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'] . " LIMIT 0, 3", array(LYCHEE_TABLE_PHOTOS, $album['id']));
|
||||||
$thumbs = Database::get()->query($query);
|
$thumbs = Database::get()->query($query);
|
||||||
|
|
||||||
# For each thumb
|
// For each thumb
|
||||||
$k = 0;
|
$k = 0;
|
||||||
while ($thumb = $thumbs->fetch_object()) {
|
while ($thumb = $thumbs->fetch_object()) {
|
||||||
$album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
|
$album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
|
||||||
$k++;
|
$k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add to return
|
// Add to return
|
||||||
$return['albums'][$album['id']] = $album;
|
$return['albums'][$album['id']] = $album;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Hash
|
// Hash
|
||||||
$return['hash'] = md5(json_encode($return));
|
$return['hash'] = md5(json_encode($return));
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
###
|
/**
|
||||||
# @name API
|
* @author Tobias Reich
|
||||||
# @author Tobias Reich
|
* @copyright 2016 by Tobias Reich
|
||||||
# @copyright 2015 by Tobias Reich
|
*/
|
||||||
###
|
|
||||||
|
|
||||||
namespace Lychee;
|
namespace Lychee;
|
||||||
|
|
||||||
@ -26,55 +25,55 @@ require(__DIR__ . '/helpers/getHashedString.php');
|
|||||||
require(__DIR__ . '/helpers/hasPermissions.php');
|
require(__DIR__ . '/helpers/hasPermissions.php');
|
||||||
require(__DIR__ . '/helpers/search.php');
|
require(__DIR__ . '/helpers/search.php');
|
||||||
|
|
||||||
# Define the called function
|
// Define the called function
|
||||||
if (isset($_POST['function'])) $fn = $_POST['function'];
|
if (isset($_POST['function'])) $fn = $_POST['function'];
|
||||||
else if (isset($_GET['function'])) $fn = $_GET['function'];
|
else if (isset($_GET['function'])) $fn = $_GET['function'];
|
||||||
else $fn = null;
|
else $fn = null;
|
||||||
|
|
||||||
# Check if a function has been specified
|
// Check if a function has been specified
|
||||||
if (!empty($fn)) {
|
if (!empty($fn)) {
|
||||||
|
|
||||||
# Start the session and set the default timezone
|
// Start the session and set the default timezone
|
||||||
session_start();
|
session_start();
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
# Validate parameters
|
// Validate parameters
|
||||||
if (isset($_POST['albumIDs'])&&Validator::isAlbumIDs($_POST['albumIDs'])===false) exit('Error: Wrong parameter type for albumIDs!');
|
if (isset($_POST['albumIDs'])&&Validator::isAlbumIDs($_POST['albumIDs'])===false) exit('Error: Wrong parameter type for albumIDs!');
|
||||||
if (isset($_POST['photoIDs'])&&Validator::isPhotoIDs($_POST['photoIDs'])===false) exit('Error: Wrong parameter type for photoIDs!');
|
if (isset($_POST['photoIDs'])&&Validator::isPhotoIDs($_POST['photoIDs'])===false) exit('Error: Wrong parameter type for photoIDs!');
|
||||||
if (isset($_POST['albumID'])&&Validator::isAlbumID($_POST['albumID'])==false) exit('Error: Wrong parameter type for albumID!');
|
if (isset($_POST['albumID'])&&Validator::isAlbumID($_POST['albumID'])==false) exit('Error: Wrong parameter type for albumID!');
|
||||||
if (isset($_POST['photoID'])&&Validator::isPhotoID($_POST['photoID'])==false) exit('Error: Wrong parameter type for photoID!');
|
if (isset($_POST['photoID'])&&Validator::isPhotoID($_POST['photoID'])==false) exit('Error: Wrong parameter type for photoID!');
|
||||||
|
|
||||||
# Check if a configuration exists
|
// Check if a configuration exists
|
||||||
if (Config::exists()===false) {
|
if (Config::exists()===false) {
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Installation Access
|
* Installation Access
|
||||||
# Limited access to configure Lychee. Only available when the config.php file is missing.
|
* Limited access to configure Lychee. Only available when the config.php file is missing.
|
||||||
###
|
*/
|
||||||
|
|
||||||
Installation::init($fn);
|
Installation::init($fn);
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if user is logged
|
// Check if user is logged
|
||||||
if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
|
if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
|
||||||
(isset($_SESSION['identifier'])&&$_SESSION['identifier']===Settings::get()['identifier'])) {
|
(isset($_SESSION['identifier'])&&$_SESSION['identifier']===Settings::get()['identifier'])) {
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Admin Access
|
* Admin Access
|
||||||
# Full access to Lychee. Only with correct password/session.
|
* Full access to Lychee. Only with correct password/session.
|
||||||
###
|
*/
|
||||||
|
|
||||||
Admin::init($fn);
|
Admin::init($fn);
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
###
|
/**
|
||||||
# Guest Access
|
* Guest Access
|
||||||
# Access to view all public folders and photos in Lychee.
|
* Access to view all public folders and photos in Lychee.
|
||||||
###
|
*/
|
||||||
|
|
||||||
Guest::init($fn);
|
Guest::init($fn);
|
||||||
exit();
|
exit();
|
||||||
|
Loading…
Reference in New Issue
Block a user