User pref columns and filters : part 1 : feeds

This commit is contained in:
Jean-Christian Paul Denis 2021-10-09 22:21:31 +02:00
parent f2a7e3bbf4
commit ca7a47ffe0
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 167 additions and 203 deletions

View File

@ -1,13 +1,17 @@
dev 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 - [ ] fix disallow self blog feeds
- [ ] add plugin muppet support (request Mathieu M.) - [ ] add plugin muppet support (request Mathieu M.)
- [ ] add log for errors - [ ] 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 2015.07.19 - Pierre Van Glabeke
- modif lien vers tous les flux - modif lien vers tous les flux

View File

@ -42,7 +42,7 @@ Once it's done you can manage your feeds from menu
## CONTRIBUTORS ## CONTRIBUTORS
* Jean-Chirstian Denis * Jean-Christian Denis
* BG * BG
* Pierre Van Glabeke * Pierre Van Glabeke

View File

@ -37,6 +37,9 @@ if ($core->auth->check('admin', $core->blog->id)) {
# Dashboard icon # Dashboard icon
$core->addBehavior('adminDashboardFavorites', ['zcfsAdminBehaviors', 'adminDashboardFavorites']); $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 # Add info about feed on post page sidebar
$core->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']); $core->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']);
$core->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']); $core->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']);
@ -55,6 +58,17 @@ if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '
*/ */
class zcfsAdminBehaviors 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. * 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. * Add javascript for toggle to post edition page header.
* *

View File

@ -24,94 +24,116 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class zcfsFeedsList extends adminGenericList 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 ($this->rs->isEmpty()) {
if ($filter) {
echo '<p><strong>' . __('No feeds matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No feeds') . '</strong></p>';
}
} 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 =
'<div class="table-outer">' .
'<table>' .
'<caption>' . ($filter ?
sprintf(__('List of %s feeds matching the filter.'), $this->rs_count) :
sprintf(__('List of entries (%s)'), $this->rs_count)
) . '</caption>';
return '<p><strong>'.__('There is no feed').'</strong></p>'; $cols = [
'title' => '<th colspan="2" class="first">' . __('Name') . '</th>',
'desc' => '<th scope="col">' . __('Feed') . '</th>',
'period' => '<th scope="col">' . __('Frequency') . '</th>',
'update' => '<th scope="col">' . __('Last update') . '</th>',
'entries' => '<th scope="col">' . __('Entries') . '</th>',
'status' => '<th scope="col">' . __('Status') . '</th>'
];
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminZcfsFeedsListHeader', $this->core, $this->rs, $cols);
$this->userColumns('zcfs_feeds', $cols);
$html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>';
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 =
'<div class="table-outer">'.
'<table class="clear">'.
'<thead>'.
'<tr>'.
'<th class="nowrap first" colspan="2">'.__('Name').'</th>'.
'<th class="nowrap">'.__('Feed').'</th>'.
'<th class="nowrap">'.__('Frequency').'</th>'.
'<th class="nowrap">'.__('Last update').'</th>'.
'<th class="nowrap">'.__('Entries').'</th>'.
'<th class="nowrap">'.__('Status').'</th>'.
'</tr>'.
'</thead>'.
'<tbody>%s</tbody>'.
'</table>'.
'</div>';
$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_status = zoneclearFeedServer::getAllStatus();
$combo_upd_int = zoneclearFeedServer::getAllUpdateInterval(); $combo_upd_int = zoneclearFeedServer::getAllUpdateInterval();
$status = $this->rs->feed_status ? $status = $this->rs->feed_status ?
'<img src="images/check-on.png" alt="enable" />' : '<img src="images/check-on.png" alt="enable" />' :
'<img src="images/check-off.png" alt="disable" />'; '<img src="images/check-off.png" alt="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; $shunk_feed = $this->rs->feed_feed;
if (strlen($shunk_feed) > 83) { if (strlen($shunk_feed) > 83) {
$shunk_feed = substr($shunk_feed,0,50).'...'.substr($shunk_feed,-20); $shunk_feed = substr($shunk_feed,0,50).'...'.substr($shunk_feed,-20);
} }
$url = 'plugin.php?p=zoneclearFeedServer&amp;part=feed&amp;feed_id='.$this->rs->feed_id; $url = 'plugin.php?p=zoneclearFeedServer&amp;part=feed&amp;feed_id=' . $this->rs->feed_id;
$cols = [
'check' => '<td class="nowrap minimal">' .
form::checkbox(['feeds[]'], $this->rs->feed_id, ['checked' => $checked]) .
'</td>',
'title' => '<td class="nowrap" scope="row">' .
'<a href="' . $url . '#feed" title="' . __('Edit') . '">' . html::escapeHTML($this->rs->feed_name) . '</a>' .
'</td>',
'desc' => '<td class="nowrap maximal">' .
'<a href="' . $this->rs->feed_feed . '" title="' . html::escapeHTML($this->rs->feed_desc) . '">' . html::escapeHTML($shunk_feed) . '</a>'.
'</td>',
'period' => '<td class="nowrap minimal count">' .
array_search($this->rs->feed_upd_int,$combo_upd_int) .
'</td>',
'update' => '<td class="nowrap minimal count">' .
($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'))
) . '</td>',
'entries' => '<td class="nowrap minimal count">' .
($entries_count ?
'<a href="' . $url . '#entries" title="' . __('View entries') . '">' . $entries_count . '</a>' :
$entries_count
) . '</td>',
'status' => '<td class="nowrap minimal status">' . $status . '</td>'
];
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminZcfsFeedsListValue', $this->core, $this->rs, $cols);
$this->userColumns('zcfs_feeds', $cols);
return return
'<tr class="line">'."\n". '<tr class="line ' . ($this->rs->feed_status ? '' : 'offline ') . '" id="p' . $this->rs->feed_id . '">' .
'<td class="nowrap">'. implode(iterator_to_array($cols)) .
form::checkbox(array('feeds[]'), $this->rs->feed_id, 0). '</tr>';
'</td>'.
'<td class="nowrap">'.
'<a href="'.$url.'#feed" title="'.__('Edit').'">'.
html::escapeHTML($this->rs->feed_name).'</a>'.
"</td>\n".
'<td class="maximal nowrap">'.
'<a href="'.$this->rs->feed_feed.'" title="'.html::escapeHTML($this->rs->feed_desc).'">'.html::escapeHTML($shunk_feed).'</a>'.
"</td>\n".
'<td class="nowrap">'.
array_search($this->rs->feed_upd_int,$combo_upd_int).
"</td>\n".
'<td class="nowrap">'.
($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'))
).
"</td>\n".
'<td class="nowrap">'.
($entries_count ?
'<a href="'.$url.'#entries" title="'.__('View entries').'">'.$entries_count.'</a>' :
$entries_count
).
"</td>\n".
'<td>'.
$status.
"</td>\n".
'</tr>'."\n";
} }
} }

114
index.php
View File

@ -696,53 +696,13 @@ else {
); );
if ($feeds_actions_page->process()) { if ($feeds_actions_page->process()) {
return null; return null;
} }
# Combos $feeds_filter = new adminGenericFilter($core, 'zcfs_feeds');
$combo_sortby = array( $feeds_filter->add('part', 'feeds');
__('Date') => 'feed_upddt', $feeds_filter->add(dcAdminFilters::getPageFilter());
__('Name') => 'lowername', $params = $feeds_filter->params();
__('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.
'&amp;part=feeds'.
'&amp;sortby='.$sortby.
'&amp;order='.$order.
'&amp;nb='.$nb_per_page.
'&amp;page=%s';
try { try {
$feeds = $zcfs->getFeeds($params); $feeds = $zcfs->getFeeds($params);
@ -750,8 +710,7 @@ else {
$feeds_list = new zcfsFeedsList( $feeds_list = new zcfsFeedsList(
$core, $core,
$feeds, $feeds,
$feeds_counter, $feeds_counter
$pager_base_url
); );
} }
catch (Exception $e) { catch (Exception $e) {
@ -761,25 +720,9 @@ else {
# Display # Display
echo echo
'<html><head><title>'.__('Feeds server').'</title>'. '<html><head><title>'.__('Feeds server').'</title>'.
dcPage::jsLoad( dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'])]) .
'index.php?pf=zoneclearFeedServer/js/feedsfilter.js' dcPage::jsFilterControl($feeds_filter->show()) .
). dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/feedsfilter.js')) .
'<script type="text/javascript">'."\n".
"//<![CDATA["."\n".
dcPage::jsVar(
'dotclear.msg.show_filters',
$show_filters ? 'true':'false'
)."\n".
dcPage::jsVar(
'dotclear.msg.filter_posts_list',
__('Show filters and display options')
)."\n".
dcPage::jsVar(
'dotclear.msg.cancel_the_filter',
__('Cancel filters and display options')
)."\n".
"//]]>\n".
"</script>\n".
dcPage::jsPageTabs(). dcPage::jsPageTabs().
# --BEHAVIOR-- packmanAdminHeader # --BEHAVIOR-- packmanAdminHeader
@ -798,51 +741,24 @@ else {
'<p class="top-add">'. '<p class="top-add">'.
'<a class="button add" href="'.$p_url.'&amp;part=feed">'. '<a class="button add" href="'.$p_url.'&amp;part=feed">'.
__('New feed').'</a></p>'. __('New feed').'</a></p>';
'<form action="'.$p_url.'&amp;part=feeds" method="get" id="filters-form">'. $feeds_filter->display('admin.plugin.zoneclearFeedServer', form::hidden('p', 'zoneclearFeedServer') . form::hidden('part', 'feeds'));
'<h3 class="out-of-screen-if-js">'.__('Show filters and display options').'</h3>'.
'<div class="table">'. $feeds_list->feedsDisplay($feeds_filter->page, $feeds_filter->nb,
'<div class="cell">'.
'<p><label for="sortby" class="ib">'.__('Order by:').'</label> '.
form::combo('sortby',$combo_sortby, $sortby).'</p>'.
'</div>'.
'<div class="cell">'.
'<p><label for="order" class="ib">'.__('Sort:').'</label> '.
form::combo('order',$combo_order, $order).'</p>'.
'</div>'.
'<div class="cell">'.
'<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'.
form::field('nb',3,3,$nb_per_page).' '.
__('entries per page').'</label></p>'.
'</div>'.
'</div>'.
'<p><input type="submit" value="'.__('Apply filters and display options').'" />'.
form::hidden(array('p'), 'zoneclearFeedServer').
form::hidden(array('part'), 'feeds').
'<br class="clear" /></p>'. //Opera sucks
'</form>'.
$feeds_list->feedsDisplay($page, $nb_per_page, $pager_base_url,
'<form action="'.$p_url.'&amp;part=feeds" method="post" id="form-actions">'. '<form action="'.$p_url.'&amp;part=feeds" method="post" id="form-actions">'.
'%s'. '%s'.
'<div class="two-cols">'. '<div class="two-cols">'.
'<p class="col checkboxes-helpers"></p>'. '<p class="col checkboxes-helpers"></p>'.
'<p class="col right">'.__('Selected feeds action:').' '. '<p class="col right">'.__('Selected feeds action:').' '.
form::combo(array('action'), $feeds_actions_page->getCombo()). form::combo(['action'], $feeds_actions_page->getCombo()).
'<input type="submit" value="'.__('ok').'" />'. '<input type="submit" value="'.__('ok').'" />'.
form::hidden(array('sortby'), $sortby). $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', $feeds_filter->values(true)) .
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->formNonce(). $core->formNonce().
'</p>'. '</p>'.
'</div>'. '</div>'.
'</form>' '</form>',
false
); );
} }

View File

@ -1,31 +1,3 @@
$(function(){ $(function(){
$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});
$filtersform = $('#filters-form');
$filtersform.before('<p><a id="filter-control" class="form-control" href="plugin.php?p=zoneclearFeedServer&amp;part=feeds" style="display:inline">'+dotclear.msg.filter_posts_list+'</a></p>')
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;
});
}); });