add user pref for posts list filters

This commit is contained in:
Jean-Christian Denis 2021-10-30 00:36:04 +02:00
parent b4224d4736
commit 27da00a377
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 81 additions and 184 deletions

View file

@ -12,7 +12,6 @@
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
@ -22,73 +21,35 @@ require dirname(__FILE__).'/_widgets.php';
if ($core->blog->settings->postwidgettext->postwidgettext_active) {
$_menu['Plugins']->addItem(
__('Post widget text'),
'plugin.php?p=postWidgetText',
'index.php?pf=postWidgetText/icon.png',
preg_match(
'/plugin.php\?p=postWidgetText(&.*)?$/',
$_SERVER['REQUEST_URI']),
$core->adminurl->get('admin.plugin.postWidgetText'),
dcPage::getPF('postWidgetText/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.postWidgetText')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('contentadmin', $core->blog->id)
);
$core->addBehavior(
'adminDashboardFavorites',
array('postWidgetTextDashboard', 'favorites')
);
$core->addBehavior('adminDashboardFavorites', ['postWidgetTextDashboard', 'favorites']);
}
# Pref
$core->addBehavior('adminFiltersLists', ['postWidgetTextAdmin', 'adminFiltersLists']);
# Post
$core->addBehavior(
'adminPostHeaders',
array('postWidgetTextAdmin', 'headers'));
$core->addBehavior(
'adminPostFormItems',
array('postWidgetTextAdmin', 'form'));
$core->addBehavior(
'adminAfterPostUpdate',
array('postWidgetTextAdmin', 'save'));
$core->addBehavior(
'adminAfterPostCreate',
array('postWidgetTextAdmin', 'save'));
$core->addBehavior(
'adminBeforePostDelete',
array('postWidgetTextAdmin', 'delete'));
$core->addBehavior('adminPostHeaders', ['postWidgetTextAdmin', 'headers']);
$core->addBehavior('adminPostFormItems', ['postWidgetTextAdmin', 'form']);
$core->addBehavior('adminAfterPostUpdate', ['postWidgetTextAdmin', 'save']);
$core->addBehavior('adminAfterPostCreate', ['postWidgetTextAdmin', 'save']);
$core->addBehavior('adminBeforePostDelete', ['postWidgetTextAdmin', 'delete']);
# Plugin "pages"
$core->addBehavior(
'adminPageHeaders',
array('postWidgetTextAdmin', 'headers'));
$core->addBehavior(
'adminPageFormItems',
array('postWidgetTextAdmin', 'form'));
$core->addBehavior(
'adminAfterPageUpdate',
array('postWidgetTextAdmin', 'save'));
$core->addBehavior(
'adminAfterPageCreate',
array('postWidgetTextAdmin', 'save'));
$core->addBehavior(
'adminBeforePageDelete',
array('postWidgetTextAdmin', 'delete'));
$core->addBehavior('adminPageHeaders', ['postWidgetTextAdmin', 'headers']);
$core->addBehavior('adminPageFormItems', ['postWidgetTextAdmin', 'form']);
$core->addBehavior('adminAfterPageUpdate', ['postWidgetTextAdmin', 'save']);
$core->addBehavior('adminAfterPageCreate', ['postWidgetTextAdmin', 'save']);
$core->addBehavior('adminBeforePageDelete', ['postWidgetTextAdmin', 'delete']);
# Plugin "importExport"
if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) {
$core->addBehavior(
'exportFull',
array('postWidgetTextBackup', 'exportFull')
);
$core->addBehavior(
'exportSingle',
array('postWidgetTextBackup', 'exportSingle')
);
$core->addBehavior(
'importInit',
array('postWidgetTextBackup', 'importInit')
);
$core->addBehavior(
'importSingle',
array('postWidgetTextBackup', 'importSingle')
);
$core->addBehavior(
'importFull',
array('postWidgetTextBackup', 'importFull')
);
$core->addBehavior('exportFull', ['postWidgetTextBackup', 'exportFull']);
$core->addBehavior('exportSingle', ['postWidgetTextBackup', 'exportSingle']);
$core->addBehavior('importInit', ['postWidgetTextBackup', 'importInit']);
$core->addBehavior('importSingle', ['postWidgetTextBackup', 'importSingle']);
$core->addBehavior('importFull', ['postWidgetTextBackup', 'importFull']);
}

View file

@ -23,9 +23,30 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/
class postWidgetTextAdmin
{
public static function sortbyCombo()
{
return [
__('Post title') => 'post_title',
__('Post date') => 'post_dt',
__('Widget title') => 'option_title',
__('Widget date') => 'option_upddt',
];
}
public static function adminFiltersLists(dcCore $core, $sorts)
{
$sorts['pwt'] = [
__('Post widget text'),
self::sortbyCombo(),
'post_dt',
'desc',
[__('entries per page'), 20]
];
}
public static function headers()
{
return dcPage::jsLoad('index.php?pf=postWidgetText/js/post.js');
return dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js'));
}
public static function form($main, $sidebar, $post)

View file

@ -23,14 +23,14 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/
class postWidgetTextList extends adminGenericList
{
public function display($page, $nb_per_page, $enclose='')
public function display($page, $nb_per_page, $enclose = '')
{
if ($this->rs->isEmpty()) {
return '<p><strong>'.__('No widget').'</strong></p>';
}
$pager = new dcPager($page, $this->rs_count, $nb_per_page,10);
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$pager->html_prev = $this->html_prev;
$pager->html_next = $this->html_next;
$pager->var_page = 'page';
@ -92,7 +92,7 @@ class postWidgetTextList extends adminGenericList
$content .=
'</tbody></table></div>';
return
echo
$pager->getLinks().
sprintf($enclose, $content).
$pager->getLinks();

151
index.php
View file

@ -12,7 +12,6 @@
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
@ -31,62 +30,27 @@ if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
dcPage::addSuccessNotice(
__('Posts widgets successfully delete.')
);
http::redirect(
$p_url
);
if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']);
} else {
$core->adminurl->redirect('admin.plugin.postWidgetText');
}
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# Combos
$sortby_combo = array(
__('Post title') => 'post_title',
__('Post date') => 'post_dt',
__('Widget title') => 'option_title',
__('Widget date') => 'option_upddt',
);
$order_combo = array(
__('Descending') => 'desc',
__('Ascending') => 'asc'
);
# Filters
$show_filters = false;
$nb_per_page = 1;
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt';
$order = !empty($_GET['order']) ? $_GET['order'] : 'desc';
$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
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'] = array((($page-1)*$nb_per_page), $nb_per_page);
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;
}
}
# filters
$filter = new adminGenericFilter($core, 'pwt');
$filter->add(dcAdminFilters::getPageFilter());
$params = $filter->params();
# Get posts with text widget
try {
$posts = $pwt->getWidgets($params);
$counter = $pwt->getWidgets($params, true);
$posts_list = new postWidgetTextList(
$core,
$posts,
$counter->f(0)
);
$posts_list = new postWidgetTextList($core, $posts, $counter->f(0));
}
catch (Exception $e) {
$core->error->add($e->getMessage());
@ -94,87 +58,34 @@ catch (Exception $e) {
# Display
echo '
<html><head><title>'.__('Post widget text').'</title>'.
dcPage::jsLoad(
'js/filter-controls.js'
).
'<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".'
<html><head><title>' . __('Post widget text') . '</title>' .
dcPage::jsLoad(dcPage::getPF('postWidgetText/js/index.js')) .
$filter->js($core->adminurl->get('admin.plugin.postWidgetText')) . '
</head>
<body>'.
<body>' .
dcPage::breadcrumb(
array(
html::escapeHTML($core->blog->name) => '',
__('Posts widgets') => ''
)
).
dcPage::notices().'
dcPage::breadcrumb([
__('Plugins') => '',
__('Posts widgets') => ''
]).
dcPage::notices();
<form action="'.$p_url.'" method="get" id="filters-form">
<h3 class="out-of-screen-if-js">'.__('Show filters and display options').'</h3>
$filter->display('admin.plugin.postWidgetText', form::hidden('p', 'postWidgetText'));
<div class="table">
<div class="cell">
<p><label for="sortby" class="ib">'.__('Order by:').'</label> '.
form::combo('sortby', $sortby_combo, $sortby).'</p>
</div>
<div class="cell">
<p><label for="order" class="ib">'.__('Sort:').'</label> '.
form::combo('order', $order_combo, $order).'</p>
</div>
<div class="cell">
<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(array('p'), 'postWidgetText').'
<br class="clear" /></p>
</form>'.
$posts_list->display($page, $nb_per_page,
'<form action="'.$p_url.'" method="post" id="form-periods">'.
'%s'.
'<div class="two-cols">'.
'<p class="col checkboxes-helpers"></p>'.
'<p class="col right">'.
'<input type="submit" name="save" value="'.__('Delete selected widgets').'" /></p>'.
form::hidden(array('sortby'), $sortby).
form::hidden(array('order'), $order).
form::hidden(array('page'), $page).
form::hidden(array('nb'), $nb_per_page).
form::hidden(array('p'), 'postWidgetText').
$core->formNonce().
'</div>'.
$posts_list->display($filter->page, $filter->nb,
'<form action="' . $core->adminurl->get('admin.plugin.postWidgetText') . '" method="post" id="form-entries">' .
'%s' .
'<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' .
'<input id="do-action" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.postWidgetText', array_merge(['p' => 'postWidgetText'], $filter->values(true))) .
$core->formNonce() .
'</div>' .
'</form>'
);
# Footer
dcPage::helpBlock('postWidgetText');
echo
'<hr class="clear"/><p class="right modules">
<a class="module-config" '.
'href="plugins.php?module=postWidgetText&amp;conf=1&amp;redir='.
urlencode('plugin.php?p=postWidgetText').'">'.__('Configuration').'</a> -
postWidgetText - '.$core->plugins->moduleInfo('postWidgetText', 'version').'&nbsp;
<img alt="'.__('postWidgetText').'" src="index.php?pf=postWidgetText/icon.png" />
</p>
</body></html>';
echo '</body></html>';

4
js/index.js Normal file
View file

@ -0,0 +1,4 @@
$(function(){
$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});
dotclear.condSubmit('#form-entries td input[type=checkbox]', '#form-entries #do-action');
});