From 4169b0533ffa4ef442e94b0b9b5143b8351c3c23 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 10 Oct 2021 00:43:37 +0200 Subject: [PATCH] User pref columns and filters : part 2 : entries --- _admin.php | 28 +++- _prepend.php | 1 + inc/lib.zcfs.list.php | 273 +++++++++++++++++++++++++------- index.php | 277 +++++---------------------------- js/{feedsfilter.js => list.js} | 0 js/postsfilter.js | 31 ---- 6 files changed, 288 insertions(+), 322 deletions(-) rename js/{feedsfilter.js => list.js} (100%) delete mode 100644 js/postsfilter.js diff --git a/_admin.php b/_admin.php index feba04f..5232e54 100644 --- a/_admin.php +++ b/_admin.php @@ -69,6 +69,17 @@ class zcfsAdminBehaviors ]; } + public static function entriesSortbyCombo() + { + return [ + __('Date') => 'post_dt', + __('Title') => 'post_title', + __('Category') => 'cat_title', + __('Author') => 'user_id', + __('Status') => 'post_status' + ]; + } + /** * Favorites. * @@ -141,6 +152,14 @@ class zcfsAdminBehaviors 'entries' => [true, __('Entries')] ] ]; + $cols['zcfs_entries'] = [ + __('Feeds server: Entries'), + [ + 'date' => [true, __('Date')], + 'category' => [true, __('Category')], + 'author' => [true, __('Author')] + ] + ]; } /** @@ -156,7 +175,14 @@ class zcfsAdminBehaviors self::feedsSortbyCombo(), 'lowername', 'asc', - [__('Links per page'), 30] + [__('feeds per page'), 30] + ]; + $sorts['zcfs_entries'] = [ + __('Feeds server: Entries'), + self::entriesSortbyCombo(), + 'post_dt', + 'desc', + [__('entries per page'), 30] ]; } diff --git a/_prepend.php b/_prepend.php index 3afead4..5f7da75 100644 --- a/_prepend.php +++ b/_prepend.php @@ -20,6 +20,7 @@ $d = dirname(__FILE__).'/inc/'; $__autoload['zoneclearFeedServer'] = $d . 'class.zoneclear.feed.server.php'; $__autoload['zcfsFeedsList'] = $d . 'lib.zcfs.list.php'; $__autoload['zcfsEntriesList'] = $d . 'lib.zcfs.list.php'; +$__autoload['adminZcfsPostFilter'] = $d . 'lib.zcfs.list.php'; $__autoload['zcfsFeedsActionsPage'] = $d . 'class.zcfs.feedsactions.php'; $__autoload['zcfsDefaultFeedsActions'] = $d . 'class.zcfs.feedsactions.php'; diff --git a/inc/lib.zcfs.list.php b/inc/lib.zcfs.list.php index 88423cd..0d484fb 100644 --- a/inc/lib.zcfs.list.php +++ b/inc/lib.zcfs.list.php @@ -45,7 +45,7 @@ class zcfsFeedsList extends adminGenericList '' . ''; $cols = [ @@ -145,40 +145,63 @@ class zcfsFeedsList extends adminGenericList */ class zcfsEntriesList extends adminGenericList { - public function display($page, $nb_per_page, $url, $enclose='') + public function display($page, $nb_per_page, $base_url, $enclose_block = '', $filter = false) { if ($this->rs->isEmpty()) { + echo '

' . ($filter ? + __('No entries matches the filter') : + __('No entries') + ) . '

'; + } else { + $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); + $pager->base_url = $base_url; - return '

'.__('No entry').'

'; + $entries = []; + if (isset($_REQUEST['feeds'])) { + foreach ($_REQUEST['feeds'] as $v) { + $entries[(integer) $v] = true; + } + } + + $html_block = '
' . + '
' . ($filter ? sprintf(__('List of %s feeds matching the filter.'), $this->rs_count) : - sprintf(__('List of entries (%s)'), $this->rs_count) + sprintf(__('List of feeds (%s)'), $this->rs_count) ) . '
' . + ''; + + $cols = [ + 'title' => '', + 'date' => '', + 'author' => '', + 'category' => '', + 'status' => '' + ]; + + $cols = new ArrayObject($cols); + $this->core->callBehavior('adminZcfsPostListHeader', $this->core, $this->rs, $cols); + + $this->userColumns('zcfs_entries', $cols); + + $html_block .= '' . implode(iterator_to_array($cols)) . '%s
' . ($filter ? + sprintf(__('List of %s entries matching the filter.'), $this->rs_count) : + sprintf(__('List of entries (%s)'), $this->rs_count) + ) . '
' . __('Title') . '' . __('Date') . '' . __('Author') . '' . __('Category') . '' . __('Status') . '
'; + if ($enclose_block) { + $html_block = sprintf($enclose_block, $html_block); + } + + echo $pager->getLinks(); + + $blocks = explode('%s', $html_block); + + echo $blocks[0]; + + while ($this->rs->fetch()) { + echo $this->postLine(isset($entries[$this->rs->post_id])); + } + + echo $blocks[1]; + + echo $pager->getLinks(); } - - $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); - $pager->base_url = $url; - $pager->html_prev = $this->html_prev; - $pager->html_next = $this->html_next; - $pager->var_page = 'page'; - - $html_block = - '
'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - '%s
'.__('Title').''.__('Date').''.__('Category').''.__('Author').''.__('Comments').''.__('Trackbacks').''.__('Status').'
'; - - $res = ''; - while ($this->rs->fetch()) { - $res .= $this->postLine(); - } - - return - $pager->getLinks(). - sprintf($enclose, sprintf($html_block, $res)). - $pager->getLinks(); } private function postLine() @@ -191,36 +214,182 @@ class zcfsEntriesList extends adminGenericList sprintf($cat_link,$this->rs->cat_id, html::escapeHTML($this->rs->cat_title)) : __('None'); - $img = '%1$s'; + $img = '%1$s'; + $img_status = ''; + $sts_class = ''; switch ($this->rs->post_status) { case 1: - $img_status = sprintf($img, __('published'), 'check-on.png'); + $img_status = sprintf($img, __('Published'), 'check-on.png'); + $sts_class = 'sts-online'; + break; case 0: - $img_status = sprintf($img, __('unpublished'), 'check-off.png'); + $img_status = sprintf($img, __('Unpublished'), 'check-off.png'); + $sts_class = 'sts-offline'; + break; case -1: - $img_status = sprintf($img, __('scheduled'), 'scheduled.png'); + $img_status = sprintf($img, __('Scheduled'), 'scheduled.png'); + $sts_class = 'sts-scheduled'; + break; case -2: - $img_status = sprintf($img, __('pending'), 'check-wrn.png'); + $img_status = sprintf($img, __('Pending'), 'check-wrn.png'); + $sts_class = 'sts-pending'; + break; } - return - ''. - ''. - form::checkbox(array('entries[]'), $this->rs->post_id, '', '', '', !$this->rs->isEditable()).''. - ''. - html::escapeHTML($this->rs->post_title).''. - ''.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt).''. - ''.$cat_title.''. - ''.$this->rs->user_id.''. - ''.$this->rs->nb_comment.''. - ''.$this->rs->nb_trackback.''. - ''.$img_status.''. - ''; + $res = ''; + + $cols = [ + 'check' => ''. + form::checkbox(array('entries[]'), $this->rs->post_id, '', '', '', !$this->rs->isEditable()).'', + 'title' => '' . + html::escapeHTML(trim(html::clean($this->rs->post_title))) . '', + 'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '', + 'author' => '' . html::escapeHTML($this->rs->user_id) . '', + 'category' => ''.$cat_title.'', + 'status' => '' . $img_status . '' + ]; + + $cols = new ArrayObject($cols); + $this->core->callBehavior('adminZcfsPostListValue', $this->core, $this->rs, $cols); + + $this->userColumns('zcfs_entries', $cols); + + $res .= implode(iterator_to_array($cols)); + $res .= ''; + + return $res; } -} \ No newline at end of file +} + +class adminZcfsPostFilter extends adminGenericFilter +{ + public function __construct(dcCore $core) + { + parent::__construct($core, 'zcfs_entries'); + + $filters = new arrayObject([ + dcAdminFilters::getPageFilter(), + $this->getPostUserFilter(), + $this->getPostCategoriesFilter(), + $this->getPostStatusFilter(), + $this->getPostMonthFilter() + ]); + + # --BEHAVIOR-- adminPostFilter + $core->callBehavior('adminZcfsPostFilter', $core, $filters); + + $filters = $filters->getArrayCopy(); + + $this->add($filters); + } + + /** + * Posts users select + */ + public function getPostUserFilter(): ?dcAdminFilter + { + $users = null; + try { + $users = $this->core->blog->getPostsUsers(); + if ($users->isEmpty()) { + return null; + } + } catch (Exception $e) { + $this->core->error->add($e->getMessage()); + return null; + } + + $combo = dcAdminCombos::getUsersCombo($users); + dcUtils::lexicalKeySort($combo); + + return (new dcAdminFilter('user_id')) + ->param() + ->title(__('Author:')) + ->options(array_merge( + ['-' => ''], + $combo + )) + ->prime(true); + } + + /** + * Posts categories select + */ + public function getPostCategoriesFilter(): ?dcAdminFilter + { + $categories = null; + try { + $categories = $this->core->blog->getCategories(); + if ($categories->isEmpty()) { + return null; + } + } catch (Exception $e) { + $this->core->error->add($e->getMessage()); + return null; + } + + $combo = [ + '-' => '', + __('(No cat)') => 'NULL' + ]; + while ($categories->fetch()) { + $combo[ + str_repeat(' ', ($categories->level - 1) * 4) . + html::escapeHTML($categories->cat_title) . ' (' . $categories->nb_post . ')' + ] = $categories->cat_id; + } + + return (new dcAdminFilter('cat_id')) + ->param() + ->title(__('Category:')) + ->options($combo) + ->prime(true); + } + + /** + * Posts status select + */ + public function getPostStatusFilter(): dcAdminFilter + { + return (new dcAdminFilter('status')) + ->param('post_status') + ->title(__('Status:')) + ->options(array_merge( + ['-' => ''], + dcAdminCombos::getPostStatusesCombo() + )); + } + + /** + * Posts by month select + */ + public function getPostMonthFilter(): ?dcAdminFilter + { + $dates = null; + try { + $dates = $this->core->blog->getDates(['type' => 'month']); + if ($dates->isEmpty()) { + return null; + } + } catch (Exception $e) { + $this->core->error->add($e->getMessage()); + return null; + } + + return (new dcAdminFilter('month')) + ->param('post_month', function($f) { return substr($f[0], 4, 2); }) + ->param('post_year', function($f) { return substr($f[0], 0, 4); }) + ->title(__('Month:')) + ->options(array_merge( + ['-' => ''], + dcAdminCombos::getDatesCombo($dates) + )); + } +} diff --git a/index.php b/index.php index c88cbd5..57ba539 100644 --- a/index.php +++ b/index.php @@ -251,95 +251,16 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { # Prepared entries list if ($feed_id && $can_view_page) { - try { - # Getting categories - $categories = $core->blog->getCategories(array( - 'post_type' => 'post' - )); - - # Getting authors - $users = $core->blog->getPostsUsers(); - - # Getting dates - $dates = $core->blog->getDates(array( - 'type' => 'month' - )); - - # Getting langs - $langs = $core->blog->getLangs(); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - - # Creating filter combo boxes - if (!$core->error->flag()) { - - $users_combo = array_merge( - array('-' => ''), - dcAdminCombos::getUsersCombo($users) - ); - - $categories_combo = array_merge( - array( - new formSelectOption('-', ''), - new formSelectOption(__('(No cat)'), 'NULL') - ), - dcAdminCombos::getCategoriesCombo($categories, false) - ); - $categories_values = array(); - foreach ($categories_combo as $cat) { - if (isset($cat->value)) { - $categories_values[$cat->value] = true; - } - } - - $status_combo = array_merge( - array('-' => ''), - dcAdminCombos::getPostStatusesCombo() - ); - - $selected_combo = array( - '-' => '', - __('Selected') => '1', - __('Not selected') => '0' - ); - - $dt_m_combo = array_merge( - array('-' => ''), - dcAdminCombos::getDatesCombo($dates) - ); - - $lang_combo = array_merge( - array('-' => ''), - dcAdminCombos::getLangsCombo($langs,false) - ); - - $sortby_combo = array( - __('Date') => 'post_dt', - __('Title') => 'post_title', - __('Category') => 'cat_title', - __('Author') => 'user_id', - __('Status') => 'post_status', - __('Selected') => 'post_selected' - ); - - $order_combo = array( - __('Descending') => 'desc', - __('Ascending') => 'asc' - ); - } - # Posts action $posts_actions_page = new dcPostsActionsPage( $core, 'plugin.php', - array( + [ 'p' => 'zoneclearFeedServer', 'part' => 'feed', 'feed_id' => $feed_id, '_ANCHOR' => 'entries' - ) + ] ); if ($posts_actions_page->process()) { @@ -348,71 +269,29 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { /* Get posts -------------------------------------------------------- */ - $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; - $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; - $status = isset($_GET['status']) ? $_GET['status'] : ''; - $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; - $month = !empty($_GET['month']) ? $_GET['month'] : ''; - $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; - $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; + $post_filter = new adminZcfsPostFilter($core); + $post_filter->add('part', 'feed'); + $post_filter->add('feed_id', $feed_id); - $show_filters = false; + # get list params + $params = $post_filter->params(); - $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; - $nb_per_page = 30; + # lexical sort + $sortby_lex = [ + // key in sorty_combo (see above) => field in SQL request + 'post_title' => 'post_title', + 'cat_title' => 'cat_title', + 'user_id' => 'P.user_id']; - if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != $_GET['nb']) { - $show_filters = true; - } - $nb_per_page = (integer) $_GET['nb']; - } + # --BEHAVIOR-- adminPostsSortbyLexCombo + $core->callBehavior('adminPostsSortbyLexCombo', [& $sortby_lex]); + + $params['order'] = (array_key_exists($post_filter->sortby, $sortby_lex) ? + $core->con->lexFields($sortby_lex[$post_filter->sortby]) : + $post_filter->sortby) . ' ' . $post_filter->order; - $params['limit'] = array((($page-1)*$nb_per_page), $nb_per_page); $params['no_content'] = true; - # - User filter - if ($user_id !== '' && in_array($user_id, $users_combo)) { - $params['user_id'] = $user_id; - $show_filters = true; - } - # - Categories filter - if ($cat_id !== '' && in_array($cat_id, $categories_combo)) { - $params['cat_id'] = $cat_id; - $show_filters = true; - } - # - Status filter - if ($status !== '' && in_array($status, $status_combo)) { - $params['post_status'] = $status; - $show_filters = true; - } - # - Selected filter - if ($selected !== '' && in_array($selected, $selected_combo)) { - $params['post_selected'] = $selected; - $show_filters = true; - } - # - Month filter - if ($month !== '' && in_array($month, $dt_m_combo)) { - $params['post_month'] = substr($month, 4, 2); - $params['post_year'] = substr($month, 0, 4); - $show_filters = true; - } - # - Lang filter - if ($lang !== '' && in_array($lang, $lang_combo)) { - $params['post_lang'] = $lang; - $show_filters = true; - } - # - Sortby and order filter - if ($sortby !== '' && in_array($sortby, $sortby_combo)) { - if ($order !== '' && in_array($order, $order_combo)){ - $params['order'] = $sortby.' '.$order; - } - if ($sortby != 'post_dt' || $order != 'desc') { - $show_filters = true; - } - } - # Get posts try { $params['feed_id'] = $feed_id; @@ -433,25 +312,8 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { echo ''.__('Feeds server').''. ($feed_id && !$core->error->flag() ? - dcPage::jsLoad( - 'index.php?pf=periodical/js/postsfilter.js' - ). - '\n" + $post_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $feed_id], '&').'#entries') . + dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) : ''). dcPage::jsPageTabs(). $next_headlink."\n".$prev_headlink. @@ -582,73 +444,22 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { # Entries if ($feed_id && $can_view_page && !$core->error->flag()) { - echo - '
'. + echo '
'; - '
'. + $post_filter->display(['admin.plugin.zoneclearFeedServer','#entries'], + form::hidden('p', 'zoneclearFeedServer') . + form::hidden('part', 'feed') . + form::hidden('feed_id', $feed_id) + ); - '

'. - __('Cancel filters and display options'). - '

'. - - '
'. - '
'. - '

'.__('Filters').'

'. - '

'. - form::combo('user_id',$users_combo,$user_id).'

'. - '

'. - form::combo('cat_id',$categories_combo,$cat_id).'

'. - '

' . - form::combo('status',$status_combo,$status).'

'. - '
'. - - '
'. - '

'. - form::combo('selected',$selected_combo,$selected).'

'. - '

'. - form::combo('month',$dt_m_combo,$month).'

'. - '

'. - form::combo('lang',$lang_combo,$lang).'

'. - '
'. - - '
'. - '

'.__('Display options').'

'. - '

'. - form::combo('sortby',$sortby_combo,$sortby).'

'. - '

'. - form::combo('order',$order_combo,$order).'

'. - '

'.__('Show').'

'. - '
'. - '
'. - - '

'. - form::hidden(array('p'), 'zoneclearFeedServer'). - form::hidden(array('part'), 'feed'). - form::hidden(array('feed_id') ,$feed_id). - '
'. //Opera sucks - '

'. - '
'. + # fix pager url + $args = $post_filter->values(); + unset($args['page']); + $args['page'] = '%s'; + $base_url = $core->adminurl->get('admin.plugin.zoneclearFeedServer', $args, '&').'#entries'; # Show posts - $post_list->display($page, $nb_per_page, - - $p_url. - '&part=feed'. - '&tab=entries'. - '&feed_id='.$feed_id. - '&user_id='.$user_id. - '&cat_id='.$cat_id. - '&status='.$status. - '&selected='.$selected. - '&month='.$month. - '&lang='.$lang. - '&sortby='.$sortby. - '&order='.$order. - '&nb='.$nb_per_page. - '&page=%s', - + $post_list->display($post_filter->page, $post_filter->nb, $base_url, '
'. '%s'. @@ -658,21 +469,12 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { '

'.__('Selected entries action:').' '. form::combo('action', $posts_actions_page->getCombo()). '

'. - form::hidden(array('part'), 'feed'). - form::hidden(array('feed_id'), $feed_id). - form::hidden(array('user_id'), $user_id). - form::hidden(array('cat_id'), $cat_id). - form::hidden(array('status'), $status). - form::hidden(array('selected'), $selected). - form::hidden(array('month'), $month). - form::hidden(array('lang'), $lang). - form::hidden(array('sortby'), $sortby). - form::hidden(array('order'), $order). - form::hidden(array('page'), $page). - form::hidden(array('nb'), $nb_per_page). + $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', $post_filter->values()) . + form::hidden('redir', $core->adminurl->get('admin.plugin.zoneclearFeedServer', $post_filter->values())) . $core->formNonce(). '
'. - '' + '', + $post_filter->show() ); echo @@ -720,9 +522,8 @@ else { # Display echo ''.__('Feeds server').''. - dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'])]) . - dcPage::jsFilterControl($feeds_filter->show()) . - dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/feedsfilter.js')) . + $feeds_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'], '&')) . + dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) . dcPage::jsPageTabs(). # --BEHAVIOR-- packmanAdminHeader diff --git a/js/feedsfilter.js b/js/list.js similarity index 100% rename from js/feedsfilter.js rename to js/list.js diff --git a/js/postsfilter.js b/js/postsfilter.js deleted file mode 100644 index 6565bac..0000000 --- a/js/postsfilter.js +++ /dev/null @@ -1,31 +0,0 @@ -$(function(){ - $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); - - $filtersform = $('#filters-form'); - $filtersform.before('

'+dotclear.msg.filter_posts_list+'

') - - if( dotclear.msg.show_filters == 'false' ) { - $filtersform.hide(); - } else { - $('#filter-control') - .addClass('open') - .text(dotclear.msg.cancel_the_filter); - } - - $('#filter-control').click(function() { - if( $(this).hasClass('open') ) { - if( dotclear.msg.show_filters == 'true' ) { - return true; - } else { - $filtersform.hide(); - $(this).removeClass('open') - .text(dotclear.msg.filter_posts_list); - } - } else { - $filtersform.show(); - $(this).addClass('open') - .text(dotclear.msg.cancel_the_filter); - } - return false; - }); -}); \ No newline at end of file