2016-09-03 21:32:55 +02:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* PhotoPage.php
|
|
|
|
* Contains the photo page template.
|
|
|
|
*
|
|
|
|
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2023-03-11 13:37:59 +01:00
|
|
|
class PhotoPage extends Template
|
2016-09-03 21:32:55 +02:00
|
|
|
{
|
2024-01-11 19:13:21 +01:00
|
|
|
private $photo;
|
|
|
|
private $metaData;
|
2024-01-11 18:54:54 +01:00
|
|
|
private $tag;
|
2016-09-03 21:32:55 +02:00
|
|
|
|
|
|
|
public function __construct(Image $photo)
|
|
|
|
{
|
|
|
|
$this->photo = $photo;
|
|
|
|
}
|
|
|
|
|
2023-03-11 13:37:59 +01:00
|
|
|
public function html_main()
|
2016-09-03 21:32:55 +02:00
|
|
|
{
|
|
|
|
$this->photoNav();
|
|
|
|
$this->photo();
|
|
|
|
|
|
|
|
echo '
|
2023-03-11 13:57:57 +01:00
|
|
|
<div class="row mt-5">
|
2024-01-11 19:20:46 +01:00
|
|
|
<div class="col-lg-9">
|
|
|
|
<div id="sub_photo" class="content-box">';
|
|
|
|
|
|
|
|
$this->userActions();
|
|
|
|
|
|
|
|
echo '
|
2023-03-11 13:57:57 +01:00
|
|
|
<h2 class="entry-title">', $this->photo->getTitle(), '</h2>';
|
2016-09-03 21:32:55 +02:00
|
|
|
|
2024-01-11 20:00:29 +01:00
|
|
|
$this->printTags('Album', 'Album', false);
|
|
|
|
$this->printTags('Tagged People', 'Person', true);
|
2016-09-03 21:32:55 +02:00
|
|
|
|
|
|
|
echo '
|
2023-03-11 13:57:57 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-11 19:20:46 +01:00
|
|
|
<div class="col-lg-3">';
|
2016-09-03 21:32:55 +02:00
|
|
|
|
|
|
|
$this->photoMeta();
|
2018-07-02 20:32:59 +02:00
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
2023-03-11 13:57:57 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-09-03 21:32:55 +02:00
|
|
|
<script type="text/javascript" src="', BASEURL, '/js/photonav.js"></script>';
|
|
|
|
}
|
|
|
|
|
2018-07-08 10:19:37 +02:00
|
|
|
protected function photo()
|
2016-09-03 21:32:55 +02:00
|
|
|
{
|
|
|
|
echo '
|
2023-11-10 22:50:51 +01:00
|
|
|
<a href="', $this->photo->getUrl(), '">
|
|
|
|
<div id="photo_frame">';
|
2016-09-03 21:32:55 +02:00
|
|
|
|
|
|
|
if ($this->photo->isPortrait())
|
2023-11-10 22:50:51 +01:00
|
|
|
{
|
|
|
|
echo '
|
2023-11-10 23:22:09 +01:00
|
|
|
<figure id="photo-figure" class="portrait-figure">',
|
2023-11-10 22:50:51 +01:00
|
|
|
$this->photo->getInlineImage(null, 960, 'normal-photo'),
|
|
|
|
$this->photo->getInlineImage(null, 960, 'blur-photo'), '
|
|
|
|
</figure>';
|
|
|
|
}
|
2016-09-03 21:32:55 +02:00
|
|
|
else
|
2023-11-10 22:50:51 +01:00
|
|
|
{
|
|
|
|
$className = $this->photo->isPanorama() ? 'panorama-figure' : 'landscape-figure';
|
|
|
|
echo '
|
2023-11-10 23:22:09 +01:00
|
|
|
<figure id="photo-figure" class="', $className, '">',
|
2023-11-10 22:50:51 +01:00
|
|
|
$this->photo->getInlineImage(1280, null, 'normal-photo'),
|
|
|
|
$this->photo->getInlineImage(1280, null, 'blur-photo'), '
|
|
|
|
</figure>';
|
|
|
|
}
|
2016-09-03 21:32:55 +02:00
|
|
|
|
|
|
|
echo '
|
2023-11-10 22:50:51 +01:00
|
|
|
</figure>
|
|
|
|
</div>
|
|
|
|
</a>';
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|
|
|
|
|
2024-01-11 18:54:54 +01:00
|
|
|
public function setTag(Tag $tag)
|
|
|
|
{
|
|
|
|
$this->tag = $tag;
|
|
|
|
}
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
private function photoNav()
|
|
|
|
{
|
2024-01-11 18:54:54 +01:00
|
|
|
if ($previousUrl = $this->photo->getUrlForPreviousInSet($this->tag))
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
2024-01-11 18:54:54 +01:00
|
|
|
<a href="', $previousUrl, '#photo_frame" id="previous_photo"><i class="bi bi-arrow-left"></i></a>';
|
2016-09-03 21:32:55 +02:00
|
|
|
else
|
|
|
|
echo '
|
2023-03-11 14:13:29 +01:00
|
|
|
<span id="previous_photo"><i class="bi bi-arrow-left"></i></span>';
|
2016-09-03 21:32:55 +02:00
|
|
|
|
2024-01-11 18:54:54 +01:00
|
|
|
if ($nextUrl = $this->photo->getUrlForNextInSet($this->tag))
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
2024-01-11 18:54:54 +01:00
|
|
|
<a href="', $nextUrl, '#photo_frame" id="next_photo"><i class="bi bi-arrow-right"></i></a>';
|
2016-09-03 21:32:55 +02:00
|
|
|
else
|
|
|
|
echo '
|
2023-03-11 14:13:29 +01:00
|
|
|
<span id="next_photo"><i class="bi bi-arrow-right"></i></span>';
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function photoMeta()
|
|
|
|
{
|
|
|
|
echo '
|
2024-01-11 19:13:21 +01:00
|
|
|
<ul class="list-group photo_meta">';
|
2016-09-03 21:32:55 +02:00
|
|
|
|
2024-01-11 19:13:21 +01:00
|
|
|
foreach ($this->metaData as $header => $body)
|
|
|
|
{
|
2022-12-25 13:44:19 +01:00
|
|
|
echo '
|
2024-01-11 19:13:21 +01:00
|
|
|
<li class="list-group-item">
|
|
|
|
<h4>', $header, '</h4>
|
|
|
|
', $body, '
|
|
|
|
</li>';
|
|
|
|
}
|
2022-12-25 13:44:19 +01:00
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
2024-01-11 19:13:21 +01:00
|
|
|
</ul>';
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|
|
|
|
|
2024-01-11 20:00:29 +01:00
|
|
|
private function printTags($header, $tagKind, $allowLinkingNewTags)
|
2016-09-03 21:32:55 +02:00
|
|
|
{
|
2024-01-11 20:47:41 +01:00
|
|
|
static $nextTagListId = 1;
|
|
|
|
$tagListId = 'tagList' . ($nextTagListId++);
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
2024-01-11 20:00:29 +01:00
|
|
|
<h3>', $header, '</h3>
|
2024-01-11 20:47:41 +01:00
|
|
|
<ul id="', $tagListId, '" class="tag-list">';
|
2016-09-03 21:32:55 +02:00
|
|
|
|
|
|
|
foreach ($this->photo->getTags() as $tag)
|
|
|
|
{
|
2024-01-11 20:00:29 +01:00
|
|
|
if ($tag->kind !== $tagKind)
|
|
|
|
continue;
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
2019-03-09 13:48:18 +01:00
|
|
|
<li id="tag-', $tag->id_tag, '">
|
2024-01-11 21:53:44 +01:00
|
|
|
<div class="input-group">
|
|
|
|
<a class="input-group-text" href="', $tag->getUrl(), '" title="View all posts tagged ', $tag->tag, '">
|
|
|
|
', $tag->tag, '
|
|
|
|
</a>';
|
2019-03-09 13:48:18 +01:00
|
|
|
|
|
|
|
if ($tag->kind === 'Person')
|
2024-01-11 20:00:29 +01:00
|
|
|
{
|
2019-03-09 13:48:18 +01:00
|
|
|
echo '
|
2024-01-11 21:53:44 +01:00
|
|
|
<a class="delete-tag btn btn-danger px-1" title="Unlink this tag from this photo" href="#" data-id="', $tag->id_tag, '">
|
|
|
|
<i class="bi bi-x"></i>
|
|
|
|
</a>';
|
2024-01-11 20:00:29 +01:00
|
|
|
}
|
2019-03-09 13:48:18 +01:00
|
|
|
|
|
|
|
echo '
|
2024-01-11 21:53:44 +01:00
|
|
|
</div>
|
2016-09-03 21:32:55 +02:00
|
|
|
</li>';
|
|
|
|
}
|
|
|
|
|
2024-01-11 20:47:41 +01:00
|
|
|
static $nextNewTagId = 1;
|
|
|
|
$newTagId = 'newTag' . ($nextNewTagId++);
|
|
|
|
|
2024-01-11 20:00:29 +01:00
|
|
|
if ($allowLinkingNewTags)
|
2024-01-11 20:47:41 +01:00
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<li style="position: relative">
|
|
|
|
<input class="form-control w-auto" type="text" id="', $newTagId, '" placeholder="Type to link a new tag">
|
|
|
|
</li>';
|
|
|
|
}
|
2024-01-11 20:00:29 +01:00
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
|
|
|
</ul>';
|
2024-01-11 20:47:41 +01:00
|
|
|
|
|
|
|
$this->printNewTagScript($tagKind, $tagListId, $newTagId);
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|
|
|
|
|
2024-01-11 20:47:41 +01:00
|
|
|
private function printNewTagScript($tagKind, $tagListId, $newTagId)
|
2016-09-04 11:23:08 +02:00
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<script type="text/javascript" src="', BASEURL, '/js/ajax.js"></script>
|
|
|
|
<script type="text/javascript" src="', BASEURL, '/js/autosuggest.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
setTimeout(function() {
|
2024-01-11 20:47:41 +01:00
|
|
|
const removeTag = function(event) {
|
2019-03-09 13:48:18 +01:00
|
|
|
event.preventDefault();
|
2024-01-11 20:47:41 +01:00
|
|
|
const request = new HttpRequest("post", "', $this->photo->getPageUrl(), '",
|
|
|
|
"id_tag=" + this.dataset["id"] + "&delete", (response) => {
|
2019-03-09 13:48:18 +01:00
|
|
|
if (!response.success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-11 20:47:41 +01:00
|
|
|
const tagNode = document.getElementById("tag-" + this.dataset["id"]);
|
2019-03-09 13:48:18 +01:00
|
|
|
tagNode.parentNode.removeChild(tagNode);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-01-11 20:47:41 +01:00
|
|
|
let tagRemovalTargets = document.querySelectorAll(".delete-tag");
|
|
|
|
tagRemovalTargets.forEach(el => el.addEventListener("click", removeTag));
|
2019-03-09 13:48:18 +01:00
|
|
|
|
2024-01-11 20:47:41 +01:00
|
|
|
let tag_autosuggest = new TagAutoSuggest({
|
|
|
|
inputElement: "', $newTagId, '",
|
|
|
|
listElement: "', $tagListId, '",
|
2016-09-04 11:23:08 +02:00
|
|
|
baseUrl: "', BASEURL, '",
|
2024-01-11 20:47:41 +01:00
|
|
|
appendCallback: (item) => {
|
|
|
|
const request = new HttpRequest("post", "', $this->photo->getPageUrl(), '",
|
|
|
|
"id_tag=" + item.id_tag, (response) => {
|
|
|
|
const newListItem = document.createElement("li");
|
|
|
|
newListItem.id = "tag-" + item.id_tag;
|
|
|
|
|
|
|
|
const newInputGroup = document.createElement("div");
|
|
|
|
newInputGroup.className = "input-group";
|
2024-01-11 21:53:44 +01:00
|
|
|
newListItem.appendChild(newInputGroup);
|
2019-03-09 13:22:32 +01:00
|
|
|
|
2024-01-11 21:53:44 +01:00
|
|
|
const newLink = document.createElement("a");
|
|
|
|
newLink.className = "input-group-text";
|
|
|
|
newLink.href = item.url;
|
|
|
|
newLink.title = "View all posts tagged " + item.label;
|
|
|
|
newLink.textContent = item.label;
|
|
|
|
newInputGroup.appendChild(newLink);
|
2024-01-11 20:47:41 +01:00
|
|
|
|
|
|
|
const removeLink = document.createElement("a");
|
|
|
|
removeLink.className = "delete-tag btn btn-danger px-1";
|
2019-03-09 13:48:18 +01:00
|
|
|
removeLink.dataset["id"] = item.id_tag;
|
|
|
|
removeLink.href = "#";
|
2024-01-11 20:47:41 +01:00
|
|
|
removeLink.innerHTML = \'<i class="bi bi-x"></i>\';
|
2019-03-09 13:48:18 +01:00
|
|
|
removeLink.addEventListener("click", removeTag);
|
2024-01-11 20:47:41 +01:00
|
|
|
newInputGroup.appendChild(removeLink);
|
2019-03-09 13:48:18 +01:00
|
|
|
|
2024-01-11 20:47:41 +01:00
|
|
|
const list = document.getElementById("', $tagListId, '");
|
|
|
|
list.insertBefore(newListItem, list.querySelector("li:last-child"));
|
2016-11-13 14:42:53 +01:00
|
|
|
}, this);
|
2016-09-04 11:23:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
2024-01-11 19:13:21 +01:00
|
|
|
public function setMetaData(array $metaData)
|
2016-09-03 21:32:55 +02:00
|
|
|
{
|
2024-01-11 19:13:21 +01:00
|
|
|
$this->metaData = $metaData;
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|
2018-07-02 20:32:59 +02:00
|
|
|
|
2023-11-11 15:29:32 +01:00
|
|
|
public function userActions()
|
2018-07-02 20:32:59 +02:00
|
|
|
{
|
2023-11-11 15:29:32 +01:00
|
|
|
if (!$this->photo->isOwnedBy(Registry::get('user')))
|
|
|
|
return;
|
|
|
|
|
2018-07-02 20:32:59 +02:00
|
|
|
echo '
|
2024-01-11 19:20:46 +01:00
|
|
|
<div class="float-end">
|
|
|
|
<a class="btn btn-primary" href="', $this->photo->getEditUrl(), '">
|
|
|
|
<i class="bi bi-pencil"></i> Edit</a>
|
2023-11-11 15:29:32 +01:00
|
|
|
<a class="btn btn-danger" href="', $this->photo->getDeleteUrl(), '&',
|
|
|
|
Session::getSessionTokenKey(), '=', Session::getSessionToken(),
|
|
|
|
'" onclick="return confirm(\'Are you sure you want to delete this photo?\');"',
|
2024-01-11 19:20:46 +01:00
|
|
|
'"><i class="bi bi-pencil"></i> Delete</a></a>
|
2018-07-02 20:32:59 +02:00
|
|
|
</div>';
|
|
|
|
}
|
2016-09-03 21:32:55 +02:00
|
|
|
}
|