2021-08-28 16:27:58 +00:00
|
|
|
<?php
|
2023-10-19 18:32:57 +00:00
|
|
|
|
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;
|
2023-10-19 18:32:57 +00:00
|
|
|
use Dotclear\App;
|
2023-08-21 14:55:06 +00:00
|
|
|
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;
|
2021-09-28 22:56:31 +00:00
|
|
|
|
2023-10-19 18:32:57 +00:00
|
|
|
/**
|
|
|
|
* @brief kUtRL links listing.
|
|
|
|
* @ingroup kUtRL
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis (author)
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-08-21 14:55:06 +00:00
|
|
|
class LinksListing extends Listing
|
|
|
|
{
|
|
|
|
public function display(Filters $filter, string $enclose_block): void
|
2021-08-28 16:27:58 +00:00
|
|
|
{
|
|
|
|
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();
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2023-08-21 14:55:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-09-28 22:56:31 +00:00
|
|
|
|
2023-08-21 14:55:06 +00:00
|
|
|
$links = [];
|
|
|
|
if (isset($_REQUEST['entries'])) {
|
|
|
|
foreach ($_REQUEST['entries'] as $v) {
|
|
|
|
$links[(int) $v] = true;
|
2021-09-28 22:56:31 +00:00
|
|
|
}
|
2023-08-21 14:55:06 +00:00
|
|
|
}
|
2021-09-28 22:56:31 +00:00
|
|
|
|
2023-11-04 17:53:06 +00:00
|
|
|
$pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
|
2021-08-28 16:27:58 +00:00
|
|
|
|
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"'),
|
|
|
|
]);
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2023-08-21 14:55:06 +00:00
|
|
|
$this->userColumns(My::id(), $cols);
|
|
|
|
|
|
|
|
$lines = [];
|
|
|
|
while ($this->rs->fetch()) {
|
2023-11-04 17:53:06 +00:00
|
|
|
$lines[] = $this->linkLine(isset($links[$this->rs->f('kut_id')]));
|
2021-09-28 22:56:31 +00:00
|
|
|
}
|
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();
|
2021-09-28 22:56:31 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 14:55:06 +00:00
|
|
|
private function linkLine(bool $checked): Para
|
2021-09-28 22:56:31 +00:00
|
|
|
{
|
|
|
|
$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())
|
2023-11-04 17:53:06 +00:00
|
|
|
->href($o->get('home'))
|
|
|
|
->title($o->get('name'))
|
|
|
|
->text($o->get('name'))
|
2023-08-21 14:55:06 +00:00
|
|
|
->render();
|
|
|
|
$hash = (new Link())
|
2023-11-04 17:53:06 +00:00
|
|
|
->href($o->get('url_base') . $hash)
|
|
|
|
->title($o->get('url_base') . $hash)
|
2023-08-21 14:55:06 +00:00
|
|
|
->text($hash)
|
|
|
|
->render();
|
2021-09-28 22:56:31 +00:00
|
|
|
}
|
2021-08-28 16:27:58 +00:00
|
|
|
|
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())
|
2023-11-04 17:53:06 +00:00
|
|
|
->href((string) $o?->get('home'))
|
2023-08-21 14:55:06 +00:00
|
|
|
->title($this->rs->kut_url)
|
|
|
|
->text($this->rs->kut_url),
|
|
|
|
]),
|
|
|
|
'kut_hash' => (new Text('td', $hash))
|
|
|
|
->class('nowrap'),
|
2023-10-19 18:32:57 +00:00
|
|
|
'kut_dt' => (new Text('td', Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, App::auth()->getInfo('user_tz')))))
|
2023-08-21 14:55:06 +00:00
|
|
|
->class('nowrap'),
|
|
|
|
'kut_service' => (new Text('td', $type))
|
|
|
|
->class('nowrap'),
|
|
|
|
]);
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2023-08-21 14:55:06 +00:00
|
|
|
$this->userColumns(My::id(), $cols);
|
2021-09-28 22:56:31 +00:00
|
|
|
|
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-08-28 16:27:58 +00:00
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
}
|