aboutsummaryrefslogtreecommitdiff
path: root/lib/lib_rss.php
diff options
context:
space:
mode:
authorGravatar Artur Weigandt <Art4@users.noreply.github.com> 2024-09-14 23:11:10 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-14 23:11:10 +0200
commit882deab455fb7b6ca020391a33bff24e088c62bf (patch)
treef0d6a3f66bf6de430ec087253fe3099cf631767f /lib/lib_rss.php
parentbea4ed69fccc7de2375363d8940af9a96e986650 (diff)
Allow SimplePie updates with composer (#4374)
* rename lib/SimplePie to lib/CustomSimplePie * add test for autoloading SimplePie with PSR-0 * install SimplePie 1.6.0 * Add SimplePie CHANGELOG.md, ignore irrelevant files * remove unmodified custom classes * rename all customized SimplePie classes * Add autoloading for SimplePie PSR-0 and CustomSimplePie classes * let CustomSimplePie extends SimplePie, remove unchanged code * let CustomSimplePieMisc extends SimplePie\Misc, remove unchanged code * Add tests for autoloading * let CustomSimplePieContentTypeSniffer extends Sniffer, remove unchanged code * remove unchanged CustomSimplePieEnclosure class The fixed typos are commited to SimplePie See https://github.com/simplepie/simplepie/pull/722/commits/133eac158cddaf5d2ddf9d9e5f42d92f944f885d * let CustomSimplePieFile extends SimplePie\File, remove unchanged code * let CustomSimplePieParser extends SimplePie\Parser, remove unchanged code * let CustomSimplePieSanitize extends SimplePie\Sanitize, remove unchanged code * let CustomSimplePieHttpParser extends SimplePie\HTTP\Parser, remove unchanged code * Remove CustomSimplePie * Switch SimplePie repo to https://github.com/FreshRSS/simplepie.git * move to latest branch, update all SimplePie source files * Use namespaced SimplePie classes, remove SimplePie library folder * Update to latest SimplePie version with FreshRSS modifications * Bump SimplePie Tests expected to fail due to missing a backport of functionalities * Add fork-specific readme * Re-implement initial syslog SimplePie GET https://github.com/FreshRSS/FreshRSS/pull/815 Lacks https://github.com/FreshRSS/FreshRSS/pull/6061 * Closer backport of syslog SimplePie GET https://github.com/FreshRSS/FreshRSS/pull/6061 But the requests logs will be in the wrong order in case of redirections * Fixes * lib update * SimplePie include a few more files * Try with cache-hash branch * Point to newer commit * Point to newer commit * Finalise logs * Finalise * Bump SimplePie commit * Bump SimplePie commit * Readme SimplePie fork * Bump SimplePie commit * Better logging * Bump SimplePie commit * Reworked approach to work with SimplePie cache Simpler FreshRSS patches * Bump SimplePie commit https://github.com/FreshRSS/simplepie/pull/22 * Simplepie846 https://github.com/FreshRSS/simplepie/pull/23 And additional fixes * Remove log * Cherry pick relevant unmerged SimplePie PRs --------- Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib/lib_rss.php')
-rw-r--r--lib/lib_rss.php31
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index d8602963e..2f1f4e3ef 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -58,23 +58,26 @@ function classAutoloader(string $class): void {
}
} elseif (strpos($class, 'Minz') === 0) {
include(LIB_PATH . '/' . str_replace('_', '/', $class) . '.php');
- } elseif (strpos($class, 'SimplePie') === 0) {
- include(LIB_PATH . '/SimplePie/' . str_replace('_', '/', $class) . '.php');
+ } elseif (str_starts_with($class, 'SimplePie\\')) {
+ $prefix = 'SimplePie\\';
+ $base_dir = LIB_PATH . '/simplepie/simplepie/src/';
+ $relative_class_name = substr($class, strlen($prefix));
+ include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
} elseif (str_starts_with($class, 'Gt\\CssXPath\\')) {
$prefix = 'Gt\\CssXPath\\';
$base_dir = LIB_PATH . '/phpgt/cssxpath/src/';
$relative_class_name = substr($class, strlen($prefix));
- require $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
+ include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
} elseif (str_starts_with($class, 'marienfressinaud\\LibOpml\\')) {
$prefix = 'marienfressinaud\\LibOpml\\';
$base_dir = LIB_PATH . '/marienfressinaud/lib_opml/src/LibOpml/';
$relative_class_name = substr($class, strlen($prefix));
- require $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
+ include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
} elseif (str_starts_with($class, 'PHPMailer\\PHPMailer\\')) {
$prefix = 'PHPMailer\\PHPMailer\\';
$base_dir = LIB_PATH . '/phpmailer/phpmailer/src/';
$relative_class_name = substr($class, strlen($prefix));
- require $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
+ include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
}
}
@@ -270,11 +273,13 @@ function sensitive_log($log): array|string {
* @param array<int,mixed> $curl_options
* @throws FreshRSS_Context_Exception
*/
-function customSimplePie(array $attributes = [], array $curl_options = []): SimplePie {
+function customSimplePie(array $attributes = [], array $curl_options = []): \SimplePie\SimplePie {
$limits = FreshRSS_Context::systemConf()->limits;
- $simplePie = new SimplePie();
+ $simplePie = new \SimplePie\SimplePie();
+ if (FreshRSS_Context::systemConf()->simplepie_syslog_enabled) {
+ $simplePie->get_registry()->register(\SimplePie\File::class, FreshRSS_SimplePieResponse::class);
+ }
$simplePie->set_useragent(FRESHRSS_USERAGENT);
- $simplePie->set_syslog(FreshRSS_Context::systemConf()->simplepie_syslog_enabled);
$simplePie->set_cache_name_function('sha1');
$simplePie->set_cache_location(CACHE_PATH);
$simplePie->set_cache_duration($limits['cache_duration']);
@@ -366,7 +371,7 @@ function sanitizeHTML(string $data, string $base = '', ?int $maxLength = null):
$simplePie = customSimplePie();
$simplePie->init();
}
- $result = html_only_entity_decode($simplePie->sanitize->sanitize($data, SIMPLEPIE_CONSTRUCT_HTML, $base));
+ $result = html_only_entity_decode($simplePie->sanitize->sanitize($data, \SimplePie\SimplePie::CONSTRUCT_HTML, $base));
if ($maxLength !== null && strlen($result) > $maxLength) {
//Sanitizing has made the result too long so try again shorter
$data = mb_strcut($result, 0, (2 * $maxLength) - strlen($result) - 2, 'UTF-8');
@@ -420,7 +425,7 @@ function enforceHttpEncoding(string $html, string $contentType = ''): string {
return $html;
}
}
- $httpCharsetNormalized = SimplePie_Misc::encoding($httpCharset);
+ $httpCharsetNormalized = \SimplePie\Misc::encoding($httpCharset);
if (in_array($httpCharsetNormalized, ['windows-1252', 'US-ASCII'], true)) {
// Default charset for HTTP, do nothing
return $html;
@@ -439,7 +444,7 @@ function enforceHttpEncoding(string $html, string $contentType = ''): string {
}
if ($httpCharsetNormalized !== 'UTF-8') {
// Try to change encoding to UTF-8 using mbstring or iconv or intl
- $utf8 = SimplePie_Misc::change_encoding($html, $httpCharsetNormalized, 'UTF-8');
+ $utf8 = \SimplePie\Misc::change_encoding($html, $httpCharsetNormalized, 'UTF-8');
if (is_string($utf8)) {
$html = stripHtmlMetaCharset($utf8);
$httpCharsetNormalized = 'UTF-8';
@@ -466,7 +471,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
if ($cacheMtime !== false && $cacheMtime > time() - intval($limits['cache_duration'])) {
$body = @file_get_contents($cachePath);
if ($body != false) {
- syslog(LOG_DEBUG, 'FreshRSS uses cache for ' . SimplePie_Misc::url_remove_credentials($url));
+ syslog(LOG_DEBUG, 'FreshRSS uses cache for ' . \SimplePie\Misc::url_remove_credentials($url));
return $body;
}
}
@@ -476,7 +481,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
}
if (FreshRSS_Context::systemConf()->simplepie_syslog_enabled) {
- syslog(LOG_INFO, 'FreshRSS GET ' . $type . ' ' . SimplePie_Misc::url_remove_credentials($url));
+ syslog(LOG_INFO, 'FreshRSS GET ' . $type . ' ' . \SimplePie\Misc::url_remove_credentials($url));
}
$accept = '*/*;q=0.8';