diff options
| author | 2018-06-09 15:58:18 +0200 | |
|---|---|---|
| committer | 2018-06-09 15:58:18 +0200 | |
| commit | 6a56894e940db0b1f7ee6788fbc38f26c80d004d (patch) | |
| tree | a0ef3d306ee3f0aa02a7addbb743af9863565691 /lib | |
| parent | 32676d59a386fe067ae0beac0287c700274f3d57 (diff) | |
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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/Configuration.php | 14 | ||||
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 26 | ||||
| -rw-r--r-- | lib/lib_rss.php | 24 |
3 files changed, 27 insertions, 37 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 5470dc85f..3e486d68e 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -90,15 +90,15 @@ class Minz_Configuration { private $configuration_setter = null; public function removeExtension($ext_name) { - self::$extensions_enabled = array_diff( - self::$extensions_enabled, - array($ext_name) - ); + unset(self::$extensions_enabled[$ext_name]); + $legacyKey = array_search($ext_name, self::$extensions_enabled, true); + if ($legacyKey !== false) { //Legacy format FreshRSS < 1.11.1 + unset(self::$extensions_enabled[$legacyKey]); + } } public function addExtension($ext_name) { - $found = array_search($ext_name, self::$extensions_enabled) !== false; - if (!$found) { - self::$extensions_enabled[] = $ext_name; + if (!isset(self::$extensions_enabled[$ext_name])) { + self::$extensions_enabled[$ext_name] = true; } } 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); + } } /** diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 04bbb2515..5f460862e 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -480,7 +480,6 @@ function recursive_unlink($dir) { return rmdir($dir); } - /** * Remove queries where $get is appearing. * @param $get the get attribute which should be removed. @@ -497,29 +496,6 @@ function remove_query_by_get($get, $queries) { return $final_queries; } - -/** - * Add a value in an array and take care it is unique. - * @param $array the array in which we add the value. - * @param $value the value to add. - */ -function array_push_unique(&$array, $value) { - $found = array_search($value, $array) !== false; - if (!$found) { - $array[] = $value; - } -} - - -/** - * Remove a value from an array. - * @param $array the array from wich value is removed. - * @param $value the value to remove. - */ -function array_remove(&$array, $value) { - $array = array_diff($array, array($value)); -} - //RFC 4648 function base64url_encode($data) { return strtr(rtrim(base64_encode($data), '='), '+/', '-_'); |
