2021-08-28 16:27:58 +00:00
|
|
|
<?php
|
2021-09-02 12:32:26 +00:00
|
|
|
/**
|
|
|
|
* @brief kUtRL, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis and contributors
|
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-08-28 21:17:13 +00:00
|
|
|
class kutrlLinkslist
|
2021-08-28 16:27:58 +00:00
|
|
|
{
|
2021-08-28 21:17:13 +00:00
|
|
|
protected $core;
|
|
|
|
protected $rs;
|
|
|
|
protected $rs_count;
|
|
|
|
protected $html_prev;
|
|
|
|
protected $html_next;
|
|
|
|
|
|
|
|
public function __construct(dcCore $core, $rs, $rs_count)
|
|
|
|
{
|
|
|
|
$this->core = &$core;
|
|
|
|
$this->rs = &$rs;
|
|
|
|
$this->rs_count = $rs_count;
|
|
|
|
$this->html_prev = __('« prev.');
|
|
|
|
$this->html_next = __('next »');
|
|
|
|
}
|
|
|
|
|
2021-09-28 22:56:31 +00:00
|
|
|
public function userColumns($type, $cols)
|
|
|
|
{
|
|
|
|
$cols_user = @$this->core->auth->user_prefs->interface->cols;
|
|
|
|
if (is_array($cols_user) || $cols_user instanceof ArrayObject) {
|
|
|
|
if (isset($cols_user[$type])) {
|
|
|
|
foreach ($cols_user[$type] as $cn => $cd) {
|
|
|
|
if (!$cd && isset($cols[$cn])) {
|
|
|
|
unset($cols[$cn]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-28 21:17:13 +00:00
|
|
|
public function display($page, $nb_per_page, $enclose_block, $filter = false)
|
2021-08-28 16:27:58 +00:00
|
|
|
{
|
|
|
|
if ($this->rs->isEmpty()) {
|
2021-08-28 21:17:13 +00:00
|
|
|
if ($filter) {
|
|
|
|
echo '<p><strong>' . __('No short link matches the filter') . '</strong></p>';
|
|
|
|
} else {
|
|
|
|
echo '<p><strong>' . __('No short link') . '</strong></p>';
|
|
|
|
}
|
2021-08-28 16:27:58 +00:00
|
|
|
} else {
|
2021-08-28 21:17:13 +00:00
|
|
|
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
|
2021-09-28 22:56:31 +00:00
|
|
|
$links = [];
|
2021-08-28 21:17:13 +00:00
|
|
|
if (isset($_REQUEST['entries'])) {
|
|
|
|
foreach ($_REQUEST['entries'] as $v) {
|
2021-09-28 22:56:31 +00:00
|
|
|
$links[(integer) $v] = true;
|
2021-08-28 21:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-09-28 22:56:31 +00:00
|
|
|
$cols = [
|
2021-10-26 21:03:38 +00:00
|
|
|
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
|
|
|
|
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
|
2021-09-28 22:56:31 +00:00
|
|
|
'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
|
|
|
|
'kut_service' => '<th scope="col">' . __('Service') . '</th>'
|
|
|
|
];
|
|
|
|
$cols = new ArrayObject($cols);
|
|
|
|
$this->userColumns('kUtRL', $cols);
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-09-28 22:56:31 +00:00
|
|
|
$html_block =
|
|
|
|
'<div class="table-outer">' .
|
|
|
|
'<table>' .
|
|
|
|
'<caption>' . ($filter ?
|
|
|
|
sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
|
|
|
|
sprintf(__('List of links (%s)'), $this->rs_count)
|
|
|
|
). '</caption>' .
|
|
|
|
'<thead>' .
|
|
|
|
'<tr>' . implode(iterator_to_array($cols)) . '</tr>' .
|
|
|
|
'</thead>' .
|
|
|
|
'<tbody>%s</tbody>' .
|
|
|
|
'</table>' .
|
|
|
|
'%s</div>';
|
|
|
|
|
|
|
|
if ($enclose_block) {
|
|
|
|
$html_block = sprintf($enclose_block, $html_block);
|
|
|
|
}
|
|
|
|
$blocks = explode('%s', $html_block);
|
|
|
|
|
|
|
|
echo $pager->getLinks() . $blocks[0];
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-08-28 21:17:13 +00:00
|
|
|
while ($this->rs->fetch()) {
|
2021-09-28 22:56:31 +00:00
|
|
|
echo $this->linkLine(isset($links[$this->rs->kut_id]));
|
|
|
|
}
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-09-28 22:56:31 +00:00
|
|
|
echo $blocks[1] . $blocks[2] . $pager->getLinks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function linkLine($checked)
|
|
|
|
{
|
|
|
|
$type = $this->rs->kut_type;
|
|
|
|
$hash = $this->rs->kut_hash;
|
|
|
|
|
|
|
|
if (null !== ($o = kutrl::quickService($type))) {
|
|
|
|
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
|
|
|
|
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
|
|
|
|
}
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-09-28 22:56:31 +00:00
|
|
|
$cols = [
|
|
|
|
'check' => '<td class="nowrap">' .
|
2021-08-28 21:17:13 +00:00
|
|
|
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
|
2021-09-28 22:56:31 +00:00
|
|
|
'</td>',
|
|
|
|
'kut_url' => '<td class="maximal" scope="row">' .
|
2021-08-28 21:17:13 +00:00
|
|
|
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
|
2021-09-28 22:56:31 +00:00
|
|
|
'</td>',
|
|
|
|
'kut_hash' => '<td class="nowrap">' .
|
|
|
|
$hash .
|
|
|
|
'</td>',
|
|
|
|
'kut_dt' => '<td class="nowrap count">' .
|
2021-08-28 21:17:13 +00:00
|
|
|
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
|
2021-09-28 22:56:31 +00:00
|
|
|
'</td>',
|
|
|
|
'kut_service' => '<td class="nowrap">' .
|
|
|
|
$type .
|
|
|
|
'</td>'
|
|
|
|
];
|
2021-08-28 16:27:58 +00:00
|
|
|
|
2021-09-28 22:56:31 +00:00
|
|
|
$cols = new ArrayObject($cols);
|
|
|
|
$this->userColumns('kUtRL', $cols);
|
|
|
|
|
|
|
|
return '<tr class="line">' . implode(iterator_to_array($cols)) . '</tr>' . "\n";
|
2021-08-28 16:27:58 +00:00
|
|
|
}
|
|
|
|
}
|