cinecturlink2/inc/lib.cinecturlink2.list.php

158 lines
5.8 KiB
PHP
Raw Normal View History

2021-09-07 12:33:18 +00:00
<?php
2021-09-07 13:21:38 +00:00
/**
* @brief cinecturlink2, a plugin for Dotclear 2
2021-11-02 22:55:41 +00:00
*
2021-09-07 13:21:38 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-02 22:55:41 +00:00
*
2021-09-07 13:21:38 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-02 22:55:41 +00:00
*
2021-09-07 13:21:38 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-07 12:33:18 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
2021-09-07 13:21:38 +00:00
return null;
2021-09-07 12:33:18 +00:00
}
class adminlistCinecturlink2
2021-09-07 12:33:18 +00:00
{
public $redir = '';
protected $rs;
protected $rs_count;
protected $html_prev;
protected $html_next;
2022-11-17 21:01:00 +00:00
public function __construct($rs, $rs_count)
2021-09-07 13:21:38 +00:00
{
2021-11-02 22:55:41 +00:00
$this->rs = &$rs;
$this->rs_count = $rs_count;
$this->html_prev = __('&#171; prev.');
$this->html_next = __('next &#187;');
}
2021-09-07 12:33:18 +00:00
2021-09-10 22:46:28 +00:00
public function userColumns($type, $cols)
{
2022-11-17 21:01:00 +00:00
$cols_user = @dcCore::app()->auth->user_prefs->interface->cols;
2021-09-10 22:46:28 +00:00
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, $redir = '')
{
$this->redir = $redir;
if ($this->rs->isEmpty()) {
if ($filter) {
echo '<p><strong>' . __('No link matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No link') . '</strong></p>';
}
} else {
2021-11-02 22:55:41 +00:00
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$links = [];
if (isset($_REQUEST['links'])) {
foreach ($_REQUEST['links'] as $v) {
2021-11-02 22:55:41 +00:00
$links[(int) $v] = true;
}
}
2021-09-07 12:33:18 +00:00
2021-09-10 22:46:28 +00:00
$cols = [
2021-11-02 22:55:41 +00:00
'title' => '<th colspan="2" class="first">' . __('Title') . '</th>',
'author' => '<th scope="col">' . __('Author') . '</th>',
'desc' => '<th scope="col">' . __('Description') . '</th>',
'link' => '<th scope="col">' . __('Links') . '</th>',
'cat' => '<th scope="col">' . __('Category') . '</th>',
'note' => '<th scope="col">' . __('Rating') . '</th>',
2022-11-17 21:01:00 +00:00
'date' => '<th scope="col">' . __('Date') . '</th>',
2021-09-10 22:46:28 +00:00
];
$cols = new ArrayObject($cols);
$this->userColumns('c2link', $cols);
2021-11-02 22:55:41 +00:00
$html_block = '<div class="table-outer">' .
'<table>' .
2021-11-02 22:55:41 +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-02 22:55:41 +00:00
) . '</caption>' .
'<thead>' .
2021-09-10 22:46:28 +00:00
'<tr>' . implode(iterator_to_array($cols)) . '</tr>' .
'</thead>' .
'<tbody>%s</tbody>' .
'</table>' .
'%s</div>';
2021-09-07 12:33:18 +00:00
2021-11-04 01:03:49 +00:00
$enclose_blocks = explode('%s', $enclose_block);
$blocks = explode('%s', $html_block);
2021-09-07 12:33:18 +00:00
2021-11-05 22:23:00 +00:00
echo $pager->getLinks() . $enclose_blocks[0] . $blocks[0];
2021-09-07 12:33:18 +00:00
while ($this->rs->fetch()) {
echo $this->linkLine(isset($links[$this->rs->link_id]));
2021-09-07 13:21:38 +00:00
}
2021-11-05 22:23:00 +00:00
echo $blocks[1] . $blocks[2] . $enclose_blocks[1] . $pager->getLinks();
2021-09-07 13:21:38 +00:00
}
}
2021-09-07 12:33:18 +00:00
private function linkLine($checked)
2021-09-07 13:21:38 +00:00
{
2021-09-10 22:46:28 +00:00
$cols = [
'check' => '<td class="nowrap minimal">' .
2021-11-02 22:55:41 +00:00
form::checkbox(['entries[]'], $this->rs->link_id, ['checked' => $checked]) .
2021-09-10 22:46:28 +00:00
'</td>',
'title' => '<td class="nowrap" scope="row">' .
2022-11-17 21:01:00 +00:00
'<a href="' . dcCore::app()->adminurl->get(
2021-11-02 22:55:41 +00:00
'admin.plugin.cinecturlink2',
2021-09-10 22:46:28 +00:00
['part' => 'link', 'linkid' => $this->rs->link_id, 'redir' => $this->redir]
) . '" title="' . __('Edit') . '">' .
html::escapeHTML($this->rs->link_title) . '</a>' .
'</td>',
'author' => '<td class="nowrap">' .
html::escapeHTML($this->rs->link_author) .
'</td>',
'desc' => '<td class="maximal">' .
html::escapeHTML($this->rs->link_desc) .
'</td>',
'link' => '<td class="nowrap">' .
2021-11-02 22:55:41 +00:00
'<a href="' . $this->rs->link_url . '" title="' .
html::escapeHTML($this->rs->link_url) .
2021-09-10 22:46:28 +00:00
'">' . __('URL') . '</a> ' .
2021-11-02 22:55:41 +00:00
'<a href="' . $this->rs->link_img . '" title="' .
html::escapeHTML($this->rs->link_img) .
2021-09-10 22:46:28 +00:00
'">' . __('image') . '</a> ' .
'</td>',
'cat' => '<td class="nowrap minimal">' .
2022-11-17 21:01:00 +00:00
'<a href="' . dcCore::app()->adminurl->get(
2021-11-02 22:55:41 +00:00
'admin.plugin.cinecturlink2',
2021-09-10 22:46:28 +00:00
['part' => 'cat', 'catid' => $this->rs->cat_id, 'redir' => $this->redir]
) . '" title="' . __('Edit') . '">' .
html::escapeHTML($this->rs->cat_title) . '</a>' .
'</td>',
'note' => '</td>' .
'<td class="nowrap count minimal">' .
html::escapeHTML($this->rs->link_note) . '/20' .
'</td>',
'date' => '<td class="nowrap count minimal">' .
dt::dt2str(
2022-11-17 21:01:00 +00:00
dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
2021-11-02 22:55:41 +00:00
$this->rs->link_upddt,
2022-11-17 21:01:00 +00:00
dcCore::app()->auth->getInfo('user_tz')
2021-09-10 22:46:28 +00:00
) .
2022-11-17 21:01:00 +00:00
'</td>',
2021-09-10 22:46:28 +00:00
];
$cols = new ArrayObject($cols);
$this->userColumns('c2link', $cols);
2021-11-02 22:55:41 +00:00
return '<tr class="line">' . implode(iterator_to_array($cols)) . '</tr>' . "\n";
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
}