2020-02-18 12:46:03 +01:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* ManageAssets.php
|
|
|
|
* Contains the asset management controller.
|
|
|
|
*
|
|
|
|
* Kabuki CMS (C) 2013-2017, Aaron van Geffen
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class ManageAssets extends HTMLController
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
// Ensure it's just admins at this point.
|
|
|
|
if (!Registry::get('user')->isAdmin())
|
|
|
|
throw new NotAllowedException();
|
|
|
|
|
2023-03-11 21:24:55 +01:00
|
|
|
if (isset($_POST['deleteChecked'], $_POST['delete']) && Session::validateSession())
|
|
|
|
$this->handleAssetDeletion();
|
|
|
|
|
2020-02-18 12:46:03 +01:00
|
|
|
Session::resetSessionToken();
|
|
|
|
|
|
|
|
$options = [
|
2023-03-11 21:24:55 +01:00
|
|
|
'form' => [
|
|
|
|
'action' => BASEURL . '/manageassets/?' . Session::getSessionTokenKey() . '=' . Session::getSessionToken(),
|
|
|
|
'method' => 'post',
|
|
|
|
'class' => 'col-md-6 text-end',
|
|
|
|
'is_embed' => true,
|
|
|
|
'buttons' => [
|
|
|
|
'deleteChecked' => [
|
|
|
|
'type' => 'submit',
|
|
|
|
'caption' => 'Delete checked',
|
|
|
|
'class' => 'btn-danger',
|
|
|
|
'onclick' => 'return confirm(\'Are you sure you want to delete these items?\')',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2020-02-18 12:46:03 +01:00
|
|
|
'columns' => [
|
2023-03-11 21:24:55 +01:00
|
|
|
'checkbox' => [
|
|
|
|
'header' => '<input type="checkbox" id="selectall">',
|
|
|
|
'is_sortable' => false,
|
|
|
|
'parse' => [
|
|
|
|
'type' => 'function',
|
|
|
|
'data' => function($row) {
|
|
|
|
return '<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">';
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2024-08-27 12:00:46 +02:00
|
|
|
'thumbnail' => [
|
|
|
|
'header' => ' ',
|
|
|
|
'is_sortable' => false,
|
|
|
|
'cell_class' => 'text-center',
|
|
|
|
'parse' => [
|
|
|
|
'type' => 'function',
|
|
|
|
'data' => function($row) {
|
|
|
|
$asset = Image::byRow($row);
|
|
|
|
$width = $height = 65;
|
|
|
|
if ($asset->isImage())
|
|
|
|
{
|
|
|
|
if ($asset->isPortrait())
|
|
|
|
$width = null;
|
|
|
|
else
|
|
|
|
$height = null;
|
|
|
|
|
|
|
|
$thumb = $asset->getThumbnailUrl($width, $height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$thumb = BASEURL . '/images/nothumb.svg';
|
|
|
|
|
|
|
|
$width = isset($width) ? $width . 'px' : 'auto';
|
|
|
|
$height = isset($height) ? $height . 'px' : 'auto';
|
|
|
|
|
|
|
|
return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2020-02-18 12:46:03 +01:00
|
|
|
'id_asset' => [
|
|
|
|
'value' => 'id_asset',
|
|
|
|
'header' => 'ID',
|
|
|
|
'is_sortable' => true,
|
|
|
|
],
|
|
|
|
'subdir' => [
|
|
|
|
'value' => 'subdir',
|
|
|
|
'header' => 'Subdirectory',
|
|
|
|
'is_sortable' => true,
|
|
|
|
],
|
|
|
|
'filename' => [
|
|
|
|
'value' => 'filename',
|
|
|
|
'header' => 'Filename',
|
|
|
|
'is_sortable' => true,
|
|
|
|
'parse' => [
|
|
|
|
'type' => 'value',
|
|
|
|
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
|
|
|
'data' => 'filename',
|
|
|
|
],
|
|
|
|
],
|
2023-03-11 17:53:53 +01:00
|
|
|
'id_user_uploaded' => [
|
|
|
|
'header' => 'User uploaded',
|
2020-02-18 12:46:03 +01:00
|
|
|
'is_sortable' => true,
|
|
|
|
'parse' => [
|
2023-03-11 17:53:53 +01:00
|
|
|
'type' => 'function',
|
|
|
|
'data' => function($row) {
|
2023-03-11 22:07:00 +01:00
|
|
|
if (!empty($row['id_user']))
|
|
|
|
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
|
|
|
$row['first_name'] . ' ' . $row['surname']);
|
2023-03-11 17:53:53 +01:00
|
|
|
else
|
|
|
|
return 'n/a';
|
|
|
|
},
|
2020-02-18 12:46:03 +01:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'dimensions' => [
|
|
|
|
'header' => 'Dimensions',
|
|
|
|
'is_sortable' => false,
|
|
|
|
'parse' => [
|
|
|
|
'type' => 'function',
|
|
|
|
'data' => function($row) {
|
|
|
|
if (!empty($row['image_width']))
|
|
|
|
return $row['image_width'] . ' x ' . $row['image_height'];
|
|
|
|
else
|
|
|
|
return 'n/a';
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
|
|
|
|
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
|
|
|
|
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
|
|
|
|
'title' => 'Manage assets',
|
|
|
|
'no_items_label' => 'No assets meet the requirements of the current filter.',
|
|
|
|
'items_per_page' => 30,
|
2023-03-11 21:24:55 +01:00
|
|
|
'index_class' => 'col-md-6',
|
2020-02-18 12:46:03 +01:00
|
|
|
'base_url' => BASEURL . '/manageassets/',
|
|
|
|
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'down') {
|
2023-03-11 17:53:53 +01:00
|
|
|
if (!in_array($order, ['id_asset', 'id_user_uploaded', 'title', 'subdir', 'filename']))
|
2020-02-18 12:46:03 +01:00
|
|
|
$order = 'id_asset';
|
|
|
|
|
|
|
|
$data = Registry::get('db')->queryAssocs('
|
2023-03-11 17:53:53 +01:00
|
|
|
SELECT a.id_asset, a.subdir, a.filename,
|
2024-08-27 12:00:46 +02:00
|
|
|
a.image_width, a.image_height, a.mimetype,
|
2023-03-11 17:53:53 +01:00
|
|
|
u.id_user, u.first_name, u.surname
|
|
|
|
FROM assets AS a
|
|
|
|
LEFT JOIN users AS u ON a.id_user_uploaded = u.id_user
|
2020-02-18 12:46:03 +01:00
|
|
|
ORDER BY {raw:order}
|
|
|
|
LIMIT {int:offset}, {int:limit}',
|
|
|
|
[
|
|
|
|
'order' => $order . ($direction == 'up' ? ' ASC' : ' DESC'),
|
|
|
|
'offset' => $offset,
|
|
|
|
'limit' => $limit,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'rows' => $data,
|
|
|
|
'order' => $order,
|
|
|
|
'direction' => $direction,
|
|
|
|
];
|
|
|
|
},
|
|
|
|
'get_count' => 'Asset::getCount',
|
|
|
|
];
|
|
|
|
|
|
|
|
$table = new GenericTable($options);
|
2023-03-11 21:24:55 +01:00
|
|
|
parent::__construct('Asset management - Page ' . $table->getCurrentPage());
|
|
|
|
|
|
|
|
$wrapper = new AssetManagementWrapper();
|
|
|
|
$this->page->adopt($wrapper);
|
|
|
|
$wrapper->adopt(new TabularData($table));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function handleAssetDeletion()
|
|
|
|
{
|
|
|
|
if (!isset($_POST['delete']) || !is_array($_POST['delete']))
|
|
|
|
throw new UnexpectedValueException();
|
|
|
|
|
|
|
|
foreach ($_POST['delete'] as $id_asset)
|
|
|
|
{
|
|
|
|
$asset = Asset::fromId($id_asset);
|
|
|
|
$asset->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Location: ' . BASEURL . '/manageassets/');
|
|
|
|
exit;
|
2020-02-18 12:46:03 +01:00
|
|
|
}
|
|
|
|
}
|