Allow to download multiple albums.
This commit adds a download item to the album and albumMulti contextMenu functions. Since the Archive class is already general enough, we can easily support to download multiple albums. This is especially nice, because we can now select individual albums.
This commit is contained in:
parent
97a379dc47
commit
7fd74462e2
@ -334,9 +334,9 @@ final class Admin extends Access {
|
||||
|
||||
private static function getAlbumArchiveAction() {
|
||||
|
||||
Validator::required(isset($_GET['albumID']), __METHOD__);
|
||||
Validator::required(isset($_GET['albumIDs']), __METHOD__);
|
||||
|
||||
$album = new Album($_GET['albumID']);
|
||||
$album = new Album($_GET['albumIDs']);
|
||||
$album->getArchive();
|
||||
|
||||
}
|
||||
|
@ -140,9 +140,9 @@ final class Guest extends Access {
|
||||
|
||||
private static function getAlbumArchiveAction() {
|
||||
|
||||
Validator::required(isset($_GET['albumID'], $_GET['password']), __METHOD__);
|
||||
Validator::required(isset($_GET['albumIDs'], $_GET['password']), __METHOD__);
|
||||
|
||||
$album = new Album($_GET['albumID']);
|
||||
$album = new Album($_GET['albumIDs']);
|
||||
|
||||
if ($album->getPublic()&&$album->getDownloadable()) {
|
||||
|
||||
|
@ -182,7 +182,7 @@ final class Album {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a download of an album.
|
||||
* Starts a download of albums.
|
||||
* @return resource|boolean Sends a ZIP-file or returns false on failure.
|
||||
*/
|
||||
public function getArchive() {
|
||||
@ -207,30 +207,12 @@ final class Album {
|
||||
$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:
|
||||
case 0:
|
||||
$photos = Database::prepare(Database::get(), 'SELECT title, url FROM ? WHERE album = 0', array(LYCHEE_TABLE_PHOTOS));
|
||||
$zipTitle = 'Unsorted';
|
||||
|
||||
// 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::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($album===false) return false;
|
||||
|
||||
// Get album object
|
||||
$album = $album->fetch_object();
|
||||
|
||||
// Album not found?
|
||||
if ($album===null) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set title
|
||||
$zipTitle = $album->title;
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$zipTitle = 'Albums';
|
||||
break;
|
||||
}
|
||||
|
||||
@ -240,10 +222,21 @@ final class Album {
|
||||
case 's':
|
||||
case 'f':
|
||||
case 'r':
|
||||
case 0:
|
||||
if (!$archive->addPhotos($zipTitle, $photos)) return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!$archive->addAlbum($zipTitle, $this->albumIDs)) return false;
|
||||
// load titles from DB
|
||||
$query = Database::prepare(Database::get(), "SELECT id, title FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
|
||||
$albums = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
if ($albums===false) return false;
|
||||
|
||||
// add these albums to zip
|
||||
while ($album = $albums->fetch_object()) {
|
||||
if (!$archive->addAlbum($album->title, $album->id)) return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -625,13 +625,16 @@ album.share = function(service) {
|
||||
|
||||
}
|
||||
|
||||
album.getArchive = function(albumID) {
|
||||
album.getArchive = function(albumIDs) {
|
||||
|
||||
let link = ''
|
||||
let url = `${ api.path }?function=Album::getArchive&albumID=${ albumID }`
|
||||
let url = `${ api.path }?function=Album::getArchive&albumIDs=${ albumIDs.join(',') }`
|
||||
|
||||
if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url)
|
||||
else link = location.href.replace(location.hash, '') + url
|
||||
var pos = location.href.indexOf('#')
|
||||
link = pos!=-1 ? location.href.substring(0, pos) : location.href
|
||||
|
||||
if (location.href.indexOf('index.html')>0) link = link.replace('index.html', url)
|
||||
else link += url
|
||||
|
||||
if (lychee.publicMode===true) link += `&password=${ encodeURIComponent(password.value) }`
|
||||
|
||||
|
@ -115,6 +115,7 @@ contextMenu.album = function(albumID, e) {
|
||||
if (album.isSmartID(albumID)) return false
|
||||
|
||||
let items = [
|
||||
{ title: build.iconic('cloud-download') + 'Download', fn: () => album.getArchive([ albumID ]) },
|
||||
{ title: build.iconic('pencil') + 'Rename', fn: () => album.setTitle([ albumID ]) },
|
||||
{ title: build.iconic('collapse-left') + 'Merge', fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumID, e) } },
|
||||
{ title: build.iconic('folder') + 'Move', fn: () => { basicContext.close(); contextMenu.moveAlbum([ albumID ], e) } },
|
||||
@ -136,6 +137,7 @@ contextMenu.albumMulti = function(albumIDs, e) {
|
||||
let autoMerge = (albumIDs.length>1 ? true : false)
|
||||
|
||||
let items = [
|
||||
{ title: build.iconic('cloud-download') + 'Download All', fn: () => album.getArchive(albumIDs) },
|
||||
{ title: build.iconic('pencil') + 'Rename All', fn: () => album.setTitle(albumIDs) },
|
||||
{ title: build.iconic('collapse-left') + 'Merge All', visible: autoMerge, fn: () => album.merge(albumIDs) },
|
||||
{ title: build.iconic('collapse-left') + 'Merge', visible: !autoMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumIDs[0], e) } },
|
||||
|
@ -49,7 +49,7 @@ header.bind = function() {
|
||||
header.dom('.header__hostedwith') .on(eventName, function() { window.open(lychee.website) })
|
||||
header.dom('#button_trash_album') .on(eventName, function() { album.delete([ album.getID() ]) })
|
||||
header.dom('#button_trash') .on(eventName, function() { photo.delete([ photo.getID() ]) })
|
||||
header.dom('#button_archive') .on(eventName, function() { album.getArchive(album.getID()) })
|
||||
header.dom('#button_archive') .on(eventName, function() { album.getArchive([ album.getID() ]) })
|
||||
header.dom('#button_star') .on(eventName, function() { photo.setStar([ photo.getID() ]) })
|
||||
header.dom('#button_back_home') .on(eventName, function() { lychee.goto(album.getParent()) })
|
||||
header.dom('#button_back') .on(eventName, function() { lychee.goto(album.getID()) })
|
||||
|
Loading…
Reference in New Issue
Block a user