diff --git a/CHANGELOG.md b/CHANGELOG.md index 1983a2b..7b061d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ xxx.xx.xx - Never fix breaking comments or complexe public url - [ ] Add public page of the list of know urls and in/visible status - [ ] Add passworded links +- fix permissions +- fix js load +- add user pref on table cols +- add user pref on filters (dc 2.20) 2021.09.16 - remove deprecated external service diff --git a/_admin.php b/_admin.php index 20eff0b..e34a096 100644 --- a/_admin.php +++ b/_admin.php @@ -25,11 +25,14 @@ $_menu['Plugins']->addItem( $core->adminurl->get('admin.plugin.kUtRL'), dcPage::getPF('kUtRL/icon.png'), preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - $core->auth->check('admin', $core->blog->id)); + $core->auth->check('admin', $core->blog->id) +); # Admin behaviors if ($core->blog->settings->kUtRL->kutrl_active) { $core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']); + $core->addBehavior('adminColumnsLists', ['adminKutrl', 'adminColumnsLists']); + $core->addBehavior('adminSortsLists', ['adminKutrl', 'adminSortsLists']); $core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); $core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']); $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url @@ -49,23 +52,56 @@ $core->addBehavior('importFull', ['backupKutrl', 'importFull']); # Admin behaviors class class adminKutrl { + public static function sortbyCombo() + { + return [ + __('Date') => 'kut_dt', + __('Short URL') => 'kut_hash', + __('Long URL') => 'kut_url', + __('Service') => 'kut_service' + ]; + } + public static function antispamDashboardFavorites(dcCore $core, $favs) { $favs->register( 'kUtRL', [ - 'title' => __('Links shortener'), - 'url' => $core->adminurl->get('admin.plugin.kUtRL'), - 'small-icon' => dcPage::getPF('kUtRL/icon.png'), - 'large-icon' => dcPage::getPF('kUtRL/icon-b.png'), + 'title' => __('Links shortener'), + 'url' => $core->adminurl->get('admin.plugin.kUtRL'), + 'small-icon' => dcPage::getPF('kUtRL/icon.png'), + 'large-icon' => dcPage::getPF('kUtRL/icon-b.png'), 'permissions' => 'admin' ] ); } + public static function adminColumnsLists(dcCore $core, $cols) + { + $cols['kUtRL'] = [ + __('URL shortener'), + [ + 'kut_hash' => [true, __('Hash')], + 'kut_dt' => [true, __('Date')], + 'kut_service' => [true, __('Service')] + ] + ]; + } + + public static function adminSortsLists(dcCore $core, $sorts) + { + $sorts['kUtRL'] = [ + __('URL shortener'), + self::sortbyCombo(), + 'kut_dt', + 'desc', + [__('Links per page'), 30] + ]; + } + public static function adminPostHeaders() { - return dcPage::jsLoad('index.php?pf=kUtRL/js/admin.js'); + return dcPage::jsLoad(dcPage::getPF('kUtRL/js/posts.js')); } public static function adminPostFormItems($main_items, $sidebar_items, $post) diff --git a/inc/lib.kutrl.lst.php b/inc/lib.kutrl.lst.php index 9a4c714..eaf7c25 100644 --- a/inc/lib.kutrl.lst.php +++ b/inc/lib.kutrl.lst.php @@ -28,6 +28,20 @@ class kutrlLinkslist $this->html_next = __('next »'); } + public function userColumns($type, $cols) + { + $cols_user = @$this->core->auth->user_prefs->interface->cols; + if (is_array($cols_user) || $cols_user instanceof ArrayObject) { + if (isset($cols_user[$type])) { + foreach ($cols_user[$type] as $cn => $cd) { + if (!$cd && isset($cols[$cn])) { + unset($cols[$cn]); + } + } + } + } + } + public function display($page, $nb_per_page, $enclose_block, $filter = false) { if ($this->rs->isEmpty()) { @@ -38,59 +52,82 @@ class kutrlLinkslist } } else { $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); - $entries = []; + $links = []; if (isset($_REQUEST['entries'])) { foreach ($_REQUEST['entries'] as $v) { - $entries[(integer) $v] = true; + $links[(integer) $v] = true; } } - $blocks = explode('%s', sprintf($enclose_block, - '
' . - ($filter ? - '' : - '' - ) . - '' . - '' . - '' . - '' . - '' . - '%s
' . sprintf(__('List of %s links matching the filter.'), $this->rs_count) . '' . sprintf(__('List of links (%s)'), $this->rs_count) . '
' . __('Hash') . '' . __('Link') . '' . __('Date') . '' . __('Service') . '
%s
' - )); + $cols = [ + 'kut_url' => '' . __('Link') . '', + 'kut_hash' => '' . __('Hash') . '', + 'kut_dt' => '' . __('Date') . '', + 'kut_service' => '' . __('Service') . '' + ]; + $cols = new ArrayObject($cols); + $this->userColumns('kUtRL', $cols); - echo $pager->getLinks().$blocks[0]; + $html_block = + '
' . + '' . + '' . + '' . + '' . implode(iterator_to_array($cols)) . '' . + '' . + '%s' . + '
' . ($filter ? + sprintf(__('List of %s links matching the filter.'), $this->rs_count) : + sprintf(__('List of links (%s)'), $this->rs_count) + ). '
' . + '%s
'; + + if ($enclose_block) { + $html_block = sprintf($enclose_block, $html_block); + } + $blocks = explode('%s', $html_block); + + echo $pager->getLinks() . $blocks[0]; while ($this->rs->fetch()) { - $type = $this->rs->kut_type; - $hash = $this->rs->kut_hash; - - if (null !== ($o = kutrl::quickService($type))) { - $type = '' . $o->name . ''; - $hash = '' . $hash . ''; - } - - echo - '' . - '' . - form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) . - '' . - '' . - $hash . - '' . - '' . - '' . $this->rs->kut_url . '' . - '' . - '' . - dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) . - '' . - '' . - $type . - '' . - ''; + echo $this->linkLine(isset($links[$this->rs->kut_id])); } - echo $blocks[1].$blocks[2].$pager->getLinks(); + echo $blocks[1] . $blocks[2] . $pager->getLinks(); } } + + private function linkLine($checked) + { + $type = $this->rs->kut_type; + $hash = $this->rs->kut_hash; + + if (null !== ($o = kutrl::quickService($type))) { + $type = '' . $o->name . ''; + $hash = '' . $hash . ''; + } + + $cols = [ + 'check' => '' . + form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) . + '', + 'kut_url' => '' . + '' . $this->rs->kut_url . '' . + '', + 'kut_hash' => '' . + $hash . + '', + 'kut_dt' => '' . + dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) . + '', + 'kut_service' => '' . + $type . + '' + ]; + + $cols = new ArrayObject($cols); + $this->userColumns('kUtRL', $cols); + + return '' . implode(iterator_to_array($cols)) . '' . "\n"; + } } \ No newline at end of file diff --git a/index.php b/index.php index e355fa9..ba6eaa2 100644 --- a/index.php +++ b/index.php @@ -190,20 +190,15 @@ if ($part == 'link') { if ($part == 'links') { $log = new kutrlLog($core); - $sortby_combo = [ - __('Date') => 'kut_dt', - __('Long link') => 'kut_url', - __('Short link') => 'kut_hash' - ]; - $order_combo = [ - __('Descending') => 'desc', - __('Ascending') => 'asc' - ]; + $sortby_combo = adminKutrl::sortbyCombo(); + $order_combo = [__('Descending') => 'desc', __('Ascending') => 'asc']; $core->auth->user_prefs->addWorkspace('interface'); - $default_sortby = 'kut_dt'; - $default_order = $core->auth->user_prefs->interface->posts_order ?: 'desc'; - $nb_per_page = $core->auth->user_prefs->interface->nb_posts_per_page ?: 30; + $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 = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby; $order = !empty($_GET['order']) ? $_GET['order'] : $default_order; $urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : ''; @@ -277,16 +272,9 @@ echo if ($part == 'links') { echo - '\n" . - dcPage::jsFilterControl($show_filters); + dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])]) . + dcPage::jsFilterControl($show_filters) . + dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); } echo @@ -498,7 +486,7 @@ if ($part == 'links') { dcPage::notices(); echo ' -
+

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

@@ -518,8 +506,9 @@ if ($part == 'links') { __('entries per page') . '

' . form::hidden('part', 'links') . - form::hidden('p', 'kUtRL') . ' - + form::hidden('p', 'kUtRL') . + form::hidden('filters-options-id', 'kUtRL') . + '

' . __('Save current options') . '

@@ -530,21 +519,27 @@ if ($part == 'links') { $list_current->display( $page, $nb_per_page, - ' + ' %s
-

+
+

+

- ' . - form::hidden(['deletelinks'], 1) . - form::hidden(['urlsrv'], $urlsrv) . - form::hidden(['sortby'], $sortby) . - form::hidden(['order'], $order) . - form::hidden(['page'], $page) . - form::hidden(['nb'], $nb_per_page) . - form::hidden(['part'], 'links') . +

' . + $core->adminurl->getHiddenFormFields( + 'admin.plugin.kUtRL',[ + 'deletelinks' => 1, + 'urlsrv' => $urlsrv, + 'sortby' => $sortby, + 'order' => $order, + 'page' => $page, + 'nb' => $nb_per_page, + 'part' => 'links' + ] + ) . $core->formNonce() . '

diff --git a/js/admin.js b/js/admin.js index d39c02b..c8d7ac2 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,7 +1,7 @@ $(function(){ - /* toogle admin form sidebar */ - $('#kUtRL h5').toggleWithLegend( - $('#kUtRL').children().not('h5'), - {cookie:'dcx_kUtRL_admin_form_sidebar',legend_click:true} - ); + $('#form-entries .checkboxes-helpers').each(function () { + dotclear.checkboxesHelpers(this, undefined, '#form-entries td input[type=checkbox]', '#form-entries #do-action'); + }); + $('#form-entries td input[type=checkbox]').enableShiftClick(); + dotclear.condSubmit('#form-entries td input[type=checkbox]', '#form-entries #do-action'); }); \ No newline at end of file diff --git a/js/posts.js b/js/posts.js new file mode 100644 index 0000000..4576328 --- /dev/null +++ b/js/posts.js @@ -0,0 +1,7 @@ +$(function(){ + /* toogle admin form sidebar */ + $('#kUtRL h5').toggleWithLegend( + $('#kUtRL').children().not('h5'), + {cookie:'dcx_kUtRL_admin_form_sidebar',legend_click:true} + ); +}); \ No newline at end of file