diff --git a/_admin.php b/_admin.php index 7d5fdce..54415b4 100644 --- a/_admin.php +++ b/_admin.php @@ -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']); } \ No newline at end of file diff --git a/inc/lib.pwt.admin.php b/inc/lib.pwt.admin.php index 3aa0ca2..9697740 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.php @@ -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) diff --git a/inc/lib.pwt.list.php b/inc/lib.pwt.list.php index dbdb0a7..20d5493 100644 --- a/inc/lib.pwt.list.php +++ b/inc/lib.pwt.list.php @@ -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 '

'.__('No widget').'

'; } - $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 .= ''; - return + echo $pager->getLinks(). sprintf($enclose, $content). $pager->getLinks(); diff --git a/index.php b/index.php index c58fa18..53a3b41 100644 --- a/index.php +++ b/index.php @@ -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 ' -'.__('Post widget text').''. -dcPage::jsLoad( - 'js/filter-controls.js' -). -'\n".' +' . __('Post widget text') . '' . +dcPage::jsLoad(dcPage::getPF('postWidgetText/js/index.js')) . +$filter->js($core->adminurl->get('admin.plugin.postWidgetText')) . ' -'. +' . -dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Posts widgets') => '' - ) -). -dcPage::notices().' +dcPage::breadcrumb([ + __('Plugins') => '', + __('Posts widgets') => '' +]). +dcPage::notices(); -
-

'.__('Show filters and display options').'

+$filter->display('admin.plugin.postWidgetText', form::hidden('p', 'postWidgetText')); -
-
-

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

-
-
-

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

-
-
-

'.__('Show').'

-
-
- -

'. -form::hidden(array('p'), 'postWidgetText').' -

-
'. - -$posts_list->display($page, $nb_per_page, - '
'. - '%s'. - '
'. - '

'. - '

'. - '

'. - 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(). - '
'. +$posts_list->display($filter->page, $filter->nb, + '' . + '%s' . + '
' . + '

' . + '

' . + '

' . + $core->adminurl->getHiddenFormFields('admin.plugin.postWidgetText', array_merge(['p' => 'postWidgetText'], $filter->values(true))) . + $core->formNonce() . + '
' . '
' ); # Footer dcPage::helpBlock('postWidgetText'); -echo -'

-'.__('Configuration').' - -postWidgetText - '.$core->plugins->moduleInfo('postWidgetText', 'version').'  -'.__('postWidgetText').' -

-'; \ No newline at end of file +echo ''; \ No newline at end of file diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..87a319d --- /dev/null +++ b/js/index.js @@ -0,0 +1,4 @@ +$(function(){ + $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); + dotclear.condSubmit('#form-entries td input[type=checkbox]', '#form-entries #do-action'); +}); \ No newline at end of file