diff options
| author | 2024-09-14 23:11:10 +0200 | |
|---|---|---|
| committer | 2024-09-14 23:11:10 +0200 | |
| commit | 882deab455fb7b6ca020391a33bff24e088c62bf (patch) | |
| tree | f0d6a3f66bf6de430ec087253fe3099cf631767f /app/Models/Feed.php | |
| parent | bea4ed69fccc7de2375363d8940af9a96e986650 (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 'app/Models/Feed.php')
| -rw-r--r-- | app/Models/Feed.php | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 37f1d8cd4..7b6fda7b6 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -95,7 +95,7 @@ class FreshRSS_Feed extends Minz_Model { } public function url(bool $includeCredentials = true): string { - return $includeCredentials ? $this->url : SimplePie_Misc::url_remove_credentials($this->url); + return $includeCredentials ? $this->url : \SimplePie\Misc::url_remove_credentials($this->url); } public function selfUrl(): string { return $this->selfUrl; @@ -343,7 +343,7 @@ class FreshRSS_Feed extends Minz_Model { * @throws Minz_FileNotExistException * @throws FreshRSS_Feed_Exception */ - public function load(bool $loadDetails = false, bool $noCache = false): ?SimplePie { + public function load(bool $loadDetails = false, bool $noCache = false): ?\SimplePie\SimplePie { if ($this->url != '') { /** * @throws Minz_FileNotExistException @@ -362,16 +362,16 @@ class FreshRSS_Feed extends Minz_Model { } $simplePie->set_feed_url($url); if (!$loadDetails) { //Only activates auto-discovery when adding a new feed - $simplePie->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); + $simplePie->set_autodiscovery_level(\SimplePie\SimplePie::LOCATOR_NONE); } if ($this->attributeBoolean('clear_cache')) { // Do not use `$simplePie->enable_cache(false);` as it would prevent caching in multiuser context $this->clearCache(); } Minz_ExtensionManager::callHook('simplepie_before_init', $simplePie, $this); - $mtime = $simplePie->init(); + $simplePieResult = $simplePie->init(); - if ((!$mtime) || !empty($simplePie->error())) { + if ($simplePieResult === false || $simplePie->get_hash() === '' || !empty($simplePie->error())) { $errorMessage = $simplePie->error(); if (empty($errorMessage)) { $errorMessage = ''; @@ -380,7 +380,7 @@ class FreshRSS_Feed extends Minz_Model { } throw new FreshRSS_Feed_Exception( ($errorMessage == '' ? 'Unknown error for feed' : $errorMessage) . - ' [' . $this->url . ']', + ' [' . \SimplePie\Misc::url_remove_credentials($this->url) . ']', $simplePie->status_code() ); } @@ -410,16 +410,17 @@ class FreshRSS_Feed extends Minz_Model { $subscribe_url = $simplePie->subscribe_url(true) ?? ''; } - $clean_url = SimplePie_Misc::url_remove_credentials($subscribe_url); + $clean_url = \SimplePie\Misc::url_remove_credentials($subscribe_url); if ($subscribe_url !== '' && $subscribe_url !== $url) { $this->_url($clean_url); } - if (($mtime === true) || ($mtime > $this->lastUpdate) || $noCache) { - //Minz_Log::debug('FreshRSS no cache ' . $mtime . ' > ' . $this->lastUpdate . ' for ' . $clean_url); + if ($noCache || $simplePie->get_hash() !== $this->attributeString('SimplePieHash')) { + // syslog(LOG_DEBUG, 'FreshRSS no cache ' . $simplePie->get_hash() . ' !== ' . $this->attributeString('SimplePieHash') . ' for ' . $clean_url); + $this->_attribute('SimplePieHash', $simplePie->get_hash()); return $simplePie; } - //Minz_Log::debug('FreshRSS use cache for ' . $clean_url); + syslog(LOG_DEBUG, 'FreshRSS SimplePie uses cache for ' . $clean_url); } } return null; @@ -428,7 +429,7 @@ class FreshRSS_Feed extends Minz_Model { /** * @return array<string> */ - public function loadGuids(SimplePie $simplePie): array { + public function loadGuids(\SimplePie\SimplePie $simplePie): array { $hasUniqueGuids = true; $testGuids = []; $guids = []; @@ -468,7 +469,7 @@ class FreshRSS_Feed extends Minz_Model { } /** @return Traversable<FreshRSS_Entry> */ - public function loadEntries(SimplePie $simplePie): Traversable { + public function loadEntries(\SimplePie\SimplePie $simplePie): Traversable { $hasBadGuids = $this->attributeBoolean('hasBadGuids'); $items = $simplePie->get_items(); @@ -575,7 +576,7 @@ class FreshRSS_Feed extends Minz_Model { if (is_array($authors)) { foreach ($authors as $author) { $authorName = $author->name != '' ? $author->name : $author->email; - if ($authorName != '') { + if (is_string($authorName) && $authorName !== '') { $authorNames .= escapeToUnicodeAlternative(strip_tags($authorName), true) . '; '; } } @@ -609,7 +610,7 @@ class FreshRSS_Feed extends Minz_Model { * returns a SimplePie initialized already with that content * @param string $feedContent the content of the feed, typically generated via FreshRSS_View::renderToString() */ - private function simplePieFromContent(string $feedContent): SimplePie { + private function simplePieFromContent(string $feedContent): \SimplePie\SimplePie { $simplePie = customSimplePie(); $simplePie->set_raw_data($feedContent); $simplePie->init(); @@ -637,7 +638,7 @@ class FreshRSS_Feed extends Minz_Model { ]; } - public function loadJson(): ?SimplePie { + public function loadJson(): ?\SimplePie\SimplePie { if ($this->url == '') { return null; } @@ -669,7 +670,7 @@ class FreshRSS_Feed extends Minz_Model { return $this->simplePieFromContent($feedContent); } - public function loadHtmlXpath(): ?SimplePie { + public function loadHtmlXpath(): ?\SimplePie\SimplePie { if ($this->url == '') { return null; } |
