diff --git a/_admin.php b/_admin.php index 1fa7a86..63eff6f 100644 --- a/_admin.php +++ b/_admin.php @@ -29,6 +29,10 @@ $core->addBehavior( 'adminFiltersLists', ['adminPeriodical', 'adminFiltersLists'] ); +$core->addBehavior( + 'adminColumnsLists', + ['adminPeriodical', 'adminColumnsLists'] +); if ($core->blog->settings->periodical->periodical_active) { @@ -139,6 +143,20 @@ class adminPeriodical $blog_settings->periodical->put('periodical_updurl', !empty($_POST['periodical_updurl'])); } + public static function adminColumnsLists(dcCore $core, $cols) + { + $cols['periodical'] = [ + __('Periodical'), + [ + 'curdt' => [true, __('Next update')], + 'pub_int' => [true, __('Frequency')], + 'pub_nb' => [true, __('Pub per update')], + 'nbposts' => [true, __('Entries')], + 'enddt' => [true, __('End date')] + ] + ]; + } + public static function adminFiltersLists(dcCore $core, $sorts) { $sorts['periodical'] = [ diff --git a/inc/lib.index.pager.php b/inc/lib.index.pager.php index f562549..92ec098 100644 --- a/inc/lib.index.pager.php +++ b/inc/lib.index.pager.php @@ -22,91 +22,111 @@ if (!defined('DC_CONTEXT_ADMIN')) { */ class adminPeriodicalList extends adminGenericList { - public function periodDisplay($page, $nb_per_page, $enclose_block='') + public function periodDisplay($filter, $enclose_block='') { $echo = ''; if ($this->rs->isEmpty()) { - $echo .= '

' .__('No period') .'

'; + if ($filter->show()) { + echo '

' . __('No period matches the filter') . '

'; + } else { + echo '

' . __('No period') . '

'; + } } else { - $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); - $pager->html_prev = $this->html_prev; - $pager->html_next = $this->html_next; + $pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10); $pager->var_page = 'page'; - $html_block = - '
' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '%s
' . __('Name') . '' . __('Next update') . '' . __('Frequency') . '' . __('Publications') . '' . __('Entries') . '' . __('End date') . '
' . - '
'; + $periods = []; + if (isset($_REQUEST['periods'])) { + foreach ($_REQUEST['periods'] as $v) { + $periods[(integer) $v] = true; + } + } + $html_block = '
'; + + $cols = new ArrayObject([ + 'name' => '', + 'curdt' => '', + 'pub_int' => '', + 'pub_nb' => '', + 'nbposts' => '', + 'enddt' => '' + ]); + + $this->userColumns('periodical', $cols); + + $html_block .= '' . implode(iterator_to_array($cols)) . '%s
' . ($filter->show() ? + sprintf(__('List of %s periods matching the filter.'), $this->rs_count) : + sprintf(__('List of %s periods.'), $this->rs_count) + ). '
' . __('Name') . '' . __('Next update') . '' . __('Frequency') . '' . __('Pub per update') . '' . __('Entries') . '' . __('End date') . '
%s
'; if ($enclose_block) { $html_block = sprintf($enclose_block, $html_block); } - - $echo .= $pager->getLinks(); - $blocks = explode('%s', $html_block); - $echo .= $blocks[0]; + echo $pager->getLinks() . $blocks[0]; while ($this->rs->fetch()) { - $echo .= $this->periodLine(); + echo $this->periodLine(isset($periods[$this->rs->periodical_id])); } - $echo .= $blocks[1]; - - $echo .= $pager->getLinks(); + echo $blocks[1] . $blocks[2] . $pager->getLinks(); } - - return $echo; } - private function periodLine() + private function periodLine($checked) { - $nb_posts = $this->rs->periodical->getPosts(['periodical_id' => $this->rs->periodical_id], true); - $nb_posts = $nb_posts->f(0); - $style = !$nb_posts ? ' offline' : ''; - $posts_links = !$nb_posts ? - '0' : - '' . $nb_posts . ''; + $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]); - $pub_int = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ? + $name = '' . html::escapeHTML($this->rs->periodical_title) . ''; + + $posts = $nb_posts ? + '' . $nb_posts . '' : + '0'; + + $interval = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ? __(array_search($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo())) : __('Unknow frequence'); - $res = - '' . - '' . form::checkbox(['periods[]'], $this->rs->periodical_id) . '' . - '' . html::escapeHTML($this->rs->periodical_title) . '' . - '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '' . - '' . $pub_int . '' . - '' . $this->rs->periodical_pub_nb .'' . - '' . $posts_links . '' . - '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '' . - ''; + $cols = new ArrayObject([ + 'check' => '' . form::checkbox(['periods[]'], $this->rs->periodical_id, ['checked' => $checked]) . '', + 'name' => '' . $name . '', + 'curdt' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '', + 'pub_int' => '' . $interval . '', + 'pub_nb' => '' . $this->rs->periodical_pub_nb . '', + 'nbposts' => '' . $posts. '', + 'enddt' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '' + ]); - return $res; + $this->userColumns('periodical', $cols); + + return + '' . + implode(iterator_to_array($cols)) . + ''; } - public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='') + public function postDisplay($filter, $base_url, $enclose_block='') { $echo = ''; if ($this->rs->isEmpty()) { - $echo .= '

' . __('No entry') . '

'; + if ($filter->show()) { + echo '

' . __('No entry matches the filter') . '

'; + } else { + echo '

' . __('No entry') . '

'; + } } else { - $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); - $pager->html_prev = $this->html_prev; - $pager->html_next = $this->html_next; + $pager = new dcPager($filter->page, $this->rs_count, $filter->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[(integer) $v] = true; + } + } + $html_block = '' . '' . @@ -128,7 +148,7 @@ class adminPeriodicalList extends adminGenericList $echo .= $blocks[0]; while ($this->rs->fetch()) { - $echo .= $this->postLine(); + $echo .= $this->postLine(isset($periodical_entries[$this->rs->post_id])); } $echo .= $blocks[1]; @@ -139,7 +159,7 @@ class adminPeriodicalList extends adminGenericList return $echo; } - private function postLine() + private function postLine($checked) { if ($this->core->auth->check('categories', $this->core->blog->id)) { $cat_link = '%s'; diff --git a/index.php b/index.php index d9e458f..03ecf2a 100644 --- a/index.php +++ b/index.php @@ -18,12 +18,10 @@ if (!defined('DC_CONTEXT_ADMIN')) { dcPage::check('usage,contentadmin'); # Objects -$s = $core->blog->settings->periodical; $per = new periodical($core); # Default values $action = isset($_POST['action']) ? $_POST['action'] : ''; -$part = isset($_REQUEST['part']) && $_REQUEST['part'] == 'period' ? 'period' : 'periods'; ############################################################ # @@ -31,17 +29,17 @@ $part = isset($_REQUEST['part']) && $_REQUEST['part'] == 'period' ? 'period' : ' # ############################################################ -if ($part == 'period') { +if ($_REQUEST['part'] == 'period') { $starting_script = ''; # Default value for period - $period_id = null; - $period_title = __('One post per day'); - $period_pub_nb = 1; + $period_id = null; + $period_title = __('One post per day'); + $period_pub_nb = 1; $period_pub_int = 'day'; - $period_curdt = date('Y-m-d H:i:00', time()); - $period_enddt = date('Y-m-d H:i:00', time() + 31536000); //one year + $period_curdt = date('Y-m-d H:i:00', time()); + $period_enddt = date('Y-m-d H:i:00', time() + 31536000); //one year # Get period if (!empty($_REQUEST['period_id'])) { @@ -52,20 +50,17 @@ if ($part == 'period') { $core->error->add(__('This period does not exist.')); $period_id = null; } else { - $period_id = $rs->periodical_id; - $period_title = $rs->periodical_title; - $period_pub_nb = $rs->periodical_pub_nb; + $period_id = $rs->periodical_id; + $period_title = $rs->periodical_title; + $period_pub_nb = $rs->periodical_pub_nb; $period_pub_int = $rs->periodical_pub_int; - $period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt)); - $period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt)); - - //todo load related posts + $period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt)); + $period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt)); } } # Set period if ($action == 'setperiod') { - # Get POST values if (!empty($_POST['period_title'])) { $period_title = $_POST['period_title']; @@ -74,7 +69,8 @@ if ($part == 'period') { $period_pub_nb = abs((integer) $_POST['period_pub_nb']); } if (!empty($_POST['period_pub_int']) - && in_array($_POST['period_pub_int'], $per->getTimesCombo())) { + && in_array($_POST['period_pub_int'], $per->getTimesCombo()) + ) { $period_pub_int = $_POST['period_pub_int']; } if (!empty($_POST['period_curdt'])) { @@ -104,17 +100,15 @@ if ($part == 'period') { # If no error, set period if (!$core->error->flag()) { - $cur = $per->openCursor(); - $cur->periodical_title = $period_title; - $cur->periodical_curdt = $period_curdt; - $cur->periodical_enddt = $period_enddt; + $cur->periodical_title = $period_title; + $cur->periodical_curdt = $period_curdt; + $cur->periodical_enddt = $period_enddt; $cur->periodical_pub_int = $period_pub_int; - $cur->periodical_pub_nb = $period_pub_nb; + $cur->periodical_pub_nb = $period_pub_nb; # Update period if ($period_id) { - $per->updPeriod($period_id, $cur); dcPage::addSuccessNotice( @@ -122,7 +116,6 @@ if ($part == 'period') { ); # Create period } else { - $period_id = $per->addPeriod($cur); dcPage::addSuccessNotice( @@ -130,16 +123,16 @@ if ($part == 'period') { ); } - http::redirect(empty($_POST['redir']) ? - $p_url . '&part=period&period_id=' . $period_id . '#period' : - $_POST['redir'] - ); + if (!empty($_POST['redir'])) { + http::redirect($_POST['redir']); + } else { + $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period'); + } } } # Actions on related posts if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) { - # Publish posts if ($action == 'publish') { try { @@ -153,10 +146,11 @@ if ($part == 'period') { __('Entries successfully published.') ); - http::redirect(empty($_POST['redir']) ? - $p_url . '&part=period&period_id=' . $period_id . '#posts' : - $_POST['redir'] - ); + if (!empty($_POST['redir'])) { + http::redirect($_POST['redir']); + } else { + $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); + } } catch (Exception $e) { $core->error->add($e->getMessage()); } @@ -175,10 +169,11 @@ if ($part == 'period') { __('Entries successfully unpublished.') ); - http::redirect(empty($_POST['redir']) ? - $p_url . '&part=period&period_id=' . $period_id . '#posts' : - $_POST['redir'] - ); + if (!empty($_POST['redir'])) { + http::redirect($_POST['redir']); + } else { + $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); + } } catch (Exception $e) { $core->error->add($e->getMessage()); } @@ -196,10 +191,11 @@ if ($part == 'period') { __('Entries successfully removed.') ); - http::redirect(empty($_POST['redir']) ? - $p_url . '&part=period&period_id=' . $period_id . '#posts' : - $_POST['redir'] - ); + if (!empty($_POST['redir'])) { + http::redirect($_POST['redir']); + } else { + $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); + } } catch (Exception $e) { $core->error->add($e->getMessage()); } @@ -213,7 +209,8 @@ if ($part == 'period') { $post_filter->add('part', 'period'); $params = $post_filter->params(); - $params['no_content'] = true; + $params['periodical_id'] = $period_id; + $params['no_content'] = true; # Get posts try { @@ -249,9 +246,7 @@ if ($part == 'period') { # Period form echo ' -
+

' . (null === $period_id ? __('New period') : __('Edit period')) . '

' . @@ -311,22 +306,18 @@ if ($part == 'period') { '#posts'; echo ' -

'; +

' . __('Entries linked to this period') . '

'; # Filters - $post_filter->display(['admin.plugin.periodical','#posts'], - $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [ - 'p' => 'periodical', - 'part' => 'period', - 'period_id' => $period_id + $post_filter->display(['admin.plugin.periodical', '#posts'], + $core->adminurl->getHiddenFormFields('admin.plugin.periodical', [ + 'period_id' => $period_id, + 'part' => 'period' ]) ); # Posts list - echo - $post_list->postDisplay($post_filter->page, $post_filter->nb, $base_url, + echo $post_list->postDisplay($post_filter, $base_url, '' . '%s' . @@ -337,10 +328,10 @@ if ($part == 'period') { '

' . __('Selected entries action:') . ' ' . form::combo('action', $combo_action) . '

' . - $core->adminurl->getHiddenFormFields('admin.plugin.periodical', $post_filter->values()) . - form::hidden(['period_id'], $period_id) . - form::hidden(['p'], 'periodical') . - form::hidden(['redir'], sprintf($base_url, $post_filter->page)) . + $core->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [ + 'period_id' => $period_id, + 'redir' => sprintf($base_url, $post_filter->page) + ])) . $core->formNonce() . '
' . '' @@ -371,10 +362,11 @@ if ($part == 'period') { __('Periods removed.') ); - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=periods' : - $_POST['redir'] - ); + if (!empty($_POST['redir'])) { + http::redirect($_POST['redir']); + } else { + $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']); + } } catch (Exception $e) { $core->error->add($e->getMessage()); } @@ -391,10 +383,11 @@ if ($part == 'period') { __('Periods emptied.') ); - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=periods' : - $_POST['redir'] - ); + if (!empty($_POST['redir'])) { + http::redirect($_POST['redir']); + } else { + $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']); + } } catch (Exception $e) { $core->error->add($e->getMessage()); } @@ -428,12 +421,10 @@ if ($part == 'period') { '' . '' . - dcPage::breadcrumb( - [ + dcPage::breadcrumb([ html::escapeHTML($core->blog->name) => '', __('Periodical') => '' - ] - ) . + ]) . dcPage::notices() . '

@@ -443,8 +434,8 @@ if ($part == 'period') { # Filters $p_filter->display('admin.plugin.periodical', form::hidden('p', 'periodical') . form::hidden('part', 'periods')); - # Posts list - echo $period_list->periodDisplay($p_filter->page, $p_filter->nb, + # Periods list + $period_list->periodDisplay($p_filter, '
' . '%s' .

' . __('Title') . '