From 55c33c024eb217895e70c911e56a71f9b87e6ee9 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Jan 2024 18:59:50 +0100 Subject: [PATCH] ViewPhoto: use class state to store Image object --- controllers/ViewPhoto.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/controllers/ViewPhoto.php b/controllers/ViewPhoto.php index 52cb2f8..c7f5815 100644 --- a/controllers/ViewPhoto.php +++ b/controllers/ViewPhoto.php @@ -8,6 +8,8 @@ class ViewPhoto extends HTMLController { + private Image $photo; + public function __construct() { // Ensure we're logged in at this point. @@ -19,22 +21,24 @@ class ViewPhoto extends HTMLController if (empty($photo)) throw new NotFoundException(); + $this->photo = $photo->getImage(); + Session::resetSessionToken(); - parent::__construct($photo->getTitle() . ' - ' . SITE_TITLE); + parent::__construct($this->photo->getTitle() . ' - ' . SITE_TITLE); if (!empty($_POST)) - $this->handleTagging($photo->getImage()); + $this->handleTagging(); else - $this->handleViewPhoto($photo); + $this->handleViewPhoto(); } - private function handleViewPhoto(Asset $photo) + private function handleViewPhoto() { - $page = new PhotoPage($photo->getImage()); + $page = new PhotoPage($this->photo); // Exif data? - $exif = EXIF::fromFile($photo->getFullPath()); + $exif = EXIF::fromFile($this->photo->getFullPath()); if ($exif) $page->setExif($exif); @@ -44,10 +48,10 @@ class ViewPhoto extends HTMLController $page->setTag($tag); $this->page->adopt($page); - $this->page->setCanonicalUrl($photo->getPageUrl()); + $this->page->setCanonicalUrl($this->photo->getPageUrl()); } - private function handleTagging(Image $photo) + private function handleTagging() { header('Content-Type: text/json; charset=utf-8'); @@ -61,7 +65,7 @@ class ViewPhoto extends HTMLController // We are! if (!isset($_POST['delete'])) { - $photo->linkTags([(int) $_POST['id_tag']]); + $this->photo->linkTags([(int) $_POST['id_tag']]); echo json_encode(['success' => true]); exit; }