2016-09-01 23:13:23 +02:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* EditAssetForm.php
|
|
|
|
* Contains the edit asset template.
|
|
|
|
*
|
|
|
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2023-03-11 14:31:44 +01:00
|
|
|
class EditAssetForm extends Template
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
2023-11-12 17:26:03 +01:00
|
|
|
private $allAlbums;
|
2016-09-01 23:13:23 +02:00
|
|
|
private $asset;
|
2023-11-12 17:26:03 +01:00
|
|
|
private $currentAlbumId;
|
2016-09-01 23:13:23 +02:00
|
|
|
private $thumbs;
|
|
|
|
|
2023-11-12 17:26:03 +01:00
|
|
|
public function __construct(array $options)
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
2023-11-12 17:26:03 +01:00
|
|
|
$this->allAlbums = $options['allAlbums'];
|
|
|
|
$this->asset = $options['asset'];
|
|
|
|
$this->currentAlbumId = $options['currentAlbumId'];
|
|
|
|
$this->thumbs = $options['thumbs'];
|
2016-09-01 23:13:23 +02:00
|
|
|
}
|
|
|
|
|
2023-03-11 14:31:44 +01:00
|
|
|
public function html_main()
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<form id="asset_form" action="" method="post" enctype="multipart/form-data">
|
2023-03-11 14:31:44 +01:00
|
|
|
<div class="content-box">
|
2023-03-12 00:53:47 +01:00
|
|
|
<div class="float-end">
|
2023-11-11 15:29:32 +01:00
|
|
|
<a class="btn btn-danger" href="', $this->asset->getDeleteUrl(), '&',
|
|
|
|
Session::getSessionTokenKey(), '=', Session::getSessionToken(),
|
|
|
|
'" onclick="return confirm(\'Are you sure you want to delete this asset?\');">',
|
|
|
|
'Delete asset</a>
|
2023-03-12 00:53:47 +01:00
|
|
|
<button class="btn btn-primary" type="submit">Save asset data</button>
|
2016-09-01 23:13:23 +02:00
|
|
|
</div>
|
|
|
|
<h2>Edit asset \'', $this->asset->getTitle(), '\' (', $this->asset->getFilename(), ')</h2>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
$this->section_replace();
|
|
|
|
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-8">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
$this->section_key_info();
|
|
|
|
$this->section_asset_meta();
|
|
|
|
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
</div>
|
|
|
|
<div class="col-md-4">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
if (!empty($this->thumbs))
|
|
|
|
$this->section_thumbnails();
|
|
|
|
|
|
|
|
$this->section_linked_tags();
|
|
|
|
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
</div>';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
$this->section_crop_editor();
|
|
|
|
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
</div>
|
2016-09-01 23:13:23 +02:00
|
|
|
</form>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function section_key_info()
|
|
|
|
{
|
|
|
|
$date_captured = $this->asset->getDateCaptured();
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
<div class="content-box key_info">
|
2016-09-01 23:13:23 +02:00
|
|
|
<h3>Key info</h3>
|
|
|
|
|
2023-11-12 17:26:03 +01:00
|
|
|
<div class="row mb-2">
|
|
|
|
<label class="col-form-label col-sm-3">Album:</label>
|
|
|
|
<div class="col-sm">
|
|
|
|
<select class="form-select" name="id_album">';
|
|
|
|
|
|
|
|
foreach ($this->allAlbums as $id_album => $album)
|
|
|
|
echo '
|
|
|
|
<option value="', $id_album, '"',
|
|
|
|
$this->currentAlbumId == $id_album ? ' selected' : '',
|
|
|
|
'>', htmlspecialchars($album), '</option>';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-12 00:53:47 +01:00
|
|
|
<div class="row mb-2">
|
|
|
|
<label class="col-form-label col-sm-3">Title (internal):</label>
|
|
|
|
<div class="col-sm">
|
|
|
|
<input class="form-control" type="text" name="title" maxlength="255" size="70" value="', $this->asset->getTitle(), '">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row mb-2">
|
|
|
|
<label class="col-form-label col-sm-3">URL slug:</label>
|
|
|
|
<div class="col-sm">
|
|
|
|
<input class="form-control" type="text" name="slug" maxlength="255" size="70" value="', $this->asset->getSlug(), '">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row mb-2">
|
|
|
|
<label class="col-form-label col-sm-3">Date captured:</label>
|
|
|
|
<div class="col-sm">
|
2023-11-12 17:14:30 +01:00
|
|
|
<input class="form-control" type="datetime-local" step="1"
|
|
|
|
name="date_captured" size="30" placeholder="Y-m-d H:i:s" value="',
|
|
|
|
$date_captured ? $date_captured->format('Y-m-d H:i:s') : '', '">
|
2023-03-12 00:53:47 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row mb-2">
|
|
|
|
<label class="col-form-label col-sm-3">Display priority:</label>
|
|
|
|
<div class="col-sm-3">
|
|
|
|
<input class="form-control" type="number" name="priority" min="0" max="100" step="1" value="', $this->asset->getPriority(), '">
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-09-01 23:13:23 +02:00
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function section_linked_tags()
|
|
|
|
{
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
<div class="content-box linked_tags">
|
2016-09-01 23:13:23 +02:00
|
|
|
<h3>Linked tags</h3>
|
2023-03-12 00:53:47 +01:00
|
|
|
<ul class="list-unstyled" id="tag_list">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
foreach ($this->asset->getTags() as $tag)
|
|
|
|
echo '
|
|
|
|
<li>
|
|
|
|
<input class="tag_check" type="checkbox" name="tag[', $tag->id_tag, ']" id="linked_tag_', $tag->id_tag, '" title="Uncheck to delete" checked>
|
|
|
|
', $tag->tag, '
|
|
|
|
</li>';
|
|
|
|
|
|
|
|
echo '
|
2023-03-12 00:53:47 +01:00
|
|
|
<li id="new_tag_container"><input class="form-control" type="text" id="new_tag" placeholder="Type to link a new tag"></li>
|
2016-09-01 23:13:23 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<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() {
|
|
|
|
var tag_autosuggest = new TagAutoSuggest({
|
|
|
|
inputElement: "new_tag",
|
|
|
|
listElement: "tag_list",
|
|
|
|
baseUrl: "', BASEURL, '",
|
|
|
|
appendCallback: function(item) {
|
|
|
|
if (document.getElementById("linked_tag_" + item.id_tag)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var newCheck = document.createElement("input");
|
|
|
|
newCheck.type = "checkbox";
|
|
|
|
newCheck.name = "tag[" + item.id_tag + "]";
|
|
|
|
newCheck.id = "linked_tag_" + item.id_tag;
|
|
|
|
newCheck.title = "Uncheck to delete";
|
|
|
|
newCheck.checked = "checked";
|
|
|
|
|
|
|
|
var newNode = document.createElement("li");
|
|
|
|
newNode.appendChild(newCheck);
|
|
|
|
|
|
|
|
var newLabel = document.createTextNode(item.label);
|
|
|
|
newNode.appendChild(newLabel);
|
|
|
|
|
|
|
|
var list = document.getElementById("tag_list");
|
|
|
|
var input = document.getElementById("new_tag_container");
|
|
|
|
list.insertBefore(newNode, input);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function section_thumbnails()
|
|
|
|
{
|
|
|
|
echo '
|
2023-03-11 14:31:44 +01:00
|
|
|
<div class="content-box linked_thumbs">
|
2016-09-01 23:13:23 +02:00
|
|
|
<h3>Thumbnails</h3>
|
2023-03-12 00:53:47 +01:00
|
|
|
View: <select class="form-select w-auto d-inline" id="thumbnail_src">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
2020-11-24 11:41:15 +01:00
|
|
|
$first = INF;
|
|
|
|
foreach ($this->thumbs as $i => $thumb)
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
2020-11-24 11:41:15 +01:00
|
|
|
$first = min($i, $first);
|
|
|
|
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
|
|
|
<option data-url="', $thumb['url'], '" data-crop_width="', $thumb['dimensions'][0], '" data-crop_height="', $thumb['dimensions'][1], '"',
|
|
|
|
isset($thumb['crop_method']) ? ' data-crop_method="' . $thumb['crop_method'] . '"' : '',
|
|
|
|
isset($thumb['crop_region']) ? ' data-crop_region="' . $thumb['crop_region'] . '"' : '', '>
|
|
|
|
', implode('x', $thumb['dimensions']);
|
|
|
|
|
|
|
|
if ($thumb['cropped'])
|
|
|
|
{
|
|
|
|
echo ' (';
|
|
|
|
switch ($thumb['crop_method'])
|
|
|
|
{
|
|
|
|
case 'b': echo 'bottom'; break;
|
|
|
|
case 'e': echo 'exact'; break;
|
|
|
|
case 's': echo 'slice'; break;
|
|
|
|
case 't': echo 'top'; break;
|
|
|
|
default: echo 'centre'; break;
|
|
|
|
}
|
|
|
|
echo ' crop)';
|
|
|
|
}
|
|
|
|
elseif ($thumb['custom_image'])
|
|
|
|
echo ' (custom)';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</select>
|
2020-11-24 11:41:15 +01:00
|
|
|
<a id="thumbnail_link" href="', $this->thumbs[$first]['url'], '" target="_blank">
|
|
|
|
<img id="thumbnail" src="', $this->thumbs[$first]['url'], '" alt="Thumbnail" style="width: 100%; height: auto;">
|
2016-09-01 23:13:23 +02:00
|
|
|
</a>
|
|
|
|
</div>
|
2020-11-29 17:12:27 +01:00
|
|
|
<script type="text/javascript" defer="defer">
|
|
|
|
document.getElementById("thumbnail_src").addEventListener("change", event => {
|
|
|
|
let selection = event.target.options[event.target.selectedIndex];
|
|
|
|
document.getElementById("thumbnail_link").href = selection.dataset.url;
|
|
|
|
document.getElementById("thumbnail").src = selection.dataset.url;
|
|
|
|
});
|
2016-09-01 23:13:23 +02:00
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function section_crop_editor()
|
|
|
|
{
|
|
|
|
if (!$this->asset->isImage())
|
|
|
|
return;
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<script type="text/javascript" src="', BASEURL, '/js/crop_editor.js"></script>
|
2020-11-29 17:12:27 +01:00
|
|
|
<script type="text/javascript" defer="defer">
|
|
|
|
let editor = new CropEditor({
|
|
|
|
submit_url: "', BASEURL, '/editasset/",
|
|
|
|
original_image_src: "', $this->asset->getUrl(), '",
|
|
|
|
editor_container_parent_id: "asset_form",
|
|
|
|
thumbnail_select_id: "thumbnail_src",
|
|
|
|
drag_target: ".crop_image_container",
|
|
|
|
asset_id: ', $this->asset->getId(), ',
|
|
|
|
after_save: function(data) {
|
|
|
|
// Update thumbnail
|
|
|
|
document.getElementById("thumbnail").src = data.url + "?" + (new Date()).getTime();
|
|
|
|
|
|
|
|
// Update select
|
|
|
|
let src = document.getElementById("thumbnail_src");
|
|
|
|
let option = src.options[src.selectedIndex];
|
|
|
|
option.dataset.crop_region = data.value;
|
|
|
|
option.textContent = option.textContent.replace(/top|bottom|centre|slice/, "exact");
|
|
|
|
|
|
|
|
// TODO: update meta
|
|
|
|
}
|
|
|
|
});
|
2016-09-01 23:13:23 +02:00
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function section_asset_meta()
|
|
|
|
{
|
|
|
|
echo '
|
2023-03-12 00:53:47 +01:00
|
|
|
<div class="content-box asset_meta mt-2">
|
|
|
|
<h3>Asset meta data</h3>';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
2023-03-12 00:53:47 +01:00
|
|
|
$i = 0;
|
2016-09-01 23:13:23 +02:00
|
|
|
foreach ($this->asset->getMeta() as $key => $meta)
|
|
|
|
{
|
|
|
|
echo '
|
2023-03-12 00:53:47 +01:00
|
|
|
<div class="input-group">
|
|
|
|
<input type="text" class="form-control" name="meta_key[', $i, ']" value="', htmlspecialchars($key), '" placeholder="key">
|
|
|
|
<input type="text" class="form-control" name="meta_value[', $i, ']" value="', htmlspecialchars($meta), '" placeholder="value">
|
|
|
|
</div>';
|
|
|
|
$i++;
|
2016-09-01 23:13:23 +02:00
|
|
|
}
|
|
|
|
|
2023-03-12 00:53:47 +01:00
|
|
|
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
2023-03-12 00:53:47 +01:00
|
|
|
<div class="input-group">
|
|
|
|
<input type="text" class="form-control" name="meta_key[', $i + 1, ']" value="" placeholder="key">
|
|
|
|
<input type="text" class="form-control" name="meta_value[', $i + 1, ']" value="" placeholder="value">
|
|
|
|
</div>
|
|
|
|
<div class="text-end mt-3">
|
|
|
|
<button class="btn btn-primary" type="submit">Save metadata</button>
|
|
|
|
</div>
|
2016-09-01 23:13:23 +02:00
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function section_replace()
|
|
|
|
{
|
|
|
|
echo '
|
2023-03-12 00:53:47 +01:00
|
|
|
<div class="content-box replace_asset mt-2">
|
2016-09-01 23:13:23 +02:00
|
|
|
<h3>Replace asset</h3>
|
2023-03-12 00:53:47 +01:00
|
|
|
File: <input class="form-control d-inline w-auto" type="file" name="replacement">
|
|
|
|
Target: <select class="form-select d-inline w-auto" name="replacement_target">
|
2016-09-01 23:13:23 +02:00
|
|
|
<option value="full">master file</option>';
|
|
|
|
|
|
|
|
foreach ($this->thumbs as $thumb)
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<option value="thumb_', implode('x', $thumb['dimensions']);
|
|
|
|
|
|
|
|
if ($thumb['cropped'])
|
|
|
|
echo $thumb['crop_method'] === 'c' ? '_c' : '_c' . $thumb['crop_method'];
|
|
|
|
|
|
|
|
echo '">
|
|
|
|
thumbnail (', implode('x', $thumb['dimensions']);
|
|
|
|
|
|
|
|
if ($thumb['cropped'])
|
|
|
|
{
|
|
|
|
echo ', ';
|
|
|
|
switch ($thumb['crop_method'])
|
|
|
|
{
|
|
|
|
case 'b': echo 'bottom'; break;
|
|
|
|
case 'e': echo 'exact'; break;
|
|
|
|
case 's': echo 'slice'; break;
|
|
|
|
case 't': echo 'top'; break;
|
|
|
|
default: echo 'centre'; break;
|
|
|
|
}
|
|
|
|
echo ' crop';
|
|
|
|
}
|
|
|
|
elseif ($thumb['custom_image'])
|
2017-12-20 14:51:23 +01:00
|
|
|
echo ', custom';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
echo ')
|
|
|
|
</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</select>
|
2023-03-12 00:53:47 +01:00
|
|
|
<button class="btn btn-primary" type="submit">Save asset</button>
|
2016-09-01 23:13:23 +02:00
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
}
|