2021-08-23 11:24:19 +00:00
|
|
|
<?php
|
2021-09-02 12:56:02 +00:00
|
|
|
/**
|
|
|
|
* @brief periodical, 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-23 11:24:19 +00:00
|
|
|
|
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
2021-08-23 22:52:29 +00:00
|
|
|
return null;
|
2021-08-23 11:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_PERIODICAL
|
|
|
|
* @brief Periodical - admin pager methods.
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
class adminPeriodicalList extends adminGenericList
|
|
|
|
{
|
2021-10-23 12:44:54 +00:00
|
|
|
public function periodDisplay($filter, $enclose_block='')
|
2021-08-23 22:52:29 +00:00
|
|
|
{
|
|
|
|
if ($this->rs->isEmpty()) {
|
2021-10-23 12:44:54 +00:00
|
|
|
if ($filter->show()) {
|
|
|
|
echo '<p><strong>' . __('No period matches the filter') . '</strong></p>';
|
|
|
|
} else {
|
|
|
|
echo '<p><strong>' . __('No period') . '</strong></p>';
|
|
|
|
}
|
2021-08-23 22:52:29 +00:00
|
|
|
} else {
|
2021-10-23 12:44:54 +00:00
|
|
|
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10);
|
2021-08-23 22:52:29 +00:00
|
|
|
$pager->var_page = 'page';
|
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
$periods = [];
|
|
|
|
if (isset($_REQUEST['periods'])) {
|
|
|
|
foreach ($_REQUEST['periods'] as $v) {
|
|
|
|
$periods[(integer) $v] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$html_block = '<div class="table-outer"><table><caption>' . ($filter->show() ?
|
|
|
|
sprintf(__('List of %s periods matching the filter.'), $this->rs_count) :
|
|
|
|
sprintf(__('List of %s periods.'), $this->rs_count)
|
|
|
|
). '</caption>';
|
|
|
|
|
|
|
|
$cols = new ArrayObject([
|
|
|
|
'name' => '<th colspan="2" class="first">' . __('Name') . '</th>',
|
|
|
|
'curdt' => '<th scope="col" class="nowrap">' . __('Next update') . '</th>',
|
|
|
|
'pub_int' => '<th scope="col" class="nowrap">' . __('Frequency') . '</th>',
|
2021-10-23 21:55:11 +00:00
|
|
|
'pub_nb' => '<th scope="col" class="nowrap">' . __('Entries per update') . '</th>',
|
2021-10-23 12:44:54 +00:00
|
|
|
'nbposts' => '<th scope="col" class="nowrap">' . __('Entries') . '</th>',
|
|
|
|
'enddt' => '<th scope="col" class="nowrap">' . __('End date') . '</th>'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->userColumns('periodical', $cols);
|
2021-08-23 22:52:29 +00:00
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
$html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>';
|
2021-08-23 22:52:29 +00:00
|
|
|
if ($enclose_block) {
|
|
|
|
$html_block = sprintf($enclose_block, $html_block);
|
|
|
|
}
|
|
|
|
$blocks = explode('%s', $html_block);
|
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
echo $pager->getLinks() . $blocks[0];
|
2021-08-23 22:52:29 +00:00
|
|
|
|
|
|
|
while ($this->rs->fetch()) {
|
2021-10-23 12:44:54 +00:00
|
|
|
echo $this->periodLine(isset($periods[$this->rs->periodical_id]));
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
echo $blocks[1] . $blocks[2] . $pager->getLinks();
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
private function periodLine($checked)
|
2021-08-23 22:52:29 +00:00
|
|
|
{
|
2021-10-23 12:44:54 +00:00
|
|
|
$nb_posts = $this->rs->periodical->getPosts(['periodical_id' => $this->rs->periodical_id], true)->f(0);
|
|
|
|
$url = $this->core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $this->rs->periodical_id]);
|
|
|
|
|
|
|
|
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a>';
|
|
|
|
|
|
|
|
$posts = $nb_posts ?
|
|
|
|
'<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' :
|
|
|
|
'0';
|
|
|
|
|
|
|
|
$interval = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ?
|
2021-08-23 22:52:29 +00:00
|
|
|
__(array_search($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo())) : __('Unknow frequence');
|
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
$cols = new ArrayObject([
|
|
|
|
'check' => '<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->periodical_id, ['checked' => $checked]) . '</td>',
|
|
|
|
'name' => '<td class="maximal">' . $name . '</td>',
|
|
|
|
'curdt' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '</td>',
|
|
|
|
'pub_int' => '<td class="nowrap">' . $interval . '</td>',
|
|
|
|
'pub_nb' => '<td class="nowrap count">' . $this->rs->periodical_pub_nb . '</td>',
|
|
|
|
'nbposts' => '<td class="nowrap count">' . $posts. '</td>',
|
|
|
|
'enddt' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '</td>'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->userColumns('periodical', $cols);
|
|
|
|
|
|
|
|
return
|
|
|
|
'<tr class="line ' . ($nb_posts ? '' : ' offline') . '" id="p' . $this->rs->periodical_id . '">' .
|
|
|
|
implode(iterator_to_array($cols)) .
|
|
|
|
'</tr>';
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
public function postDisplay($filter, $base_url, $enclose_block='')
|
2021-08-23 22:52:29 +00:00
|
|
|
{
|
|
|
|
$echo = '';
|
|
|
|
if ($this->rs->isEmpty()) {
|
2021-10-23 12:44:54 +00:00
|
|
|
if ($filter->show()) {
|
|
|
|
echo '<p><strong>' . __('No entry matches the filter') . '</strong></p>';
|
|
|
|
} else {
|
|
|
|
echo '<p><strong>' . __('No entry') . '</strong></p>';
|
|
|
|
}
|
2021-08-23 22:52:29 +00:00
|
|
|
} else {
|
2021-10-23 12:44:54 +00:00
|
|
|
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10);
|
2021-08-23 22:52:29 +00:00
|
|
|
$pager->base_url = $base_url;
|
|
|
|
$pager->var_page = 'page';
|
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
$periodical_entries = [];
|
|
|
|
if (isset($_REQUEST['periodical_entries'])) {
|
|
|
|
foreach ($_REQUEST['periodical_entries'] as $v) {
|
|
|
|
$periodical_entries[(integer) $v] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-24 07:33:15 +00:00
|
|
|
$cols = [
|
|
|
|
'title' => '<th colspan="2" class="first">' . __('Title') . '</th>',
|
|
|
|
'date' => '<th scope="col">' . __('Date') . '</th>',
|
|
|
|
'category' => '<th scope="col">' . __('Category') . '</th>',
|
|
|
|
'author' => '<th scope="col">' . __('Author') . '</th>',
|
|
|
|
'status' => '<th scope="col">' . __('Status') . '</th>',
|
|
|
|
'create' => '<th scope="col" class="nowrap">' . __('Create date') . '</th>'
|
|
|
|
];
|
|
|
|
|
2021-08-23 22:52:29 +00:00
|
|
|
$html_block =
|
2021-10-24 07:33:15 +00:00
|
|
|
'<div class="table-outer"><table><caption>' . ($filter->show() ?
|
2021-10-23 21:55:11 +00:00
|
|
|
sprintf(__('List of %s entries matching the filter.'), $this->rs_count) :
|
|
|
|
sprintf(__('List of %s entries.'), $this->rs_count)
|
2021-10-24 07:33:15 +00:00
|
|
|
). '</caption><tr>' . implode($cols) . '</tr>%s</table>%s</div>';
|
2021-08-23 22:52:29 +00:00
|
|
|
|
|
|
|
if ($enclose_block) {
|
|
|
|
$html_block = sprintf($enclose_block, $html_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
$blocks = explode('%s', $html_block);
|
|
|
|
|
2021-10-24 07:33:15 +00:00
|
|
|
echo $pager->getLinks() . $blocks[0];
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-08-23 22:52:29 +00:00
|
|
|
while ($this->rs->fetch()) {
|
2021-10-24 07:33:15 +00:00
|
|
|
echo $this->postLine(isset($periodical_entries[$this->rs->post_id]));
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-10-24 07:33:15 +00:00
|
|
|
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" /> %1$s';
|
|
|
|
|
|
|
|
echo $blocks[1] . '<p class="info">' . __('Legend: ') .
|
|
|
|
sprintf($img, __('Published'), 'check-on.png') . ' - ' .
|
|
|
|
sprintf($img, __('Unpublished'), 'check-off.png') . ' - ' .
|
|
|
|
sprintf($img, __('Scheduled'), 'scheduled.png') . ' - ' .
|
|
|
|
sprintf($img, __('Pending'), 'check-wrn.png') . ' - ' .
|
|
|
|
sprintf($img, __('Protected'), 'locker.png') . ' - ' .
|
|
|
|
sprintf($img, __('Selected'), 'selected.png') . ' - ' .
|
|
|
|
sprintf($img, __('Attachments'), 'attach.png') .
|
|
|
|
'</p>' . $blocks[2] . $pager->getLinks();
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
private function postLine($checked)
|
2021-08-23 22:52:29 +00:00
|
|
|
{
|
|
|
|
if ($this->core->auth->check('categories', $this->core->blog->id)) {
|
|
|
|
$cat_link = '<a href="category.php?id=%s">%s</a>';
|
|
|
|
} else {
|
|
|
|
$cat_link = '%2$s';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->rs->cat_title) {
|
|
|
|
$cat_title = sprintf(
|
|
|
|
$cat_link,
|
|
|
|
$this->rs->cat_id,
|
|
|
|
html::escapeHTML($this->rs->cat_title)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$cat_title = __('None');
|
|
|
|
}
|
|
|
|
|
|
|
|
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
|
|
|
|
switch ($this->rs->post_status)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
$img_status = sprintf($img, __('published'), 'check-on.png');
|
|
|
|
break;
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-08-23 22:52:29 +00:00
|
|
|
case 0:
|
|
|
|
$img_status = sprintf($img, __('unpublished'), 'check-off.png');
|
|
|
|
break;
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-08-23 22:52:29 +00:00
|
|
|
case -1:
|
|
|
|
$img_status = sprintf($img, __('scheduled'), 'scheduled.png');
|
|
|
|
break;
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2021-08-23 22:52:29 +00:00
|
|
|
case -2:
|
|
|
|
$img_status = sprintf($img, __('pending'), 'check-wrn.png');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$protected = '';
|
|
|
|
if ($this->rs->post_password) {
|
|
|
|
$protected = sprintf($img, __('protected'), 'locker.png');
|
|
|
|
}
|
|
|
|
|
|
|
|
$selected = '';
|
|
|
|
if ($this->rs->post_selected) {
|
|
|
|
$selected = sprintf($img, __('selected'), 'selected.png');
|
|
|
|
}
|
|
|
|
|
|
|
|
$attach = '';
|
|
|
|
$nb_media = $this->rs->countMedia();
|
|
|
|
if ($nb_media > 0) {
|
|
|
|
$attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
|
|
|
|
$attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png');
|
|
|
|
}
|
|
|
|
|
2021-10-24 07:33:15 +00:00
|
|
|
$cols = [
|
|
|
|
'check' => '<td class="minimal">' . form::checkbox(['periodical_entries[]'], $this->rs->post_id, ['checked' => $checked]) . '</td>',
|
|
|
|
'title' => '<td class="maximal"><a href="' . $this->rs->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '" ' .
|
|
|
|
'title="' . html::escapeHTML($this->rs->getURL()) . '">' . html::escapeHTML($this->rs->post_title) . '</a></td>',
|
|
|
|
'date' => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>',
|
|
|
|
'category' => '<td class="nowrap">' . $cat_title . '</td>',
|
|
|
|
'author' => '<td class="nowrap">' . $this->rs->user_id . '</td>',
|
|
|
|
'status' => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>',
|
|
|
|
'create' => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_creadt, $this->rs->core->auth->getInfo('user_tz')) . '</td>'
|
|
|
|
];
|
|
|
|
|
|
|
|
return '<tr class="line">' . implode($cols) . '</tr>';;
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
}
|