'.
- ''.
- 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' => 'rs->getURL()) . '">' .
+ 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
''.
+ echo '
';
- '
'.
+ # 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,
'
'.
- ''
+ '',
+ $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