update to PSR12

This commit is contained in:
Jean-Christian Denis 2021-11-06 16:30:19 +01:00
parent b0e2547f1d
commit 92521cdbf9
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
17 changed files with 625 additions and 566 deletions

View file

@ -2,10 +2,11 @@
- [ ] 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 generic filters (dc 2.20)
- add user pref for columns and filters options - add user pref for columns and filters options (dc 2.20)
- fix redirections, page title, posts feed form - fix redirections, page title, posts feed form
- update translation - update translation
- update to PSR12
2021.09.16 2021.09.16
- fix Dotclear 2.19 compatibility - fix Dotclear 2.19 compatibility

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -24,14 +23,14 @@ $_menu['Plugins']->addItem(
$core->adminurl->get('admin.plugin.zoneclearFeedServer'), $core->adminurl->get('admin.plugin.zoneclearFeedServer'),
dcPage::getPF('zoneclearFeedServer/icon.png'), dcPage::getPF('zoneclearFeedServer/icon.png'),
preg_match( preg_match(
'/' . preg_quote($core->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/', '/' . preg_quote($core->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/',
$_SERVER['REQUEST_URI'] $_SERVER['REQUEST_URI']
), ),
$core->auth->check('admin', $core->blog->id) $core->auth->check('admin', $core->blog->id)
); );
# Delete related info about feed post in meta table # Delete related info about feed post in meta table
$core->addBehavior('adminBeforePostDelete',['zcfsAdminBehaviors', 'adminBeforePostDelete']); $core->addBehavior('adminBeforePostDelete', ['zcfsAdminBehaviors', 'adminBeforePostDelete']);
if ($core->auth->check('admin', $core->blog->id)) { if ($core->auth->check('admin', $core->blog->id)) {
@ -47,7 +46,6 @@ if ($core->auth->check('admin', $core->blog->id)) {
# Take care about tweakurls (thanks Mathieu M.) # Take care about tweakurls (thanks Mathieu M.)
if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) { if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) {
$core->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']); $core->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']);
} }
@ -107,8 +105,8 @@ class zcfsAdminBehaviors
*/ */
public static function adminDashboardFavoritesActive($request, $params) public static function adminDashboardFavoritesActive($request, $params)
{ {
return $request == 'plugin.php' return $request == 'plugin.php'
&& isset($params['p']) && isset($params['p'])
&& $params['p'] == 'zoneclearFeedServer'; && $params['p'] == 'zoneclearFeedServer';
} }
@ -127,10 +125,10 @@ class zcfsAdminBehaviors
return null; return null;
} }
$fav['title'] .= '<br />'.sprintf(__('%s feed disabled', '%s feeds disabled', $count), $count); $fav['title'] .= '<br />' . sprintf(__('%s feed disabled', '%s feeds disabled', $count), $count);
$fav['large-icon'] = dcPage::getPF('zoneclearFeedServer/icon-big-update.png'); $fav['large-icon'] = dcPage::getPF('zoneclearFeedServer/icon-big-update.png');
$fav['url'] = $core->adminurl->get( $fav['url'] = $core->adminurl->get(
'admin.plugin.zoneclearFeedServer', 'admin.plugin.zoneclearFeedServer',
['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc'] ['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc']
); );
} }
@ -146,18 +144,18 @@ class zcfsAdminBehaviors
$cols['zcfs_feeds'] = [ $cols['zcfs_feeds'] = [
__('Feeds server: Feeds'), __('Feeds server: Feeds'),
[ [
'desc' => [true, __('Feed')], 'desc' => [true, __('Feed')],
'period' => [true, __('Frequency')], 'period' => [true, __('Frequency')],
'update' => [true, __('Last update')], 'update' => [true, __('Last update')],
'entries' => [true, __('Entries')] 'entries' => [true, __('Entries')]
] ]
]; ];
$cols['zcfs_entries'] = [ $cols['zcfs_entries'] = [
__('Feeds server: Entries'), __('Feeds server: Entries'),
[ [
'date' => [true, __('Date')], 'date' => [true, __('Date')],
'category' => [true, __('Category')], 'category' => [true, __('Category')],
'author' => [true, __('Author')] 'author' => [true, __('Author')]
] ]
]; ];
} }
@ -188,7 +186,7 @@ class zcfsAdminBehaviors
/** /**
* Add javascript for toggle to post edition page header. * Add javascript for toggle to post edition page header.
* *
* @return string Page header * @return string Page header
*/ */
public static function adminPostHeaders() public static function adminPostHeaders()
@ -198,7 +196,7 @@ class zcfsAdminBehaviors
/** /**
* Add form to post sidebar. * Add form to post sidebar.
* *
* @param ArrayObject $main_items Main items * @param ArrayObject $main_items Main items
* @param ArrayObject $sidebar_items Sidebar items * @param ArrayObject $sidebar_items Sidebar items
* @param record $post Post record or null * @param record $post Post record or null
@ -253,7 +251,7 @@ class zcfsAdminBehaviors
$edit = sprintf( $edit = sprintf(
'<p><a href="%s">%s</a></p>', '<p><a href="%s">%s</a></p>',
$core->adminurl->get( $core->adminurl->get(
'admin.plugin.zoneclearFeedServer', 'admin.plugin.zoneclearFeedServer',
['part' => 'feed', 'feed_id' => $fid->meta_id] ['part' => 'feed', 'feed_id' => $fid->meta_id]
), ),
__('Edit this feed') __('Edit this feed')
@ -261,8 +259,7 @@ class zcfsAdminBehaviors
} }
} }
$sidebar_items['options-box']['items']['zcfs'] = $sidebar_items['options-box']['items']['zcfs'] = '<div id="zcfs">' .
'<div id="zcfs">'.
'<h5>' . __('Feed source') . '</h5>' . '<h5>' . __('Feed source') . '</h5>' .
'<p>' . '<p>' .
'<a href="' . $url . '" title="' . $author . ' - ' . $url . '">' . __('feed URL') . '</a> - ' . '<a href="' . $url . '" title="' . $author . ' - ' . $url . '">' . __('feed URL') . '</a> - ' .
@ -274,7 +271,7 @@ class zcfsAdminBehaviors
/** /**
* Delete related info about feed post in meta table. * Delete related info about feed post in meta table.
* *
* @param integer $post_id Post id * @param integer $post_id Post id
*/ */
public static function adminBeforePostDelete($post_id) public static function adminBeforePostDelete($post_id)
@ -283,14 +280,14 @@ class zcfsAdminBehaviors
$core->con->execute( $core->con->execute(
'DELETE FROM ' . $core->prefix . 'meta ' . 'DELETE FROM ' . $core->prefix . 'meta ' .
'WHERE post_id = ' . ((integer) $post_id) . ' ' . 'WHERE post_id = ' . ((int) $post_id) . ' ' .
'AND meta_type ' . $core->con->in([ 'AND meta_type ' . $core->con->in([
'zoneclearfeed_url', 'zoneclearfeed_url',
'zoneclearfeed_author', 'zoneclearfeed_author',
'zoneclearfeed_site', 'zoneclearfeed_site',
'zoneclearfeed_sitename', 'zoneclearfeed_sitename',
'zoneclearfeed_id' 'zoneclearfeed_id'
]).' ' ]) . ' '
); );
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_MODULE')) { if (!defined('DC_CONTEXT_MODULE')) {
return null; return null;
} }
@ -21,16 +20,16 @@ $redir = empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['r
$core->blog->settings->addNamespace('zoneclearFeedServer'); $core->blog->settings->addNamespace('zoneclearFeedServer');
$s = $core->blog->settings->zoneclearFeedServer; $s = $core->blog->settings->zoneclearFeedServer;
$active = (boolean) $s->zoneclearFeedServer_active; $active = (bool) $s->zoneclearFeedServer_active;
$pub_active = (boolean) $s->zoneclearFeedServer_pub_active; $pub_active = (bool) $s->zoneclearFeedServer_pub_active;
$post_status_new = (boolean) $s->zoneclearFeedServer_post_status_new; $post_status_new = (bool) $s->zoneclearFeedServer_post_status_new;
$bhv_pub_upd = (integer) $s->zoneclearFeedServer_bhv_pub_upd; $bhv_pub_upd = (int) $s->zoneclearFeedServer_bhv_pub_upd;
$update_limit = (integer) $s->zoneclearFeedServer_update_limit; $update_limit = (int) $s->zoneclearFeedServer_update_limit;
$keep_empty_feed = (boolean) $s->zoneclearFeedServer_keep_empty_feed; $keep_empty_feed = (bool) $s->zoneclearFeedServer_keep_empty_feed;
$tag_case = (integer) $s->zoneclearFeedServer_tag_case; $tag_case = (int) $s->zoneclearFeedServer_tag_case;
$post_full_tpl = @unserialize($s->zoneclearFeedServer_post_full_tpl); $post_full_tpl = @unserialize($s->zoneclearFeedServer_post_full_tpl);
$post_title_redir = @unserialize($s->zoneclearFeedServer_post_title_redir); $post_title_redir = @unserialize($s->zoneclearFeedServer_post_title_redir);
$feeduser = (string) $s->zoneclearFeedServer_user; $feeduser = (string) $s->zoneclearFeedServer_user;
if ($update_limit < 1) { if ($update_limit < 1) {
$update_limit = 10; $update_limit = 10;
@ -47,16 +46,16 @@ $zc = new zoneclearFeedServer($core);
# -- Set settings -- # -- Set settings --
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
$active = !empty($_POST['active']); $active = !empty($_POST['active']);
$pub_active = !empty($_POST['pub_active']); $pub_active = !empty($_POST['pub_active']);
$post_status_new = !empty($_POST['post_status_new']); $post_status_new = !empty($_POST['post_status_new']);
$bhv_pub_upd = (integer) $_POST['bhv_pub_upd']; $bhv_pub_upd = (int) $_POST['bhv_pub_upd'];
$limit = abs((integer) $_POST['update_limit']); $limit = abs((int) $_POST['update_limit']);
$keep_empty_feed = !empty($_POST['keep_empty_feed']); $keep_empty_feed = !empty($_POST['keep_empty_feed']);
$tag_case = (integer) $_POST['tag_case']; $tag_case = (int) $_POST['tag_case'];
$post_full_tpl = $_POST['post_full_tpl']; $post_full_tpl = $_POST['post_full_tpl'];
$post_title_redir = $_POST['post_title_redir']; $post_title_redir = $_POST['post_title_redir'];
$feeduser = (string) $_POST['feeduser']; $feeduser = (string) $_POST['feeduser'];
if ($limit < 1) { if ($limit < 1) {
$limit = 10; $limit = 10;
@ -79,7 +78,7 @@ if (!empty($_POST['save'])) {
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
$core->adminurl->redirect( $core->adminurl->redirect(
'admin.plugins', 'admin.plugins',
['module' => 'zoneclearFeedServer', 'conf' => 1, 'redir' => $list->getRedir()] ['module' => 'zoneclearFeedServer', 'conf' => 1, 'redir' => $list->getRedir()]
); );
} catch (Exception $e) { } catch (Exception $e) {
@ -111,8 +110,8 @@ $pub_page_url = $core->blog->url . $core->url->getBase('zoneclearFeedsPage');
# -- Display form -- # -- Display form --
if (!is_writable(DC_TPL_CACHE)) { if (!is_writable(DC_TPL_CACHE)) {
echo '<p class="error">'. __('Dotclear cache is not writable or not well configured!') . '</p>'; echo '<p class="error">' . __('Dotclear cache is not writable or not well configured!') . '</p>';
} }
echo ' echo '
<div class="fieldset"> <div class="fieldset">
@ -142,7 +141,7 @@ echo '
<p><label for="post_status_new">' . __('Status of new posts:') . '</label>' . <p><label for="post_status_new">' . __('Status of new posts:') . '</label>' .
form::combo('post_status_new', $combo_status, $post_status_new) . '</p> form::combo('post_status_new', $combo_status, $post_status_new) . '</p>
<p><label for="feeduser">'. <p><label for="feeduser">' .
__('Owner of entries created by zoneclearFeedServer:') . '</label>' . __('Owner of entries created by zoneclearFeedServer:') . '</label>' .
form::combo('feeduser', $combo_admins, $feeduser) . '</p> form::combo('feeduser', $combo_admins, $feeduser) . '</p>
@ -154,8 +153,10 @@ form::combo('tag_case', $combo_tagcase, $tag_case) . '</p>
<p><label for="bhv_pub_upd">' . __('Update feeds on public side:') . '</label>' . <p><label for="bhv_pub_upd">' . __('Update feeds on public side:') . '</label>' .
form::combo('bhv_pub_upd', $combo_pubupd, $bhv_pub_upd) . '</p> form::combo('bhv_pub_upd', $combo_pubupd, $bhv_pub_upd) . '</p>
<p class="classic"><label for="update_limit" class="ib">' . sprintf(__('Update %s feed(s) at a time.'), <p class="classic"><label for="update_limit" class="ib">' . sprintf(
form::number('update_limit', ['min' => 0, 'max' => 20, 'default' => $update_limit])) . '</label></p> __('Update %s feed(s) at a time.'),
form::number('update_limit', ['min' => 0, 'max' => 20, 'default' => $update_limit])
) . '</label></p>
<p><label for="keep_empty_feed">' . <p><label for="keep_empty_feed">' .
form::checkbox('keep_empty_feed', 1, $keep_empty_feed) . __('Keep active empty feeds') . '</label></p> form::checkbox('keep_empty_feed', 1, $keep_empty_feed) . __('Keep active empty feeds') . '</label></p>
@ -167,7 +168,7 @@ form::checkbox('pub_active', 1, $pub_active) . __('Enable public page') . '</lab
<p>' . __('Redirect to original post on:') . '</p><ul>'; <p>' . __('Redirect to original post on:') . '</p><ul>';
foreach($zc->getPublicUrlTypes($core) as $k => $v) { foreach ($zc->getPublicUrlTypes($core) as $k => $v) {
echo sprintf( echo sprintf(
'<li><label for="post_title_redir_%s">%s%s</label></li>', '<li><label for="post_title_redir_%s">%s%s</label></li>',
$v, $v,
@ -182,7 +183,7 @@ echo '
<p>' . __('Show full content on:') . '</p><ul>'; <p>' . __('Show full content on:') . '</p><ul>';
foreach($zc->getPublicUrlTypes($core) as $k => $v) { foreach ($zc->getPublicUrlTypes($core) as $k => $v) {
echo sprintf( echo sprintf(
'<li><label for="post_full_tpl_%s">%s%s</label></li>', '<li><label for="post_full_tpl_%s">%s%s</label></li>',
$v, $v,
@ -193,4 +194,4 @@ foreach($zc->getPublicUrlTypes($core) as $k => $v) {
echo '</ul></div></div>'; echo '</ul></div></div>';
dcPage::helpBlock('zoneclearFeedServer'); dcPage::helpBlock('zoneclearFeedServer');

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -28,4 +27,4 @@ $this->registerModule(
'details' => 'https://plugins.dotaddict.org/dc2/details/pacKman', 'details' => 'https://plugins.dotaddict.org/dc2/details/pacKman',
'repository' => 'https://raw.githubusercontent.com/JcDenis/zoneclearFeedServer/master/dcstore.xml' 'repository' => 'https://raw.githubusercontent.com/JcDenis/zoneclearFeedServer/master/dcstore.xml'
] ]
); );

View file

@ -1,19 +1,18 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$mod_id = 'zoneclearFeedServer'; $mod_id = 'zoneclearFeedServer';
$dc_min = $this->modules[$mod_id]['requires'][0][1]; $dc_min = $this->modules[$mod_id]['requires'][0][1];
@ -29,11 +28,13 @@ try {
} }
# Check Dotclear version # Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare') if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false) || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)
) { ) {
throw new Exception(sprintf( throw new Exception(sprintf(
'%s requires Dotclear %s', $mod_id, $dc_min '%s requires Dotclear %s',
$mod_id,
$dc_min
)); ));
} }
@ -65,7 +66,7 @@ try {
->index('idx_zcfs_type', 'btree', 'feed_type') ->index('idx_zcfs_type', 'btree', 'feed_type')
->index('idx_zcfs_blog', 'btree', 'blog_id'); ->index('idx_zcfs_blog', 'btree', 'blog_id');
$ti = new dbStruct($core->con, $core->prefix); $ti = new dbStruct($core->con, $core->prefix);
$changes = $ti->synchronize($t); $changes = $ti->synchronize($t);
# Settings # Settings
@ -78,18 +79,19 @@ try {
$s->put('zoneclearFeedServer_update_limit', 1, 'integer', 'Number of feeds to update at one time', false, true); $s->put('zoneclearFeedServer_update_limit', 1, 'integer', 'Number of feeds to update at one time', false, true);
$s->put('zoneclearFeedServer_keep_empty_feed', false, 'boolean', 'Keep active empty feeds', false, true); $s->put('zoneclearFeedServer_keep_empty_feed', false, 'boolean', 'Keep active empty feeds', false, true);
$s->put('zoneclearFeedServer_tag_case', 0, 'integer', 'How to transform imported tags', false, true); $s->put('zoneclearFeedServer_tag_case', 0, 'integer', 'How to transform imported tags', false, true);
$s->put('zoneclearFeedServer_user', '', 'string','User id that has right on post', false, true); $s->put('zoneclearFeedServer_user', '', 'string', 'User id that has right on post', false, true);
$s->put('zoneclearFeedServer_post_full_tpl', serialize(array('post', 'category', 'tag', 'archive')), 'string', 'List of templates types for full feed', false, true); $s->put('zoneclearFeedServer_post_full_tpl', serialize(['post', 'category', 'tag', 'archive']), 'string', 'List of templates types for full feed', false, true);
$s->put('zoneclearFeedServer_post_title_redir', serialize(array('feed')), 'string', 'List of templates types for redirection to original post', false, true); $s->put('zoneclearFeedServer_post_title_redir', serialize(['feed']), 'string', 'List of templates types for redirection to original post', false, true);
# Set module version # Set module version
$core->setVersion( $core->setVersion(
$mod_id, $mod_id,
$this->moduleInfo($mod_id, 'version') $this->moduleInfo($mod_id, 'version')
); );
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
return false; return false;
} }

View file

@ -1,27 +1,26 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$d = dirname(__FILE__).'/inc/'; $d = dirname(__FILE__) . '/inc/';
$__autoload['zoneclearFeedServer'] = $d . 'class.zoneclear.feed.server.php'; $__autoload['zoneclearFeedServer'] = $d . 'class.zoneclear.feed.server.php';
$__autoload['zcfsFeedsList'] = $d . 'lib.zcfs.list.php'; $__autoload['zcfsFeedsList'] = $d . 'lib.zcfs.list.php';
$__autoload['zcfsEntriesList'] = $d . 'lib.zcfs.list.php'; $__autoload['zcfsEntriesList'] = $d . 'lib.zcfs.list.php';
$__autoload['adminZcfsPostFilter'] = $d . 'lib.zcfs.list.php'; $__autoload['adminZcfsPostFilter'] = $d . 'lib.zcfs.list.php';
$__autoload['zcfsFeedsActionsPage'] = $d . 'class.zcfs.feedsactions.php'; $__autoload['zcfsFeedsActionsPage'] = $d . 'class.zcfs.feedsactions.php';
$__autoload['zcfsDefaultFeedsActions'] = $d . 'class.zcfs.feedsactions.php'; $__autoload['zcfsDefaultFeedsActions'] = $d . 'class.zcfs.feedsactions.php';
// public url for page of description of the flux // public url for page of description of the flux
@ -34,5 +33,5 @@ $core->url->register(
// Add to report on plugin activityReport // Add to report on plugin activityReport
if (defined('ACTIVITY_REPORT')) { if (defined('ACTIVITY_REPORT')) {
require_once $d .'lib.zcfs.activityreport.php'; require_once $d . 'lib.zcfs.activityreport.php';
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -47,8 +46,8 @@ $tpl_blocks = [
'FeedsHeader', 'FeedsHeader',
'FeedIf' 'FeedIf'
]; ];
foreach($tpl_blocks as $v) { foreach ($tpl_blocks as $v) {
$core->tpl->addBlock('zc' .$v, ['zcfsTemplate', $v]); $core->tpl->addBlock('zc' . $v, ['zcfsTemplate', $v]);
} }
# Register tempalte values # Register tempalte values
@ -70,7 +69,7 @@ $tpl_values = [
'FeedSiteURL', 'FeedSiteURL',
'FeedFeedURL' 'FeedFeedURL'
]; ];
foreach($tpl_values as $v) { foreach ($tpl_values as $v) {
$core->tpl->addValue('zc' . $v, ['zcfsTemplate', $v]); $core->tpl->addValue('zc' . $v, ['zcfsTemplate', $v]);
} }
@ -83,7 +82,7 @@ class zcfsPublicBehaviors
{ {
/** /**
* Remember others post extension. * Remember others post extension.
* *
* @param record $rs record instance * @param record $rs record instance
*/ */
public static function coreBlogGetPosts(record $rs) public static function coreBlogGetPosts(record $rs)
@ -94,7 +93,7 @@ class zcfsPublicBehaviors
/** /**
* Update feeds after contents. * Update feeds after contents.
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @return string Document * @return string Document
*/ */
@ -111,7 +110,7 @@ class zcfsPublicBehaviors
/** /**
* Generic behavior for before and after public content. * Generic behavior for before and after public content.
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @return null NULL * @return null NULL
*/ */
@ -125,7 +124,7 @@ class zcfsPublicBehaviors
/** /**
* Update feeds by an Ajax request (background). * Update feeds by an Ajax request (background).
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @param context $_ctx context instance * @param context $_ctx context instance
* @return string HTML content * @return string HTML content
@ -148,7 +147,7 @@ class zcfsPublicBehaviors
"\n<!-- JS for zoneclearFeedServer --> \n" . "\n<!-- JS for zoneclearFeedServer --> \n" .
dcutils::jsLoad($core->blog->url . $core->url->getBase('zoneclearFeedsPage') . '/zcfsupd.js') . dcutils::jsLoad($core->blog->url . $core->url->getBase('zoneclearFeedsPage') . '/zcfsupd.js') .
"<script type=\"text/javascript\"> \n//<![CDATA[\n" . "<script type=\"text/javascript\"> \n//<![CDATA[\n" .
" \$(function(){if(!document.getElementById){return;} " . ' $(function(){if(!document.getElementById){return;} ' .
" $('body').zoneclearFeedServer({blog_url:'" . " $('body').zoneclearFeedServer({blog_url:'" .
$blog_url . "',blog_id:'" . $blog_id . "'}); " . $blog_url . "',blog_id:'" . $blog_id . "'}); " .
" })\n" . " })\n" .
@ -165,7 +164,7 @@ class zcfsRsExtPosts extends rsExtPost
{ {
/** /**
* Get feed meta. * Get feed meta.
* *
* @param record $rs record instance * @param record $rs record instance
* @param string $info Feed info key * @param string $info Feed info key
* @return string Feed info value * @return string Feed info value
@ -183,7 +182,7 @@ class zcfsRsExtPosts extends rsExtPost
/** /**
* Call other rs extension. * Call other rs extension.
* *
* @param string $type Type of extension * @param string $type Type of extension
* @param array $args Arguments * @param array $args Arguments
* @return mixed record extension ressource * @return mixed record extension ressource
@ -203,7 +202,7 @@ class zcfsRsExtPosts extends rsExtPost
/** /**
* Get author link from post to feed. * Get author link from post to feed.
* *
* @param record $rs record instance * @param record $rs record instance
* @return string Author link * @return string Author link
*/ */
@ -213,79 +212,78 @@ class zcfsRsExtPosts extends rsExtPost
$site = $rs->zcFeed('site'); $site = $rs->zcFeed('site');
$sitename = $rs->zcFeed('sitename'); $sitename = $rs->zcFeed('sitename');
return $author && $sitename ? return $author && $sitename ?
sprintf('%s (<a href="%s">%s</a>)', $author, $site, $sitename) : sprintf('%s (<a href="%s">%s</a>)', $author, $site, $sitename) :
self::zcFeedBrother('getAuthorLink', [&$rs]); self::zcFeedBrother('getAuthorLink', [&$rs]);
} }
/** /**
* Get author CN from post to feed. * Get author CN from post to feed.
* *
* @param record $rs record instance * @param record $rs record instance
* @return string Author CN * @return string Author CN
*/ */
public static function getAuthorCN($rs) public static function getAuthorCN($rs)
{ {
$author = $rs->zcFeed('author'); $author = $rs->zcFeed('author');
return $author ?
$author : return $author ?
$author :
self::zcFeedBrother('getAuthorCN', [&$rs]); self::zcFeedBrother('getAuthorCN', [&$rs]);
} }
/** /**
* Get post link from post to feed. * Get post link from post to feed.
* *
* @param record $rs record instance * @param record $rs record instance
* @return string Post link * @return string Post link
*/ */
public static function getURL($rs) public static function getURL($rs)
{ {
$url = $rs->zcFeed('url'); $url = $rs->zcFeed('url');
$types = @unserialize($rs->core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_post_title_redir); $types = @unserialize($rs->core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_post_title_redir);
$full = is_array($types) && in_array($rs->core->url->type, $types); $full = is_array($types) && in_array($rs->core->url->type, $types);
return $url && $full ? return $url && $full ?
zoneclearFeedServer::absoluteURL($rs->zcFeed('site'), $url) : zoneclearFeedServer::absoluteURL($rs->zcFeed('site'), $url) :
self::zcFeedBrother('getURL', [&$rs]); self::zcFeedBrother('getURL', [&$rs]);
} }
/** /**
* Get post content from post to feed. * Get post content from post to feed.
* *
* @param record $rs record instance * @param record $rs record instance
* @return string Post content * @return string Post content
*/ */
public static function getContent($rs, $absolute_urls = false) public static function getContent($rs, $absolute_urls = false)
{ {
$url = $rs->zcFeed('url'); $url = $rs->zcFeed('url');
$sitename = $rs->zcFeed('sitename'); $sitename = $rs->zcFeed('sitename');
$content = self::zcFeedBrother('getContent', [&$rs, $absolute_urls]); $content = self::zcFeedBrother('getContent', [&$rs, $absolute_urls]);
if ($url && $sitename && $rs->post_type == 'post') { if ($url && $sitename && $rs->post_type == 'post') {
$types = @unserialize($rs->core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_post_full_tpl); $types = @unserialize($rs->core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_post_full_tpl);
if (is_array($types) && in_array($rs->core->url->type, $types)) { if (is_array($types) && in_array($rs->core->url->type, $types)) {
return $content . sprintf(
return $content . sprintf(
'<p class="zoneclear-original"><em>%s</em></p>', '<p class="zoneclear-original"><em>%s</em></p>',
sprintf(__('Original post on <a href="%s">%s</a>'), $url, $sitename) sprintf(__('Original post on <a href="%s">%s</a>'), $url, $sitename)
); );
} else {
$content = context::remove_html($content);
$content = context::cut_string($content, 350);
$content = html::escapeHTML($content);
return sprintf(
'<p>%s... <em><a href="%s" title="%s">%s</a></em></p>',
$content,
self::getURL($rs),
__('Read more details about this feed'),
__('Continue reading')
);
} }
} else { $content = context::remove_html($content);
return $content; $content = context::cut_string($content, 350);
$content = html::escapeHTML($content);
return sprintf(
'<p>%s... <em><a href="%s" title="%s">%s</a></em></p>',
$content,
self::getURL($rs),
__('Read more details about this feed'),
__('Continue reading')
);
} }
return $content;
} }
} }
@ -298,7 +296,7 @@ class zcfsUrlHandler extends dcUrlHandlers
{ {
/** /**
* Feeds source page and update methods. * Feeds source page and update methods.
* *
* @param array $args Page arguments * @param array $args Page arguments
* @return mixed * @return mixed
*/ */
@ -322,25 +320,25 @@ class zcfsUrlHandler extends dcUrlHandlers
$zc = new zoneclearFeedServer($core); $zc = new zoneclearFeedServer($core);
if ($zc->checkFeedsUpdate()) { if ($zc->checkFeedsUpdate()) {
$msg = sprintf( $msg = sprintf(
'<status>%s</status><message>s%</message>', '<status>%s</status><message>s%</message>',
'ok', 'ok',
'Feeds updated successfully' 'Feeds updated successfully'
); );
} }
} catch (Exception $e) {
} }
catch (Exception $e) {}
} }
if (empty($msg)) { if (empty($msg)) {
$msg = sprintf( $msg = sprintf(
'<status>%s</status><message>s%</message>', '<status>%s</status><message>s%</message>',
'failed', 'failed',
'Failed to update feeds' 'Failed to update feeds'
); );
} }
header('Content-Type: application/xml; charset=UTF-8'); header('Content-Type: application/xml; charset=UTF-8');
echo echo
'<?xml version="1.0" encoding="utf-8"?> ' . "\n" . '<?xml version="1.0" encoding="utf-8"?> ' . "\n" .
'<response><rsp>' . "\n" . '<response><rsp>' . "\n" .
$msg . "\n" . $msg . "\n" .
'</rsp></response>'; '</rsp></response>';
@ -360,7 +358,7 @@ class zcfsUrlHandler extends dcUrlHandlers
# Server feeds description page # Server feeds description page
} elseif (in_array($args, ['', '/']) && $s->zoneclearFeedServer_pub_active) { } elseif (in_array($args, ['', '/']) && $s->zoneclearFeedServer_pub_active) {
$tplset = $core->themes->moduleInfo($core->blog->settings->system->theme, 'tplset'); $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme, 'tplset');
$path = dirname(__FILE__) . '/default-templates/'; $path = dirname(__FILE__) . '/default-templates/';
if (!empty($tplset) && is_dir($path . $tplset)) { if (!empty($tplset) && is_dir($path . $tplset)) {
$core->tpl->setPath($core->tpl->getPath(), $path . $tplset); $core->tpl->setPath($core->tpl->getPath(), $path . $tplset);
} else { } else {
@ -387,9 +385,9 @@ class zcfsTemplate
public static function Feeds($a, $c) public static function Feeds($a, $c)
{ {
$lastn = -1; $lastn = -1;
$p = ''; $p = '';
if (isset($a['lastn'])) { if (isset($a['lastn'])) {
$lastn = abs((integer) $a['lastn']) +0; $lastn = abs((int) $a['lastn']) + 0;
$p .= "\$zcfs_params['limit'] = " . $lastn . ";\n"; $p .= "\$zcfs_params['limit'] = " . $lastn . ";\n";
} }
if (isset($a['cat_id'])) { if (isset($a['cat_id'])) {
@ -402,7 +400,7 @@ class zcfsTemplate
$p .= "\$zcfs_params['feed_url'] = '" . addslashes($a['site_url']) . "';\n"; $p .= "\$zcfs_params['feed_url'] = '" . addslashes($a['site_url']) . "';\n";
} }
if (isset($a['feed_status'])) { if (isset($a['feed_status'])) {
$p .= "\$zcfs_params['feed_status'] = " . ((integer) $a['feed_status']) . ";\n"; $p .= "\$zcfs_params['feed_status'] = " . ((int) $a['feed_status']) . ";\n";
} else { } else {
$p .= "\$zcfs_params['feed_status'] = 1;\n"; $p .= "\$zcfs_params['feed_status'] = 1;\n";
} }
@ -414,22 +412,32 @@ class zcfsTemplate
} }
$sortby = 'feed_creadt'; $sortby = 'feed_creadt';
$order = 'desc'; $order = 'desc';
if (isset($a['sortby'])) { if (isset($a['sortby'])) {
switch ($a['sortby']) { switch ($a['sortby']) {
case 'name': $sortby = 'lowername'; break; case 'name': $sortby = 'lowername';
case 'owner' : $sortby = 'feed_owner'; break;
case 'date' : $sortby = 'feed_dt'; break; break;
case 'update' : $sortby = 'feed_upddt'; break; case 'owner': $sortby = 'feed_owner';
case 'id' : $sortby = 'feed_id'; break;
break;
case 'date': $sortby = 'feed_dt';
break;
case 'update': $sortby = 'feed_upddt';
break;
case 'id': $sortby = 'feed_id';
break;
} }
} }
if (isset($a['order']) && preg_match('/^(desc|asc)$/i', $a['order'])) { if (isset($a['order']) && preg_match('/^(desc|asc)$/i', $a['order'])) {
$order = $a['order']; $order = $a['order'];
} }
$p .= "\$zcfs_params['order'] = '" . $sortby . " " . $order . "';\n"; $p .= "\$zcfs_params['order'] = '" . $sortby . ' ' . $order . "';\n";
return return
'<?php ' . $p . '<?php ' . $p .
'$_ctx->feeds_params = $zcfs_params;' . "\n" . '$_ctx->feeds_params = $zcfs_params;' . "\n" .
'$zcfs = new zoneclearFeedServer($core);' . "\n" . '$zcfs = new zoneclearFeedServer($core);' . "\n" .
@ -453,7 +461,7 @@ class zcfsTemplate
if (isset($a['site_url'])) { if (isset($a['site_url'])) {
$url = trim($a['feed_url']); $url = trim($a['feed_url']);
if (substr($url, 0, 1) == '!') { if (substr($url, 0, 1) == '!') {
$url = substr($url, 1); $url = substr($url, 1);
$if[] = '$_ctx->feeds->feed_url != "' . addslashes($url) . '"'; $if[] = '$_ctx->feeds->feed_url != "' . addslashes($url) . '"';
} else { } else {
$if[] = '$_ctx->feeds->feed_url == "' . addslashes($url) . '"'; $if[] = '$_ctx->feeds->feed_url == "' . addslashes($url) . '"';
@ -462,7 +470,7 @@ class zcfsTemplate
if (isset($a['feed_url'])) { if (isset($a['feed_url'])) {
$url = trim($a['feed_feed']); $url = trim($a['feed_feed']);
if (substr($url, 0, 1) == '!') { if (substr($url, 0, 1) == '!') {
$url = substr($url, 1); $url = substr($url, 1);
$if[] = '$_ctx->feeds->feed_feed != "' . addslashes($url) . '"'; $if[] = '$_ctx->feeds->feed_feed != "' . addslashes($url) . '"';
} else { } else {
$if[] = '$_ctx->feeds->feed_feed == "' . addslashes($url) . '"'; $if[] = '$_ctx->feeds->feed_feed == "' . addslashes($url) . '"';
@ -472,36 +480,36 @@ class zcfsTemplate
$category = addslashes(trim($a['category'])); $category = addslashes(trim($a['category']));
if (substr($category, 0, 1) == '!') { if (substr($category, 0, 1) == '!') {
$category = substr($category, 1); $category = substr($category, 1);
$if[] = '($_ctx->feeds->cat_url != "' . $category . '")'; $if[] = '($_ctx->feeds->cat_url != "' . $category . '")';
} else { } else {
$if[] = '($_ctx->feeds->cat_url == "' . $category . '")'; $if[] = '($_ctx->feeds->cat_url == "' . $category . '")';
} }
} }
if (isset($a['first'])) { if (isset($a['first'])) {
$sign = (boolean) $a['first'] ? '=' : '!'; $sign = (bool) $a['first'] ? '=' : '!';
$if[] = '$_ctx->feeds->index() ' . $sign . '= 0'; $if[] = '$_ctx->feeds->index() ' . $sign . '= 0';
} }
if (isset($a['odd'])) { if (isset($a['odd'])) {
$sign = (boolean) $a['odd'] ? '=' : '!'; $sign = (bool) $a['odd'] ? '=' : '!';
$if[] = '($_ctx->feeds->index()+1)%2 ' .$sign. ' = 1'; $if[] = '($_ctx->feeds->index()+1)%2 ' . $sign . ' = 1';
} }
if (isset($a['has_category'])) { if (isset($a['has_category'])) {
$sign = (boolean) $a['has_category'] ? '' : '!'; $sign = (bool) $a['has_category'] ? '' : '!';
$if[] = $sign . '$_ctx->feeds->cat_id'; $if[] = $sign . '$_ctx->feeds->cat_id';
} }
if (isset($a['has_description'])) { if (isset($a['has_description'])) {
$sign = (boolean) $a['has_description'] ? '' : '!'; $sign = (bool) $a['has_description'] ? '' : '!';
$if[] = $sign . '$_ctx->feeds->feed_desc'; $if[] = $sign . '$_ctx->feeds->feed_desc';
} }
return empty($if) ? return empty($if) ?
$c : $c :
'<?php if(' . implode(' ' . $operator . ' ', $if) . ') : ?>' . $c . '<?php endif; ?>'; '<?php if(' . implode(' ' . $operator . ' ', $if) . ') : ?>' . $c . '<?php endif; ?>';
} }
public static function FeedIfFirst($a) public static function FeedIfFirst($a)
{ {
$ret = isset($a['return']) ? $a['return'] : 'first'; $ret = $a['return'] ?? 'first';
$ret = html::escapeHTML($ret); $ret = html::escapeHTML($ret);
return return
@ -511,7 +519,7 @@ class zcfsTemplate
public static function FeedIfOdd($a) public static function FeedIfOdd($a)
{ {
$ret = isset($a['return']) ? $a['return'] : 'odd'; $ret = $a['return'] ?? 'odd';
$ret = html::escapeHTML($ret); $ret = html::escapeHTML($ret);
return return
@ -561,7 +569,7 @@ class zcfsTemplate
return empty($a['full']) ? return empty($a['full']) ?
'<?php echo ' . sprintf($f, '$_ctx->feeds->feed_lang') . '; ?>' : '<?php echo ' . sprintf($f, '$_ctx->feeds->feed_lang') . '; ?>' :
'<?php $langs = l10n::getISOcodes(); if (isset($langs[$_ctx->feeds->feed_lang])) { echo ' . '<?php $langs = l10n::getISOcodes(); if (isset($langs[$_ctx->feeds->feed_lang])) { echo ' .
sprintf($f, '$langs[$_ctx->feeds->feed_lang]') .'; } else { echo ' . sprintf($f, '$langs[$_ctx->feeds->feed_lang]') . '; } else { echo ' .
sprintf($f, '$_ctx->feeds->feed_lang') . '; } unset($langs); ?>'; sprintf($f, '$_ctx->feeds->feed_lang') . '; } unset($langs); ?>';
} }
@ -582,18 +590,18 @@ class zcfsTemplate
public static function FeedsHeader($a, $c) public static function FeedsHeader($a, $c)
{ {
return "<?php if (\$_ctx->feeds->isStart()) : ?>" . $c . "<?php endif; ?>"; return '<?php if ($_ctx->feeds->isStart()) : ?>' . $c . '<?php endif; ?>';
} }
public static function FeedsFooter($a, $c) public static function FeedsFooter($a, $c)
{ {
return "<?php if (\$_ctx->feeds->isEnd()) : ?>" . $c . "<?php endif; ?>"; return '<?php if ($_ctx->feeds->isEnd()) : ?>' . $c . '<?php endif; ?>';
} }
public static function FeedsCount($a) public static function FeedsCount($a)
{ {
$none = 'no sources'; $none = 'no sources';
$one = 'one source'; $one = 'one source';
$more = '%d sources'; $more = '%d sources';
if (isset($a['none'])) { if (isset($a['none'])) {
@ -614,13 +622,13 @@ class zcfsTemplate
" printf(__('" . $one . "'),\$fcount);\n" . " printf(__('" . $one . "'),\$fcount);\n" .
"} else {\n" . "} else {\n" .
" printf(__('" . $more . "'),\$fcount);\n" . " printf(__('" . $more . "'),\$fcount);\n" .
"} unset(\$fcount); ?>"; '} unset($fcount); ?>';
} }
public static function FeedsEntriesCount($a) public static function FeedsEntriesCount($a)
{ {
$none = __('no entries'); $none = __('no entries');
$one = __('one entry'); $one = __('one entry');
$more = __('%d entries'); $more = __('%d entries');
if (isset($a['none'])) { if (isset($a['none'])) {
@ -636,7 +644,7 @@ class zcfsTemplate
return return
"<?php \$fcount = 0; \$allfeeds = \$_ctx->feeds->zc->getFeeds(); \n" . "<?php \$fcount = 0; \$allfeeds = \$_ctx->feeds->zc->getFeeds(); \n" .
"if (!\$allfeeds->isEmpty()) { \n" . "if (!\$allfeeds->isEmpty()) { \n" .
" while (\$allfeeds->fetch()) { " . ' while ($allfeeds->fetch()) { ' .
" \$fcount += (integer) \$_ctx->feeds->zc->getPostsByFeed(array('feed_id'=>\$allfeeds->feed_id),true)->f(0); " . " \$fcount += (integer) \$_ctx->feeds->zc->getPostsByFeed(array('feed_id'=>\$allfeeds->feed_id),true)->f(0); " .
" } \n" . " } \n" .
"} \n" . "} \n" .
@ -646,13 +654,13 @@ class zcfsTemplate
" printf(__('" . $one . "'),\$fcount);\n" . " printf(__('" . $one . "'),\$fcount);\n" .
"} else {\n" . "} else {\n" .
" printf(__('" . $more . "'),\$fcount);\n" . " printf(__('" . $more . "'),\$fcount);\n" .
"} unset(\$allfeeds,\$fcount); ?>"; '} unset($allfeeds,$fcount); ?>';
} }
public static function FeedEntriesCount($a) public static function FeedEntriesCount($a)
{ {
$none = 'no entries'; $none = 'no entries';
$one = 'one entry'; $one = 'one entry';
$more = '%d entries'; $more = '%d entries';
if (isset($a['none'])) { if (isset($a['none'])) {
@ -666,14 +674,14 @@ class zcfsTemplate
} }
return return
"<?php \$fcount = \$_ctx->feeds->zc->getPostsByFeed(array('feed_id'=>\$_ctx->feeds->feed_id),true)->f(0); \n". "<?php \$fcount = \$_ctx->feeds->zc->getPostsByFeed(array('feed_id'=>\$_ctx->feeds->feed_id),true)->f(0); \n" .
"if (\$fcount == 0) {\n" . "if (\$fcount == 0) {\n" .
" printf(__('" . $none . "'),\$fcount);\n" . " printf(__('" . $none . "'),\$fcount);\n" .
"} elseif (\$fcount == 1) {\n" . "} elseif (\$fcount == 1) {\n" .
" printf(__('" . $one . "'),\$fcount);\n" . " printf(__('" . $one . "'),\$fcount);\n" .
"} else {\n" . "} else {\n" .
" printf(__('" . $more . "'),\$fcount);\n" . " printf(__('" . $more . "'),\$fcount);\n" .
"} unset(\$fcount); ?>"; '} unset($fcount); ?>';
} }
protected static function getValue($a, $v) protected static function getValue($a, $v)
@ -683,8 +691,7 @@ class zcfsTemplate
protected static function getOperator($op) protected static function getOperator($op)
{ {
switch (strtolower($op)) switch (strtolower($op)) {
{
case 'or': case 'or':
case '||': case '||':
return '||'; return '||';
@ -706,4 +713,4 @@ class extZcfeeds
return __('List of feeds'); return __('List of feeds');
} }
} }
} }

View file

@ -1,82 +1,113 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$mod_id = 'zoneclearFeedServer'; $mod_id = 'zoneclearFeedServer';
$this->addUserAction( $this->addUserAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ $mod_id, /* action */
/* desc */ __('delete all settings') 'delete_all',
/* ns */
$mod_id,
/* desc */
__('delete all settings')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */
/* action */ 'delete', 'tables',
/* ns */ 'zc_feed', /* action */
/* desc */ __('delete table') 'delete',
/* ns */
'zc_feed',
/* desc */
__('delete table')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ $mod_id, /* action */
/* desc */ __('delete plugin files') 'delete',
/* ns */
$mod_id,
/* desc */
__('delete plugin files')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ $mod_id, /* action */
/* desc */ __('delete the version number') 'delete',
/* ns */
$mod_id,
/* desc */
__('delete the version number')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ $mod_id, /* action */
/* desc */ sprintf(__('delete all %s settings'), $mod_id) 'delete_all',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete all %s settings'), $mod_id)
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'tables', /* type */
/* action */ 'delete', 'tables',
/* ns */ 'zc_feed', /* action */
/* desc */ sprintf(__('delete %s table'), $mod_id) 'delete',
/* ns */
'zc_feed',
/* desc */
sprintf(__('delete %s table'), $mod_id)
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ $mod_id, /* action */
/* desc */ sprintf(__('delete %s plugin files'), $mod_id) 'delete',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete %s plugin files'), $mod_id)
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ $mod_id, /* action */
/* desc */ sprintf(__('delete %s version number'), $mod_id) 'delete',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete %s version number'), $mod_id)
); );
$this->addDirectCallback( $this->addDirectCallback(
/* function */ 'zoneclearfeedServerUninstall', /* function */
/* desc */ 'delete feeds relations' 'zoneclearfeedServerUninstall',
/* desc */
'delete feeds relations'
); );
function zoneclearfeedServerUninstall($core, $id) function zoneclearfeedServerUninstall($core, $id)
{ {
if ($id != 'zoneclearFeedServer') { if ($id != 'zoneclearFeedServer') {
return null; return null;
} }
//... //...
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -33,7 +32,7 @@ class zoneclearFeedServerWidget
{ {
/** /**
* Widget configuration for sources list. * Widget configuration for sources list.
* *
* @param dcWidget $w dcWidget instance * @param dcWidget $w dcWidget instance
*/ */
public static function adminSource($w) public static function adminSource($w)
@ -50,23 +49,23 @@ class zoneclearFeedServerWidget
__('Feeds sources'), __('Feeds sources'),
) )
->setting( ->setting(
'sortby', 'sortby',
__('Order by:'), __('Order by:'),
'feed_upd_last', 'feed_upd_last',
'combo', 'combo',
[ [
__('Last update') => 'feed_upd_last', __('Last update') => 'feed_upd_last',
__('Name') => 'lowername', __('Name') => 'lowername',
__('Create date') => 'feed_creadt' __('Create date') => 'feed_creadt'
] ]
) )
->setting( ->setting(
'sort', 'sort',
__('Sort:'), __('Sort:'),
'desc', 'desc',
'combo', 'combo',
[ [
__('Ascending') => 'asc', __('Ascending') => 'asc',
__('Descending') => 'desc' __('Descending') => 'desc'
] ]
) )
@ -90,7 +89,7 @@ class zoneclearFeedServerWidget
/** /**
* Widget configuration for feeds info. * Widget configuration for feeds info.
* *
* @param dcWidget $w dcWidget instance * @param dcWidget $w dcWidget instance
*/ */
public static function adminNumber($w) public static function adminNumber($w)
@ -108,8 +107,8 @@ class zoneclearFeedServerWidget
) )
->setting( ->setting(
'title', 'title',
__('Title:') __('Title:'),
,__('Feeds numbers'), __('Feeds numbers'),
'text' 'text'
) )
->setting( ->setting(
@ -144,7 +143,7 @@ class zoneclearFeedServerWidget
/** /**
* Widget for sources list. * Widget for sources list.
* *
* @param dcWidget $w dcWidget instance * @param dcWidget $w dcWidget instance
*/ */
public static function publicSource($w) public static function publicSource($w)
@ -155,18 +154,18 @@ class zoneclearFeedServerWidget
return null; return null;
} }
if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|| $w->homeonly == 1 && !$core->url->isHome($core->url->type) || $w->homeonly == 1 && !$core->url->isHome($core->url->type)
|| $w->homeonly == 2 && $core->url->isHome($core->url->type) || $w->homeonly == 2 && $core->url->isHome($core->url->type)
) { ) {
return null; return null;
} }
$p = []; $p = [];
$p['order'] = ($w->sortby && in_array($w->sortby, ['feed_upd_last', 'lowername', 'feed_creadt'])) ? $p['order'] = ($w->sortby && in_array($w->sortby, ['feed_upd_last', 'lowername', 'feed_creadt'])) ?
$w->sortby . ' ' : 'feed_upd_last '; $w->sortby . ' ' : 'feed_upd_last ';
$p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC'; $p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC';
$p['limit'] = abs((integer) $w->limit); $p['limit'] = abs((int) $w->limit);
$p['feed_status'] = 1; $p['feed_status'] = 1;
$zc = new zoneclearFeedServer($core); $zc = new zoneclearFeedServer($core);
@ -177,10 +176,10 @@ class zoneclearFeedServerWidget
} }
$lines = []; $lines = [];
$i = 1; $i = 1;
while($rs->fetch()) { while ($rs->fetch()) {
$lines[] = sprintf( $lines[] = sprintf(
'<li><a href="%s" title="%s">%s</a></li>', '<li><a href="%s" title="%s">%s</a></li>',
$rs->feed_url, $rs->feed_url,
$rs->feed_owner, $rs->feed_owner,
$rs->feed_name $rs->feed_name
@ -207,7 +206,7 @@ class zoneclearFeedServerWidget
/** /**
* Widget for feeds info. * Widget for feeds info.
* *
* @param dcWidget $w dcWidget instance * @param dcWidget $w dcWidget instance
*/ */
public static function publicNumber($w) public static function publicNumber($w)
@ -218,20 +217,20 @@ class zoneclearFeedServerWidget
return; return;
} }
if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|| $w->homeonly == 1 && !$core->url->isHome($core->url->type) || $w->homeonly == 1 && !$core->url->isHome($core->url->type)
|| $w->homeonly == 2 && $core->url->isHome($core->url->type) || $w->homeonly == 2 && $core->url->isHome($core->url->type)
) { ) {
return null; return null;
} }
$zc = new zoneclearFeedServer($core); $zc = new zoneclearFeedServer($core);
$content = ''; $content = '';
# Feed # Feed
if ($w->feed_show) { if ($w->feed_show) {
$title = ($w->feed_title ? sprintf( $title = ($w->feed_title ? sprintf(
'<strong>%s</strong> ', '<strong>%s</strong> ',
html::escapeHTML($w->feed_title) html::escapeHTML($w->feed_title)
) : ''); ) : '');
@ -257,7 +256,7 @@ class zoneclearFeedServerWidget
if (!$feeds->isEmpty()) { if (!$feeds->isEmpty()) {
while ($feeds->fetch()) { while ($feeds->fetch()) {
$count += (integer) $zc->getPostsByFeed(['feed_id' => $feeds->feed_id], true)->f(0); $count += (int) $zc->getPostsByFeed(['feed_id' => $feeds->feed_id], true)->f(0);
} }
} }
$title = ($w->entry_title ? sprintf( $title = ($w->entry_title ? sprintf(
@ -283,4 +282,4 @@ class zoneclearFeedServerWidget
sprintf('<ul>%s</ul>', $content) sprintf('<ul>%s</ul>', $content)
); );
} }
} }

View file

@ -7,14 +7,14 @@
$opts = getopt('d:c:b:u:h'); $opts = getopt('d:c:b:u:h');
function help($status=0) function help($status = 0)
{ {
echo echo
"Options: \n". "Options: \n" .
" -h shows this help\n". " -h shows this help\n" .
" -d DotClear root path\n". " -d DotClear root path\n" .
" -c DotClear conf path\n". " -c DotClear conf path\n" .
" -b Blog ID\n". " -b Blog ID\n" .
" -u User ID\n\n"; " -u User ID\n\n";
exit($status); exit($status);
} }
@ -46,37 +46,37 @@ if (isset($opts['b'])) {
} }
if (!$dc_root || !is_dir($dc_root)) { if (!$dc_root || !is_dir($dc_root)) {
fwrite(STDERR,"DotClear root path is not defined\n\n"); fwrite(STDERR, "DotClear root path is not defined\n\n");
help(1); help(1);
} }
if (!$dc_conf || !is_readable($dc_conf)) { if (!$dc_conf || !is_readable($dc_conf)) {
fwrite(STDERR,"DotClear configuration not found\n\n"); fwrite(STDERR, "DotClear configuration not found\n\n");
help(1); help(1);
} }
if (!$blog_id) { if (!$blog_id) {
fwrite(STDERR,"Blog ID is not defined\n\n"); fwrite(STDERR, "Blog ID is not defined\n\n");
help(1); help(1);
} }
$_SERVER['DC_RC_PATH'] = $dc_conf; $_SERVER['DC_RC_PATH'] = $dc_conf;
unset($dc_conf); unset($dc_conf);
define('DC_BLOG_ID',$blog_id); define('DC_BLOG_ID', $blog_id);
unset($blog_id); unset($blog_id);
require $dc_root.'/inc/prepend.php'; require $dc_root . '/inc/prepend.php';
unset($dc_root); unset($dc_root);
$core->setBlog(DC_BLOG_ID); $core->setBlog(DC_BLOG_ID);
if ($core->blog->id == null) { if ($core->blog->id == null) {
fwrite(STDERR,"Blog is not defined\n"); fwrite(STDERR, "Blog is not defined\n");
exit(1); exit(1);
} }
if (!isset($opts['u']) || !$core->auth->checkUser($opts['u'])) { if (!isset($opts['u']) || !$core->auth->checkUser($opts['u'])) {
fwrite(STDERR,"Unable to set user\n"); fwrite(STDERR, "Unable to set user\n");
exit(1); exit(1);
} }
@ -88,6 +88,6 @@ try {
$zc = new zoneclearFeedServer($core); $zc = new zoneclearFeedServer($core);
$zc->checkFeedsUpdate(); $zc->checkFeedsUpdate();
} catch (Exception $e) { } catch (Exception $e) {
fwrite(STDERR,$e->getMessage()."\n"); fwrite(STDERR, $e->getMessage() . "\n");
exit(1); exit(1);
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class zcfsFeedsActionsPage extends dcActionsPage class zcfsFeedsActionsPage extends dcActionsPage
{ {
public $zcfs; public $zcfs;
@ -24,7 +23,7 @@ class zcfsFeedsActionsPage extends dcActionsPage
'sortby', 'order', 'page', 'nb' 'sortby', 'order', 'page', 'nb'
]; ];
$this->field_entries = 'feeds'; $this->field_entries = 'feeds';
$this->caller_title = __('Feeds'); $this->caller_title = __('Feeds');
$this->loadDefaults(); $this->loadDefaults();
} }
@ -36,7 +35,7 @@ class zcfsFeedsActionsPage extends dcActionsPage
public function beginPage($breadcrumb = '', $head = '') public function beginPage($breadcrumb = '', $head = '')
{ {
echo echo
'<html><head><title>' . __('Feeds server') . '</title>' . '<html><head><title>' . __('Feeds server') . '</title>' .
dcPage::jsLoad('js/_posts_actions.js') . dcPage::jsLoad('js/_posts_actions.js') .
$head . $head .
@ -57,8 +56,8 @@ class zcfsFeedsActionsPage extends dcActionsPage
$this->beginPage( $this->beginPage(
dcPage::breadcrumb([ dcPage::breadcrumb([
html::escapeHTML($this->core->blog->name) => '', html::escapeHTML($this->core->blog->name) => '',
$this->getCallerTitle() => $this->getRedirection(true), $this->getCallerTitle() => $this->getRedirection(true),
__('Feeds actions') => '' __('Feeds actions') => ''
]) ])
); );
$this->endPage(); $this->endPage();
@ -70,13 +69,13 @@ class zcfsFeedsActionsPage extends dcActionsPage
$params['feed_id'] = $from['feeds']; $params['feed_id'] = $from['feeds'];
$feeds = $this->zcfs->getFeeds($params); $feeds = $this->zcfs->getFeeds($params);
while ($feeds->fetch()) { while ($feeds->fetch()) {
$this->entries[$feeds->feed_id] = $feeds->feed_name; $this->entries[$feeds->feed_id] = $feeds->feed_name;
} }
$this->rs = $feeds; $this->rs = $feeds;
} else { } else {
$this->rs = $this->core->con->select( $this->rs = $this->core->con->select(
"SELECT blog_id FROM " . $this->core->prefix . "blog WHERE false" 'SELECT blog_id FROM ' . $this->core->prefix . 'blog WHERE false'
); );
} }
} }
@ -129,13 +128,13 @@ class zcfsDefaultFeedsActions
public static function doEnableFeed(dcCore $core, zcfsFeedsActionsPage $ap, $post) public static function doEnableFeed(dcCore $core, zcfsFeedsActionsPage $ap, $post)
{ {
$enable = $ap->getAction() == 'enablefeed'; $enable = $ap->getAction() == 'enablefeed';
$ids = $ap->getIDs(); $ids = $ap->getIDs();
if (empty($ids)) { if (empty($ids)) {
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
foreach($ids as $id) { foreach ($ids as $id) {
$ap->zcfs->enableFeed($id, $enable); $ap->zcfs->enableFeed($id, $enable);
} }
@ -151,8 +150,7 @@ class zcfsDefaultFeedsActions
'%d feed has been successfully disabled.', '%d feed has been successfully disabled.',
'%d feeds have been successfully disabled.', '%d feeds have been successfully disabled.',
count($ids) count($ids)
) ),
,
count($ids) count($ids)
)); ));
$ap->redirect(true); $ap->redirect(true);
@ -174,14 +172,12 @@ class zcfsDefaultFeedsActions
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
foreach($ids as $id) { foreach ($ids as $id) {
$posts = $ap->zcfs->getPostsByFeed([ $posts = $ap->zcfs->getPostsByFeed([
'feed_id' => $id 'feed_id' => $id
]); ]);
while($posts->fetch()) { while ($posts->fetch()) {
$core->blog->delPost($posts->post_id); $core->blog->delPost($posts->post_id);
$core->con->execute( $core->con->execute(
'DELETE FROM ' . $core->prefix . 'meta ' . 'DELETE FROM ' . $core->prefix . 'meta ' .
@ -192,7 +188,7 @@ class zcfsDefaultFeedsActions
} }
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Entries have been successfully deleted.') __('Entries have been successfully deleted.')
); );
$ap->redirect(true); $ap->redirect(true);
} }
@ -205,7 +201,7 @@ class zcfsDefaultFeedsActions
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
foreach($ids as $id) { foreach ($ids as $id) {
$ap->zcfs->delFeed($id); $ap->zcfs->delFeed($id);
} }
@ -228,7 +224,7 @@ class zcfsDefaultFeedsActions
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
foreach($ids as $id) { foreach ($ids as $id) {
$ap->zcfs->checkFeedsUpdate($id, true); $ap->zcfs->checkFeedsUpdate($id, true);
} }
@ -251,8 +247,8 @@ class zcfsDefaultFeedsActions
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
foreach($ids as $id) { foreach ($ids as $id) {
$cur = $ap->zcfs->openCursor(); $cur = $ap->zcfs->openCursor();
$cur->feed_upd_last = 0; $cur->feed_upd_last = 0;
$ap->zcfs->updFeed($id, $cur); $ap->zcfs->updFeed($id, $cur);
$ap->zcfs->checkFeedsUpdate($id, true); $ap->zcfs->checkFeedsUpdate($id, true);
@ -278,10 +274,10 @@ class zcfsDefaultFeedsActions
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
$cat_id = abs((integer) $post['upd_cat_id']); $cat_id = abs((int) $post['upd_cat_id']);
foreach($ids as $id) { foreach ($ids as $id) {
$cur = $ap->zcfs->openCursor(); $cur = $ap->zcfs->openCursor();
$cur->cat_id = $cat_id == 0 ? null : $cat_id; $cur->cat_id = $cat_id == 0 ? null : $cat_id;
$ap->zcfs->updFeed($id, $cur); $ap->zcfs->updFeed($id, $cur);
} }
@ -302,11 +298,12 @@ class zcfsDefaultFeedsActions
$ap->beginPage( $ap->beginPage(
dcPage::breadcrumb([ dcPage::breadcrumb([
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Feeds server') => '', __('Feeds server') => '',
$ap->getCallerTitle() => $ap->getRedirection(true), $ap->getCallerTitle() => $ap->getRedirection(true),
__('Change category for this selection') => '' __('Change category for this selection') => ''
])); ])
);
echo echo
'<form action="' . $ap->getURI() . '" method="post">' . '<form action="' . $ap->getURI() . '" method="post">' .
@ -315,7 +312,7 @@ class zcfsDefaultFeedsActions
form::combo(['upd_cat_id'], $categories_combo, '') . form::combo(['upd_cat_id'], $categories_combo, '') .
$core->formNonce() . $core->formNonce() .
$ap->getHiddenFields() . $ap->getHiddenFields() .
form::hidden(['action'], 'changecat') . form::hidden(['action'], 'changecat') .
'<input type="submit" value="' . __('Save') . '" /></p>' . '<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>'; '</form>';
@ -332,10 +329,10 @@ class zcfsDefaultFeedsActions
throw new Exception(__('No feeds selected')); throw new Exception(__('No feeds selected'));
} }
$upd_int = abs((integer) $post['upd_upd_int']); $upd_int = abs((int) $post['upd_upd_int']);
foreach($ids as $id) { foreach ($ids as $id) {
$cur = $ap->zcfs->openCursor(); $cur = $ap->zcfs->openCursor();
$cur->feed_upd_int = $upd_int; $cur->feed_upd_int = $upd_int;
$ap->zcfs->updFeed($id, $cur); $ap->zcfs->updFeed($id, $cur);
} }
@ -349,17 +346,17 @@ class zcfsDefaultFeedsActions
count($ids) count($ids)
)); ));
$ap->redirect(true); $ap->redirect(true);
} } else {
else {
$ap->beginPage( $ap->beginPage(
dcPage::breadcrumb( dcPage::breadcrumb(
[ [
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Feeds server') => '', __('Feeds server') => '',
$ap->getCallerTitle() => $ap->getRedirection(true), $ap->getCallerTitle() => $ap->getRedirection(true),
__('Change update frequency for this selection') => '' __('Change update frequency for this selection') => ''
])); ]
)
);
echo echo
'<form action="' . $ap->getURI() . '" method="post">' . '<form action="' . $ap->getURI() . '" method="post">' .
@ -375,4 +372,4 @@ class zcfsDefaultFeedsActions
$ap->endPage(); $ap->endPage();
} }
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -22,8 +21,8 @@ if (!defined('DC_RC_PATH')) {
*/ */
class zoneclearFeedServer class zoneclearFeedServer
{ {
public static $nethttp_timeout = 5; public static $nethttp_timeout = 5;
public static $nethttp_agent = 'zoneclearFeedServer - http://zoneclear.org'; public static $nethttp_agent = 'zoneclearFeedServer - http://zoneclear.org';
public static $nethttp_maxredirect = 2; public static $nethttp_maxredirect = 2;
public $core; public $core;
@ -34,7 +33,7 @@ class zoneclearFeedServer
/** /**
* Constructor. * Constructor.
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
*/ */
public function __construct(dcCore $core) public function __construct(dcCore $core)
@ -47,7 +46,7 @@ class zoneclearFeedServer
/** /**
* Short openCursor. * Short openCursor.
* *
* @return cursor cursor instance * @return cursor cursor instance
*/ */
public function openCursor() public function openCursor()
@ -57,7 +56,7 @@ class zoneclearFeedServer
/** /**
* Update feed record. * Update feed record.
* *
* @param integer $id Feed id * @param integer $id Feed id
* @param cursor $cur cursor instance * @param cursor $cur cursor instance
*/ */
@ -66,7 +65,7 @@ class zoneclearFeedServer
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
try { try {
$id = (integer) $id; $id = (int) $id;
if ($id < 1) { if ($id < 1) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
@ -83,6 +82,7 @@ class zoneclearFeedServer
$this->trigger(); $this->trigger();
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -100,10 +100,10 @@ class zoneclearFeedServer
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
try { try {
$cur->feed_id = $this->getNextId(); $cur->feed_id = $this->getNextId();
$cur->blog_id = $this->blog; $cur->blog_id = $this->blog;
$cur->feed_creadt = date('Y-m-d H:i:s'); $cur->feed_creadt = date('Y-m-d H:i:s');
$cur->feed_upddt = date('Y-m-d H:i:s'); $cur->feed_upddt = date('Y-m-d H:i:s');
//add getFeedCursor here //add getFeedCursor here
@ -112,6 +112,7 @@ class zoneclearFeedServer
$this->trigger(); $this->trigger();
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -123,7 +124,7 @@ class zoneclearFeedServer
/** /**
* Quick enable / disable feed. * Quick enable / disable feed.
* *
* @param integer $id Feed Id * @param integer $id Feed Id
* @param boolean $enable Enable or disable feed * @param boolean $enable Enable or disable feed
* @param integer $time Force update time * @param integer $time Force update time
@ -131,7 +132,7 @@ class zoneclearFeedServer
public function enableFeed($id, $enable = true, $time = null) public function enableFeed($id, $enable = true, $time = null)
{ {
try { try {
$id = (integer) $id; $id = (int) $id;
if ($id < 1) { if ($id < 1) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
@ -140,10 +141,10 @@ class zoneclearFeedServer
$cur = $this->openCursor(); $cur = $this->openCursor();
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
$cur->feed_upddt = date('Y-m-d H:i:s'); $cur->feed_upddt = date('Y-m-d H:i:s');
$cur->feed_status = (integer) $enable; $cur->feed_status = (int) $enable;
if (null !== $time) { if (null !== $time) {
$cur->feed_upd_last = (integer) $time; $cur->feed_upd_last = (int) $time;
} }
$cur->update(sprintf( $cur->update(sprintf(
@ -155,6 +156,7 @@ class zoneclearFeedServer
$this->trigger(); $this->trigger();
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -162,15 +164,15 @@ class zoneclearFeedServer
$this->core->callBehavior('zoneclearFeedServerAfterEnableFeed', $id, $enable, $time); $this->core->callBehavior('zoneclearFeedServerAfterEnableFeed', $id, $enable, $time);
} }
# #
/** /**
* Delete record (this not deletes post). * Delete record (this not deletes post).
* *
* @param integer $id Feed Id * @param integer $id Feed Id
*/ */
public function delFeed($id) public function delFeed($id)
{ {
$id = (integer) $id; $id = (int) $id;
if ($id < 1) { if ($id < 1) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
@ -190,22 +192,20 @@ class zoneclearFeedServer
/** /**
* Get related posts. * Get related posts.
* *
* @param array $params Query params * @param array $params Query params
* @param boolean $count_only Return only result count * @param boolean $count_only Return only result count
* @return record record instance * @return record record instance
*/ */
public function getPostsByFeed($params = array(), $count_only = false) public function getPostsByFeed($params = [], $count_only = false)
{ {
if (!isset($params['feed_id'])) { if (!isset($params['feed_id'])) {
return null; return null;
} }
$params['from'] = $params['from'] = 'LEFT JOIN ' . $this->core->prefix . 'meta F ' .
'LEFT JOIN ' . $this->core->prefix . 'meta F ' .
'ON P.post_id = F.post_id '; 'ON P.post_id = F.post_id ';
$params['sql'] = $params['sql'] = "AND P.blog_id = '" . $this->blog . "' " .
"AND P.blog_id = '" . $this->blog . "' " .
"AND F.meta_type = 'zoneclearfeed_id' " . "AND F.meta_type = 'zoneclearfeed_id' " .
"AND F.meta_id = '" . $this->con->escape($params['feed_id']) . "' "; "AND F.meta_id = '" . $this->con->escape($params['feed_id']) . "' ";
@ -216,12 +216,12 @@ class zoneclearFeedServer
/** /**
* Get feed record. * Get feed record.
* *
* @param array $params Query params * @param array $params Query params
* @param boolean $count_only Return only result count * @param boolean $count_only Return only result count
* @return record record instance * @return record record instance
*/ */
public function getFeeds($params = array(), $count_only = false) public function getFeeds($params = [], $count_only = false)
{ {
if ($count_only) { if ($count_only) {
$strReq = 'SELECT count(Z.feed_id) '; $strReq = 'SELECT count(Z.feed_id) ';
@ -231,8 +231,7 @@ class zoneclearFeedServer
$content_req .= implode(', ', $params['columns']) . ', '; $content_req .= implode(', ', $params['columns']) . ', ';
} }
$strReq = $strReq = 'SELECT Z.feed_id, Z.feed_creadt, Z.feed_upddt, Z.feed_type, ' .
'SELECT Z.feed_id, Z.feed_creadt, Z.feed_upddt, Z.feed_type, ' .
'Z.blog_id, Z.cat_id, ' . 'Z.blog_id, Z.cat_id, ' .
'Z.feed_upd_int, Z.feed_upd_last, Z.feed_status, ' . 'Z.feed_upd_int, Z.feed_upd_last, Z.feed_status, ' .
$content_req . $content_req .
@ -243,8 +242,7 @@ class zoneclearFeedServer
'C.cat_title, C.cat_url, C.cat_desc '; 'C.cat_title, C.cat_url, C.cat_desc ';
} }
$strReq .= $strReq .= 'FROM ' . $this->table . ' Z ' .
'FROM ' . $this->table . ' Z ' .
'LEFT OUTER JOIN ' . $this->core->prefix . 'category C ON Z.cat_id = C.cat_id '; 'LEFT OUTER JOIN ' . $this->core->prefix . 'category C ON Z.cat_id = C.cat_id ';
if (!empty($params['from'])) { if (!empty($params['from'])) {
@ -261,9 +259,9 @@ class zoneclearFeedServer
if (!empty($params['feed_id'])) { if (!empty($params['feed_id'])) {
if (is_array($params['feed_id'])) { if (is_array($params['feed_id'])) {
array_walk($params['feed_id'], function(&$v, $k) { if($v !== null) { $v = (integer) $v; }}); array_walk($params['feed_id'], function (&$v, $k) { if ($v !== null) { $v = (int) $v; }});
} else { } else {
$params['feed_id'] = [(integer) $params['feed_id']]; $params['feed_id'] = [(int) $params['feed_id']];
} }
$strReq .= 'AND Z.feed_id ' . $this->con->in($params['feed_id']); $strReq .= 'AND Z.feed_id ' . $this->con->in($params['feed_id']);
} }
@ -275,7 +273,7 @@ class zoneclearFeedServer
$strReq .= "AND Z.feed_url = '" . $this->con->escape($params['feed_url']) . "' "; $strReq .= "AND Z.feed_url = '" . $this->con->escape($params['feed_url']) . "' ";
} }
if (isset($params['feed_status'])) { if (isset($params['feed_status'])) {
$strReq .= "AND Z.feed_status = " . ((integer) $params['feed_status']) . " "; $strReq .= 'AND Z.feed_status = ' . ((int) $params['feed_status']) . ' ';
} }
if (!empty($params['q'])) { if (!empty($params['q'])) {
@ -299,7 +297,7 @@ class zoneclearFeedServer
$strReq .= $this->con->limit($params['limit']); $strReq .= $this->con->limit($params['limit']);
} }
$rs = $this->con->select($strReq); $rs = $this->con->select($strReq);
$rs->zc = $this; $rs->zc = $this;
return $rs; return $rs;
@ -307,7 +305,7 @@ class zoneclearFeedServer
/** /**
* Get next table id. * Get next table id.
* *
* @return record record instance * @return record record instance
*/ */
private function getNextId() private function getNextId()
@ -319,7 +317,7 @@ class zoneclearFeedServer
/** /**
* Lock a file to see if an update is ongoing. * Lock a file to see if an update is ongoing.
* *
* @return boolean True if file is locked * @return boolean True if file is locked
*/ */
public function lockUpdate() public function lockUpdate()
@ -327,14 +325,14 @@ class zoneclearFeedServer
try { try {
# Need flock function # Need flock function
if (!function_exists('flock')) { if (!function_exists('flock')) {
throw New Exception("Can't call php function named flock"); throw new Exception("Can't call php function named flock");
} }
# Cache writable ? # Cache writable ?
if (!is_writable(DC_TPL_CACHE)) { if (!is_writable(DC_TPL_CACHE)) {
throw new Exception("Can't write in cache fodler"); throw new Exception("Can't write in cache fodler");
} }
# Set file path # Set file path
$f_md5 = md5($this->blog); $f_md5 = md5($this->blog);
$cached_file = sprintf( $cached_file = sprintf(
'%s/%s/%s/%s/%s.txt', '%s/%s/%s/%s/%s.txt',
DC_TPL_CACHE, DC_TPL_CACHE,
@ -353,18 +351,18 @@ class zoneclearFeedServer
if (!file_exists($cached_file)) { if (!file_exists($cached_file)) {
!$fp = @fopen($cached_file, 'w'); !$fp = @fopen($cached_file, 'w');
if ($fp === false) { if ($fp === false) {
throw New Exception("Can't create file"); throw new Exception("Can't create file");
} }
fwrite($fp, '1', strlen('1')); fwrite($fp, '1', strlen('1'));
fclose($fp); fclose($fp);
} }
# Open file # Open file
if (!($fp = @fopen($cached_file, 'r+'))) { if (!($fp = @fopen($cached_file, 'r+'))) {
throw New Exception("Can't open file"); throw new Exception("Can't open file");
} }
# Lock file # Lock file
if (!flock($fp, LOCK_EX)) { if (!flock($fp, LOCK_EX)) {
throw New Exception("Can't lock file"); throw new Exception("Can't lock file");
} }
$this->lock = $fp; $this->lock = $fp;
@ -378,7 +376,6 @@ class zoneclearFeedServer
/** /**
* Unlock file of update process. * Unlock file of update process.
*
*/ */
public function unlockUpdate() public function unlockUpdate()
{ {
@ -388,7 +385,7 @@ class zoneclearFeedServer
/** /**
* Check and add/update post related to record if needed. * Check and add/update post related to record if needed.
* *
* @param integer $id Feed Id * @param integer $id Feed Id
* @param boolean $throw Throw exception or end silently * @param boolean $throw Throw exception or end silently
* @return boolean True if process succeed * @return boolean True if process succeed
@ -408,11 +405,11 @@ class zoneclearFeedServer
dt::setTZ($this->core->blog->settings->system->blog_timezone); dt::setTZ($this->core->blog->settings->system->blog_timezone);
$time = time(); $time = time();
$s = $this->core->blog->settings->zoneclearFeedServer; $s = $this->core->blog->settings->zoneclearFeedServer;
# All feeds or only one (from admin) # All feeds or only one (from admin)
$f = !$id ? $f = !$id ?
$this->getFeeds(['feed_status' => 1, 'order' => 'feed_upd_last ASC']) : $this->getFeeds(['feed_status' => 1, 'order' => 'feed_upd_last ASC']) :
$this->getFeeds(['feed_id' => $id]); $this->getFeeds(['feed_id' => $id]);
# No feed # No feed
@ -423,10 +420,10 @@ class zoneclearFeedServer
# Set feeds user # Set feeds user
$this->enableUser($s->zoneclearFeedServer_user); $this->enableUser($s->zoneclearFeedServer_user);
$updates = false; $updates = false;
$loop_mem = []; $loop_mem = [];
$limit = abs((integer) $s->zoneclearFeedServer_update_limit); $limit = abs((int) $s->zoneclearFeedServer_update_limit);
if ($limit < 1) { if ($limit < 1) {
$limit = 10; $limit = 10;
} }
@ -435,9 +432,9 @@ class zoneclearFeedServer
$cur_post = $this->con->openCursor($this->core->prefix . 'post'); $cur_post = $this->con->openCursor($this->core->prefix . 'post');
$cur_meta = $this->con->openCursor($this->core->prefix . 'meta'); $cur_meta = $this->con->openCursor($this->core->prefix . 'meta');
while($f->fetch()) { while ($f->fetch()) {
# Check if feed need update # Check if feed need update
if ($id || $i < $limit && $f->feed_status == 1 if ($id || $i < $limit && $f->feed_status == 1
&& $time > $f->feed_upd_last + $f->feed_upd_int && $time > $f->feed_upd_last + $f->feed_upd_int
) { ) {
$i++; $i++;
@ -455,8 +452,8 @@ class zoneclearFeedServer
$i++; $i++;
# Not updated since last visit # Not updated since last visit
} elseif (!$id } elseif (!$id
&& '' != $feed->pubdate && '' != $feed->pubdate
&& strtotime($feed->pubdate) < $f->feed_upd_last && strtotime($feed->pubdate) < $f->feed_upd_last
) { ) {
# Set update time of this feed # Set update time of this feed
@ -481,7 +478,7 @@ class zoneclearFeedServer
continue; continue;
} }
$item_link = $this->con->escape($item_link); $item_link = $this->con->escape($item_link);
$is_new_published_entry = false; $is_new_published_entry = false;
# Not updated since last visit # Not updated since last visit
@ -499,9 +496,9 @@ class zoneclearFeedServer
$old_post = $this->con->select( $old_post = $this->con->select(
'SELECT P.post_id, P.post_status ' . 'SELECT P.post_id, P.post_status ' .
'FROM ' . $this->core->prefix . 'post P ' . 'FROM ' . $this->core->prefix . 'post P ' .
'INNER JOIN ' . $this->core->prefix . 'meta M '. 'INNER JOIN ' . $this->core->prefix . 'meta M ' .
'ON P.post_id = M.post_id ' . 'ON P.post_id = M.post_id ' .
"WHERE blog_id='" . $this->blog . "' " . "WHERE blog_id='" . $this->blog . "' " .
"AND meta_type = 'zoneclearfeed_url' " . "AND meta_type = 'zoneclearfeed_url' " .
"AND meta_id = '" . $item_link . "' " "AND meta_id = '" . $item_link . "' "
); );
@ -512,20 +509,20 @@ class zoneclearFeedServer
if ($f->cat_id) { if ($f->cat_id) {
$cur_post->cat_id = $f->cat_id; $cur_post->cat_id = $f->cat_id;
} }
$post_content = $item->content ? $item->content : $item->description; $post_content = $item->content ? $item->content : $item->description;
$cur_post->post_content = html::absoluteURLs($post_content,$feed->link); $cur_post->post_content = html::absoluteURLs($post_content, $feed->link);
$cur_post->post_title = $item->title ? $item->title : text::cutString(html::clean($cur_post->post_content), 60); $cur_post->post_title = $item->title ? $item->title : text::cutString(html::clean($cur_post->post_content), 60);
$creator = $item->creator ? $item->creator : $f->feed_owner; $creator = $item->creator ? $item->creator : $f->feed_owner;
try { try {
# Create entry # Create entry
if ($old_post->isEmpty()) { if ($old_post->isEmpty()) {
# Post # Post
$cur_post->user_id = $this->core->auth->userID(); $cur_post->user_id = $this->core->auth->userID();
$cur_post->post_format = 'xhtml'; $cur_post->post_format = 'xhtml';
$cur_post->post_status = (integer) $s->zoneclearFeedServer_post_status_new; $cur_post->post_status = (int) $s->zoneclearFeedServer_post_status_new;
$cur_post->post_open_comment = 0; $cur_post->post_open_comment = 0;
$cur_post->post_open_tb = 0; $cur_post->post_open_tb = 0;
# --BEHAVIOR-- zoneclearFeedServerBeforePostCreate # --BEHAVIOR-- zoneclearFeedServerBeforePostCreate
$this->core->callBehavior( $this->core->callBehavior(
@ -550,7 +547,7 @@ class zoneclearFeedServer
$is_new_published_entry = true; $is_new_published_entry = true;
} }
# Update entry # Update entry
} else { } else {
$post_id = $old_post->post_id; $post_id = $old_post->post_id;
@ -570,7 +567,7 @@ class zoneclearFeedServer
# Quick delete old meta # Quick delete old meta
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->core->prefix . 'meta ' . 'DELETE FROM ' . $this->core->prefix . 'meta ' .
'WHERE post_id = ' . $post_id . ' ' . 'WHERE post_id = ' . $post_id . ' ' .
"AND meta_type LIKE 'zoneclearfeed_%' " "AND meta_type LIKE 'zoneclearfeed_%' "
); );
# Delete old tags # Delete old tags
@ -589,37 +586,37 @@ class zoneclearFeedServer
} }
# Quick add new meta # Quick add new meta
$meta = new ArrayObject(); $meta = new ArrayObject();
$meta->tweeter = $f->feed_tweeter; $meta->tweeter = $f->feed_tweeter;
$cur_meta->clean(); $cur_meta->clean();
$cur_meta->post_id = $post_id; $cur_meta->post_id = $post_id;
$cur_meta->meta_type = 'zoneclearfeed_url'; $cur_meta->meta_type = 'zoneclearfeed_url';
$cur_meta->meta_id = $meta->url = $item_link; $cur_meta->meta_id = $meta->url = $item_link;
$cur_meta->insert(); $cur_meta->insert();
$cur_meta->clean(); $cur_meta->clean();
$cur_meta->post_id = $post_id; $cur_meta->post_id = $post_id;
$cur_meta->meta_type = 'zoneclearfeed_author'; $cur_meta->meta_type = 'zoneclearfeed_author';
$cur_meta->meta_id = $meta->author = $creator; $cur_meta->meta_id = $meta->author = $creator;
$cur_meta->insert(); $cur_meta->insert();
$cur_meta->clean(); $cur_meta->clean();
$cur_meta->post_id = $post_id; $cur_meta->post_id = $post_id;
$cur_meta->meta_type = 'zoneclearfeed_site'; $cur_meta->meta_type = 'zoneclearfeed_site';
$cur_meta->meta_id = $meta->site = $f->feed_url; $cur_meta->meta_id = $meta->site = $f->feed_url;
$cur_meta->insert(); $cur_meta->insert();
$cur_meta->clean(); $cur_meta->clean();
$cur_meta->post_id = $post_id; $cur_meta->post_id = $post_id;
$cur_meta->meta_type = 'zoneclearfeed_sitename'; $cur_meta->meta_type = 'zoneclearfeed_sitename';
$cur_meta->meta_id = $meta->sitename = $f->feed_name; $cur_meta->meta_id = $meta->sitename = $f->feed_name;
$cur_meta->insert(); $cur_meta->insert();
$cur_meta->clean(); $cur_meta->clean();
$cur_meta->post_id = $post_id; $cur_meta->post_id = $post_id;
$cur_meta->meta_type = 'zoneclearfeed_id'; $cur_meta->meta_type = 'zoneclearfeed_id';
$cur_meta->meta_id = $meta->id = $f->feed_id; $cur_meta->meta_id = $meta->id = $f->feed_id;
$cur_meta->insert(); $cur_meta->insert();
# Add new tags # Add new tags
@ -627,8 +624,8 @@ class zoneclearFeedServer
if ($f->feed_get_tags) { if ($f->feed_get_tags) {
# Some feed subjects contains more than one tag # Some feed subjects contains more than one tag
foreach($item->subject as $subjects) { foreach ($item->subject as $subjects) {
$tmp = $this->core->meta->splitMetaValues($subjects); $tmp = $this->core->meta->splitMetaValues($subjects);
$tags = array_merge($tags, $tmp); $tags = array_merge($tags, $tmp);
} }
$tags = array_unique($tags); $tags = array_unique($tags);
@ -637,10 +634,16 @@ class zoneclearFeedServer
foreach ($tags as $tag) { foreach ($tags as $tag) {
# Change tags case # Change tags case
switch((integer) $s->zoneclearFeedServer_tag_case) { switch ((int) $s->zoneclearFeedServer_tag_case) {
case 3: $tag = strtoupper($tag); break; case 3: $tag = strtoupper($tag);
case 2: $tag = strtolower($tag); break;
case 1: $tag = ucfirst(strtolower($tag)); break; break;
case 2: $tag = strtolower($tag);
break;
case 1: $tag = ucfirst(strtolower($tag));
break;
default: /* do nothing */ break; default: /* do nothing */ break;
} }
if (!in_array($tag, $formated_tags)) { if (!in_array($tag, $formated_tags)) {
@ -663,11 +666,11 @@ class zoneclearFeedServer
$cur_post, $cur_post,
$meta $meta
); );
} catch (Exception $e) { } catch (Exception $e) {
$this->con->rollback(); $this->con->rollback();
$this->enableUser(false); $this->enableUser(false);
$this->unlockUpdate(); $this->unlockUpdate();
throw $e; throw $e;
} }
$updates = true; $updates = true;
@ -684,7 +687,7 @@ class zoneclearFeedServer
/** /**
* Set permission to update post table. * Set permission to update post table.
* *
* @param boolean $enable Enable or disable perm * @param boolean $enable Enable or disable perm
*/ */
public function enableUser($enable = false) public function enableUser($enable = false)
@ -694,7 +697,7 @@ class zoneclearFeedServer
if (!$this->core->auth->checkUser($enable)) { if (!$this->core->auth->checkUser($enable)) {
throw new Exception('Unable to set user'); throw new Exception('Unable to set user');
} }
# Disable # Disable
} else { } else {
$this->core->auth = null; $this->core->auth = null;
$this->core->auth = new dcAuth($this->core); $this->core->auth = new dcAuth($this->core);
@ -703,14 +706,14 @@ class zoneclearFeedServer
/** /**
* Read and parse external feeds. * Read and parse external feeds.
* *
* @param string $f Feed URL * @param string $f Feed URL
* @return arrayObject Parsed feed * @return arrayObject Parsed feed
*/ */
public static function readFeed($f) public static function readFeed($f)
{ {
try { try {
$feed_reader = new feedReader; $feed_reader = new feedReader();
$feed_reader->setCacheDir(DC_TPL_CACHE); $feed_reader->setCacheDir(DC_TPL_CACHE);
$feed_reader->setTimeout(self::$nethttp_timeout); $feed_reader->setTimeout(self::$nethttp_timeout);
$feed_reader->setMaxRedirects(self::$nethttp_maxredirect); $feed_reader->setMaxRedirects(self::$nethttp_maxredirect);
@ -732,13 +735,13 @@ class zoneclearFeedServer
/** /**
* Check if an URL is well formed * Check if an URL is well formed
* *
* @param string $url URL * @param string $url URL
* @return Boolean True if URL is allowed * @return Boolean True if URL is allowed
*/ */
public static function validateURL($url) public static function validateURL($url)
{ {
return false !== strpos($url, 'http://') return false !== strpos($url, 'http://')
|| false !== strpos($url, 'https://'); || false !== strpos($url, 'https://');
} }
@ -746,7 +749,7 @@ class zoneclearFeedServer
* Get full URL. * Get full URL.
* *
* Know bugs: anchor is not well parsed. * Know bugs: anchor is not well parsed.
* *
* @param string $root Root URL * @param string $root Root URL
* @param string $url An URL * @param string $url An URL
* @return string Parse URL * @return string Parse URL
@ -778,7 +781,7 @@ class zoneclearFeedServer
/** /**
* Get list of feeds status. * Get list of feeds status.
* *
* @return array List of names/values of feeds status * @return array List of names/values of feeds status
*/ */
public static function getAllStatus() public static function getAllStatus()
@ -791,7 +794,7 @@ class zoneclearFeedServer
/** /**
* Get list of predefined interval. * Get list of predefined interval.
* *
* @return array List of Name/time of intervals * @return array List of Name/time of intervals
*/ */
public static function getAllUpdateInterval() public static function getAllUpdateInterval()
@ -808,7 +811,7 @@ class zoneclearFeedServer
/** /**
* Get list of (super)admins of current blog. * Get list of (super)admins of current blog.
* *
* @return array List of UserCNs/UserIds * @return array List of UserCNs/UserIds
*/ */
public function getAllBlogAdmins() public function getAllBlogAdmins()
@ -840,8 +843,8 @@ class zoneclearFeedServer
'FROM ' . $this->con->escapeSystem($this->core->prefix . 'user') . ' U ' . 'FROM ' . $this->con->escapeSystem($this->core->prefix . 'user') . ' U ' .
'LEFT JOIN ' . $this->con->escapeSystem($this->core->prefix . 'permissions') . ' P ' . 'LEFT JOIN ' . $this->con->escapeSystem($this->core->prefix . 'permissions') . ' P ' .
'ON U.user_id=P.user_id ' . 'ON U.user_id=P.user_id ' .
'WHERE U.user_status = 1 '. 'WHERE U.user_status = 1 ' .
"AND P.blog_id = '" .$this->blog . "' " . "AND P.blog_id = '" . $this->blog . "' " .
"AND P.permissions LIKE '%|admin|%' " "AND P.permissions LIKE '%|admin|%' "
); );
@ -862,13 +865,13 @@ class zoneclearFeedServer
/** /**
* Get list of urls where entries could be hacked. * Get list of urls where entries could be hacked.
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @return array List of names/types of URLs * @return array List of names/types of URLs
*/ */
public static function getPublicUrlTypes(dcCore $core) public static function getPublicUrlTypes(dcCore $core)
{ {
$types = array(); $types = [];
# --BEHAVIOR-- zoneclearFeedServerPublicUrlTypes # --BEHAVIOR-- zoneclearFeedServerPublicUrlTypes
$core->callBehavior('zoneclearFeedServerPublicUrlTypes', $types); $core->callBehavior('zoneclearFeedServerPublicUrlTypes', $types);
@ -885,7 +888,7 @@ class zoneclearFeedServer
/** /**
* Take care about plugin tweakurls (thanks Mathieu M.). * Take care about plugin tweakurls (thanks Mathieu M.).
* *
* @param cursor $cur cursor instance * @param cursor $cur cursor instance
* @param integer $id Post Id * @param integer $id Post Id
*/ */
@ -893,6 +896,6 @@ class zoneclearFeedServer
{ {
global $core; global $core;
$cur->post_url = tweakUrls::tweakBlogURL($cur->post_url); $cur->post_url = tweakUrls::tweakBlogURL($cur->post_url);
$core->auth->sudo(array($core->blog, 'updPost'), $id, $cur); $core->auth->sudo([$core->blog, 'updPost'], $id, $cur);
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -107,7 +106,7 @@ class zoneclearFeedServerActivityReportBehaviors
} }
} }
public static function updFeedRecord($cur,$id) public static function updFeedRecord($cur, $id)
{ {
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
global $core; global $core;
@ -165,4 +164,4 @@ class zoneclearFeedServerActivityReportBehaviors
$logs $logs
); );
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -36,13 +35,13 @@ class zcfsFeedsList extends adminGenericList
$entries = []; $entries = [];
if (isset($_REQUEST['feeds'])) { if (isset($_REQUEST['feeds'])) {
foreach ($_REQUEST['feeds'] as $v) { foreach ($_REQUEST['feeds'] as $v) {
$entries[(integer) $v] = true; $entries[(int) $v] = true;
} }
} }
$html_block = $html_block = '<div class="table-outer">' .
'<div class="table-outer">' . '<table>' .
'<table>' . '<caption>' . (
'<caption>' . ($filter ? $filter ?
sprintf(__('List of %s feeds matching the filter.'), $this->rs_count) : sprintf(__('List of %s feeds matching the filter.'), $this->rs_count) :
sprintf(__('List of feeds (%s)'), $this->rs_count) sprintf(__('List of feeds (%s)'), $this->rs_count)
) . '</caption>'; ) . '</caption>';
@ -84,44 +83,46 @@ class zcfsFeedsList extends adminGenericList
private function feedsLine($checked) 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" />';
$entries_count = $this->rs->zc->getPostsByFeed(['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 = [ $cols = [
'check' => '<td class="nowrap minimal">' . 'check' => '<td class="nowrap minimal">' .
form::checkbox(['feeds[]'], $this->rs->feed_id, ['checked' => $checked]) . form::checkbox(['feeds[]'], $this->rs->feed_id, ['checked' => $checked]) .
'</td>', '</td>',
'title' => '<td class="nowrap" scope="row">' . 'title' => '<td class="nowrap" scope="row">' .
'<a href="' . $url . '#feed" title="' . __('Edit') . '">' . html::escapeHTML($this->rs->feed_name) . '</a>' . '<a href="' . $url . '#feed" title="' . __('Edit') . '">' . html::escapeHTML($this->rs->feed_name) . '</a>' .
'</td>', '</td>',
'desc' => '<td class="nowrap maximal">' . 'desc' => '<td class="nowrap maximal">' .
'<a href="' . $this->rs->feed_feed . '" title="' . html::escapeHTML($this->rs->feed_desc) . '">' . html::escapeHTML($shunk_feed) . '</a>'. '<a href="' . $this->rs->feed_feed . '" title="' . html::escapeHTML($this->rs->feed_desc) . '">' . html::escapeHTML($shunk_feed) . '</a>' .
'</td>', '</td>',
'period' => '<td class="nowrap minimal count">' . 'period' => '<td class="nowrap minimal count">' .
array_search($this->rs->feed_upd_int,$combo_upd_int) . array_search($this->rs->feed_upd_int, $combo_upd_int) .
'</td>', '</td>',
'update' => '<td class="nowrap minimal count">' . 'update' => '<td class="nowrap minimal count">' .
($this->rs->feed_upd_last < 1 ? (
__('never') : $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')) dt::str(__('%Y-%m-%d %H:%M'), $this->rs->feed_upd_last, $this->rs->zc->core->auth->getInfo('user_tz'))
) . '</td>', ) . '</td>',
'entries' => '<td class="nowrap minimal count">' . 'entries' => '<td class="nowrap minimal count">' .
($entries_count ? (
$entries_count ?
'<a href="' . $url . '#entries" title="' . __('View entries') . '">' . $entries_count . '</a>' : '<a href="' . $url . '#entries" title="' . __('View entries') . '">' . $entries_count . '</a>' :
$entries_count $entries_count
) . '</td>', ) . '</td>',
'status' => '<td class="nowrap minimal status">' . $status . '</td>' 'status' => '<td class="nowrap minimal status">' . $status . '</td>'
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
@ -129,7 +130,7 @@ class zcfsFeedsList extends adminGenericList
$this->userColumns('zcfs_feeds', $cols); $this->userColumns('zcfs_feeds', $cols);
return return
'<tr class="line ' . ($this->rs->feed_status ? '' : 'offline ') . '" id="p' . $this->rs->feed_id . '">' . '<tr class="line ' . ($this->rs->feed_status ? '' : 'offline ') . '" id="p' . $this->rs->feed_id . '">' .
implode(iterator_to_array($cols)) . implode(iterator_to_array($cols)) .
'</tr>'; '</tr>';
@ -147,24 +148,26 @@ class zcfsEntriesList extends adminGenericList
public function display($page, $nb_per_page, $base_url, $enclose_block = '', $filter = false) public function display($page, $nb_per_page, $base_url, $enclose_block = '', $filter = false)
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
echo '<p><strong>' . ($filter ? echo '<p><strong>' . (
$filter ?
__('No entries matches the filter') : __('No entries matches the filter') :
__('No entries') __('No entries')
) . '</strong></p>'; ) . '</strong></p>';
} else { } else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$pager->base_url = $base_url; $pager->base_url = $base_url;
$entries = []; $entries = [];
if (isset($_REQUEST['feeds'])) { if (isset($_REQUEST['feeds'])) {
foreach ($_REQUEST['feeds'] as $v) { foreach ($_REQUEST['feeds'] as $v) {
$entries[(integer) $v] = true; $entries[(int) $v] = true;
} }
} }
$html_block = '<div class="table-outer clear">' . $html_block = '<div class="table-outer clear">' .
'<table>' . '<table>' .
'<caption>' . ($filter ? '<caption>' . (
$filter ?
sprintf(__('List of %s entries matching the filter.'), $this->rs_count) : sprintf(__('List of %s entries matching the filter.'), $this->rs_count) :
sprintf(__('List of entries (%s)'), $this->rs_count) sprintf(__('List of entries (%s)'), $this->rs_count)
) . '</caption>'; ) . '</caption>';
@ -206,11 +209,11 @@ class zcfsEntriesList extends adminGenericList
private function postLine() private function postLine()
{ {
$cat_link = $this->core->auth->check('categories', $this->core->blog->id) ? $cat_link = $this->core->auth->check('categories', $this->core->blog->id) ?
'<a href="category.php?id=%s" title="'.__('Edit category').'">%s</a>' '<a href="category.php?id=%s" title="' . __('Edit category') . '">%s</a>'
: '%2$s'; : '%2$s';
$cat_title = $this->rs->cat_title ? $cat_title = $this->rs->cat_title ?
sprintf($cat_link,$this->rs->cat_id, html::escapeHTML($this->rs->cat_title)) sprintf($cat_link, $this->rs->cat_id, html::escapeHTML($this->rs->cat_title))
: __('None'); : __('None');
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
@ -243,15 +246,15 @@ class zcfsEntriesList extends adminGenericList
' id="p' . $this->rs->post_id . '">'; ' id="p' . $this->rs->post_id . '">';
$cols = [ $cols = [
'check' => '<td class="nowrap minimal">'. 'check' => '<td class="nowrap minimal">' .
form::checkbox(array('entries[]'), $this->rs->post_id, '', '', '', !$this->rs->isEditable()).'</td>', form::checkbox(['entries[]'], $this->rs->post_id, '', '', '', !$this->rs->isEditable()) . '</td>',
'title' => '<td scope="row" class="maximal"><a href="' . 'title' => '<td scope="row" class="maximal"><a href="' .
$this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '" ' . $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '" ' .
'title="' . html::escapeHTML($this->rs->getURL()) . '">' . 'title="' . html::escapeHTML($this->rs->getURL()) . '">' .
html::escapeHTML(trim(html::clean($this->rs->post_title))) . '</a></td>', html::escapeHTML(trim(html::clean($this->rs->post_title))) . '</a></td>',
'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>', 'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>',
'author' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_id) . '</td>', 'author' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_id) . '</td>',
'category' => '<td class="nowrap">'.$cat_title.'</td>', 'category' => '<td class="nowrap">' . $cat_title . '</td>',
'status' => '<td class="nowrap status">' . $img_status . '</td>' 'status' => '<td class="nowrap status">' . $img_status . '</td>'
]; ];
@ -301,6 +304,7 @@ class adminZcfsPostFilter extends adminGenericFilter
public function getPostUserFilter(): ?dcAdminFilter public function getPostUserFilter(): ?dcAdminFilter
{ {
$users = null; $users = null;
try { try {
$users = $this->core->blog->getPostsUsers(); $users = $this->core->blog->getPostsUsers();
if ($users->isEmpty()) { if ($users->isEmpty()) {
@ -308,6 +312,7 @@ class adminZcfsPostFilter extends adminGenericFilter
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); $this->core->error->add($e->getMessage());
return null; return null;
} }
@ -330,6 +335,7 @@ class adminZcfsPostFilter extends adminGenericFilter
public function getPostCategoriesFilter(): ?dcAdminFilter public function getPostCategoriesFilter(): ?dcAdminFilter
{ {
$categories = null; $categories = null;
try { try {
$categories = $this->core->blog->getCategories(); $categories = $this->core->blog->getCategories();
if ($categories->isEmpty()) { if ($categories->isEmpty()) {
@ -337,12 +343,13 @@ class adminZcfsPostFilter extends adminGenericFilter
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); $this->core->error->add($e->getMessage());
return null; return null;
} }
$combo = [ $combo = [
'-' => '', '-' => '',
__('(No cat)') => 'NULL' __('(No cat)') => 'NULL'
]; ];
while ($categories->fetch()) { while ($categories->fetch()) {
$combo[ $combo[
@ -378,6 +385,7 @@ class adminZcfsPostFilter extends adminGenericFilter
public function getPostMonthFilter(): ?dcAdminFilter public function getPostMonthFilter(): ?dcAdminFilter
{ {
$dates = null; $dates = null;
try { try {
$dates = $this->core->blog->getDates(['type' => 'month']); $dates = $this->core->blog->getDates(['type' => 'month']);
if ($dates->isEmpty()) { if ($dates->isEmpty()) {
@ -385,12 +393,13 @@ class adminZcfsPostFilter extends adminGenericFilter
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); $this->core->error->add($e->getMessage());
return null; return null;
} }
return (new dcAdminFilter('month')) return (new dcAdminFilter('month'))
->param('post_month', function($f) { return substr($f[0], 4, 2); }) ->param('post_month', function ($f) { return substr($f[0], 4, 2); })
->param('post_year', function($f) { return substr($f[0], 0, 4); }) ->param('post_year', function ($f) { return substr($f[0], 0, 4); })
->title(__('Month:')) ->title(__('Month:'))
->options(array_merge( ->options(array_merge(
['-' => ''], ['-' => ''],

165
index.php
View file

@ -1,22 +1,20 @@
<?php <?php
/** /**
* @brief zoneclearFeedServer, a plugin for Dotclear 2 * @brief zoneclearFeedServer, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis, BG, Pierre Van Glabeke * @author Jean-Christian Denis, BG, Pierre Van Glabeke
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
if ($core->getVersion('zoneclearFeedServer') != if ($core->getVersion('zoneclearFeedServer') != $core->plugins->moduleInfo('zoneclearFeedServer', 'version')
$core->plugins->moduleInfo('zoneclearFeedServer', 'version')
) { ) {
return null; return null;
} }
@ -49,7 +47,7 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$can_view_page = true; $can_view_page = true;
$feed_headlink = '<link rel="%s" title="%s" href="' . $p_url . '&amp;part=feed&amp;feed_id=%s" />'; $feed_headlink = '<link rel="%s" title="%s" href="' . $p_url . '&amp;part=feed&amp;feed_id=%s" />';
$feed_link = '<a href="' . $p_url . '&amp;part=feed&amp;feed_id=%s" title="%s">%s</a>'; $feed_link = '<a href="' . $p_url . '&amp;part=feed&amp;feed_id=%s" title="%s">%s</a>';
$next_link = $prev_link = $next_headlink = $prev_headlink = null; $next_link = $prev_link = $next_headlink = $prev_headlink = null;
@ -58,11 +56,12 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$combo_status = $zcfs->getAllStatus(); $combo_status = $zcfs->getAllStatus();
$combo_upd_int = $zcfs->getAllUpdateInterval(); $combo_upd_int = $zcfs->getAllUpdateInterval();
$combo_categories = ['-' => '']; $combo_categories = ['-' => ''];
try { try {
$categories = $core->blog->getCategories(['post_type' => 'post']); $categories = $core->blog->getCategories(['post_type' => 'post']);
while ($categories->fetch()) { while ($categories->fetch()) {
$combo_categories[ $combo_categories[
str_repeat('&nbsp;&nbsp;', $categories->level-1) . str_repeat('&nbsp;&nbsp;', $categories->level - 1) .
'&bull; ' . html::escapeHTML($categories->cat_title) '&bull; ' . html::escapeHTML($categories->cat_title)
] = $categories->cat_id; ] = $categories->cat_id;
} }
@ -77,7 +76,7 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
if ($feed->isEmpty()) { if ($feed->isEmpty()) {
$core->error->add(__('This feed does not exist.')); $core->error->add(__('This feed does not exist.'));
$can_view_page = false; $can_view_page = false;
} else { } else {
$feed_id = $feed->feed_id; $feed_id = $feed->feed_id;
$feed_name = $feed->feed_name; $feed_name = $feed->feed_name;
$feed_desc = $feed->feed_desc; $feed_desc = $feed->feed_desc;
@ -92,53 +91,69 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$feed_status = $feed->feed_status; $feed_status = $feed->feed_status;
$feed_upd_int = $feed->feed_upd_int; $feed_upd_int = $feed->feed_upd_int;
$next_params = array( $next_params = [
'sql' => 'AND feed_id < ' . $feed_id . ' ', 'sql' => 'AND feed_id < ' . $feed_id . ' ',
'limit' => 1 'limit' => 1
); ];
$next_rs = $zcfs->getFeeds($next_params); $next_rs = $zcfs->getFeeds($next_params);
$prev_params = array( $prev_params = [
'sql' => 'AND feed_id > ' . $feed_id . ' ', 'sql' => 'AND feed_id > ' . $feed_id . ' ',
'limit' => 1 'limit' => 1
); ];
$prev_rs = $zcfs->getFeeds($prev_params); $prev_rs = $zcfs->getFeeds($prev_params);
if (!$next_rs->isEmpty()) { if (!$next_rs->isEmpty()) {
$next_link = sprintf($feed_link, $next_rs->feed_id, $next_link = sprintf(
html::escapeHTML($next_rs->feed_name), __('next feed') . '&nbsp;&#187;'); $feed_link,
$next_headlink = sprintf($feed_headlink, 'next', $next_rs->feed_id,
html::escapeHTML($next_rs->feed_name), $next_rs->feed_id); html::escapeHTML($next_rs->feed_name),
__('next feed') . '&nbsp;&#187;'
);
$next_headlink = sprintf(
$feed_headlink,
'next',
html::escapeHTML($next_rs->feed_name),
$next_rs->feed_id
);
} }
if (!$prev_rs->isEmpty()) { if (!$prev_rs->isEmpty()) {
$prev_link = sprintf($feed_link, $prev_rs->feed_id, $prev_link = sprintf(
html::escapeHTML($prev_rs->feed_name), '&#171;&nbsp;' . __('previous feed')); $feed_link,
$prev_headlink = sprintf($feed_headlink, 'previous', $prev_rs->feed_id,
html::escapeHTML($prev_rs->feed_name), $prev_rs->feed_id); html::escapeHTML($prev_rs->feed_name),
'&#171;&nbsp;' . __('previous feed')
);
$prev_headlink = sprintf(
$feed_headlink,
'previous',
html::escapeHTML($prev_rs->feed_name),
$prev_rs->feed_id
);
} }
} }
} }
if (!empty($_POST['action']) && $_POST['action'] == 'savefeed') { if (!empty($_POST['action']) && $_POST['action'] == 'savefeed') {
try { try {
$feed_name = $_POST['feed_name']; $feed_name = $_POST['feed_name'];
$feed_desc = $_POST['feed_desc']; $feed_desc = $_POST['feed_desc'];
$feed_owner = $_POST['feed_owner']; $feed_owner = $_POST['feed_owner'];
$feed_tweeter = $_POST['feed_tweeter']; $feed_tweeter = $_POST['feed_tweeter'];
$feed_url = $_POST['feed_url']; $feed_url = $_POST['feed_url'];
$feed_feed = $_POST['feed_feed']; $feed_feed = $_POST['feed_feed'];
$feed_lang = $_POST['feed_lang']; $feed_lang = $_POST['feed_lang'];
$feed_tags = $_POST['feed_tags']; $feed_tags = $_POST['feed_tags'];
$feed_get_tags = empty($_POST['feed_get_tags']) ? 0 : 1; $feed_get_tags = empty($_POST['feed_get_tags']) ? 0 : 1;
$feed_cat_id = $_POST['feed_cat_id']; $feed_cat_id = $_POST['feed_cat_id'];
$feed_upd_int = $_POST['feed_upd_int']; $feed_upd_int = $_POST['feed_upd_int'];
if (isset($_POST['feed_status'])) { if (isset($_POST['feed_status'])) {
$feed_status = (integer) $_POST['feed_status']; $feed_status = (int) $_POST['feed_status'];
} }
$testfeed_params['feed_feed'] = $feed_feed; $testfeed_params['feed_feed'] = $feed_feed;
if ($feed_id) { if ($feed_id) {
$testfeed_params['sql'] ='AND feed_id <> '.$feed_id.' '; $testfeed_params['sql'] = 'AND feed_id <> ' . $feed_id . ' ';
} }
if ($zcfs->getFeeds($testfeed_params, true)->f(0)) { if ($zcfs->getFeeds($testfeed_params, true)->f(0)) {
throw new Exception(__('Record with same feed URL already exists.')); throw new Exception(__('Record with same feed URL already exists.'));
@ -158,14 +173,14 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$get_feed_cat_id = $core->blog->getCategory($feed_cat_id); $get_feed_cat_id = $core->blog->getCategory($feed_cat_id);
if ($feed_cat_id != '' && !$get_feed_cat_id) { if ($feed_cat_id != '' && !$get_feed_cat_id) {
throw new Exception(__('You must provide valid category.')); throw new Exception(__('You must provide valid category.'));
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
if (!empty($_POST['action']) && $_POST['action'] == 'savefeed' && !$core->error->flag()) { if (!empty($_POST['action']) && $_POST['action'] == 'savefeed' && !$core->error->flag()) {
$cur = $zcfs->openCursor(); $cur = $zcfs->openCursor();
$cur->feed_name = $feed_name; $cur->feed_name = $feed_name;
$cur->feed_desc = $feed_desc; $cur->feed_desc = $feed_desc;
$cur->feed_owner = $feed_owner; $cur->feed_owner = $feed_owner;
@ -174,10 +189,10 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$cur->feed_feed = $feed_feed; $cur->feed_feed = $feed_feed;
$cur->feed_lang = $feed_lang; $cur->feed_lang = $feed_lang;
$cur->feed_tags = $feed_tags; $cur->feed_tags = $feed_tags;
$cur->feed_get_tags = (integer) $feed_get_tags; $cur->feed_get_tags = (int) $feed_get_tags;
$cur->cat_id = $feed_cat_id != '' ? (integer) $feed_cat_id : null; $cur->cat_id = $feed_cat_id != '' ? (int) $feed_cat_id : null;
$cur->feed_status = (integer) $feed_status; $cur->feed_status = (int) $feed_status;
$cur->feed_upd_int = (integer) $feed_upd_int; $cur->feed_upd_int = (int) $feed_upd_int;
# Update feed # Update feed
if ($feed_id) { if ($feed_id) {
@ -194,12 +209,13 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
__('Feed successfully updated.') __('Feed successfully updated.')
); );
$core->adminurl->redirect( $core->adminurl->redirect(
'admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $feed_id] 'admin.plugin.zoneclearFeedServer',
['part' => 'feed', 'feed_id' => $feed_id]
); );
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} else { } else {
try { try {
# --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedCreate # --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedCreate
$core->callBehavior('adminBeforeZoneclearFeedServerFeedCreate', $cur); $core->callBehavior('adminBeforeZoneclearFeedServerFeedCreate', $cur);
@ -213,7 +229,8 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
__('Feed successfully created.') __('Feed successfully created.')
); );
$core->adminurl->redirect( $core->adminurl->redirect(
'admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $return_id] 'admin.plugin.zoneclearFeedServer',
['part' => 'feed', 'feed_id' => $return_id]
); );
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
@ -262,8 +279,8 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# posts # posts
try { try {
$posts = $zcfs->getPostsByFeed($params); $posts = $zcfs->getPostsByFeed($params);
$counter = $zcfs->getPostsByFeed($params,true); $counter = $zcfs->getPostsByFeed($params, true);
$post_list = new zcfsEntriesList( $post_list = new zcfsEntriesList(
$core, $core,
$posts, $posts,
@ -275,10 +292,10 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
} }
# display # display
echo echo
'<html><head><title>' . __('Feeds server') . '</title>' . '<html><head><title>' . __('Feeds server') . '</title>' .
($feed_id && !$core->error->flag() ? ($feed_id && !$core->error->flag() ?
$post_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $feed_id], '&').'#entries') . $post_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $feed_id], '&') . '#entries') .
dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js'))
: '') . : '') .
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
@ -290,12 +307,12 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
'</head><body>' . '</head><body>' .
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Feeds server') => $p_url, __('Feeds server') => $p_url,
($feed_id ? __('Edit feed') : __('New feed')) => '' ($feed_id ? __('Edit feed') : __('New feed')) => ''
]). ]) .
dcPage::notices() . dcPage::notices() .
($feed_id ? '<h3>' . sprintf(__('Edit feed "%s"'), $feed_name) .'</h3>' : ''); ($feed_id ? '<h3>' . sprintf(__('Edit feed "%s"'), $feed_name) . '</h3>' : '');
# Feed # Feed
if ($can_view_page) { if ($can_view_page) {
@ -394,11 +411,11 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
'</div>' . '</div>' .
'<p class="clear"> '<p class="clear">
<input type="submit" name="save" value="'.__('Save').' (s)" accesskey="s"/>' . <input type="submit" name="save" value="' . __('Save') . ' (s)" accesskey="s"/>' .
$core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [ $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [
'part' => 'feed', 'part' => 'feed',
'feed_id' => $feed_id, 'feed_id' => $feed_id,
'action' => 'savefeed' 'action' => 'savefeed'
]) . ]) .
$core->formNonce() . $core->formNonce() .
'</p> '</p>
@ -408,10 +425,11 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# entries # entries
if ($feed_id && $can_view_page && !$core->error->flag()) { if ($feed_id && $can_view_page && !$core->error->flag()) {
echo '<div class="multi-part" title="'.__('Entries').'" id="entries">'; echo '<div class="multi-part" title="' . __('Entries') . '" id="entries">';
# show filters # show filters
$post_filter->display(['admin.plugin.zoneclearFeedServer','#entries'], $post_filter->display(
['admin.plugin.zoneclearFeedServer','#entries'],
$core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [ $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [
'part' => 'feed', 'part' => 'feed',
'feed_id' => $feed_id 'feed_id' => $feed_id
@ -425,10 +443,10 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# show posts # show posts
$post_list->display( $post_list->display(
$post_filter->page, $post_filter->page,
$post_filter->nb, $post_filter->nb,
$core->adminurl->get('admin.plugin.zoneclearFeedServer', $args, '&') . '#entries', $core->adminurl->get('admin.plugin.zoneclearFeedServer', $args, '&') . '#entries',
'<form action="' . $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed']) . '#entries" method="post" id="form-entries">'. '<form action="' . $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed']) . '#entries" method="post" id="form-entries">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
@ -448,12 +466,11 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
echo '</div>'; echo '</div>';
} }
############################################################ ############################################################
# #
# All feeds # All feeds
# #
############################################################ ############################################################
} else { } else {
# actions # actions
$feeds_actions_page = new zcfsFeedsActionsPage( $feeds_actions_page = new zcfsFeedsActionsPage(
@ -474,9 +491,9 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# feeds # feeds
try { try {
$feeds = $zcfs->getFeeds($params); $feeds = $zcfs->getFeeds($params);
$feeds_counter = $zcfs->getFeeds($params, true)->f(0); $feeds_counter = $zcfs->getFeeds($params, true)->f(0);
$feeds_list = new zcfsFeedsList( $feeds_list = new zcfsFeedsList(
$core, $core,
$feeds, $feeds,
$feeds_counter $feeds_counter
@ -486,7 +503,7 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
} }
# display # display
echo echo
'<html><head><title>' . __('Feeds server') . '</title>' . '<html><head><title>' . __('Feeds server') . '</title>' .
$feeds_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'], '&')) . $feeds_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'], '&')) .
dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) . dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) .
@ -498,9 +515,9 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
'</head><body>' . '</head><body>' .
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Feeds server') => '' __('Feeds server') => ''
]). ]) .
dcPage::notices() . dcPage::notices() .
'<p class="top-add">' . '<p class="top-add">' .
@ -508,11 +525,13 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
__('New feed') . '</a></p>'; __('New feed') . '</a></p>';
$feeds_filter->display( $feeds_filter->display(
'admin.plugin.zoneclearFeedServer', 'admin.plugin.zoneclearFeedServer',
$core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', ['part', 'feeds']) $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', ['part', 'feeds'])
); );
$feeds_list->feedsDisplay($feeds_filter->page, $feeds_filter->nb, $feeds_list->feedsDisplay(
$feeds_filter->page,
$feeds_filter->nb,
'<form action="' . $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part', 'feeds']) . '" method="post" id="form-actions">' . '<form action="' . $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part', 'feeds']) . '" method="post" id="form-actions">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
@ -529,4 +548,4 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
); );
} }
echo '</body></html>'; echo '</body></html>';

View file

@ -1,17 +1,15 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief zoneclearFeedServer, a plugin for Dotclear 2
# This file is part of zoneclearFeedServer, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors * @subpackage Plugin
# *
# Licensed under the GPL version 2.0 license. * @author Jean-Christian Denis, BG, Pierre Van Glabeke
# A copy of this license is available in LICENSE file or at *
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ */
if (!isset($__resources['help']['zoneclearFeedServer'])) {
if (!isset($__resources['help']['zoneclearFeedServer'])) $__resources['help']['zoneclearFeedServer'] = dirname(__FILE__) . '/help/zoneclearFeedServer.html';
{ }
$__resources['help']['zoneclearFeedServer'] = dirname(__FILE__).'/help/zoneclearFeedServer.html';
}

View file

@ -1,17 +1,15 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief zoneclearFeedServer, a plugin for Dotclear 2
# This file is part of zoneclearFeedServer, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors * @subpackage Plugin
# *
# Licensed under the GPL version 2.0 license. * @author Jean-Christian Denis, BG, Pierre Van Glabeke
# A copy of this license is available in LICENSE file or at *
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ */
if (!isset($__resources['help']['zoneclearFeedServer'])) {
if (!isset($__resources['help']['zoneclearFeedServer'])) $__resources['help']['zoneclearFeedServer'] = dirname(__FILE__) . '/help/zoneclearFeedServer.html';
{ }
$__resources['help']['zoneclearFeedServer'] = dirname(__FILE__).'/help/zoneclearFeedServer.html';
}