Added setPublic and setPassword to Album

This commit is contained in:
Tobias Reich 2014-04-04 17:56:08 +02:00
parent 6b4aaa6a23
commit ce3914e801
4 changed files with 76 additions and 13 deletions

View File

@ -281,7 +281,7 @@ album = {
} else {
params = "setAlbumPublic&albumID=" + albumID;
params = "setAlbumPublic&albumID=" + albumID + "&password=";
album.json.password = false;
}

File diff suppressed because one or more lines are too long

View File

@ -21,27 +21,29 @@ switch ($_POST['function']) {
echo json_encode(getAlbum($_POST['albumID']));
break;
case 'addAlbum': $album = new Album($database, $plugins, $settings, null);
case 'addAlbum': if (!isset($_POST['title'])) exit();
$album = new Album($database, $plugins, $settings, null);
echo $album->add($_POST['title']);
break;
case 'setAlbumTitle': if (!isset($_POST['albumIDs'])) exit();
case 'setAlbumTitle': if (!isset($_POST['albumIDs'], $_POST['title'])) exit();
$album = new Album($database, $plugins, $settings, $_POST['albumIDs']);
echo $album->setTitle($_POST['title']);
break;
case 'setAlbumDescription': if (!isset($_POST['albumID'])) exit();
case 'setAlbumDescription': if (!isset($_POST['albumID'], $_POST['description'])) exit();
$album = new Album($database, $plugins, $settings, $_POST['albumID']);
echo $album->setDescription($_POST['description']);
break;
case 'setAlbumPublic': if (isset($_POST['albumID']))
if (!isset($_POST['password'])) $_POST['password'] = '';
echo setAlbumPublic($_POST['albumID'], $_POST['password']);
case 'setAlbumPublic': if (!isset($_POST['albumID'], $_POST['password'])) exit();
$album = new Album($database, $plugins, $settings, $_POST['albumID']);
echo $album->setPublic($_POST['password']);
break;
case 'setAlbumPassword': if (isset($_POST['albumID'], $_POST['password']))
echo setAlbumPassword($_POST['albumID'], $_POST['password']);
case 'setAlbumPassword': if (!isset($_POST['albumID'], $_POST['password'])) exit();
$album = new Album($database, $plugins, $settings, $_POST['albumID']);
echo $album->setPassword($_POST['password']);
break;
case 'deleteAlbum': if (!isset($_POST['albumIDs'])) exit();

View File

@ -157,6 +157,61 @@ class Album {
}
public function setPublic($password) {
if (!isset($this->database, $this->albumIDs)) return false;
# Call plugins
$this->plugins('setPublic:before', func_get_args());
# Get public
$albums = $this->database->query("SELECT id, public FROM lychee_albums WHERE id IN ('$this->albumIDs');");
while ($album = $albums->fetch_object()) {
# Invert public
$public = ($album->public=='0' ? 1 : 0);
# Set public
$result = $this->database->query("UPDATE lychee_albums SET public = '$public', password = NULL WHERE id = '$album->id';");
if (!$result) return false;
# Reset permissions for photos
if ($public===1) {
$result = $this->database->query("UPDATE lychee_photos SET public = 0 WHERE album = '$album->id';");
if (!$result) return false;
}
}
# Call plugins
$this->plugins('setPublic:after', func_get_args());
# Set password
if (isset($password)&&strlen($password)>0) return $this->setPassword($password);
return true;
}
public function setPassword($password) {
if (!isset($this->database, $this->albumIDs)) return false;
# Call plugins
$this->plugins('setPassword:before', func_get_args());
# Execute query
$result = $this->database->query("UPDATE lychee_albums SET password = '$password' WHERE id IN ('$this->albumIDs');");
# Call plugins
$this->plugins('setPassword:after', func_get_args());
if (!$result) return false;
return true;
}
public function delete($albumIDs) {
if (!isset($this->database, $this->albumIDs)) return false;
@ -189,6 +244,9 @@ class Album {
if (!isset($this->database, $this->albumIDs)) return false;
# Call plugins
$this->plugins('getArchive:before', func_get_args());
# Photos query
switch($this->albumIDs) {
case 's':
@ -245,6 +303,9 @@ class Album {
# Delete zip
unlink($filename);
# Call plugins
$this->plugins('getArchive:after', func_get_args());
return true;
}