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
|
|
|
{
|
|
|
|
echo '
|
2024-01-11 20:00:29 +01:00
|
|
|
<h3>', $header, '</h3>
|
|
|
|
<ul id="tag_list" class="d-flex">';
|
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 20:00:29 +01:00
|
|
|
<a href="', $tag->getUrl(), '" title="View all posts tagged ', $tag->tag, '">
|
|
|
|
<div class="input-group">
|
|
|
|
<span class="input-group-text">', $tag->tag, '</span>';
|
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 20:00:29 +01:00
|
|
|
<a class="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>';
|
|
|
|
}
|
2019-03-09 13:48:18 +01:00
|
|
|
|
|
|
|
echo '
|
2024-01-11 20:00:29 +01:00
|
|
|
</div>
|
|
|
|
</a>
|
2016-09-03 21:32:55 +02:00
|
|
|
</li>';
|
|
|
|
}
|
|
|
|
|
2024-01-11 20:00:29 +01:00
|
|
|
if ($allowLinkingNewTags)
|
|
|
|
$this->linkNewTags();
|
|
|
|
|
2016-09-03 21:32:55 +02:00
|
|
|
echo '
|
|
|
|
</ul>';
|
|
|
|
}
|
|
|
|
|
2016-09-04 11:23:08 +02:00
|
|
|
private function linkNewTags()
|
|
|
|
{
|
|
|
|
echo '
|
2024-01-11 20:00:29 +01:00
|
|
|
<li style="position: relative">
|
|
|
|
<input class="form-control w-auto" type="text" id="new_tag" placeholder="Type to link a new tag">
|
|
|
|
</li>
|
2016-09-04 11:23:08 +02:00
|
|
|
<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() {
|
2019-03-09 13:48:18 +01:00
|
|
|
var removeTag = function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var that = this;
|
|
|
|
var request = new HttpRequest("post", "', $this->photo->getPageUrl(), '",
|
|
|
|
"id_tag=" + this.dataset["id"] + "&delete", function(response) {
|
|
|
|
if (!response.success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tagNode = document.getElementById("tag-" + that.dataset["id"]);
|
|
|
|
tagNode.parentNode.removeChild(tagNode);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var tagRemovalTargets = document.getElementsByClassName("delete-tag");
|
2020-02-22 17:40:34 +01:00
|
|
|
for (var i = 0; i < tagRemovalTargets.length; i++) {
|
|
|
|
tagRemovalTargets[i].addEventListener("click", removeTag);
|
|
|
|
}
|
2019-03-09 13:48:18 +01:00
|
|
|
|
2016-09-04 11:23:08 +02:00
|
|
|
var tag_autosuggest = new TagAutoSuggest({
|
|
|
|
inputElement: "new_tag",
|
|
|
|
listElement: "tag_list",
|
|
|
|
baseUrl: "', BASEURL, '",
|
|
|
|
appendCallback: function(item) {
|
2016-11-13 14:42:53 +01:00
|
|
|
var request = new HttpRequest("post", "', $this->photo->getPageUrl(), '",
|
|
|
|
"id_tag=" + item.id_tag, function(response) {
|
2019-03-09 13:22:32 +01:00
|
|
|
var newLink = document.createElement("a");
|
|
|
|
newLink.href = item.url;
|
|
|
|
|
2016-11-13 14:42:53 +01:00
|
|
|
var newLabel = document.createTextNode(item.label);
|
2019-03-09 13:22:32 +01:00
|
|
|
newLink.appendChild(newLabel);
|
|
|
|
|
2019-03-09 13:48:18 +01:00
|
|
|
var removeLink = document.createElement("a");
|
|
|
|
removeLink.className = "delete-tag";
|
|
|
|
removeLink.dataset["id"] = item.id_tag;
|
|
|
|
removeLink.href = "#";
|
|
|
|
removeLink.addEventListener("click", removeTag);
|
|
|
|
|
|
|
|
var crossmark = document.createTextNode("❌");
|
|
|
|
removeLink.appendChild(crossmark);
|
|
|
|
|
2019-03-09 13:22:32 +01:00
|
|
|
var newNode = document.createElement("li");
|
2019-03-09 13:48:18 +01:00
|
|
|
newNode.id = "tag-" + item.id_tag;
|
2019-03-09 13:22:32 +01:00
|
|
|
newNode.appendChild(newLink);
|
2019-03-09 13:48:18 +01:00
|
|
|
newNode.appendChild(removeLink);
|
2016-11-13 14:42:53 +01:00
|
|
|
|
|
|
|
var list = document.getElementById("tag_list");
|
|
|
|
list.appendChild(newNode);
|
|
|
|
}, 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
|
|
|
}
|