diff --git a/CHANGELOG.md b/CHANGELOG.md index e3a2ef0..5463499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,17 @@ dev -- [ ] fix Dotclear 2.19 compatibility -- [ ] fix php7.3+ php8.0 compatibility -- [ ] clean up code -- [x] fix license -- [ ] fix translations -- [x] remove all SoCialMe feature as this plugin is dead - [ ] fix disallow self blog feeds - [ ] add plugin muppet support (request Mathieu M.) - [ ] add log for errors +- [ ] add generic filters +- [ ] add user pref for columns and filters options + +2021.09.16 +- fix Dotclear 2.19 compatibility +- fix php7.3+ php8.0 compatibility +- clean up code +- fix license +- remove all SoCialMe feature as this plugin is dead +- cometics fixes on admin pages 2015.07.19 - Pierre Van Glabeke - modif lien vers tous les flux diff --git a/README.md b/README.md index 37612f6..6965a5c 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Once it's done you can manage your feeds from menu ## CONTRIBUTORS - * Jean-Chirstian Denis + * Jean-Christian Denis * BG * Pierre Van Glabeke diff --git a/_admin.php b/_admin.php index 9a83c73..feba04f 100644 --- a/_admin.php +++ b/_admin.php @@ -37,6 +37,9 @@ if ($core->auth->check('admin', $core->blog->id)) { # Dashboard icon $core->addBehavior('adminDashboardFavorites', ['zcfsAdminBehaviors', 'adminDashboardFavorites']); + # User pref + $core->addBehavior('adminColumnsLists', ['zcfsAdminBehaviors', 'adminColumnsLists']); + $core->addBehavior('adminFiltersLists', ['zcfsAdminBehaviors', 'adminFiltersLists']); # Add info about feed on post page sidebar $core->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']); $core->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']); @@ -55,6 +58,17 @@ if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', ' */ class zcfsAdminBehaviors { + public static function feedsSortbyCombo() + { + return [ + __('Date') => 'feed_upddt', + __('Name') => 'lowername', + __('Frequency') => 'feed_upd_int', + __('Date of update') => 'feed_upd_last', + __('Status') => 'feed_status' + ]; + } + /** * Favorites. * @@ -110,6 +124,42 @@ class zcfsAdminBehaviors ); } + /** + * User pref columns lists. + * + * @param dcCore $core dcCore instance + * @param arrayObject $cols Columns + */ + public static function adminColumnsLists(dcCore $core, $cols) + { + $cols['zcfs_feeds'] = [ + __('Feeds server: Feeds'), + [ + 'desc' => [true, __('Feed')], + 'period' => [true, __('Frequency')], + 'update' => [true, __('Last update')], + 'entries' => [true, __('Entries')] + ] + ]; + } + + /** + * User pref filters options. + * + * @param dcCore $core dcCore instance + * @param arrayObject $sorts Sort options + */ + public static function adminFiltersLists(dcCore $core, $sorts) + { + $sorts['zcfs_feeds'] = [ + __('Feeds server: Feeds'), + self::feedsSortbyCombo(), + 'lowername', + 'asc', + [__('Links per page'), 30] + ]; + } + /** * Add javascript for toggle to post edition page header. * diff --git a/inc/lib.zcfs.list.php b/inc/lib.zcfs.list.php index b2ee487..88423cd 100644 --- a/inc/lib.zcfs.list.php +++ b/inc/lib.zcfs.list.php @@ -24,94 +24,116 @@ if (!defined('DC_CONTEXT_ADMIN')) { */ class zcfsFeedsList extends adminGenericList { - public function feedsDisplay($page, $nb_per_page, $url, $enclose='') + public function feedsDisplay($page, $nb_per_page, $enclose_block = '', $filter = false) { if ($this->rs->isEmpty()) { + if ($filter) { + echo '

' . __('No feeds matches the filter') . '

'; + } else { + echo '

' . __('No feeds') . '

'; + } + } else { + $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); + $entries = []; + if (isset($_REQUEST['feeds'])) { + foreach ($_REQUEST['feeds'] as $v) { + $entries[(integer) $v] = true; + } + } + $html_block = + '
' . + '' . + ''; - return '

'.__('There is no feed').'

'; + $cols = [ + 'title' => '', + 'desc' => '', + 'period' => '', + 'update' => '', + 'entries' => '', + 'status' => '' + ]; + $cols = new ArrayObject($cols); + + $this->core->callBehavior('adminZcfsFeedsListHeader', $this->core, $this->rs, $cols); + + $this->userColumns('zcfs_feeds', $cols); + + $html_block .= '' . implode(iterator_to_array($cols)) . '%s
' . ($filter ? + sprintf(__('List of %s feeds matching the filter.'), $this->rs_count) : + sprintf(__('List of entries (%s)'), $this->rs_count) + ) . '
' . __('Name') . '' . __('Feed') . '' . __('Frequency') . '' . __('Last update') . '' . __('Entries') . '' . __('Status') . '
%s
'; + if ($enclose_block) { + $html_block = sprintf($enclose_block, $html_block); + } + + echo $pager->getLinks(); + + $blocks = explode('%s', $html_block); + + echo $blocks[0]; + + while ($this->rs->fetch()) { + echo $this->feedsLine(isset($entries[$this->rs->feed_id])); + } + + echo $blocks[1]; + echo $blocks[2]; + echo $pager->getLinks(); } - - $pager = new dcPager($page, $this->rs_count ,$nb_per_page, 10); - - $pager->base_url = $url; - - $html_block = - '
'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - '%s'. - '
'.__('Name').''.__('Feed').''.__('Frequency').''.__('Last update').''.__('Entries').''.__('Status').'
'. - '
'; - - $res = ''; - while ($this->rs->fetch()) { - $res .= $this->feedsLine(); - } - - return - $pager->getLinks(). - sprintf($enclose, sprintf($html_block, $res)). - $pager->getLinks(); } - private function feedsLine() + private function feedsLine($checked) { $combo_status = zoneclearFeedServer::getAllStatus(); $combo_upd_int = zoneclearFeedServer::getAllUpdateInterval(); $status = $this->rs->feed_status ? 'enable' : 'disable'; - $category = $this->rs->cat_id ? - $this->rs->cat_title : __('no categories'); - $entries_count = $this->rs->zc->getPostsByFeed(array('feed_id' => $this->rs->feed_id), true)->f(0); + $entries_count = $this->rs->zc->getPostsByFeed(['feed_id' => $this->rs->feed_id], true)->f(0); $shunk_feed = $this->rs->feed_feed; if (strlen($shunk_feed) > 83) { $shunk_feed = substr($shunk_feed,0,50).'...'.substr($shunk_feed,-20); } - $url = 'plugin.php?p=zoneclearFeedServer&part=feed&feed_id='.$this->rs->feed_id; + $url = 'plugin.php?p=zoneclearFeedServer&part=feed&feed_id=' . $this->rs->feed_id; - return - ''."\n". - ''. - form::checkbox(array('feeds[]'), $this->rs->feed_id, 0). - ''. - ''. - ''. - html::escapeHTML($this->rs->feed_name).''. - "\n". - ''. - ''.html::escapeHTML($shunk_feed).''. - "\n". - ''. - array_search($this->rs->feed_upd_int,$combo_upd_int). - "\n". - ''. - ($this->rs->feed_upd_last < 1 ? - __('never') : - dt::str(__('%Y-%m-%d %H:%M'), $this->rs->feed_upd_last,$this->rs->zc->core->auth->getInfo('user_tz')) - ). - "\n". - ''. - ($entries_count ? - ''.$entries_count.'' : - $entries_count - ). - "\n". - ''. - $status. - "\n". - ''."\n"; + $cols = [ + 'check' => '' . + form::checkbox(['feeds[]'], $this->rs->feed_id, ['checked' => $checked]) . + '', + 'title' => '' . + '' . html::escapeHTML($this->rs->feed_name) . '' . + '', + 'desc' => '' . + '' . html::escapeHTML($shunk_feed) . ''. + '', + 'period' => '' . + array_search($this->rs->feed_upd_int,$combo_upd_int) . + '', + 'update' => '' . + ($this->rs->feed_upd_last < 1 ? + __('never') : + dt::str(__('%Y-%m-%d %H:%M'), $this->rs->feed_upd_last, $this->rs->zc->core->auth->getInfo('user_tz')) + ) . '', + 'entries' => '' . + ($entries_count ? + '' . $entries_count . '' : + $entries_count + ) . '', + 'status' => '' . $status . '' + ]; + + $cols = new ArrayObject($cols); + $this->core->callBehavior('adminZcfsFeedsListValue', $this->core, $this->rs, $cols); + + $this->userColumns('zcfs_feeds', $cols); + + return + '' . + implode(iterator_to_array($cols)) . + ''; } } diff --git a/index.php b/index.php index 6097217..c88cbd5 100644 --- a/index.php +++ b/index.php @@ -696,53 +696,13 @@ else { ); if ($feeds_actions_page->process()) { - return null; } - # Combos - $combo_sortby = array( - __('Date') => 'feed_upddt', - __('Name') => 'lowername', - __('Frequency') => 'feed_upd_int', - __('Date of update') => 'feed_upd_last', - __('Status') => 'feed_status' - ); - - $combo_order = array( - __('Descending') => 'desc', - __('Ascending') => 'asc' - ); - - # Prepared lists - $show_filters = false; - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'feed_upddt'; - $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; - $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; - $nb_per_page = 30; - if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != $_GET['nb']) $show_filters = true; - $nb_per_page = (integer) $_GET['nb']; - } - - $params = array(); - $params['limit'] = array((($page-1)*$nb_per_page), $nb_per_page); - - if ($sortby != '' && in_array($sortby, $combo_sortby)) { - if ($order != '' && in_array($order, $combo_order)) { - $params['order'] = $sortby.' '.$order; - } - if ($sortby != 'feed_upddt' || $order != 'desc') { - $show_filters = true; - } - } - - $pager_base_url = $p_url. - '&part=feeds'. - '&sortby='.$sortby. - '&order='.$order. - '&nb='.$nb_per_page. - '&page=%s'; + $feeds_filter = new adminGenericFilter($core, 'zcfs_feeds'); + $feeds_filter->add('part', 'feeds'); + $feeds_filter->add(dcAdminFilters::getPageFilter()); + $params = $feeds_filter->params(); try { $feeds = $zcfs->getFeeds($params); @@ -750,8 +710,7 @@ else { $feeds_list = new zcfsFeedsList( $core, $feeds, - $feeds_counter, - $pager_base_url + $feeds_counter ); } catch (Exception $e) { @@ -761,25 +720,9 @@ else { # Display echo ''.__('Feeds server').''. - dcPage::jsLoad( - 'index.php?pf=zoneclearFeedServer/js/feedsfilter.js' - ). - '\n". + dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'])]) . + dcPage::jsFilterControl($feeds_filter->show()) . + dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/feedsfilter.js')) . dcPage::jsPageTabs(). # --BEHAVIOR-- packmanAdminHeader @@ -798,51 +741,24 @@ else { '

'. ''. - __('New feed').'

'. + __('New feed').'

'; - '
'. - '

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

'. + $feeds_filter->display('admin.plugin.zoneclearFeedServer', form::hidden('p', 'zoneclearFeedServer') . form::hidden('part', 'feeds')); - '
'. - '
'. - '

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

'. - '
'. - '
'. - '

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

'. - '
'. - '
'. - '

'.__('Show').'

'. - '
'. - '
'. - - '

'. - form::hidden(array('p'), 'zoneclearFeedServer'). - form::hidden(array('part'), 'feeds'). - '

'. //Opera sucks - '
'. - - $feeds_list->feedsDisplay($page, $nb_per_page, $pager_base_url, + $feeds_list->feedsDisplay($feeds_filter->page, $feeds_filter->nb, '
'. '%s'. '
'. '

'. '

'.__('Selected feeds action:').' '. - form::combo(array('action'), $feeds_actions_page->getCombo()). + form::combo(['action'], $feeds_actions_page->getCombo()). ''. - 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'), 'zoneclearFeedServer'). - form::hidden(array('part'), 'feeds'). + $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', $feeds_filter->values(true)) . $core->formNonce(). '

'. '
'. - '
' + '', + false ); } diff --git a/js/feedsfilter.js b/js/feedsfilter.js index eb7021d..062e010 100644 --- a/js/feedsfilter.js +++ b/js/feedsfilter.js @@ -1,31 +1,3 @@ $(function(){ $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); - - $filtersform = $('#filters-form'); - $filtersform.before('

'+dotclear.msg.filter_posts_list+'

') - - if( dotclear.msg.show_filters == 'false' ) { - $filtersform.hide(); - } else { - $('#filter-control') - .addClass('open') - .text(dotclear.msg.cancel_the_filter); - } - - $('#filter-control').click(function() { - if( $(this).hasClass('open') ) { - if( dotclear.msg.show_filters == 'true' ) { - return true; - } else { - $filtersform.hide(); - $(this).removeClass('open') - .text(dotclear.msg.filter_posts_list); - } - } else { - $filtersform.show(); - $(this).addClass('open') - .text(dotclear.msg.cancel_the_filter); - } - return false; - }); }); \ No newline at end of file