diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index f6872df4..30118097 100644 --- a/controllers/ViewPhotoAlbum.php +++ b/controllers/ViewPhotoAlbum.php @@ -107,8 +107,11 @@ class ViewPhotoAlbum extends HTMLController if (!empty($active_filter)) $url_params['by'] = $active_filter; - if (!empty($url_params)) - $index->setUrlSuffix('?' . http_build_query($url_params)); + $url_suffix = http_build_query($url_params); + $index->setUrlSuffix('?' . $url_suffix); + + $menu_items = $this->getEditMenuItems('&' . $url_suffix); + $index->setEditMenuItems($menu_items); } // Make a page index as needed, while we're at it. @@ -228,6 +231,46 @@ class ViewPhotoAlbum extends HTMLController return $buttons; } + private function getEditMenuItems($url_suffix) + { + $items = []; + $sess = '&' . Session::getSessionTokenKey() . '=' . Session::getSessionToken(); + + if (Registry::get('user')->isLoggedIn()) + { + $items[] = [ + 'label' => 'Edit image', + 'uri' => fn($image) => $image->getEditUrl() . $url_suffix, + ]; + + $items[] = [ + 'label' => 'Delete image', + 'uri' => fn($image) => $image->getDeleteUrl() . $url_suffix . $sess, + 'onclick' => 'return confirm(\'Are you sure you want to delete this image?\');', + ]; + } + + if (Registry::get('user')->isAdmin()) + { + $items[] = [ + 'label' => 'Make album cover', + 'uri' => fn($image) => $image->getEditUrl() . $url_suffix . '&album_cover' . $sess, + ]; + + $items[] = [ + 'label' => 'Increase priority', + 'uri' => fn($image) => $image->getEditUrl() . $url_suffix . '&inc_prio' . $sess, + ]; + + $items[] = [ + 'label' => 'Decrease priority', + 'uri' => fn($image) => $image->getEditUrl() . $url_suffix . '&dec_prio' . $sess, + ]; + } + + return $items; + } + private function getHeaderBox(Tag $tag) { // Can we go up a level? diff --git a/models/Asset.php b/models/Asset.php index ce3be242..eaabbd0a 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -36,6 +36,11 @@ class Asset $this->date_captured = new DateTime($data['date_captured']); } + public function canBeEditedBy(User $user) + { + return $this->isOwnedBy($user) || $user->isAdmin(); + } + public static function cleanSlug($slug) { // Only alphanumerical chars, underscores and forward slashes are allowed diff --git a/templates/PhotosIndex.php b/templates/PhotosIndex.php index a104bca2..37a2efc5 100644 --- a/templates/PhotosIndex.php +++ b/templates/PhotosIndex.php @@ -14,7 +14,7 @@ class PhotosIndex extends Template protected $show_labels; protected $previous_header = ''; - protected $edit_url_suffix; + protected $edit_menu_items = []; protected $photo_url_suffix; const PANORAMA_WIDTH = 1256; @@ -85,27 +85,24 @@ class PhotosIndex extends Template protected function editMenu(Image $image) { - $edit_url = $image->getEditUrl() . $this->edit_url_suffix; + if (empty($this->edit_menu_items)) + return; echo '