diff --git a/controllers/EditAsset.php b/controllers/EditAsset.php index 6937f98..d5582d1 100644 --- a/controllers/EditAsset.php +++ b/controllers/EditAsset.php @@ -30,6 +30,40 @@ class EditAsset extends HTMLController header('Location: ' . $redirectUrl); exit; } + else + { + $isPrioChange = isset($_REQUEST['inc_prio']) || isset($_REQUEST['dec_prio']); + $isCoverChange = isset($_REQUEST['album_cover'], $_REQUEST['in']); + $madeChanges = false; + + if ($user->isAdmin() && $isPrioChange && Session::validateSession('get')) + { + if (isset($_REQUEST['inc_prio'])) + $priority = $asset->priority + 1; + else + $priority = $asset->priority - 1; + + $asset->priority = max(0, min(100, $priority)); + $asset->save(); + $madeChanges = true; + } + elseif ($user->isAdmin() && $isCoverChange && Session::validateSession('get')) + { + $tag = Tag::fromId($_REQUEST['in']); + $tag->id_asset_thumb = $asset->getId(); + $tag->save(); + $madeChanges = true; + } + + if ($madeChanges) + { + if (isset($_SERVER['HTTP_REFERER'])) + header('Location: ' . $_SERVER['HTTP_REFERER']); + else + header('Location: ' . BASEURL . '/' . $asset->getSubdir()); + exit; + } + } // Get a list of available photo albums $allAlbums = []; @@ -61,10 +95,12 @@ class EditAsset extends HTMLController // Key info if (isset($_POST['title'], $_POST['slug'], $_POST['date_captured'], $_POST['priority'])) { - $date_captured = !empty($_POST['date_captured']) ? + $asset->date_captured = !empty($_POST['date_captured']) ? new DateTime(str_replace('T', ' ', $_POST['date_captured'])) : null; - $slug = Asset::cleanSlug($_POST['slug']); - $asset->setKeyData(htmlspecialchars($_POST['title']), $slug, $date_captured, intval($_POST['priority'])); + $asset->slug = Asset::cleanSlug($_POST['slug']); + $asset->title = htmlspecialchars($_POST['title']); + $asset->priority = intval($_POST['priority']); + $asset->save(); } // Changing parent album? diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index 2a9c0ca..1d2272a 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 c2973c7..eaabbd0 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -8,17 +8,17 @@ class Asset { - protected $id_asset; - protected $id_user_uploaded; - protected $subdir; - protected $filename; - protected $title; - protected $slug; - protected $mimetype; - protected $image_width; - protected $image_height; - protected $date_captured; - protected $priority; + public $id_asset; + public $id_user_uploaded; + public $subdir; + public $filename; + public $title; + public $slug; + public $mimetype; + public $image_width; + public $image_height; + public $date_captured; + public $priority; protected $meta; protected $tags; @@ -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 @@ -675,26 +680,26 @@ class Asset FROM assets'); } - public function setKeyData($title, $slug, DateTime $date_captured = null, $priority) + public function save() { - $params = [ - 'id_asset' => $this->id_asset, - 'title' => $title, - 'slug' => $slug, - 'priority' => $priority, - ]; - - if (isset($date_captured)) - $params['date_captured'] = $date_captured->format('Y-m-d H:i:s'); + if (empty($this->id_asset)) + throw new UnexpectedValueException(); return Registry::get('db')->query(' UPDATE assets - SET title = {string:title}, - slug = {string:slug},' . (isset($date_captured) ? ' - date_captured = {datetime:date_captured},' : '') . ' + SET id_asset = {int:id_asset}, + id_user_uploaded = {int:id_user_uploaded}, + subdir = {string:subdir}, + filename = {string:filename}, + title = {string:title}, + slug = {string:slug}, + mimetype = {string:mimetype}, + image_width = {int:image_width}, + image_height = {int:image_height}, + date_captured = {datetime:date_captured}, priority = {int:priority} WHERE id_asset = {int:id_asset}', - $params); + get_object_vars($this)); } protected function getUrlForAdjacentInSet($prevNext, ?Tag $tag, $activeFilter) diff --git a/public/css/admin.css b/public/css/admin.css index 24c1941..3213d44 100644 --- a/public/css/admin.css +++ b/public/css/admin.css @@ -1,27 +1,3 @@ -/* Edit icon on tiled grids ------------------------------*/ -.polaroid { - position: relative; -} -.polaroid a.edit { - background: var(--bs-body-bg); - border-radius: 3px; - box-shadow: 1px 1px 2px rgba(0,0,0,0.3); - color: var(--bs-body-color); - opacity: 0; - left: 20px; - line-height: 1.5; - padding: 5px 10px; - position: absolute; - transition: 0.25s; - top: 20px; - z-index: 50; -} -.polaroid:hover > a.edit { - opacity: 1; -} - - /* Crop editor ----------------*/ #crop_editor { diff --git a/public/css/default.css b/public/css/default.css index ee3b117..03f25f1 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -296,6 +296,34 @@ div.polaroid a { } +/* Edit icon on tiled grids +-----------------------------*/ +.polaroid { + position: relative; +} +.polaroid div.edit { + box-shadow: 1px 1px 2px rgba(0,0,0,0.3); + opacity: 0; + left: 20px; + position: absolute; + transition: 0.25s; + top: 20px; + z-index: 50; +} +.polaroid div.edit .dropdown-item { + line-height: 1.4; +} +.polaroid div.edit .dropdown-toggle { + line-height: 1.4; + padding: 0.25rem 0.5rem; +} +.polaroid div.edit .dropdown-toggle::after { + margin-left: 0; +} +.polaroid:hover > div.edit { + opacity: 1; +} + /* Album title boxes ----------------------*/ diff --git a/templates/PhotoPage.php b/templates/PhotoPage.php index 0b30954..39d6c79 100644 --- a/templates/PhotoPage.php +++ b/templates/PhotoPage.php @@ -25,7 +25,15 @@ class PhotoPage extends Template echo '
-
+
'; + + $this->photoMeta(); + + echo ' +
+
+
+
'; $this->userActions(); @@ -39,12 +47,6 @@ class PhotoPage extends Template echo '
-
'; - - $this->photoMeta(); - - echo ' -
'; } @@ -109,12 +111,12 @@ class PhotoPage extends Template private function photoMeta() { echo ' -