diff --git a/_admin.php b/_admin.php index e34a096..b9f1d38 100644 --- a/_admin.php +++ b/_admin.php @@ -32,7 +32,7 @@ $_menu['Plugins']->addItem( if ($core->blog->settings->kUtRL->kutrl_active) { $core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']); $core->addBehavior('adminColumnsLists', ['adminKutrl', 'adminColumnsLists']); - $core->addBehavior('adminSortsLists', ['adminKutrl', 'adminSortsLists']); + $core->addBehavior('adminFiltersLists', ['adminKutrl', 'adminFiltersLists']); $core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); $core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']); $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url @@ -88,7 +88,7 @@ class adminKutrl ]; } - public static function adminSortsLists(dcCore $core, $sorts) + public static function adminFiltersLists(dcCore $core, $sorts) { $sorts['kUtRL'] = [ __('URL shortener'), diff --git a/index.php b/index.php index ba6eaa2..72eafce 100644 --- a/index.php +++ b/index.php @@ -22,7 +22,6 @@ dcPage::check('admin'); $s = $core->blog->settings->kUtRL; # Default values -$show_filters = false; $p_url = $core->adminurl->get('admin.plugin.kUtRL'); $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'links'; $action = isset($_POST['action']) ? $_POST['action'] : ''; @@ -190,46 +189,32 @@ if ($part == 'link') { if ($part == 'links') { $log = new kutrlLog($core); - $sortby_combo = adminKutrl::sortbyCombo(); - $order_combo = [__('Descending') => 'desc', __('Ascending') => 'asc']; + $kUtRL_filter = new adminGenericFilter($core, 'kUtRL'); - $core->auth->user_prefs->addWorkspace('interface'); - $sorts_user = @$core->auth->user_prefs->interface->sorts; - $default_sortby = $sorts_user['kUtRL'][0] ?? 'kut_dt'; - $default_order = $sorts_user['kUtRL'][1] ?? 'desc'; - $nb_per_page = !empty($sorts_user['kUtRL'][2]) ? $sorts_user['kUtRL'][2] : 30; + $sortby = $kUtRL_filter->getFilter('sortby'); + $order = $kUtRL_filter->getFilter('order'); + $nb = $kUtRL_filter->getFilter('nb'); - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby; - $order = !empty($_GET['order']) ? $_GET['order'] : $default_order; - $urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : ''; $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; - $show_filters = false; - - if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != (integer) $_GET['nb']) { - $show_filters = true; - } - $nb_per_page = (integer) $_GET['nb']; - } + $kUtRL_filter->setFilter('page', $page); + $kUtRL_filter->setFilter('part', 'links'); $params = []; - $params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page]; - - if (!in_array($sortby, $sortby_combo)) { - $sortby = $default_sortby; - } - - if (!in_array($order, $order_combo)) { - $order = $default_order; - } + $params['limit'] = [(($page-1)*$nb), $nb]; $params['order'] = $sortby . ' ' . $order; - if ($urlsrv != '' && in_array($urlsrv, $lst_services_combo)) { - $params['kut_type'] = $urlsrv; + $urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : ''; + if ($urlsrv === '' || !in_array($urlsrv, $lst_services_combo)) { + $urlsrv = ''; } - - if ($sortby != $default_sortby || $order != $default_order || $urlsrv != '') { - $show_filters = true; + $urlsrv = $kUtRL_filter->setFilter([ + 'id' => 'urlsrv', + 'value' => $urlsrv, + 'title' => __('Service:'), + 'combo' => $lst_services_combo + ]); + if ($urlsrv != '') { + $params['kut_type'] = $urlsrv; } try { @@ -259,7 +244,7 @@ if ($part == 'links') { __('Links successfully deleted') ); - http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page); + http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb . '&page=' . $page); } catch (Exception $e) { $core->error->add($e->getMessage()); } @@ -273,7 +258,7 @@ echo if ($part == 'links') { echo dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])]) . - dcPage::jsFilterControl($show_filters) . + dcPage::jsFilterControl($kUtRL_filter->show()) . dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); } @@ -485,40 +470,11 @@ if ($part == 'links') { ) . dcPage::notices(); - echo ' -
'; + $kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links')); $list_current->display( $page, - $nb_per_page, + $nb, '', - $show_filters + $kUtRL_filter->show() ); }