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

View file

@ -23,9 +23,30 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class postWidgetTextAdmin 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() 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) public static function form($main, $sidebar, $post)

View file

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

151
index.php
View file

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

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');
});