add generic filters for period

This commit is contained in:
Jean-Christian Paul Denis 2021-10-23 00:42:30 +02:00
parent 39c9f329ec
commit 7888922dce
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
5 changed files with 32 additions and 383 deletions

311
index.php
View File

@ -208,197 +208,12 @@ if ($part == 'period') {
# Prepare combos for posts list # Prepare combos for posts list
if ($period_id) { if ($period_id) {
try { # Filters
# Getting categories $post_filter = new adminPostFilter($core);
$categories = $core->blog->getCategories(['post_type' => 'post']); $post_filter->add('part', 'period');
# Getting authors $params = $post_filter->params();
$users = $core->blog->getPostsUsers();
# Getting dates
$dates = $core->blog->getDates(['type' => 'month']);
# Getting langs
$langs = $core->blog->getLangs();
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# Creating filter combo boxes
if ($period_id && !$core->error->flag()) {
# Users combo
$users_combo = array_merge(
['-' => ''],
dcAdminCombos::getUsersCombo($users)
);
# Categories combo
$categories_combo = array_merge(
[
new formSelectOption('-', ''),
new formSelectOption(__('(No cat)'), 'NULL')
],
dcAdminCombos::getCategoriesCombo($categories, false)
);
$categories_values = [];
foreach ($categories_combo as $cat) {
if (isset($cat->value)) {
$categories_values[$cat->value] = true;
}
}
# Status combo
$status_combo = array_merge(
['-' => ''],
dcAdminCombos::getPostStatusesCombo()
);
# Selection combo
$selected_combo = [
'-' => '',
__('Selected') => '1',
__('Not selected') => '0'
];
# Attachments combo
$attachment_combo = [
'-' => '',
__('With attachments') => '1',
__('Without attachments') => '0'
];
# Months combo
$dt_m_combo = array_merge(
['-' => ''],
dcAdminCombos::getDatesCombo($dates)
);
# Langs combo
$lang_combo = array_merge(
['-' => ''],
dcAdminCombos::getLangsCombo($langs, false)
);
# Sort_by combo
$sortby_combo = [
__('Date') => 'post_dt',
__('Title') => 'post_title',
__('Category') => 'cat_title',
__('Author') => 'user_id',
__('Status') => 'post_status',
__('Selected') => 'post_selected',
__('Number of comments') => 'nb_comment',
__('Number of trackbacks') => 'nb_trackback'
];
# order combo
$order_combo = [
__('Descending') => 'desc',
__('Ascending') => 'asc'
];
# parse filters
$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'] : '';
$attachment = isset($_GET['attachment']) ? $_GET['attachment'] : '';
$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';
$show_filters = false;
$page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1;
$nb_per_page = 30;
if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
if ($nb_per_page != $_GET['nb']) {
$show_filters = true;
}
$nb_per_page = (integer) $_GET['nb'];
}
$params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page];
$params['no_content'] = true; $params['no_content'] = true;
$params['periodical_id'] = $period_id;
# - User filter
if ($user_id !== '' && in_array($user_id, $users_combo)) {
$params['user_id'] = $user_id;
$show_filters = true;
} else {
$user_id='';
}
# - Categories filter
if ($cat_id !== '' && isset($categories_values[$cat_id])) {
$params['cat_id'] = $cat_id;
$show_filters = true;
} else {
$cat_id='';
}
# - Status filter
if ($status !== '' && in_array($status, $status_combo)) {
$params['post_status'] = $status;
$show_filters = true;
} else {
$status='';
}
# - Selected filter
if ($selected !== '' && in_array($selected, $selected_combo)) {
$params['post_selected'] = $selected;
$show_filters = true;
} else {
$selected='';
}
# - Selected filter
if ($attachment !== '' && in_array($attachment, $attachment_combo)) {
$params['media'] = $attachment;
$params['link_type'] = 'attachment';
$show_filters = true;
} else {
$attachment='';
}
# - 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;
} else {
$month='';
}
# - Lang filter
if ($lang !== '' && in_array($lang, $lang_combo)) {
$params['post_lang'] = $lang;
$show_filters = true;
} else {
$lang='';
}
# - Sortby and order filter
if ($sortby !== '' && in_array($sortby, $sortby_combo)) {
if ($order !== '' && in_array($order, $order_combo)) {
$params['order'] = $sortby.' '.$order;
} else {
$order='desc';
}
if ($sortby != 'post_dt' || $order != 'desc') {
$show_filters = true;
}
} else {
$sortby='post_dt';
$order='desc';
}
# Get posts # Get posts
try { try {
@ -410,25 +225,8 @@ if ($part == 'period') {
} }
$starting_script = $starting_script =
dcPage::jsLoad( dcPage::jsLoad('index.php?pf=periodical/js/checkbox.js') .
'index.php?pf=periodical/js/postsfilter.js' $post_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts');
) .
'<script type="text/javascript">' . "\n" .
"//<![CDATA[" . "\n" .
dcPage::jsVar(
'dotclear.msg.show_filters',
$show_filters ? 'true':'false'
) . "\n" .
dcPage::jsVar(
'dotclear.msg.filter_posts_list',
__('Show filters and display options')
) . "\n" .
dcPage::jsVar(
'dotclear.msg.cancel_the_filter',
__('Cancel filters and display options')
) . "\n" .
"//]]>\n" .
"</script>\n";
} }
# Display # Display
@ -491,7 +289,7 @@ if ($part == 'period') {
if ($period_id && !$core->error->flag()) { if ($period_id && !$core->error->flag()) {
# Actions combo box # Actions combo box
$combo_action = array(); $combo_action = [];
$combo_action[__('Entries')][__('Publish')] = 'publish'; $combo_action[__('Entries')][__('Publish')] = 'publish';
$combo_action[__('Entries')][__('Unpublish')] = 'unpublish'; $combo_action[__('Entries')][__('Unpublish')] = 'unpublish';
$combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical'; $combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical';
@ -499,16 +297,16 @@ if ($part == 'period') {
$base_url = $p_url . $base_url = $p_url .
'&amp;period_id=' .$period_id . '&amp;period_id=' .$period_id .
'&amp;part=period' . '&amp;part=period' .
'&amp;user_id=' . $user_id . '&amp;user_id=' . $post_filter->user_id .
'&amp;cat_id=' . $cat_id . '&amp;cat_id=' . $post_filter->cat_id .
'&amp;status=' . $status . '&amp;status=' . $post_filter->status .
'&amp;selected=' . $selected . '&amp;selected=' . $post_filter->selected .
'&amp;attachment=' . $attachment . '&amp;attachment=' . $post_filter->attachment .
'&amp;month=' . $month . '&amp;month=' . $post_filter->month .
'&amp;lang=' . $lang . '&amp;lang=' . $post_filter->lang .
'&amp;sortby=' . $sortby . '&amp;sortby=' . $post_filter->sortby .
'&amp;order=' . $order . '&amp;order=' . $post_filter->order .
'&amp;nb=' . $nb_per_page . '&amp;nb=' . $post_filter->nb .
'&amp;page=%s' . '&amp;page=%s' .
'#posts'; '#posts';
@ -518,57 +316,17 @@ if ($part == 'period') {
'" id="posts">'; '" id="posts">';
# Filters # Filters
echo $post_filter->display(['admin.plugin.periodical','#posts'],
'<form action="' . $p_url . '#posts" method="get" id="filters-form">' . $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [
'p' => 'periodical',
'<h3 class="out-of-screen-if-js">' . 'part' => 'period',
__('Cancel filters and display options') . 'period_id' => $period_id
'</h3>' . ])
);
'<div class="table">' .
'<div class="cell">' .
'<h4>' . __('Filters') . '</h4>' .
'<p><label for="user_id" class="ib">' . __('Author:') . '</label> ' .
form::combo('user_id', $users_combo, $user_id) . '</p>' .
'<p><label for="cat_id" class="ib">' . __('Category:') . '</label> ' .
form::combo('cat_id', $categories_combo, $cat_id) . '</p>' .
'<p><label for="status" class="ib">' . __('Status:') . '</label> ' .
form::combo('status', $status_combo, $status) . '</p> ' .
'</div>' .
'<div class="cell filters-sibling-cell">' .
'<p><label for="selected" class="ib">' . __('Selected:') . '</label> ' .
form::combo('selected', $selected_combo, $selected) .'</p>' .
'<p><label for="attachment" class="ib">' . __('Attachments:') . '</label> ' .
form::combo('attachment', $attachment_combo, $attachment) . '</p>' .
'<p><label for="month" class="ib">' . __('Month:') . '</label> ' .
form::combo('month', $dt_m_combo,$month) . '</p>' .
'<p><label for="lang" class="ib">' . __('Lang:') . '</label> ' .
form::combo('lang', $lang_combo, $lang) . '</p> ' .
'</div>'.
'<div class="cell filters-options">' .
'<h4>' . __('Display options') . '</h4>' .
'<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' .
form::combo('sortby', $sortby_combo, $sortby) . '</p>' .
'<p><label for="order" class="ib">' . __('Sort:') . '</label> ' .
form::combo('order', $order_combo, $order) . '</p>' .
'<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' .
form::field('nb', 3, 3, $nb_per_page) . ' ' .
__('entries per page') . '</label></p>' .
'</div>' .
'</div>' .
'<p><input type="submit" value="' . __('Apply filters and display options') . '" />' .
form::hidden(['p'], 'periodical') .
form::hidden(['part'], 'period') .
form::hidden(['period_id'], $period_id) .
'<br class="clear" /></p>' . //Opera sucks
'</form>';
# Posts list # Posts list
echo echo
$post_list->postDisplay($page, $nb_per_page, $base_url, $post_list->postDisplay($post_filter->page, $post_filter->nb, $base_url,
'<form action="' . $p_url . '" method="post" id="form-entries">' . '<form action="' . $p_url . '" method="post" id="form-entries">' .
'%s' . '%s' .
@ -579,21 +337,10 @@ if ($part == 'period') {
'<p class="col right">' . __('Selected entries action:') . ' ' . '<p class="col right">' . __('Selected entries action:') . ' ' .
form::combo('action', $combo_action) . form::combo('action', $combo_action) .
'<input type="submit" value="' . __('ok') . '" /></p>' . '<input type="submit" value="' . __('ok') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', $post_filter->values()) .
form::hidden(['period_id'], $period_id) . form::hidden(['period_id'], $period_id) .
form::hidden(['user_id'], $user_id) .
form::hidden(['cat_id'], $cat_id) .
form::hidden(['status'], $status) .
form::hidden(['selected'], $selected) .
form::hidden(['attachment'], $attachment) .
form::hidden(['month'], $month) .
form::hidden(['lang'], $lang) .
form::hidden(['sortby'], $sortby) .
form::hidden(['order'], $order) .
form::hidden(['page'], $page) .
form::hidden(['nb'], $nb_per_page) .
form::hidden(['p'], 'periodical') . form::hidden(['p'], 'periodical') .
form::hidden(['part'], 'period') . form::hidden(['redir'], sprintf($base_url, $post_filter->page)) .
form::hidden(['redir'], sprintf($base_url, $page)) .
$core->formNonce() . $core->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'
@ -660,7 +407,7 @@ if ($part == 'period') {
# Filters # Filters
$p_filter = new adminGenericFilter($core, 'periodical'); $p_filter = new adminGenericFilter($core, 'periodical');
$p_filter->add('part', 'period'); $p_filter->add('part', 'periods');
$params = $p_filter->params(); $params = $p_filter->params();
@ -676,7 +423,7 @@ if ($part == 'period') {
# Display # Display
echo echo
'<html><head><title>' . __('Periodical') . '</title>' . '<html><head><title>' . __('Periodical') . '</title>' .
//dcPage::jsLoad('index.php?pf=periodical/js/periodsfilter.js') . dcPage::jsLoad('index.php?pf=periodical/js/checkbox.js') .
$p_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) . $p_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) .
'</head>' . '</head>' .
'<body>' . '<body>' .

3
js/checkbox.js Normal file
View File

@ -0,0 +1,3 @@
$(function(){
$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});
});

View File

@ -1,16 +1,3 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
*
* This file is part of periodical, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2013 Jean-Christian Denis and contributors
* contact@jcdenis.fr http://jcd.lv
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* -- END LICENSE BLOCK ------------------------------------*/
$(function(){ $(function(){
var periodicalstart=document.getElementById('period_curdt'); var periodicalstart=document.getElementById('period_curdt');
if(periodicalstart!=undefined){ if(periodicalstart!=undefined){

View File

@ -1,44 +0,0 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
*
* This file is part of periodical, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2013 Jean-Christian Denis and contributors
* contact@jcdenis.fr http://jcd.lv
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* -- END LICENSE BLOCK ------------------------------------*/
$(function(){
$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});
$filtersform = $('#filters-form');
$filtersform.before('<p><a id="filter-control" class="form-control" href="plugin.php?p=periodical&amp;part=periods" style="display:inline">'+dotclear.msg.filter_posts_list+'</a></p>')
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;
});
});

View File

@ -1,44 +0,0 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
*
* This file is part of periodical, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2013 Jean-Christian Denis and contributors
* contact@jcdenis.fr http://jcd.lv
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* -- END LICENSE BLOCK ------------------------------------*/
$(function(){
$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});
$filtersform = $('#filters-form');
$filtersform.before('<p><a id="filter-control" class="form-control" href="plugin.php?p=periodical&amp;part=period&amp;period_id='+$('#filters-form input[name=period_id]').val()+'#posts" style="display:inline">'+dotclear.msg.filter_posts_list+'</a></p>')
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;
});
});