isLoggedIn()) throw new NotAllowedException(); $photo = Asset::fromSlug($_GET['slug']); if (empty($photo)) throw new NotFoundException(); $this->photo = $photo->getImage(); Session::resetSessionToken(); parent::__construct($this->photo->getTitle() . ' - ' . SITE_TITLE); if (!empty($_POST)) $this->handleTagging(); else $this->handleViewPhoto(); } private function handleViewPhoto() { $page = new PhotoPage($this->photo); // Exif data? $exif = EXIF::fromFile($this->photo->getFullPath()); if ($exif) $page->setExif($exif); // What tag are we browsing? $tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null; if (isset($tag)) $page->setTag($tag); $this->page->adopt($page); $this->page->setCanonicalUrl($this->photo->getPageUrl()); } private function handleTagging() { header('Content-Type: text/json; charset=utf-8'); // Are we tagging a photo? if (!isset($_POST['id_tag'])) { echo json_encode(['error' => true, 'msg' => 'Invalid tag request.']); exit; } // We are! if (!isset($_POST['delete'])) { $this->photo->linkTags([(int) $_POST['id_tag']]); echo json_encode(['success' => true]); exit; } // ... deleting, that is. else { $photo->unlinkTags([(int) $_POST['id_tag']]); echo json_encode(['success' => true]); exit; } } }