kUtRL/inc/lib.kutrl.lst.php

131 lines
4.4 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
*/
2021-08-28 21:17:13 +00:00
class kutrlLinkslist
{
2021-08-28 21:17:13 +00:00
protected $rs;
protected $rs_count;
protected $html_prev;
protected $html_next;
2022-11-20 16:15:36 +00:00
public function __construct($rs, $rs_count)
2021-08-28 21:17:13 +00:00
{
$this->rs = &$rs;
$this->rs_count = $rs_count;
$this->html_prev = __('&#171; prev.');
$this->html_next = __('next &#187;');
}
public function userColumns($type, $cols)
{
2022-11-20 16:15:36 +00:00
$cols_user = @dcCore::app()->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)
{
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>';
}
} else {
2021-11-06 15:43:02 +00:00
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$links = [];
2021-08-28 21:17:13 +00:00
if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) {
2021-11-06 15:43:02 +00:00
$links[(int) $v] = true;
2021-08-28 21:17:13 +00:00
}
}
$cols = [
2021-11-06 15:43:02 +00:00
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
2022-11-20 16:15:36 +00:00
'kut_service' => '<th scope="col">' . __('Service') . '</th>',
];
$cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols);
2021-11-06 15:43:02 +00:00
$html_block = '<div class="table-outer">' .
'<table>' .
2021-11-06 15:43:02 +00:00
'<caption>' . (
$filter ?
sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
sprintf(__('List of links (%s)'), $this->rs_count)
2021-11-06 15:43:02 +00:00
) . '</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 21:17:13 +00:00
while ($this->rs->fetch()) {
echo $this->linkLine(isset($links[$this->rs->kut_id]));
}
echo $blocks[1] . $blocks[2] . $pager->getLinks();
}
}
private function linkLine($checked)
{
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
2022-11-20 16:15:36 +00:00
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>';
}
$cols = [
'check' => '<td class="nowrap">' .
2021-11-06 15:43:02 +00:00
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
'</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>' .
'</td>',
'kut_hash' => '<td class="nowrap">' .
$hash .
'</td>',
'kut_dt' => '<td class="nowrap count">' .
2022-11-20 16:15:36 +00:00
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, dcCore::app()->auth->getInfo('user_tz')) .
'</td>',
2021-11-06 15:43:02 +00:00
'kut_service' => '<td class="nowrap">' .
$type .
2022-11-20 16:15:36 +00:00
'</td>',
];
$cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols);
2021-11-06 15:43:02 +00:00
return '<tr class="line">' . implode(iterator_to_array($cols)) . '</tr>' . "\n";
}
2021-11-06 15:43:02 +00:00
}