core = &$core;
$this->rs = &$rs;
$this->rs_count = $rs_count;
$this->html_prev = __('« prev.');
$this->html_next = __('next »');
}
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]);
}
}
}
}
}
public function display($page, $nb_per_page, $enclose_block, $filter = false)
{
if ($this->rs->isEmpty()) {
if ($filter) {
echo '
' . __('No short link matches the filter') . '
';
} else {
echo '' . __('No short link') . '
';
}
} else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$links = [];
if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) {
$links[(integer) $v] = true;
}
}
$cols = [
'kut_url' => '' . __('Link') . ' | ',
'kut_hash' => '' . __('Hash') . ' | ',
'kut_dt' => '' . __('Date') . ' | ',
'kut_service' => '' . __('Service') . ' | '
];
$cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols);
$html_block =
'' .
'
' .
'' . ($filter ?
sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
sprintf(__('List of links (%s)'), $this->rs_count)
). '' .
'' .
'' . implode(iterator_to_array($cols)) . '
' .
'' .
'%s' .
'
' .
'%s
';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
$blocks = explode('%s', $html_block);
echo $pager->getLinks() . $blocks[0];
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;
if (null !== ($o = kutrl::quickService($type))) {
$type = '' . $o->name . '';
$hash = '' . $hash . '';
}
$cols = [
'check' => '' .
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
' | ',
'kut_url' => '' .
'' . $this->rs->kut_url . '' .
' | ',
'kut_hash' => '' .
$hash .
' | ',
'kut_dt' => '' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
' | ',
'kut_service' => '' .
$type .
' | '
];
$cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols);
return '' . implode(iterator_to_array($cols)) . '
' . "\n";
}
}