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
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2018-07-08 10:19:37 +02:00
|
|
|
parent::__construct($photo->getTitle() . ' - ' . SITE_TITLE);
|
|
|
|
|
|
|
|
$author = $photo->getAuthor();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['confirm_delete']) || isset($_REQUEST['delete_confirmed']))
|
|
|
|
$this->handleConfirmDelete($user, $author, $photo);
|
|
|
|
else
|
|
|
|
$this->handleViewPhoto($user, $author, $photo);
|
|
|
|
|
|
|
|
// Add an edit button to the admin bar.
|
|
|
|
if ($user->isAdmin())
|
|
|
|
$this->admin_bar->appendItem(BASEURL . '/editasset/?id=' . $photo->getId(), 'Edit this photo');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function handleConfirmDelete(User $user, User $author, Asset $photo)
|
|
|
|
{
|
|
|
|
if (!($user->isAdmin() || $user->getUserId() === $author->getUserId()))
|
|
|
|
throw new NotAllowedException();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['confirm_delete']))
|
|
|
|
{
|
|
|
|
$page = new ConfirmDeletePage($photo->getImage());
|
|
|
|
$this->page->adopt($page);
|
|
|
|
}
|
|
|
|
else if (isset($_REQUEST['delete_confirmed']))
|
|
|
|
{
|
|
|
|
$album_url = $photo->getSubdir();
|
|
|
|
$photo->delete();
|
|
|
|
|
|
|
|
header('Location: ' . BASEURL . '/' . $album_url);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function handleViewPhoto(User $user, User $author, Asset $photo)
|
|
|
|
{
|
2016-11-13 14:42:53 +01:00
|
|
|
if (!empty($_POST))
|
|
|
|
$this->handleTagging($photo->getImage());
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
$page = new PhotoPage($photo->getImage());
|
|
|
|
|
|
|
|
// Exif data?
|
|
|
|
$exif = EXIF::fromFile($photo->getFullPath());
|
|
|
|
if ($exif)
|
|
|
|
$page->setExif($exif);
|
|
|
|
|
2016-09-04 16:00:39 +02:00
|
|
|
// What tag are we browsing?
|
|
|
|
$tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null;
|
|
|
|
$id_tag = isset($tag) ? $tag->id_tag : null;
|
|
|
|
|
|
|
|
// Find previous photo in set.
|
|
|
|
$previous_url = $photo->getUrlForPreviousInSet($id_tag);
|
|
|
|
if ($previous_url)
|
|
|
|
$page->setPreviousPhotoUrl($previous_url);
|
|
|
|
|
|
|
|
// ... and the next photo, too.
|
|
|
|
$next_url = $photo->getUrlForNextInSet($id_tag);
|
|
|
|
if ($next_url)
|
|
|
|
$page->setNextPhotoUrl($next_url);
|
|
|
|
|
2018-07-02 20:32:59 +02:00
|
|
|
if ($user->isAdmin() || $user->getUserId() === $author->getUserId())
|
|
|
|
$page->setIsAssetOwner(true);
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
$this->page->adopt($page);
|
|
|
|
$this->page->setCanonicalUrl($photo->getPageUrl());
|
|
|
|
}
|
2016-11-13 14:42:53 +01:00
|
|
|
|
|
|
|
private function handleTagging(Image $photo)
|
|
|
|
{
|
|
|
|
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!
|
|
|
|
$photo->linkTags([(int) $_POST['id_tag']]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
|
|
exit;
|
|
|
|
}
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|