From 2f30a63038e2887c5131f56f18409917006827a6 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 11 Sep 2021 00:46:28 +0200 Subject: [PATCH] add user pref for list options --- CHANGELOG.md | 1 + _admin.php | 20 ++++- inc/lib.cinecturlink2.list.php | 129 +++++++++++++++++++-------------- 3 files changed, 96 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8a65b0..8fde797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.8.1 - dev - [ ] update public templates - [ ] fix javascript +- [x] add user pref for list options 0.8 - 2021.09.09 - fix compatibility Dotclear v2.19 diff --git a/_admin.php b/_admin.php index 459f507..c0c3ab9 100644 --- a/_admin.php +++ b/_admin.php @@ -22,12 +22,16 @@ $_menu['Plugins']->addItem( $core->adminurl->get('admin.plugin.cinecturlink2'), dcPage::getPF('cinecturlink2/icon.png'), preg_match( - '/' . preg_quote($core->adminurl->get('admin.plugin.dcAdvancedCleaner')) . '(&.*)?$/', + '/' . preg_quote($core->adminurl->get('admin.plugin.cinecturlink2')) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), $core->auth->check('contentadmin', $core->blog->id) ); +$core->addBehavior( + 'adminColumnsLists', + ['cinecturlink2AdminBehaviors', 'adminColumnsLists'] +); $core->addBehavior( 'adminDashboardFavorites', ['cinecturlink2AdminBehaviors', 'adminDashboardFavorites'] @@ -35,6 +39,20 @@ $core->addBehavior( class cinecturlink2AdminBehaviors { + public static function adminColumnsLists($core, $cols) + { + $cols['c2link'] = [ + __('Cinecturlink'), [ + 'date' => [true, __('Date')], + 'cat' => [true, __('Category')], + 'author' => [true, __('Author')], + 'desc' => [false, _('Category')], + 'link' => [true, _('Liens')], + 'note' => [true, __('Rating')], + ] + ]; + } + public static function adminDashboardFavorites($core, $favs) { $favs->register('cinecturlink2', [ diff --git a/inc/lib.cinecturlink2.list.php b/inc/lib.cinecturlink2.list.php index 0a1eb85..ff3c35c 100644 --- a/inc/lib.cinecturlink2.list.php +++ b/inc/lib.cinecturlink2.list.php @@ -34,6 +34,20 @@ class adminlistCinecturlink2 $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, $redir = '') { $this->redir = $redir; @@ -52,6 +66,18 @@ class adminlistCinecturlink2 } } + $cols = [ + 'title' => '' . __('Title') . '', + 'author' => '' . __('Author') . '', + 'desc' => '' . __('Description') . '', + 'link' => '' . __('Links') . '', + 'cat' => '' . __('Category') . '', + 'note' => '' . __('Rating') . '', + 'date' => '' . __('Date') . '' + ]; + $cols = new ArrayObject($cols); + $this->userColumns('c2link', $cols); + $html_block = '
' . '' . @@ -60,15 +86,7 @@ class adminlistCinecturlink2 sprintf(__('List of links (%s)'), $this->rs_count) ). '' . '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . + '' . implode(iterator_to_array($cols)) . '' . '' . '%s' . '
' . __('Title') . '' . __('Author') . '' . __('Description') . '' . __('Links') . '' . __('Category') . '' . __('Rating') . '' . __('Date') . '
' . @@ -91,49 +109,54 @@ class adminlistCinecturlink2 private function linkLine($checked) { - return - '' . - '' . - form::checkbox(['entries[]'], $this->rs->link_id, ['checked' => $checked]) . - '' . - '' . - '' . - html::escapeHTML($this->rs->link_title) . '' . - '' . - '' . - html::escapeHTML($this->rs->link_author) . - '' . - '' . - html::escapeHTML($this->rs->link_desc) . - '' . - '' . - '' . __('URL') . ' ' . - '' . __('image') . ' ' . - '' . - '' . - '' . - html::escapeHTML($this->rs->cat_title) . '' . - '' . - '' . - html::escapeHTML($this->rs->link_note) . '/20' . - '' . - '' . - dt::dt2str( - $this->core->blog->settings->system->date_format . ', ' . $this->core->blog->settings->system->time_format, - $this->rs->link_upddt, - $this->core->auth->getInfo('user_tz') - ) . - '' . - '' . "\n"; + $cols = [ + 'check' => '' . + form::checkbox(['entries[]'], $this->rs->link_id, ['checked' => $checked]) . + '', + 'title' => '' . + '' . + html::escapeHTML($this->rs->link_title) . '' . + '', + 'author' => '' . + html::escapeHTML($this->rs->link_author) . + '', + 'desc' => '' . + html::escapeHTML($this->rs->link_desc) . + '', + 'link' => '' . + '' . __('URL') . ' ' . + '' . __('image') . ' ' . + '', + 'cat' => '' . + '' . + html::escapeHTML($this->rs->cat_title) . '' . + '', + 'note' => '' . + '' . + html::escapeHTML($this->rs->link_note) . '/20' . + '', + 'date' => '' . + dt::dt2str( + $this->core->blog->settings->system->date_format . ', ' . $this->core->blog->settings->system->time_format, + $this->rs->link_upddt, + $this->core->auth->getInfo('user_tz') + ) . + '' + ]; + + $cols = new ArrayObject($cols); + $this->userColumns('c2link', $cols); + + return '' . implode(iterator_to_array($cols)) . '' . "\n"; } } \ No newline at end of file