From 4b289a5e83a56d30da5d0379de91fa583f7a52dd Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 15 Jan 2024 11:40:33 +0100 Subject: [PATCH] Download: allow limiting by user uploaded as well --- controllers/Download.php | 14 +++++++++++--- controllers/ViewPhotoAlbum.php | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/controllers/Download.php b/controllers/Download.php index b5de549..95fd163 100644 --- a/controllers/Download.php +++ b/controllers/Download.php @@ -21,22 +21,30 @@ class Download $tag = (int)$_GET['tag']; $album = Tag::fromId($tag); + if (isset($_GET['by']) && ($user = Member::fromSlug($_GET['by'])) !== false) + $id_user_uploaded = $user->getUserId(); + else + $id_user_uploaded = null; + if (isset($_SESSION['current_export'])) throw new UserFacingException('You can only export one album at the same time. Please wait until the other download finishes, or try again later.'); // So far so good? - $this->exportAlbum($album); + $this->exportAlbum($album, $id_user_uploaded); exit; } - private function exportAlbum(Tag $album) + private function exportAlbum(Tag $album, $id_user_uploaded) { $files = []; $album_ids = array_merge([$album->id_tag], $this->getChildAlbumIds($album->id_tag)); foreach ($album_ids as $album_id) { - $iterator = AssetIterator::getByOptions(['id_tag' => $album_id]); + $iterator = AssetIterator::getByOptions([ + 'id_tag' => $album_id, + 'id_user_uploaded' => $id_user_uploaded, + ]); while ($asset = $iterator->next()) $files[] = join(DIRECTORY_SEPARATOR, [$asset->getSubdir(), $asset->getFilename()]); } diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index ff188a3..3c7be88 100644 --- a/controllers/ViewPhotoAlbum.php +++ b/controllers/ViewPhotoAlbum.php @@ -79,7 +79,7 @@ class ViewPhotoAlbum extends HTMLController } // Add an interface to query and modify the album/tag - $buttons = $this->getAlbumButtons($tag); + $buttons = $this->getAlbumButtons($tag, $active_filter); $button_strip = new AlbumButtonBox($buttons, $filters, $active_filter); $this->page->adopt($button_strip); @@ -174,15 +174,16 @@ class ViewPhotoAlbum extends HTMLController return $albums; } - private function getAlbumButtons(Tag $tag) + private function getAlbumButtons(Tag $tag, $active_filter) { $buttons = []; $user = Registry::get('user'); if ($user->isLoggedIn()) { + $suffix = !empty($active_filter) ? '&by=' . $active_filter : ''; $buttons[] = [ - 'url' => BASEURL . '/download/?tag=' . $tag->id_tag, + 'url' => BASEURL . '/download/?tag=' . $tag->id_tag . $suffix, 'caption' => 'Download album', ]; }