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 = - '' . __('Name') . ' | ' . - '' . __('Next update') . ' | ' . - '' . __('Frequency') . ' | ' . - '' . __('Publications') . ' | ' . - '' . __('Entries') . ' | ' . - '' . __('End date') . ' | ' . - '
---|
' . __('Name') . ' | ', + 'curdt' => '' . __('Next update') . ' | ', + 'pub_int' => '' . __('Frequency') . ' | ', + 'pub_nb' => '' . __('Pub per update') . ' | ', + 'nbposts' => '' . __('Entries') . ' | ', + 'enddt' => '' . __('End date') . ' | ' + ]); + + $this->userColumns('periodical', $cols); + + $html_block .= '
---|
' . __('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 = '' . __('Title') . ' | ' . @@ -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 ' -
---|