Added getArchive to Album
This commit is contained in:
parent
9ab72f05f5
commit
6b4aaa6a23
@ -138,8 +138,9 @@ switch ($_POST['function']) {
|
|||||||
echo getFeed($_GET['albumID']);
|
echo getFeed($_GET['albumID']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getAlbumArchive': if (isset($_GET['albumID']))
|
case 'getAlbumArchive': if (!isset($_GET['albumID'])) exit();
|
||||||
getAlbumArchive($_GET['albumID']);
|
$album = new Album($database, $plugins, $settings, $_GET['albumID']);
|
||||||
|
$album->getArchive();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getPhotoArchive': if (isset($_GET['photoID']))
|
case 'getPhotoArchive': if (isset($_GET['photoID']))
|
||||||
|
@ -85,21 +85,22 @@ switch ($_POST['function']) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getAlbumArchive': if (isset($_GET['albumID'], $_GET['password'])) {
|
case 'getAlbumArchive': if (!isset($_GET['albumID'], $_GET['password'])) exit();
|
||||||
|
|
||||||
// Album Download
|
// Album Download
|
||||||
if (isAlbumPublic($_GET['albumID'])) {
|
if (isAlbumPublic($_GET['albumID'])) {
|
||||||
// Album Public
|
// Album Public
|
||||||
if (checkAlbumPassword($_GET['albumID'], $_GET['password']))
|
if (checkAlbumPassword($_GET['albumID'], $_GET['password'])) {
|
||||||
getAlbumArchive($_GET['albumID']);
|
$album = new Album($database, $plugins, $settings, $_GET['albumID']);
|
||||||
else
|
$album->getArchive();
|
||||||
exit('Warning: Wrong password!');
|
|
||||||
} else {
|
} else {
|
||||||
// Album Private
|
exit('Warning: Wrong password!');
|
||||||
exit('Warning: Album private or not downloadable!');
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Album Private
|
||||||
|
exit('Warning: Album private or not downloadable!');
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getPhotoArchive': if (isset($_GET['photoID'], $_GET['password'])) {
|
case 'getPhotoArchive': if (isset($_GET['photoID'], $_GET['password'])) {
|
||||||
|
@ -32,7 +32,7 @@ class Album {
|
|||||||
if (!isset($this->plugins, $action, $args)) return false;
|
if (!isset($this->plugins, $action, $args)) return false;
|
||||||
|
|
||||||
# Call plugins
|
# Call plugins
|
||||||
$this->plugins->activate("Albums:$action", $args);
|
$this->plugins->activate("Album:$action", $args);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -185,4 +185,68 @@ class Album {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getArchive() {
|
||||||
|
|
||||||
|
if (!isset($this->database, $this->albumIDs)) return false;
|
||||||
|
|
||||||
|
# Photos query
|
||||||
|
switch($this->albumIDs) {
|
||||||
|
case 's':
|
||||||
|
$photos = "SELECT url FROM lychee_photos WHERE public = '1';";
|
||||||
|
$zipTitle = 'Public';
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
$photos = "SELECT url FROM lychee_photos WHERE star = '1';";
|
||||||
|
$zipTitle = 'Starred';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$photos = "SELECT url FROM lychee_photos WHERE album = '$this->albumIDs';";
|
||||||
|
$zipTitle = 'Unsorted';
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute query
|
||||||
|
$photos = $this->database->query($photos);
|
||||||
|
|
||||||
|
# Init vars
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$files = array();
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
# Parse each url
|
||||||
|
while ($photo = $photos->fetch_object()) {
|
||||||
|
$files[$i] = '../uploads/big/' . $photo->url;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set title
|
||||||
|
$album = $this->database->query("SELECT title FROM lychee_albums WHERE id = '$this->albumIDs' LIMIT 1;");
|
||||||
|
if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) $zipTitle = $album->fetch_object()->title;
|
||||||
|
|
||||||
|
# Create zip
|
||||||
|
$filename = "../data/$zipTitle.zip";
|
||||||
|
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) return false;
|
||||||
|
|
||||||
|
# Add each photo
|
||||||
|
foreach ($files AS $file) {
|
||||||
|
$newFile = explode('/', $file);
|
||||||
|
$newFile = array_reverse($newFile);
|
||||||
|
$zip->addFile($file, $zipTitle . '/' . $newFile[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Finish zip
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
# Send zip
|
||||||
|
header("Content-Type: application/zip");
|
||||||
|
header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
|
||||||
|
header("Content-Length: ".filesize($filename));
|
||||||
|
readfile($filename);
|
||||||
|
|
||||||
|
# Delete zip
|
||||||
|
unlink($filename);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user