2016-09-03 21:32:55 +02:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* ViewPhoto.php
|
|
|
|
* Contains the view photo controller
|
|
|
|
*
|
|
|
|
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class ViewPhoto extends HTMLController
|
|
|
|
{
|
2024-01-11 18:59:50 +01:00
|
|
|
private Image $photo;
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-09-04 16:17:02 +02:00
|
|
|
// Ensure we're logged in at this point.
|
2018-07-08 10:19:37 +02:00
|
|
|
$user = Registry::get('user');
|
|
|
|
if (!$user->isLoggedIn())
|
2016-09-04 16:17:02 +02:00
|
|
|
throw new NotAllowedException();
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
$photo = Asset::fromSlug($_GET['slug']);
|
|
|
|
if (empty($photo))
|
|
|
|
throw new NotFoundException();
|
|
|
|
|
2024-01-11 18:59:50 +01:00
|
|
|
$this->photo = $photo->getImage();
|
|
|
|
|
2023-11-15 14:40:45 +01:00
|
|
|
Session::resetSessionToken();
|
|
|
|
|
2024-01-11 18:59:50 +01:00
|
|
|
parent::__construct($this->photo->getTitle() . ' - ' . SITE_TITLE);
|
2018-07-08 10:19:37 +02:00
|
|
|
|
2023-11-11 15:29:32 +01:00
|
|
|
if (!empty($_POST))
|
2024-01-11 18:59:50 +01:00
|
|
|
$this->handleTagging();
|
2018-07-08 10:19:37 +02:00
|
|
|
else
|
2024-01-11 18:59:50 +01:00
|
|
|
$this->handleViewPhoto();
|
2018-07-08 10:19:37 +02:00
|
|
|
}
|
|
|
|
|
2024-01-11 18:59:50 +01:00
|
|
|
private function handleViewPhoto()
|
2018-07-08 10:19:37 +02:00
|
|
|
{
|
2024-01-11 18:59:50 +01:00
|
|
|
$page = new PhotoPage($this->photo);
|
2016-09-03 21:32:55 +02:00
|
|
|
|
2024-01-11 19:13:21 +01:00
|
|
|
// Any (EXIF) meta data?
|
|
|
|
$metaData = $this->prepareMetaData();
|
|
|
|
$page->setMetaData($metaData);
|
2016-09-03 21:32:55 +02:00
|
|
|
|
2016-09-04 16:00:39 +02:00
|
|
|
// What tag are we browsing?
|
|
|
|
$tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null;
|
2024-01-11 18:54:54 +01:00
|
|
|
if (isset($tag))
|
|
|
|
$page->setTag($tag);
|
2016-09-04 16:00:39 +02:00
|
|
|
|
2024-01-15 00:43:02 +01:00
|
|
|
// Keeping tabs on a filter?
|
|
|
|
if (isset($_GET['by']))
|
|
|
|
{
|
|
|
|
// Let's first verify that the filter is valid
|
|
|
|
$contributors = array_filter($tag->getContributorList(), fn($el) => $el['slug'] === $_GET['by']);
|
|
|
|
if (count($contributors) !== 1)
|
|
|
|
throw new UnexpectedValueException('Invalid filter for this album or tag.');
|
|
|
|
|
|
|
|
// Alright, let's run with it then
|
|
|
|
$filter = reset($contributors);
|
|
|
|
$page->setActiveFilter($filter['slug']);
|
|
|
|
}
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
$this->page->adopt($page);
|
2024-01-11 18:59:50 +01:00
|
|
|
$this->page->setCanonicalUrl($this->photo->getPageUrl());
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|
2016-11-13 14:42:53 +01:00
|
|
|
|
2024-01-11 18:59:50 +01:00
|
|
|
private function handleTagging()
|
2016-11-13 14:42:53 +01:00
|
|
|
{
|
|
|
|
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!
|
2019-03-09 13:48:18 +01:00
|
|
|
if (!isset($_POST['delete']))
|
|
|
|
{
|
2024-01-11 18:59:50 +01:00
|
|
|
$this->photo->linkTags([(int) $_POST['id_tag']]);
|
2019-03-09 13:48:18 +01:00
|
|
|
echo json_encode(['success' => true]);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ... deleting, that is.
|
|
|
|
else
|
|
|
|
{
|
2024-01-11 19:13:21 +01:00
|
|
|
$this->photo->unlinkTags([(int) $_POST['id_tag']]);
|
2019-03-09 13:48:18 +01:00
|
|
|
echo json_encode(['success' => true]);
|
|
|
|
exit;
|
|
|
|
}
|
2016-11-13 14:42:53 +01:00
|
|
|
}
|
2024-01-11 19:13:21 +01:00
|
|
|
|
|
|
|
private function prepareMetaData()
|
|
|
|
{
|
|
|
|
if (!($exif = EXIF::fromFile($this->photo->getFullPath())))
|
|
|
|
throw new UnexpectedValueException('Photo file not found!');
|
|
|
|
|
|
|
|
$metaData = [];
|
|
|
|
|
|
|
|
if (!empty($exif->created_timestamp))
|
|
|
|
$metaData['Date Taken'] = date("j M Y, H:i:s", $exif->created_timestamp);
|
|
|
|
|
|
|
|
if ($author = $this->photo->getAuthor())
|
|
|
|
$metaData['Uploaded by'] = $author->getfullName();
|
|
|
|
|
|
|
|
if (!empty($exif->camera))
|
|
|
|
$metaData['Camera Model'] = $exif->camera;
|
|
|
|
|
|
|
|
if (!empty($exif->shutter_speed))
|
|
|
|
$metaData['Shutter Speed'] = $exif->shutterSpeedFraction();
|
|
|
|
|
|
|
|
if (!empty($exif->aperture))
|
2024-01-12 10:42:51 +01:00
|
|
|
$metaData['Aperture'] = 'f/' . number_format($exif->aperture, 1);
|
2024-01-11 19:13:21 +01:00
|
|
|
|
|
|
|
if (!empty($exif->focal_length))
|
2024-01-12 10:42:51 +01:00
|
|
|
$metaData['Focal Length'] = $exif->focal_length . ' mm';
|
2024-01-11 19:13:21 +01:00
|
|
|
|
|
|
|
if (!empty($exif->iso))
|
|
|
|
$metaData['ISO Speed'] = $exif->iso;
|
|
|
|
|
|
|
|
if (!empty($exif->software))
|
|
|
|
$metaData['Software'] = $exif->software;
|
|
|
|
|
|
|
|
return $metaData;
|
|
|
|
}
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|