|
@@ -8,8 +8,8 @@ final class Album {
|
|
|
|
|
|
public function __construct($albumIDs) {
|
|
|
|
|
|
- # Init vars
|
|
|
- $this->albumIDs = $albumIDs;
|
|
|
+ // Init vars
|
|
|
+ $this->albumIDs = $albumIDs;
|
|
|
|
|
|
return true;
|
|
|
|
|
@@ -17,22 +17,22 @@ final class Album {
|
|
|
|
|
|
public function add($title = 'Untitled') {
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Parse
|
|
|
+ // Parse
|
|
|
if (strlen($title)>50) $title = substr($title, 0, 50);
|
|
|
|
|
|
- # Properties
|
|
|
- $public = 0;
|
|
|
- $visible = 1;
|
|
|
+ // Properties
|
|
|
+ $public = 0;
|
|
|
+ $visible = 1;
|
|
|
|
|
|
- # Database
|
|
|
- $sysstamp = time();
|
|
|
- $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);
|
|
|
+ // Database
|
|
|
+ $sysstamp = time();
|
|
|
+ $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);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if (!$result) {
|
|
@@ -45,31 +45,31 @@ final class Album {
|
|
|
|
|
|
public static function prepareData(array $data) {
|
|
|
|
|
|
- # This function requires the following album-attributes and turns them
|
|
|
- # into a front-end friendly format: id, title, public, sysstamp, password
|
|
|
- # Note that some attributes remain unchanged
|
|
|
+ // This function requires the following album-attributes and turns them
|
|
|
+ // into a front-end friendly format: id, title, public, sysstamp, password
|
|
|
+ // Note that some attributes remain unchanged
|
|
|
|
|
|
- # Init
|
|
|
+ // Init
|
|
|
$album = null;
|
|
|
|
|
|
- # Set unchanged attributes
|
|
|
- $album['id'] = $data['id'];
|
|
|
- $album['title'] = $data['title'];
|
|
|
- $album['public'] = $data['public'];
|
|
|
+ // Set unchanged attributes
|
|
|
+ $album['id'] = $data['id'];
|
|
|
+ $album['title'] = $data['title'];
|
|
|
+ $album['public'] = $data['public'];
|
|
|
|
|
|
- # Additional attributes
|
|
|
- # Only part of $album when available
|
|
|
- if (isset($data['description'])) $album['description'] = $data['description'];
|
|
|
- if (isset($data['visible'])) $album['visible'] = $data['visible'];
|
|
|
- if (isset($data['downloadable'])) $album['downloadable'] = $data['downloadable'];
|
|
|
+ // Additional attributes
|
|
|
+ // Only part of $album when available
|
|
|
+ if (isset($data['description'])) $album['description'] = $data['description'];
|
|
|
+ if (isset($data['visible'])) $album['visible'] = $data['visible'];
|
|
|
+ if (isset($data['downloadable'])) $album['downloadable'] = $data['downloadable'];
|
|
|
|
|
|
- # Parse date
|
|
|
+ // Parse date
|
|
|
$album['sysdate'] = date('F Y', $data['sysstamp']);
|
|
|
|
|
|
- # Parse password
|
|
|
+ // Parse password
|
|
|
$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());
|
|
|
|
|
|
return $album;
|
|
@@ -78,85 +78,90 @@ final class Album {
|
|
|
|
|
|
public function get() {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Get album information
|
|
|
+ // Get album information
|
|
|
switch ($this->albumIDs) {
|
|
|
|
|
|
- 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));
|
|
|
- break;
|
|
|
+ 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));
|
|
|
+ break;
|
|
|
|
|
|
- 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));
|
|
|
- break;
|
|
|
+ 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));
|
|
|
+ break;
|
|
|
|
|
|
- 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));
|
|
|
- break;
|
|
|
+ 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));
|
|
|
+ break;
|
|
|
|
|
|
- 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));
|
|
|
- break;
|
|
|
+ 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));
|
|
|
+ break;
|
|
|
|
|
|
- default: $query = Database::prepare(Database::get(), "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
- $albums = Database::get()->query($query);
|
|
|
- $return = $albums->fetch_assoc();
|
|
|
- $return = Album::prepareData($return);
|
|
|
- $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
- break;
|
|
|
+ default:
|
|
|
+ $query = Database::prepare(Database::get(), "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
+ $albums = Database::get()->query($query);
|
|
|
+ $return = $albums->fetch_assoc();
|
|
|
+ $return = Album::prepareData($return);
|
|
|
+ $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
+ break;
|
|
|
|
|
|
}
|
|
|
|
|
|
- # Get photos
|
|
|
- $photos = Database::get()->query($query);
|
|
|
- $previousPhotoID = '';
|
|
|
+ // Get photos
|
|
|
+ $photos = Database::get()->query($query);
|
|
|
+ $previousPhotoID = '';
|
|
|
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);
|
|
|
|
|
|
- # Set previous and next photoID for navigation purposes
|
|
|
+ // Set previous and next photoID for navigation purposes
|
|
|
$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'];
|
|
|
$previousPhotoID = $photo['id'];
|
|
|
|
|
|
- # Add to return
|
|
|
+ // Add to return
|
|
|
$return['content'][$photo['id']] = $photo;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($photos->num_rows===0) {
|
|
|
|
|
|
- # Album empty
|
|
|
+ // Album empty
|
|
|
$return['content'] = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- # Enable next and previous for the first and last photo
|
|
|
- $lastElement = end($return['content']);
|
|
|
- $lastElementId = $lastElement['id'];
|
|
|
- $firstElement = reset($return['content']);
|
|
|
- $firstElementId = $firstElement['id'];
|
|
|
+ // Enable next and previous for the first and last photo
|
|
|
+ $lastElement = end($return['content']);
|
|
|
+ $lastElementId = $lastElement['id'];
|
|
|
+ $firstElement = reset($return['content']);
|
|
|
+ $firstElementId = $firstElement['id'];
|
|
|
|
|
|
if ($lastElementId!==$firstElementId) {
|
|
|
- $return['content'][$lastElementId]['nextPhoto'] = $firstElementId;
|
|
|
- $return['content'][$firstElementId]['previousPhoto'] = $lastElementId;
|
|
|
+ $return['content'][$lastElementId]['nextPhoto'] = $firstElementId;
|
|
|
+ $return['content'][$firstElementId]['previousPhoto'] = $lastElementId;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- $return['id'] = $this->albumIDs;
|
|
|
- $return['num'] = $photos->num_rows;
|
|
|
+ $return['id'] = $this->albumIDs;
|
|
|
+ $return['num'] = $photos->num_rows;
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
return $return;
|
|
@@ -165,45 +170,45 @@ final class Album {
|
|
|
|
|
|
public function getAll($public = true) {
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Initialize return var
|
|
|
+ // Initialize return var
|
|
|
$return = array(
|
|
|
- 'smartalbums' => null,
|
|
|
- 'albums' => null,
|
|
|
- 'num' => 0
|
|
|
+ 'smartalbums' => null,
|
|
|
+ 'albums' => null,
|
|
|
+ 'num' => 0
|
|
|
);
|
|
|
|
|
|
- # Get SmartAlbums
|
|
|
+ // Get SmartAlbums
|
|
|
if ($public===false) $return['smartalbums'] = $this->getSmartInfo();
|
|
|
|
|
|
- # Albums query
|
|
|
- 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));
|
|
|
+ // Albums query
|
|
|
+ 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));
|
|
|
|
|
|
- # Execute query
|
|
|
+ // Execute query
|
|
|
$albums = Database::get()->query($query);
|
|
|
if (!$albums) {
|
|
|
Log::error(__METHOD__, __LINE__, 'Could not get all albums (' . Database::get()->error . ')');
|
|
|
exit('Error: ' . Database::get()->error);
|
|
|
}
|
|
|
|
|
|
- # For each album
|
|
|
+ // For each album
|
|
|
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);
|
|
|
|
|
|
- # Thumbs
|
|
|
+ // Thumbs
|
|
|
if (($public===true&&$album['password']==='0')||
|
|
|
($public===false)) {
|
|
|
|
|
|
- # 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']));
|
|
|
- $thumbs = Database::get()->query($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']));
|
|
|
+ $thumbs = Database::get()->query($query);
|
|
|
|
|
|
- # For each thumb
|
|
|
+ // For each thumb
|
|
|
$k = 0;
|
|
|
while ($thumb = $thumbs->fetch_object()) {
|
|
|
$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;
|
|
|
|
|
|
}
|
|
|
|
|
|
- # Num of albums
|
|
|
+ // Num of albums
|
|
|
$return['num'] = $albums->num_rows;
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
return $return;
|
|
@@ -229,25 +234,25 @@ final class Album {
|
|
|
|
|
|
private function getSmartInfo() {
|
|
|
|
|
|
- # Initialize return var
|
|
|
+ // Initialize return var
|
|
|
$return = array(
|
|
|
- 'unsorted' => null,
|
|
|
- 'public' => null,
|
|
|
- 'starred' => null,
|
|
|
- 'recent' => null
|
|
|
+ 'unsorted' => null,
|
|
|
+ 'public' => null,
|
|
|
+ 'starred' => null,
|
|
|
+ 'recent' => null
|
|
|
);
|
|
|
|
|
|
- ###
|
|
|
- # Unsorted
|
|
|
- ###
|
|
|
+ /**
|
|
|
+ * Unsorted
|
|
|
+ */
|
|
|
|
|
|
- $query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE album = 0 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
|
|
- $unsorted = Database::get()->query($query);
|
|
|
- $i = 0;
|
|
|
+ $query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE album = 0 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
|
|
+ $unsorted = Database::get()->query($query);
|
|
|
+ $i = 0;
|
|
|
|
|
|
$return['unsorted'] = array(
|
|
|
- 'thumbs' => array(),
|
|
|
- 'num' => $unsorted->num_rows
|
|
|
+ 'thumbs' => array(),
|
|
|
+ 'num' => $unsorted->num_rows
|
|
|
);
|
|
|
|
|
|
while($row = $unsorted->fetch_object()) {
|
|
@@ -257,17 +262,17 @@ final class Album {
|
|
|
} else break;
|
|
|
}
|
|
|
|
|
|
- ###
|
|
|
- # Starred
|
|
|
- ###
|
|
|
+ /**
|
|
|
+ * Starred
|
|
|
+ */
|
|
|
|
|
|
- $query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE star = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
|
|
- $starred = Database::get()->query($query);
|
|
|
- $i = 0;
|
|
|
+ $query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE star = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
|
|
+ $starred = Database::get()->query($query);
|
|
|
+ $i = 0;
|
|
|
|
|
|
$return['starred'] = array(
|
|
|
- 'thumbs' => array(),
|
|
|
- 'num' => $starred->num_rows
|
|
|
+ 'thumbs' => array(),
|
|
|
+ 'num' => $starred->num_rows
|
|
|
);
|
|
|
|
|
|
while($row3 = $starred->fetch_object()) {
|
|
@@ -277,17 +282,17 @@ final class Album {
|
|
|
} else break;
|
|
|
}
|
|
|
|
|
|
- ###
|
|
|
- # Public
|
|
|
- ###
|
|
|
+ /**
|
|
|
+ * Public
|
|
|
+ */
|
|
|
|
|
|
- $query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE public = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
|
|
- $public = Database::get()->query($query);
|
|
|
- $i = 0;
|
|
|
+ $query = Database::prepare(Database::get(), 'SELECT thumbUrl FROM ? WHERE public = 1 ' . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS));
|
|
|
+ $public = Database::get()->query($query);
|
|
|
+ $i = 0;
|
|
|
|
|
|
$return['public'] = array(
|
|
|
- 'thumbs' => array(),
|
|
|
- 'num' => $public->num_rows
|
|
|
+ 'thumbs' => array(),
|
|
|
+ 'num' => $public->num_rows
|
|
|
);
|
|
|
|
|
|
while($row2 = $public->fetch_object()) {
|
|
@@ -297,17 +302,17 @@ final class Album {
|
|
|
} 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));
|
|
|
- $recent = Database::get()->query($query);
|
|
|
- $i = 0;
|
|
|
+ $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);
|
|
|
+ $i = 0;
|
|
|
|
|
|
$return['recent'] = array(
|
|
|
- 'thumbs' => array(),
|
|
|
- 'num' => $recent->num_rows
|
|
|
+ 'thumbs' => array(),
|
|
|
+ 'num' => $recent->num_rows
|
|
|
);
|
|
|
|
|
|
while($row3 = $recent->fetch_object()) {
|
|
@@ -317,117 +322,117 @@ final class Album {
|
|
|
} else break;
|
|
|
}
|
|
|
|
|
|
- # Return SmartAlbums
|
|
|
+ // Return SmartAlbums
|
|
|
return $return;
|
|
|
|
|
|
}
|
|
|
|
|
|
public function getArchive() {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Illicit chars
|
|
|
+ // Illicit chars
|
|
|
$badChars = array_merge(
|
|
|
- array_map('chr', range(0,31)),
|
|
|
- array("<", ">", ":", '"', "/", "\\", "|", "?", "*")
|
|
|
- );
|
|
|
+ array_map('chr', range(0,31)),
|
|
|
+ array("<", ">", ":", '"', "/", "\\", "|", "?", "*")
|
|
|
+ );
|
|
|
|
|
|
- # Photos query
|
|
|
+ // Photos query
|
|
|
switch($this->albumIDs) {
|
|
|
case 's':
|
|
|
- $photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE public = 1', array(LYCHEE_TABLE_PHOTOS));
|
|
|
- $zipTitle = 'Public';
|
|
|
+ $photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE public = 1', array(LYCHEE_TABLE_PHOTOS));
|
|
|
+ $zipTitle = 'Public';
|
|
|
break;
|
|
|
case 'f':
|
|
|
- $photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE star = 1', array(LYCHEE_TABLE_PHOTOS));
|
|
|
- $zipTitle = 'Starred';
|
|
|
+ $photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE star = 1', array(LYCHEE_TABLE_PHOTOS));
|
|
|
+ $zipTitle = 'Starred';
|
|
|
break;
|
|
|
case 'r':
|
|
|
- $photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) GROUP BY checksum', array(LYCHEE_TABLE_PHOTOS));
|
|
|
- $zipTitle = 'Recent';
|
|
|
+ $photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) GROUP BY checksum', array(LYCHEE_TABLE_PHOTOS));
|
|
|
+ $zipTitle = 'Recent';
|
|
|
break;
|
|
|
default:
|
|
|
- $photos = Database::prepare(Database::get(), "SELECT title, url FROM ? WHERE album = '?'", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
- $zipTitle = 'Unsorted';
|
|
|
+ $photos = Database::prepare(Database::get(), "SELECT title, url FROM ? WHERE album = '?'", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
+ $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)) {
|
|
|
|
|
|
$query = Database::prepare(Database::get(), "SELECT title FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
$album = Database::get()->query($query);
|
|
|
|
|
|
- # Error in database query
|
|
|
+ // Error in database query
|
|
|
if (!$album) {
|
|
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- # Fetch object
|
|
|
+ // Fetch object
|
|
|
$album = $album->fetch_object();
|
|
|
|
|
|
- # Photo not found
|
|
|
+ // Photo not found
|
|
|
if ($album===null) {
|
|
|
Log::error(__METHOD__, __LINE__, 'Album not found. Cannot start download.');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- # Set title
|
|
|
+ // Set title
|
|
|
$zipTitle = $album->title;
|
|
|
|
|
|
}
|
|
|
|
|
|
- # Escape title
|
|
|
+ // Escape title
|
|
|
$zipTitle = str_replace($badChars, '', $zipTitle);
|
|
|
|
|
|
$filename = LYCHEE_DATA . $zipTitle . '.zip';
|
|
|
|
|
|
- # Create zip
|
|
|
+ // Create zip
|
|
|
$zip = new ZipArchive();
|
|
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
|
|
|
Log::error(__METHOD__, __LINE__, 'Could not create ZipArchive');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- # Execute query
|
|
|
+ // Execute query
|
|
|
$photos = Database::get()->query($photos);
|
|
|
|
|
|
- # Check if album empty
|
|
|
+ // Check if album empty
|
|
|
if ($photos->num_rows==0) {
|
|
|
Log::error(__METHOD__, __LINE__, 'Could not create ZipArchive without images');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- # Parse each path
|
|
|
+ // Parse each path
|
|
|
$files = array();
|
|
|
while ($photo = $photos->fetch_object()) {
|
|
|
|
|
|
- # Parse url
|
|
|
+ // Parse url
|
|
|
$photo->url = LYCHEE_UPLOADS_BIG . $photo->url;
|
|
|
|
|
|
- # Parse title
|
|
|
+ // Parse title
|
|
|
$photo->title = str_replace($badChars, '', $photo->title);
|
|
|
if (!isset($photo->title)||$photo->title==='') $photo->title = 'Untitled';
|
|
|
|
|
|
- # Check if readable
|
|
|
+ // Check if readable
|
|
|
if (!@is_readable($photo->url)) continue;
|
|
|
|
|
|
- # Get extension of image
|
|
|
+ // Get extension of image
|
|
|
$extension = getExtension($photo->url);
|
|
|
|
|
|
- # Set title for photo
|
|
|
+ // Set title for photo
|
|
|
$zipFileName = $zipTitle . '/' . $photo->title . $extension;
|
|
|
|
|
|
- # Check for duplicates
|
|
|
+ // Check for duplicates
|
|
|
if (!empty($files)) {
|
|
|
$i = 1;
|
|
|
while (in_array($zipFileName, $files)) {
|
|
|
|
|
|
- # Set new title for photo
|
|
|
+ // Set new title for photo
|
|
|
$zipFileName = $zipTitle . '/' . $photo->title . '-' . $i . $extension;
|
|
|
|
|
|
$i++;
|
|
@@ -435,27 +440,27 @@ final class Album {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- # Add to array
|
|
|
+ // Add to array
|
|
|
$files[] = $zipFileName;
|
|
|
|
|
|
- # Add photo to zip
|
|
|
+ // Add photo to zip
|
|
|
$zip->addFile($photo->url, $zipFileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
- # Finish zip
|
|
|
+ // Finish zip
|
|
|
$zip->close();
|
|
|
|
|
|
- # Send zip
|
|
|
+ // Send zip
|
|
|
header("Content-Type: application/zip");
|
|
|
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
|
|
|
header("Content-Length: " . filesize($filename));
|
|
|
readfile($filename);
|
|
|
|
|
|
- # Delete zip
|
|
|
+ // Delete zip
|
|
|
unlink($filename);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
return true;
|
|
@@ -464,17 +469,17 @@ final class Album {
|
|
|
|
|
|
public function setTitle($title = 'Untitled') {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Execute query
|
|
|
- $query = Database::prepare(Database::get(), "UPDATE ? SET title = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $title, $this->albumIDs));
|
|
|
+ // Execute query
|
|
|
+ $query = Database::prepare(Database::get(), "UPDATE ? SET title = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $title, $this->albumIDs));
|
|
|
$result = Database::get()->query($query);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if (!$result) {
|
|
@@ -487,17 +492,17 @@ final class Album {
|
|
|
|
|
|
public function setDescription($description = '') {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Execute query
|
|
|
- $query = Database::prepare(Database::get(), "UPDATE ? SET description = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $description, $this->albumIDs));
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ // Execute query
|
|
|
+ $query = Database::prepare(Database::get(), "UPDATE ? SET description = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $description, $this->albumIDs));
|
|
|
+ $result = Database::get()->query($query);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if (!$result) {
|
|
@@ -510,20 +515,20 @@ final class Album {
|
|
|
|
|
|
public function getPublic() {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f') return false;
|
|
|
|
|
|
- # Execute query
|
|
|
- $query = Database::prepare(Database::get(), "SELECT public FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
- $albums = Database::get()->query($query);
|
|
|
- $album = $albums->fetch_object();
|
|
|
+ // Execute query
|
|
|
+ $query = Database::prepare(Database::get(), "SELECT public FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
+ $albums = Database::get()->query($query);
|
|
|
+ $album = $albums->fetch_object();
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if ($album->public==1) return true;
|
|
@@ -533,20 +538,20 @@ final class Album {
|
|
|
|
|
|
public function getDownloadable() {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f'||$this->albumIDs==='r') return false;
|
|
|
|
|
|
- # Execute query
|
|
|
- $query = Database::prepare(Database::get(), "SELECT downloadable FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
- $albums = Database::get()->query($query);
|
|
|
- $album = $albums->fetch_object();
|
|
|
+ // Execute query
|
|
|
+ $query = Database::prepare(Database::get(), "SELECT downloadable FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
+ $albums = Database::get()->query($query);
|
|
|
+ $album = $albums->fetch_object();
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if ($album->downloadable==1) return true;
|
|
@@ -556,39 +561,39 @@ final class Album {
|
|
|
|
|
|
public function setPublic($public, $password, $visible, $downloadable) {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Convert values
|
|
|
- $public = ($public==='1' ? 1 : 0);
|
|
|
- $visible = ($visible==='1' ? 1 : 0);
|
|
|
- $downloadable = ($downloadable==='1' ? 1 : 0);
|
|
|
+ // Convert values
|
|
|
+ $public = ($public==='1' ? 1 : 0);
|
|
|
+ $visible = ($visible==='1' ? 1 : 0);
|
|
|
+ $downloadable = ($downloadable==='1' ? 1 : 0);
|
|
|
|
|
|
- # 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));
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ // 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));
|
|
|
+ $result = Database::get()->query($query);
|
|
|
if (!$result) {
|
|
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- # Reset permissions for photos
|
|
|
+ // Reset permissions for photos
|
|
|
if ($public===1) {
|
|
|
- $query = Database::prepare(Database::get(), "UPDATE ? SET public = 0 WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ $query = Database::prepare(Database::get(), "UPDATE ? SET public = 0 WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
+ $result = Database::get()->query($query);
|
|
|
if (!$result) {
|
|
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
- # Set password
|
|
|
+ // Set password
|
|
|
if (isset($password)&&strlen($password)>0) return $this->setPassword($password);
|
|
|
|
|
|
return true;
|
|
@@ -597,33 +602,33 @@ final class Album {
|
|
|
|
|
|
private function setPassword($password) {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
if (strlen($password)>0) {
|
|
|
|
|
|
- # Get hashed password
|
|
|
+ // Get hashed password
|
|
|
$password = getHashedString($password);
|
|
|
|
|
|
- # Set hashed password
|
|
|
- # Do not prepare $password because it is hashed and save
|
|
|
- # 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));
|
|
|
+ // Set hashed password
|
|
|
+ // Do not prepare $password because it is hashed and save
|
|
|
+ // 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));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- # Unset password
|
|
|
- $query = Database::prepare(Database::get(), "UPDATE ? SET password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
+ // Unset password
|
|
|
+ $query = Database::prepare(Database::get(), "UPDATE ? SET password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
|
|
|
}
|
|
|
|
|
|
- # Execute query
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ // Execute query
|
|
|
+ $result = Database::get()->query($query);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if (!$result) {
|
|
@@ -636,18 +641,18 @@ final class Album {
|
|
|
|
|
|
public function checkPassword($password) {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Execute query
|
|
|
- $query = Database::prepare(Database::get(), "SELECT password FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
- $albums = Database::get()->query($query);
|
|
|
- $album = $albums->fetch_object();
|
|
|
+ // Execute query
|
|
|
+ $query = Database::prepare(Database::get(), "SELECT password FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
+ $albums = Database::get()->query($query);
|
|
|
+ $album = $albums->fetch_object();
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if ($album->password=='') return true;
|
|
@@ -658,35 +663,35 @@ final class Album {
|
|
|
|
|
|
public function merge() {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Convert to array
|
|
|
+ // Convert to array
|
|
|
$albumIDs = explode(',', $this->albumIDs);
|
|
|
|
|
|
- # Get first albumID
|
|
|
+ // Get first albumID
|
|
|
$albumID = array_splice($albumIDs, 0, 1);
|
|
|
$albumID = $albumID[0];
|
|
|
|
|
|
- $query = Database::prepare(Database::get(), "UPDATE ? SET album = ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $albumID, $this->albumIDs));
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ $query = Database::prepare(Database::get(), "UPDATE ? SET album = ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $albumID, $this->albumIDs));
|
|
|
+ $result = Database::get()->query($query);
|
|
|
|
|
|
if (!$result) {
|
|
|
Log::error(__METHOD__, __LINE__, Database::get()->error);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- # $albumIDs contains all IDs without the first albumID
|
|
|
- # Convert to string
|
|
|
+ // $albumIDs contains all IDs without the first albumID
|
|
|
+ // Convert to string
|
|
|
$filteredIDs = implode(',', $albumIDs);
|
|
|
|
|
|
- $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $filteredIDs));
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $filteredIDs));
|
|
|
+ $result = Database::get()->query($query);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if (!$result) {
|
|
@@ -699,20 +704,20 @@ final class Album {
|
|
|
|
|
|
public function delete() {
|
|
|
|
|
|
- # Check dependencies
|
|
|
+ // Check dependencies
|
|
|
Validator::required(isset($this->albumIDs), __METHOD__);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
|
|
|
|
|
- # Init vars
|
|
|
+ // Init vars
|
|
|
$error = false;
|
|
|
|
|
|
- # Execute query
|
|
|
- $query = Database::prepare(Database::get(), "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
+ // Execute query
|
|
|
+ $query = Database::prepare(Database::get(), "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
|
|
|
$photos = Database::get()->query($query);
|
|
|
|
|
|
- # For each album delete photo
|
|
|
+ // For each album delete photo
|
|
|
while ($row = $photos->fetch_object()) {
|
|
|
|
|
|
$photo = new Photo($row->id);
|
|
@@ -720,11 +725,11 @@ final class Album {
|
|
|
|
|
|
}
|
|
|
|
|
|
- # Delete albums
|
|
|
- $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
- $result = Database::get()->query($query);
|
|
|
+ // Delete albums
|
|
|
+ $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
|
|
+ $result = Database::get()->query($query);
|
|
|
|
|
|
- # Call plugins
|
|
|
+ // Call plugins
|
|
|
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
|
|
|
|
|
if ($error) return false;
|