2021-08-23 11:24:19 +00:00
|
|
|
<?php
|
2023-10-19 20:32:21 +00:00
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\periodical;
|
|
|
|
|
|
|
|
use ArrayObject;
|
2023-10-19 20:32:21 +00:00
|
|
|
use Dotclear\App;
|
2023-07-29 20:48:09 +00:00
|
|
|
use Dotclear\Core\Backend\Filter\{
|
|
|
|
Filters,
|
|
|
|
FilterPosts
|
|
|
|
};
|
|
|
|
use Dotclear\Core\Backend\Listing\{
|
|
|
|
Listing,
|
|
|
|
Pager
|
|
|
|
};
|
2023-04-22 16:59:33 +00:00
|
|
|
use Dotclear\Helper\Date;
|
2023-04-08 12:15:18 +00:00
|
|
|
use Dotclear\Helper\Html\Form\Checkbox;
|
|
|
|
use Dotclear\Helper\Html\Html;
|
2021-08-23 11:24:19 +00:00
|
|
|
|
|
|
|
/**
|
2023-10-19 20:32:21 +00:00
|
|
|
* @brief periodical periods list class.
|
|
|
|
* @ingroup periodical
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
2021-08-23 11:24:19 +00:00
|
|
|
*/
|
2023-07-29 20:48:09 +00:00
|
|
|
class ManageList extends Listing
|
2021-08-23 11:24:19 +00:00
|
|
|
{
|
2023-04-22 22:14:18 +00:00
|
|
|
/**
|
|
|
|
* Display periods list.
|
|
|
|
*
|
2023-07-29 20:48:09 +00:00
|
|
|
* @param Filters $filter The periods filter
|
|
|
|
* @param string $enclose_block The enclose block
|
2023-04-22 22:14:18 +00:00
|
|
|
*/
|
2023-07-29 20:48:09 +00:00
|
|
|
public function periodDisplay(Filters $filter, string $enclose_block = ''): void
|
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 {
|
2023-07-29 20:48:09 +00:00
|
|
|
$pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
|
2023-03-24 22:12:11 +00:00
|
|
|
$pager->var_page = 'page';
|
2021-08-23 22:52:29 +00:00
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
$periods = [];
|
|
|
|
if (isset($_REQUEST['periods'])) {
|
|
|
|
foreach ($_REQUEST['periods'] as $v) {
|
2022-11-14 21:08:00 +00:00
|
|
|
$periods[(int) $v] = true;
|
2021-10-23 12:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 21:08:00 +00:00
|
|
|
$html_block = '<div class="table-outer"><table><caption>' . (
|
|
|
|
$filter->show() ?
|
2021-10-23 12:44:54 +00:00
|
|
|
sprintf(__('List of %s periods matching the filter.'), $this->rs_count) :
|
|
|
|
sprintf(__('List of %s periods.'), $this->rs_count)
|
2022-11-14 21:08:00 +00:00
|
|
|
) . '</caption>';
|
2021-10-23 12:44:54 +00:00
|
|
|
|
|
|
|
$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>',
|
2022-11-14 21:08:00 +00:00
|
|
|
'enddt' => '<th scope="col" class="nowrap">' . __('End date') . '</th>',
|
2021-10-23 12:44:54 +00:00
|
|
|
]);
|
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
$this->userColumns(My::id(), $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()) {
|
2023-04-22 22:14:18 +00:00
|
|
|
$this->periodLine(isset($periods[(int) $this->rs->f('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
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
/**
|
|
|
|
* Display a period list line.
|
|
|
|
*
|
|
|
|
* @param bool $checked Selected line
|
|
|
|
*/
|
|
|
|
private function periodLine(bool $checked): void
|
2021-08-23 22:52:29 +00:00
|
|
|
{
|
2023-10-19 20:32:21 +00:00
|
|
|
$tz = App::auth()->getInfo('user_tz');
|
2023-03-24 22:12:11 +00:00
|
|
|
$nb_posts = Utils::getPosts(['periodical_id' => $this->rs->f('periodical_id')], true)->f(0);
|
2023-07-29 20:48:09 +00:00
|
|
|
$url = My::manageUrl(['part' => 'period', 'period_id' => $this->rs->f('periodical_id')]);
|
2023-04-22 22:14:18 +00:00
|
|
|
$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';
|
2023-03-24 22:12:11 +00:00
|
|
|
$interval = in_array($this->rs->f('periodical_pub_int'), My::periodCombo()) ?
|
|
|
|
__((string) array_search($this->rs->f('periodical_pub_int'), My::periodCombo())) : __('Unknow frequence');
|
2021-08-23 22:52:29 +00:00
|
|
|
|
2021-10-23 12:44:54 +00:00
|
|
|
$cols = new ArrayObject([
|
2023-04-08 12:15:18 +00:00
|
|
|
'check' => '<td class="nowrap">' . (new Checkbox(['periods[]'], $checked))->value($this->rs->f('periodical_id'))->render() . '</td>',
|
2021-10-23 12:44:54 +00:00
|
|
|
'name' => '<td class="maximal">' . $name . '</td>',
|
2023-04-22 22:14:18 +00:00
|
|
|
'curdt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_curdt'), $tz ?? 'UTC') . '</td>',
|
2021-10-23 12:44:54 +00:00
|
|
|
'pub_int' => '<td class="nowrap">' . $interval . '</td>',
|
2023-03-24 22:12:11 +00:00
|
|
|
'pub_nb' => '<td class="nowrap count">' . $this->rs->f('periodical_pub_nb') . '</td>',
|
2022-11-14 21:08:00 +00:00
|
|
|
'nbposts' => '<td class="nowrap count">' . $posts . '</td>',
|
2023-04-22 22:14:18 +00:00
|
|
|
'enddt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_enddt'), $tz ?? 'UTC') . '</td>',
|
2021-10-23 12:44:54 +00:00
|
|
|
]);
|
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
$this->userColumns(My::id(), $cols);
|
2021-10-23 12:44:54 +00:00
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
echo
|
|
|
|
'<tr class="line ' . ($nb_posts ? '' : ' offline') . '" id="p' . $this->rs->f('periodical_id') . '">' .
|
|
|
|
implode(iterator_to_array($cols)) .
|
|
|
|
'</tr>';
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
/**
|
|
|
|
* Display period posts list.
|
|
|
|
*
|
2023-07-29 20:48:09 +00:00
|
|
|
* @param FilterPosts $filter The posts filter
|
|
|
|
* @param string $base_url The page base URL
|
|
|
|
* @param string $enclose_block The enclose block
|
2023-04-22 22:14:18 +00:00
|
|
|
*/
|
2023-07-29 20:48:09 +00:00
|
|
|
public function postDisplay(FilterPosts $filter, string $base_url, string $enclose_block = ''): void
|
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 {
|
2023-07-29 20:48:09 +00:00
|
|
|
$pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('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) {
|
2022-11-14 21:08:00 +00:00
|
|
|
$periodical_entries[(int) $v] = true;
|
2021-10-23 12:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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>',
|
2022-11-14 21:08:00 +00:00
|
|
|
'create' => '<th scope="col" class="nowrap">' . __('Create date') . '</th>',
|
2021-10-24 07:33:15 +00:00
|
|
|
];
|
|
|
|
|
2022-11-14 21:08:00 +00:00
|
|
|
$html_block = '<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)
|
2022-11-14 21:08:00 +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()) {
|
2023-04-22 22:14:18 +00:00
|
|
|
$this->postLine(isset($periodical_entries[(int) $this->rs->f('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
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
/**
|
|
|
|
* Display post list line.
|
|
|
|
*
|
|
|
|
* @param bool $checked Selected line
|
|
|
|
*/
|
|
|
|
private function postLine(bool $checked): void
|
2021-08-23 22:52:29 +00:00
|
|
|
{
|
2023-10-19 20:32:21 +00:00
|
|
|
if (App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_CATEGORIES]), App::blog()->id())) {
|
2021-08-23 22:52:29 +00:00
|
|
|
$cat_link = '<a href="category.php?id=%s">%s</a>';
|
|
|
|
} else {
|
|
|
|
$cat_link = '%2$s';
|
|
|
|
}
|
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
if ($this->rs->f('cat_title')) {
|
2021-08-23 22:52:29 +00:00
|
|
|
$cat_title = sprintf(
|
|
|
|
$cat_link,
|
2023-03-24 22:12:11 +00:00
|
|
|
$this->rs->f('cat_id'),
|
2023-04-08 12:15:18 +00:00
|
|
|
Html::escapeHTML($this->rs->f('cat_title'))
|
2021-08-23 22:52:29 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$cat_title = __('None');
|
|
|
|
}
|
|
|
|
|
2022-11-14 21:08:00 +00:00
|
|
|
$img_status = '';
|
|
|
|
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
|
2023-03-24 22:12:11 +00:00
|
|
|
switch ((int) $this->rs->f('post_status')) {
|
2023-10-19 20:32:21 +00:00
|
|
|
case App::blog()::POST_PUBLISHED:
|
2021-08-23 22:52:29 +00:00
|
|
|
$img_status = sprintf($img, __('published'), 'check-on.png');
|
2022-11-14 21:08:00 +00:00
|
|
|
|
|
|
|
break;
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2023-10-19 20:32:21 +00:00
|
|
|
case App::blog()::POST_UNPUBLISHED:
|
2021-08-23 22:52:29 +00:00
|
|
|
$img_status = sprintf($img, __('unpublished'), 'check-off.png');
|
2022-11-14 21:08:00 +00:00
|
|
|
|
|
|
|
break;
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2023-10-19 20:32:21 +00:00
|
|
|
case App::blog()::POST_SCHEDULED:
|
2021-08-23 22:52:29 +00:00
|
|
|
$img_status = sprintf($img, __('scheduled'), 'scheduled.png');
|
2022-11-14 21:08:00 +00:00
|
|
|
|
|
|
|
break;
|
2021-09-02 12:56:02 +00:00
|
|
|
|
2023-10-19 20:32:21 +00:00
|
|
|
case App::blog()::POST_PENDING:
|
2021-08-23 22:52:29 +00:00
|
|
|
$img_status = sprintf($img, __('pending'), 'check-wrn.png');
|
2022-11-14 21:08:00 +00:00
|
|
|
|
|
|
|
break;
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$protected = '';
|
2023-03-24 22:12:11 +00:00
|
|
|
if ($this->rs->f('post_password')) {
|
2021-08-23 22:52:29 +00:00
|
|
|
$protected = sprintf($img, __('protected'), 'locker.png');
|
|
|
|
}
|
|
|
|
|
|
|
|
$selected = '';
|
2023-03-24 22:12:11 +00:00
|
|
|
if ($this->rs->f('post_selected')) {
|
2021-08-23 22:52:29 +00:00
|
|
|
$selected = sprintf($img, __('selected'), 'selected.png');
|
|
|
|
}
|
|
|
|
|
2022-11-14 21:08:00 +00:00
|
|
|
$attach = '';
|
2021-08-23 22:52:29 +00:00
|
|
|
$nb_media = $this->rs->countMedia();
|
|
|
|
if ($nb_media > 0) {
|
|
|
|
$attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
|
2022-11-14 21:08:00 +00:00
|
|
|
$attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png');
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 20:32:21 +00:00
|
|
|
$tz = App::auth()->getInfo('user_tz');
|
2023-04-22 22:14:18 +00:00
|
|
|
|
2021-10-24 07:33:15 +00:00
|
|
|
$cols = [
|
2023-04-08 12:15:18 +00:00
|
|
|
'check' => '<td class="minimal">' . (new Checkbox(['periodical_entries[]'], $checked))->value($this->rs->f('post_id'))->render() . '</td>',
|
2023-10-19 20:32:21 +00:00
|
|
|
'title' => '<td class="maximal"><a href="' . App::postTypes()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '" ' .
|
2023-04-08 12:15:18 +00:00
|
|
|
'title="' . Html::escapeHTML($this->rs->getURL()) . '">' . Html::escapeHTML($this->rs->post_title) . '</a></td>',
|
2023-04-22 16:59:33 +00:00
|
|
|
'date' => '<td class="nowrap">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . '</td>',
|
2021-10-24 07:33:15 +00:00
|
|
|
'category' => '<td class="nowrap">' . $cat_title . '</td>',
|
2023-03-24 22:12:11 +00:00
|
|
|
'author' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>',
|
2021-10-24 07:33:15 +00:00
|
|
|
'status' => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>',
|
2023-04-22 22:14:18 +00:00
|
|
|
'create' => '<td class="nowrap">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_creadt'), $tz ?? 'UTC') . '</td>',
|
2021-10-24 07:33:15 +00:00
|
|
|
];
|
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
echo '<tr class="line">' . implode($cols) . '</tr>';
|
2021-08-23 22:52:29 +00:00
|
|
|
}
|
2022-11-14 21:08:00 +00:00
|
|
|
}
|