From 6a56894e940db0b1f7ee6788fbc38f26c80d004d Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 9 Jun 2018 15:58:18 +0200 Subject: New extension event + Tumblr GDPR (#1924) * New extension event + Tumblr GDPR https://github.com/FreshRSS/FreshRSS/issues/1894 simplepie_before_init event * Refactor extension enabling + Tumblr GDPR enabled by default Add possibility for extensions to be enabled by default, and disabled back by users. * Minor whitespace --- lib/Minz/ExtensionManager.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'lib/Minz/ExtensionManager.php') diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 10c49a8b6..3914217ac 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -35,6 +35,10 @@ class Minz_ExtensionManager { 'list' => array(), 'signature' => 'OneToOne', ), + 'simplepie_before_init' => array( // function($simplePie, $feed) -> none + 'list' => array(), + 'signature' => 'PassArguments', + ), ); private static $ext_to_hooks = array(); @@ -160,7 +164,8 @@ class Minz_ExtensionManager { self::$ext_list[$name] = $ext; if ($ext->getType() === 'system' && - in_array($name, self::$ext_auto_enabled)) { + (!empty(self::$ext_auto_enabled[$name]) || + in_array($name, self::$ext_auto_enabled, true))) { //Legacy format < FreshRSS 1.11.1 self::enable($ext->getName()); } @@ -189,8 +194,12 @@ class Minz_ExtensionManager { * @param string[] $ext_list the names of extensions we want to load. */ public static function enableByList($ext_list) { - foreach ($ext_list as $ext_name) { - self::enable($ext_name); + foreach ($ext_list as $ext_name => $ext_status) { + if (is_int($ext_name)) { //Legacy format int=>name + self::enable($ext_status); + } elseif ($ext_status) { //New format name=>Boolean + self::enable($ext_name); + } } } @@ -255,10 +264,15 @@ class Minz_ExtensionManager { } $signature = self::$hook_list[$hook_name]['signature']; - $signature = 'self::call' . $signature; $args = func_get_args(); - - return call_user_func_array($signature, $args); + if ($signature === 'PassArguments') { + array_shift($args); + foreach (self::$hook_list[$hook_name]['list'] as $function) { + call_user_func_array($function, $args); + } + } else { + return call_user_func_array('self::call' . $signature, $args); + } } /** -- cgit v1.2.3 From 031acde003b85ae34a4996d0c02fdc41ffae5515 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 13 Jun 2018 09:27:02 +0200 Subject: Fix extension hook for updated articles (#1932) * Fix extension hook for updated articles https://github.com/FreshRSS/FreshRSS/issues/1926 * Enable extensions during PubSubHubbub * A little array protection * Changelog 1926 https://github.com/FreshRSS/FreshRSS/issues/1926 https://github.com/FreshRSS/FreshRSS/pull/1932 * Add null check --- CHANGELOG.md | 1 + app/Controllers/feedController.php | 9 ++++++++- lib/Minz/ExtensionManager.php | 3 +++ p/api/pshb.php | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/Minz/ExtensionManager.php') diff --git a/CHANGELOG.md b/CHANGELOG.md index 30779d42f..0ffd9c373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Built-in extension to fix Tumblr feeds from European Union due to GDPR [#1894](https://github.com/FreshRSS/FreshRSS/issues/1894) * Bug fixing * Fix bug in case of bad i18n in extensions [#1797](https://github.com/FreshRSS/FreshRSS/issues/1797) + * Fix extension callback for updated articles and PubSubHubbub [#1926](https://github.com/FreshRSS/FreshRSS/issues/1926) * Fix regression in fetching full articles content [#1917](https://github.com/FreshRSS/FreshRSS/issues/1917) * Fix several bugs in the new Fever API [#1930](https://github.com/FreshRSS/FreshRSS/issues/1930) * Updated sharing to Mastodon [#1904](https://github.com/FreshRSS/FreshRSS/issues/1904) diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index ca85e7cb8..ec88156f9 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -351,13 +351,20 @@ class FreshRSS_feed_Controller extends Minz_ActionController { //This entry already exists and is unchanged. TODO: Remove the test with the zero'ed hash in FreshRSS v1.3 $oldGuids[] = $entry->guid(); } else { //This entry already exists but has been updated - //Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->id() . + //Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->url() . //', old hash ' . $existingHash . ', new hash ' . $entry->hash()); $mark_updated_article_unread = $feed->attributes('mark_updated_article_unread') !== null ? ( $feed->attributes('mark_updated_article_unread') ) : FreshRSS_Context::$user_conf->mark_updated_article_unread; $needFeedCacheRefresh = $mark_updated_article_unread; $entry->_isRead(FreshRSS_Context::$user_conf->mark_updated_article_unread ? false : null); //Change is_read according to policy. + + $entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry); + if ($entry === null) { + // An extension has returned a null value, there is nothing to insert. + continue; + } + if (!$entryDAO->inTransaction()) { $entryDAO->beginTransaction(); } diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 3914217ac..b086c4001 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -194,6 +194,9 @@ class Minz_ExtensionManager { * @param string[] $ext_list the names of extensions we want to load. */ public static function enableByList($ext_list) { + if (!is_array($ext_list)) { + return; + } foreach ($ext_list as $ext_name => $ext_status) { if (is_int($ext_name)) { //Legacy format int=>name self::enable($ext_status); diff --git a/p/api/pshb.php b/p/api/pshb.php index 57a7bb0dd..ac78bfd74 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -116,6 +116,8 @@ if ($self !== base64url_decode($canonical64)) { $self = base64url_decode($canonical64); } +Minz_ExtensionManager::init(); + $nb = 0; foreach ($users as $userFilename) { $username = basename($userFilename, '.txt'); @@ -132,6 +134,10 @@ foreach ($users as $userFilename) { join_path(FRESHRSS_PATH, 'config-user.default.php')); new Minz_ModelPdo($username); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init FreshRSS_Context::init(); + if (FreshRSS_Context::$user_conf != null) { + Minz_ExtensionManager::enableByList(FreshRSS_Context::$user_conf->extensions_enabled); + } + list($updated_feeds, $feed, $nb_new_articles) = FreshRSS_feed_Controller::actualizeFeed(0, $self, false, $simplePie); if ($updated_feeds > 0 || $feed != false) { $nb++; -- cgit v1.2.3