diff --git a/_admin.php b/_admin.php index e9210b8..c4b3374 100644 --- a/_admin.php +++ b/_admin.php @@ -34,8 +34,8 @@ $core->addBehavior( ); $core->addBehavior( - 'adminSortsLists', - ['cinecturlink2AdminBehaviors', 'adminSortsLists'] + 'adminFiltersLists', + ['cinecturlink2AdminBehaviors', 'adminFiltersLists'] ); $core->addBehavior( 'adminDashboardFavorites', @@ -44,6 +44,19 @@ $core->addBehavior( class cinecturlink2AdminBehaviors { + public static function adminSortbyCombo() + { + return [ + __('Date') => 'link_upddt', + __('Title') => 'link_title', + __('Category') => 'cat_id', + __('Author') => 'link_author', + __('Description') => 'link_desc', + __('Link') => 'link_url', + __('Rating') => 'link_note' + ]; + } + public static function adminColumnsLists($core, $cols) { $cols['c2link'] = [ @@ -59,22 +72,14 @@ class cinecturlink2AdminBehaviors ]; } - public static function adminSortsLists($core, $sorts) + public static function adminFiltersLists($core, $sorts) { $sorts['c2link'] = [ __('Cinecturlink'), - [ - __('Date') => 'link_upddt', - __('Title') => 'link_title', - __('Category') => 'cat_id', - __('Author') => 'link_author', - __('Description') => 'link_desc', - __('Link') => 'link_url', - __('Rating') => 'link_note' - ], + self::adminSortbyCombo(), 'link_upddt', 'desc', - null + [__('Links per page'), 30] ]; } diff --git a/index.php b/index.php index d89f487..9928dd1 100644 --- a/index.php +++ b/index.php @@ -32,6 +32,7 @@ $catdesc = $_POST['catdesc'] ?? ''; $redir = $_REQUEST['redir'] ?? ''; $part = $_REQUEST['part'] ?? 'links'; $entries = $_POST['entries'] ?? []; +$page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; $headers = ''; $breadcrumb = [ html::escapeHTML($core->blog->name) => '', @@ -136,65 +137,39 @@ if ($part == 'updlinkscat') { } if ($part == 'links') { - $sortby_combo = [ - __('Date') => 'link_upddt', - __('Title') => 'link_title', - __('Category') => 'cat_id', - __('Author') => 'link_author', - __('Description') => 'link_desc', - __('Liens') => 'link_url', - __('Rating') => 'link_note' - ]; - $order_combo = [ - __('Descending') => 'desc', - __('Ascending') => 'asc' - ]; $action_combo = [ __('Delete') => 'dellinks', __('Change category') => 'updlinkscat', __('Change rating') => 'updlinksnote' ]; - $show_filters = false; - $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; + $c2link_filter = new adminGenericFilter($core, 'c2link'); - $core->auth->user_prefs->addWorkspace('interface'); - $sorts_user = @$core->auth->user_prefs->interface->sorts; - $default_sortby = $sorts_user['c2link'][0] ?? 'link_upddt'; - $default_order = $sorts_user['c2link'][1] ?? 'desc'; - $nb_per_page = !empty($sorts_user['c2link'][2]) ? $sorts_user['c2link'][2] : 30; + $sortby = $c2link_filter->getFilter('sortby'); + $order = $c2link_filter->getFilter('order'); + $nb = $c2link_filter->getFilter('nb'); - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby; - $order = !empty($_GET['order']) ? $_GET['order'] : $default_order; - - if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != (integer) $_GET['nb']) { - $show_filters = true; - } - $nb_per_page = (integer) $_GET['nb']; - } - if (!in_array($sortby, $sortby_combo)) { - $sortby = $default_sortby; - } - if (!in_array($order, $order_combo)) { - $order = $default_order; - } - if ($sortby != $default_sortby || $order != $default_order) { - $show_filters = true; - } + $c2link_filter->setFilter('page', $page); + $c2link_filter->setFilter('part', 'links'); $params = []; $params['link_type'] = 'cinecturlink'; - $params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page]; + $params['limit'] = [(($page - 1) * $nb), $nb]; $params['no_content'] = true; $params['order'] = $sortby . ' ' . $order; - if ($catid !== '' && in_array($catid, $categories_combo)) { - $params['cat_id'] = $catid; - $show_filters = true; - } else { + if ($catid === '' || !in_array($catid, $categories_combo)) { $catid = ''; } + $catid = $c2link_filter->setFilter([ + 'id' => 'catid', + 'value' => $catid, + 'title' => __('Category:'), + 'combo' => $categories_combo + ]); + if ($catid != '') { + $params['cat_id'] = $catid; + } $links_list = null; @@ -209,7 +184,7 @@ if ($part == 'links') { $breadcrumb[__('My cinecturlink')] = ''; $headers .= dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links'])]) . - dcPage::jsFilterControl($show_filters) . + dcPage::jsFilterControl($c2link_filter->show()) . dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/c2links.js')); } @@ -523,17 +498,8 @@ if ($part == 'updlinkscat') { } if ($part == "links") { - $links_redir = $core->adminurl->get( - 'admin.plugin.cinecturlink2', - [ - 'part' => 'links', - 'catid' => $catid, - 'sortby' => $sortby, - 'order' => $order, - 'page' => $page, - 'nb' => $nb_per_page - ] - ); + $links_redir = $core->adminurl->get('admin.plugin.cinecturlink2', $c2link_filter->getFilters()); + echo '