aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Configuration.php14
-rw-r--r--lib/Minz/ExtensionManager.php29
-rw-r--r--lib/Minz/Translate.php26
-rw-r--r--lib/SimplePie/SimplePie.php7
-rw-r--r--lib/lib_rss.php86
5 files changed, 50 insertions, 112 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..b086c4001 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,15 @@ 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);
+ 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);
+ } elseif ($ext_status) { //New format name=>Boolean
+ self::enable($ext_name);
+ }
}
}
@@ -255,10 +267,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/Minz/Translate.php b/lib/Minz/Translate.php
index d9cd59f7e..db76e9214 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -64,12 +64,16 @@ class Minz_Translate {
$list_langs = array();
foreach (self::$path_list as $path) {
- $path_langs = array_values(array_diff(
- scandir($path),
- array('..', '.')
- ));
-
- $list_langs = array_merge($list_langs, $path_langs);
+ $scan = scandir($path);
+ if (is_array($scan)) {
+ $path_langs = array_values(array_diff(
+ $scan,
+ array('..', '.')
+ ));
+ if (is_array($path_langs)) {
+ $list_langs = array_merge($list_langs, $path_langs);
+ }
+ }
}
return array_unique($list_langs);
@@ -80,12 +84,10 @@ class Minz_Translate {
* @param $path a path containing i18n directories (e.g. ./en/, ./fr/).
*/
public static function registerPath($path) {
- if (in_array($path, self::$path_list)) {
- return;
+ if (!in_array($path, self::$path_list) && is_dir($path)) {
+ self::$path_list[] = $path;
+ self::loadLang($path);
}
-
- self::$path_list[] = $path;
- self::loadLang($path);
}
/**
@@ -94,7 +96,7 @@ class Minz_Translate {
*/
private static function loadLang($path) {
$lang_path = $path . '/' . self::$lang_name;
- if (!file_exists($lang_path) || is_null(self::$lang_name)) {
+ if (!file_exists($lang_path) || self::$lang_name == '') {
// The lang path does not exist, nothing more to do.
return;
}
diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php
index 5cd445b6d..b591bcddd 100644
--- a/lib/SimplePie/SimplePie.php
+++ b/lib/SimplePie/SimplePie.php
@@ -1322,7 +1322,12 @@ class SimplePie
function cleanMd5($rss)
{
- return md5(preg_replace(array('#<(lastBuildDate|pubDate|updated|feedDate|dc:date|slash:comments)>[^<]+</\\1>#', '#<!--.+?-->#s'), '', $rss));
+ return md5(preg_replace(array(
+ '#<(lastBuildDate|pubDate|updated|feedDate|dc:date|slash:comments)>[^<]+</\\1>#',
+ '#<(media:starRating|media:statistics) [^/<>]+/>#',
+ '#<!--.+?-->#s',
+ ), '', $rss));
+
}
/**
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index abb20f16a..5f460862e 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -253,68 +253,6 @@ function sanitizeHTML($data, $base = '') {
return html_only_entity_decode($simplePie->sanitize->sanitize($data, SIMPLEPIE_CONSTRUCT_HTML, $base));
}
-/* permet de récupérer le contenu d'un article pour un flux qui n'est pas complet */
-function get_content_by_parsing($url, $path, $attributes = array()) {
- require_once(LIB_PATH . '/lib_phpQuery.php');
- $system_conf = Minz_Configuration::get('system');
- $limits = $system_conf->limits;
- $feed_timeout = empty($attributes['timeout']) ? 0 : intval($attributes['timeout']);
-
- if ($system_conf->simplepie_syslog_enabled) {
- syslog(LOG_INFO, 'FreshRSS GET ' . SimplePie_Misc::url_remove_credentials($url));
- }
-
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_REFERER => SimplePie_Misc::url_remove_credentials($url),
- CURLOPT_HTTPHEADER => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
- CURLOPT_USERAGENT => FRESHRSS_USERAGENT,
- CURLOPT_CONNECTTIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
- CURLOPT_TIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
- //CURLOPT_FAILONERROR => true;
- CURLOPT_MAXREDIRS => 4,
- CURLOPT_RETURNTRANSFER => true,
- ));
- if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') {
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646
- }
- if (defined('CURLOPT_ENCODING')) {
- curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings
- }
- curl_setopt_array($ch, $system_conf->curl_options);
- if (isset($attributes['ssl_verify'])) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $attributes['ssl_verify'] ? 2 : 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $attributes['ssl_verify'] ? true : false);
- }
- $html = curl_exec($ch);
- $c_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- $c_error = curl_error($ch);
- curl_close($ch);
-
- if ($c_status != 200 || $c_error != '') {
- Minz_Log::warning('Error fetching content: HTTP code ' . $c_status . ': ' . $c_error . ' ' . $url);
- }
-
- if ($html) {
- $doc = phpQuery::newDocument($html);
- $content = $doc->find($path);
-
- foreach (pq('img[data-src]') as $img) {
- $imgP = pq($img);
- $dataSrc = $imgP->attr('data-src');
- if (strlen($dataSrc) > 4) {
- $imgP->attr('src', $dataSrc);
- $imgP->removeAttr('data-src');
- }
- }
-
- return sanitizeHTML($content->__toString(), $url);
- } else {
- throw new Exception();
- }
-}
-
/**
* Add support of image lazy loading
* Move content from src attribute to data-original
@@ -542,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.
@@ -559,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), '='), '+/', '-_');