rs->isEmpty()) {
if ($filter->show()) {
echo '
' . __('No period matches the filter') . '
';
} else {
echo '' . __('No period') . '
';
}
} else {
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
$pager->var_page = 'page';
$periods = [];
if (isset($_REQUEST['periods'])) {
foreach ($_REQUEST['periods'] as $v) {
$periods[(int) $v] = true;
}
}
$html_block = '' . (
$filter->show() ?
sprintf(__('List of %s periods matching the filter.'), $this->rs_count) :
sprintf(__('List of %s periods.'), $this->rs_count)
) . '';
$cols = new ArrayObject([
'name' => '' . __('Name') . ' | ',
'curdt' => '' . __('Next update') . ' | ',
'pub_int' => '' . __('Frequency') . ' | ',
'pub_nb' => '' . __('Entries per update') . ' | ',
'nbposts' => '' . __('Entries') . ' | ',
'enddt' => '' . __('End date') . ' | ',
]);
$this->userColumns(My::id(), $cols);
$html_block .= '' . 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->periodLine(isset($periods[(int) $this->rs->f('periodical_id')]));
}
echo $blocks[1] . $blocks[2] . $pager->getLinks();
}
}
private function periodLine(bool $checked): string
{
$nb_posts = Utils::getPosts(['periodical_id' => $this->rs->f('periodical_id')], true)->f(0);
$url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $this->rs->f('periodical_id')]);
$name = '' . html::escapeHTML($this->rs->periodical_title) . '';
$posts = $nb_posts ?
'' . $nb_posts . '' :
'0';
$interval = in_array($this->rs->f('periodical_pub_int'), My::periodCombo()) ?
__((string) array_search($this->rs->f('periodical_pub_int'), My::periodCombo())) : __('Unknow frequence');
$cols = new ArrayObject([
'check' => '' . form::checkbox(['periods[]'], $this->rs->f('periodical_id'), ['checked' => $checked]) . ' | ',
'name' => '' . $name . ' | ',
'curdt' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_curdt'), dcCore::app()->auth->getInfo('user_tz')) . ' | ',
'pub_int' => '' . $interval . ' | ',
'pub_nb' => '' . $this->rs->f('periodical_pub_nb') . ' | ',
'nbposts' => '' . $posts . ' | ',
'enddt' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_enddt'), dcCore::app()->auth->getInfo('user_tz')) . ' | ',
]);
$this->userColumns(My::id(), $cols);
return
'' .
implode(iterator_to_array($cols)) .
'
';
}
public function postDisplay(adminPostFilter $filter, string $base_url, string $enclose_block = ''): void
{
$echo = '';
if ($this->rs->isEmpty()) {
if ($filter->show()) {
echo '' . __('No entry matches the filter') . '
';
} else {
echo '' . __('No entry') . '
';
}
} else {
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
$pager->base_url = $base_url;
$pager->var_page = 'page';
$periodical_entries = [];
if (isset($_REQUEST['periodical_entries'])) {
foreach ($_REQUEST['periodical_entries'] as $v) {
$periodical_entries[(int) $v] = true;
}
}
$cols = [
'title' => '' . __('Title') . ' | ',
'date' => '' . __('Date') . ' | ',
'category' => '' . __('Category') . ' | ',
'author' => '' . __('Author') . ' | ',
'status' => '' . __('Status') . ' | ',
'create' => '' . __('Create date') . ' | ',
];
$html_block = '' . (
$filter->show() ?
sprintf(__('List of %s entries matching the filter.'), $this->rs_count) :
sprintf(__('List of %s entries.'), $this->rs_count)
) . '' . implode($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->postLine(isset($periodical_entries[(int) $this->rs->f('post_id')]));
}
$img = ' %1$s';
echo $blocks[1] . '' . __('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') .
'
' . $blocks[2] . $pager->getLinks();
}
}
private function postLine(bool $checked): string
{
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CATEGORIES]), dcCore::app()->blog->id)) {
$cat_link = '%s';
} else {
$cat_link = '%2$s';
}
if ($this->rs->f('cat_title')) {
$cat_title = sprintf(
$cat_link,
$this->rs->f('cat_id'),
html::escapeHTML($this->rs->f('cat_title'))
);
} else {
$cat_title = __('None');
}
$img_status = '';
$img = '';
switch ((int) $this->rs->f('post_status')) {
case dcBlog::POST_PUBLISHED:
$img_status = sprintf($img, __('published'), 'check-on.png');
break;
case dcBlog::POST_UNPUBLISHED:
$img_status = sprintf($img, __('unpublished'), 'check-off.png');
break;
case dcBlog::POST_SCHEDULED:
$img_status = sprintf($img, __('scheduled'), 'scheduled.png');
break;
case dcBlog::POST_PENDING:
$img_status = sprintf($img, __('pending'), 'check-wrn.png');
break;
}
$protected = '';
if ($this->rs->f('post_password')) {
$protected = sprintf($img, __('protected'), 'locker.png');
}
$selected = '';
if ($this->rs->f('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');
}
$cols = [
'check' => '' . form::checkbox(['periodical_entries[]'], $this->rs->f('post_id'), ['checked' => $checked]) . ' | ',
'title' => 'rs->getURL()) . '">' . html::escapeHTML($this->rs->post_title) . ' | ',
'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . ' | ',
'category' => '' . $cat_title . ' | ',
'author' => '' . $this->rs->f('user_id') . ' | ',
'status' => '' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . ' | ',
'create' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_creadt'), dcCore::app()->auth->getInfo('user_tz')) . ' | ',
];
return '' . implode($cols) . '
';
;
}
}