Added new functions to Album class
This commit is contained in:
parent
33667f70c6
commit
d49e4792cc
@ -25,12 +25,14 @@ switch ($_POST['function']) {
|
|||||||
echo $album->add($_POST['title']);
|
echo $album->add($_POST['title']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'setAlbumTitle': if (isset($_POST['albumIDs'], $_POST['title']))
|
case 'setAlbumTitle': if (!isset($_POST['albumIDs'])) exit();
|
||||||
echo setAlbumTitle($_POST['albumIDs'], $_POST['title']);
|
$album = new Album($database, $plugins, $settings, $_POST['albumIDs']);
|
||||||
|
echo $album->setTitle($_POST['title']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'setAlbumDescription': if (isset($_POST['albumID'], $_POST['description']))
|
case 'setAlbumDescription': if (!isset($_POST['albumID'])) exit();
|
||||||
echo setAlbumDescription($_POST['albumID'], $_POST['description']);
|
$album = new Album($database, $plugins, $settings, $_POST['albumID']);
|
||||||
|
echo $album->setDescription($_POST['description']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'setAlbumPublic': if (isset($_POST['albumID']))
|
case 'setAlbumPublic': if (isset($_POST['albumID']))
|
||||||
@ -42,8 +44,9 @@ switch ($_POST['function']) {
|
|||||||
echo setAlbumPassword($_POST['albumID'], $_POST['password']);
|
echo setAlbumPassword($_POST['albumID'], $_POST['password']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'deleteAlbum': if (isset($_POST['albumIDs']))
|
case 'deleteAlbum': if (!isset($_POST['albumIDs'])) exit();
|
||||||
echo deleteAlbum($_POST['albumIDs']);
|
$album = new Album($database, $plugins, $settings, $_POST['albumIDs']);
|
||||||
|
echo $album->delete($_POST['albumIDs']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Photo Functions
|
// Photo Functions
|
||||||
|
@ -12,10 +12,10 @@ class Album {
|
|||||||
|
|
||||||
private $database = null;
|
private $database = null;
|
||||||
private $plugins = null;
|
private $plugins = null;
|
||||||
private $settings = array();
|
private $settings = null;
|
||||||
private $albumIDs = array();
|
private $albumIDs = null;
|
||||||
|
|
||||||
public function __construct($database = null, $plugins = null, $settings = null, $albumIDs = array()) {
|
public function __construct($database, $plugins, $settings, $albumIDs) {
|
||||||
|
|
||||||
# Init vars
|
# Init vars
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
@ -62,7 +62,7 @@ class Album {
|
|||||||
|
|
||||||
public function getAll($public) {
|
public function getAll($public) {
|
||||||
|
|
||||||
if (!isset($public)) return false;
|
if (!isset($this->database, $this->settings, $public)) return false;
|
||||||
|
|
||||||
# Call plugins
|
# Call plugins
|
||||||
$this->plugins('getAll:before', func_get_args());
|
$this->plugins('getAll:before', func_get_args());
|
||||||
@ -114,4 +114,75 @@ class Album {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setTitle($title = 'Untitled') {
|
||||||
|
|
||||||
|
if (!isset($this->database, $this->albumIDs)) return false;
|
||||||
|
|
||||||
|
# Call plugins
|
||||||
|
$this->plugins('setTitle:before', func_get_args());
|
||||||
|
|
||||||
|
# Parse
|
||||||
|
if (strlen($title)>50) $title = substr($title, 0, 50);
|
||||||
|
|
||||||
|
# Execute query
|
||||||
|
$result = $this->database->query("UPDATE lychee_albums SET title = '$title' WHERE id IN ($this->albumIDs);");
|
||||||
|
|
||||||
|
# Call plugins
|
||||||
|
$this->plugins('setTitle:after', func_get_args());
|
||||||
|
|
||||||
|
if (!$result) return false;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription($description = '') {
|
||||||
|
|
||||||
|
if (!isset($this->database, $this->albumIDs)) return false;
|
||||||
|
|
||||||
|
# Call plugins
|
||||||
|
$this->plugins('setDescription:before', func_get_args());
|
||||||
|
|
||||||
|
# Parse
|
||||||
|
$description = htmlentities($description);
|
||||||
|
if (strlen($description)>1000) return false;
|
||||||
|
|
||||||
|
# Execute query
|
||||||
|
$result = $this->database->query("UPDATE lychee_albums SET description = '$description' WHERE id IN ($this->albumIDs);");
|
||||||
|
|
||||||
|
# Call plugins
|
||||||
|
$this->plugins('setDescription:after', func_get_args());
|
||||||
|
|
||||||
|
if (!$result) return false;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($albumIDs) {
|
||||||
|
|
||||||
|
if (!isset($this->database, $this->albumIDs)) return false;
|
||||||
|
|
||||||
|
# Call plugins
|
||||||
|
$this->plugins('delete:before', func_get_args());
|
||||||
|
|
||||||
|
# Init vars
|
||||||
|
$error = false;
|
||||||
|
|
||||||
|
# Execute query
|
||||||
|
$result = $this->database->query("SELECT id FROM lychee_photos WHERE album IN ($albumIDs);");
|
||||||
|
|
||||||
|
# For each album delete photo
|
||||||
|
while ($row = $result->fetch_object())
|
||||||
|
if (!deletePhoto($row->id)) $error = true;
|
||||||
|
|
||||||
|
# Delete albums
|
||||||
|
$result = $this->database->query("DELETE FROM lychee_albums WHERE id IN ($albumIDs);");
|
||||||
|
|
||||||
|
# Call plugins
|
||||||
|
$this->plugins('delete:after', func_get_args());
|
||||||
|
|
||||||
|
if ($error||!$result) return false;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user