kUtRL/src/LinksListing.php

151 lines
4.5 KiB
PHP
Raw Normal View History

<?php
/**
* @brief kUtRL, a plugin for Dotclear 2
2021-11-06 15:43:02 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:43:02 +00:00
*
* @author Jean-Christian Denis and contributors
2021-11-06 15:43:02 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2023-08-21 14:55:06 +00:00
declare(strict_types=1);
2021-08-28 21:17:13 +00:00
2023-08-21 14:55:06 +00:00
namespace Dotclear\Plugin\kUtRL;
2021-08-28 21:17:13 +00:00
2023-08-21 14:55:06 +00:00
use ArrayObject;
use dcCore;
use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Core\Backend\Listing\{
Listing,
Pager
};
use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Link,
Note,
Para,
Text,
};
use Dotclear\Helper\Html\Html;
2023-08-21 14:55:06 +00:00
class LinksListing extends Listing
{
public function display(Filters $filter, string $enclose_block): void
{
if ($this->rs->isEmpty()) {
2023-08-21 14:55:06 +00:00
echo (new Note())
->class('info')
->text($filter->show() ? __('No short link matches the filter') : __('No short link'))
->render();
2023-08-21 14:55:06 +00:00
return;
}
2023-08-21 14:55:06 +00:00
$links = [];
if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) {
$links[(int) $v] = true;
}
2023-08-21 14:55:06 +00:00
}
2023-08-21 14:55:06 +00:00
$pager = new Pager((int) $filter->value('page'), $this->rs_count, (int) $filter->nb, 10);
2023-08-21 14:55:06 +00:00
$cols = new ArrayObject([
'kut_url' => (new Text('th', __('Link')))
->class('first')
->extra('colspan="2"'),
'kut_hash' => (new Text('th', __('Hash')))
->extra('scope="col"'),
'kut_dt' => (new Text('th', __('Date')))
->extra('scope="col"'),
'kut_service' => (new Text('th', __('Service')))
->extra('scope="col"'),
]);
2023-08-21 14:55:06 +00:00
$this->userColumns(My::id(), $cols);
$lines = [];
while ($this->rs->fetch()) {
$lines[] = $this->linkLine(isset($links[$this->rs->kut_id]));
}
2023-08-21 14:55:06 +00:00
echo
$pager->getLinks() .
sprintf(
$enclose_block,
(new Div())
->class('table-outer')
->items([
(new Para(null, 'table'))
->items([
(new Text(
'caption',
$filter->show() ?
sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
sprintf(__('List of links. (%s)'), $this->rs_count)
)),
(new Para(null, 'tr'))
->items(iterator_to_array($cols)),
(new Para(null, 'tbody'))
->items($lines),
]),
])
->render()
) .
$pager->getLinks();
}
2023-08-21 14:55:06 +00:00
private function linkLine(bool $checked): Para
{
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
2023-08-21 14:55:06 +00:00
if (null !== ($o = Utils::quickService($type))) {
$type = (new Link())
->href($o->home)
->title($o->name)
->text($o->name)
->render();
$hash = (new Link())
->href($o->url_base . $hash)
->title($o->url_base . $hash)
->text($hash)
->render();
}
2023-08-21 14:55:06 +00:00
$cols = new ArrayObject([
'check' => (new Para(null, 'td'))
->class('nowrap minimal')
->items([
(new Checkbox(['entries[]'], $checked))
->value($this->rs->kut_id),
]),
'kut_url' => (new Para(null, 'td'))
->class('maximal')
->items([
(new Link())
->href($o->home)
->title($this->rs->kut_url)
->text($this->rs->kut_url),
]),
'kut_hash' => (new Text('td', $hash))
->class('nowrap'),
'kut_dt' => (new Text('td', Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, dcCore::app()->auth->getInfo('user_tz')))))
->class('nowrap'),
'kut_service' => (new Text('td', $type))
->class('nowrap'),
]);
2023-08-21 14:55:06 +00:00
$this->userColumns(My::id(), $cols);
2023-08-21 14:55:06 +00:00
return
(new Para('p' . $this->rs->kut_id, 'tr'))
->class('line')
->items(iterator_to_array($cols));
}
2021-11-06 15:43:02 +00:00
}