From 8f9c4143fcc133f28db4c3f618649fb1170e33b4 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 6 Jan 2023 19:53:43 +0100 Subject: Better enclosures (#4944) * Better enclosures #fix https://github.com/FreshRSS/FreshRSS/issues/4702 Improvement of https://github.com/FreshRSS/FreshRSS/pull/2898 * A few fixes * Better enclosure titles * Improve thumbnails * Implement thumbnail for HTML+XPath * Avoid duplicate enclosures #fix https://github.com/FreshRSS/FreshRSS/issues/1668 * Fix regex * Add basic support for media:credit And use
for enclosures * Fix link encoding + simplify code * Fix some SimplePie bugs Encoding errors in enclosure links * Remove debugging syslog * Remove debugging syslog * SimplePie fix multiple RSS2 enclosures #fix https://github.com/FreshRSS/FreshRSS/issues/4974 * Improve thumbnails * Performance with yield Avoid generating all enclosures if not used * API keep providing enclosures inside content Clients are typically not showing the enclosures to the users (tested with News+, FeedMe, Readrops, Fluent Reader Lite) * Lint * Fix API output enclosure * Fix API content strcut * API tolerate enclosures without a type --- lib/SimplePie/SimplePie/Enclosure.php | 2 +- lib/SimplePie/SimplePie/Item.php | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'lib/SimplePie') diff --git a/lib/SimplePie/SimplePie/Enclosure.php b/lib/SimplePie/SimplePie/Enclosure.php index cc0d038b5..04bade09f 100644 --- a/lib/SimplePie/SimplePie/Enclosure.php +++ b/lib/SimplePie/SimplePie/Enclosure.php @@ -627,7 +627,7 @@ class SimplePie_Enclosure { if ($this->link !== null) { - return urldecode($this->link); + return $this->link; } return null; diff --git a/lib/SimplePie/SimplePie/Item.php b/lib/SimplePie/SimplePie/Item.php index 2fb1d3284..1285fd536 100644 --- a/lib/SimplePie/SimplePie/Item.php +++ b/lib/SimplePie/SimplePie/Item.php @@ -427,7 +427,16 @@ class SimplePie_Item { if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) { - $this->data['thumbnail'] = $return[0]['attribs']['']; + $thumbnail = $return[0]['attribs']['']; + if (empty($thumbnail['url'])) + { + $this->data['thumbnail'] = null; + } + else + { + $thumbnail['url'] = $this->sanitize($thumbnail['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); + $this->data['thumbnail'] = $thumbnail; + } } else { @@ -2847,9 +2856,9 @@ class SimplePie_Item } } - if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure')) + foreach ($this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure') ?? [] as $enclosure) { - if (isset($enclosure[0]['attribs']['']['url'])) + if (isset($enclosure['attribs']['']['url'])) { // Attributes $bitrate = null; @@ -2867,15 +2876,15 @@ class SimplePie_Item $url = null; $width = null; - $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0])); + $url = $this->sanitize($enclosure['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure)); $url = $this->feed->sanitize->https_url($url); - if (isset($enclosure[0]['attribs']['']['type'])) + if (isset($enclosure['attribs']['']['type'])) { - $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); + $type = $this->sanitize($enclosure['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); } - if (isset($enclosure[0]['attribs']['']['length'])) + if (isset($enclosure['attribs']['']['length'])) { - $length = intval($enclosure[0]['attribs']['']['length']); + $length = intval($enclosure['attribs']['']['length']); } // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor -- cgit v1.2.3 From 9b5de54a9c96110b42f71681aa635e2e2c3b8756 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Feb 2023 14:34:47 +0100 Subject: Remove -x on some files not needing it (#5065) --- app/Controllers/configureController.php | 0 app/Controllers/entryController.php | 0 app/Controllers/feedController.php | 0 app/Controllers/indexController.php | 0 app/Controllers/javascriptController.php | 0 app/i18n/es/admin.php | 0 app/i18n/es/conf.php | 0 app/i18n/es/feedback.php | 0 app/i18n/es/gen.php | 0 app/i18n/es/index.php | 0 app/i18n/es/install.php | 0 app/i18n/es/sub.php | 0 lib/SimplePie/SimplePie/Registry.php | 0 p/i/index.php | 0 p/themes/icons/look.svg | 0 15 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 app/Controllers/configureController.php mode change 100755 => 100644 app/Controllers/entryController.php mode change 100755 => 100644 app/Controllers/feedController.php mode change 100755 => 100644 app/Controllers/indexController.php mode change 100755 => 100644 app/Controllers/javascriptController.php mode change 100755 => 100644 app/i18n/es/admin.php mode change 100755 => 100644 app/i18n/es/conf.php mode change 100755 => 100644 app/i18n/es/feedback.php mode change 100755 => 100644 app/i18n/es/gen.php mode change 100755 => 100644 app/i18n/es/index.php mode change 100755 => 100644 app/i18n/es/install.php mode change 100755 => 100644 app/i18n/es/sub.php mode change 100755 => 100644 lib/SimplePie/SimplePie/Registry.php mode change 100755 => 100644 p/i/index.php mode change 100755 => 100644 p/themes/icons/look.svg (limited to 'lib/SimplePie') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php old mode 100755 new mode 100644 diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php old mode 100755 new mode 100644 diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php old mode 100755 new mode 100644 diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php old mode 100755 new mode 100644 diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/admin.php b/app/i18n/es/admin.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/conf.php b/app/i18n/es/conf.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/feedback.php b/app/i18n/es/feedback.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/gen.php b/app/i18n/es/gen.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/index.php b/app/i18n/es/index.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/install.php b/app/i18n/es/install.php old mode 100755 new mode 100644 diff --git a/app/i18n/es/sub.php b/app/i18n/es/sub.php old mode 100755 new mode 100644 diff --git a/lib/SimplePie/SimplePie/Registry.php b/lib/SimplePie/SimplePie/Registry.php old mode 100755 new mode 100644 diff --git a/p/i/index.php b/p/i/index.php old mode 100755 new mode 100644 diff --git a/p/themes/icons/look.svg b/p/themes/icons/look.svg old mode 100755 new mode 100644 -- cgit v1.2.3 From 32acd6c13e92971714aa5ba47827cb3410c4cddf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 4 Mar 2023 11:18:56 +0100 Subject: SimplePie use single constant for default HTTP Accept header (#5083) * Use single constant for default SimplePie HTTP Accept And add missing headers in `SimplePie_Locator::body()` Follow-up of https://github.com/simplepie/simplepie/commit/5d966b9f64a6034f89b019152d7cad9059f8819f * Update SimplePie default HTTP Accept Fix https://github.com/FreshRSS/FreshRSS/pull/5079#issuecomment-1421619176 The `*/*` breaks Mastodon content negotiation * Revert "Update SimplePie default HTTP Accept" This reverts commit 13a5a5cb3b2fa6bdd57be8b3f84dc37ed814ccf6. * Same as upstream --- lib/SimplePie/SimplePie.php | 10 ++++++++-- lib/SimplePie/SimplePie/Locator.php | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/SimplePie') diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php index 9983f577e..c0b2e24f6 100644 --- a/lib/SimplePie/SimplePie.php +++ b/lib/SimplePie/SimplePie.php @@ -418,6 +418,12 @@ define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16); */ class SimplePie { + + /** + * @internal Default value of the HTTP Accept header when fetching/locating feeds + */ + public const DEFAULT_HTTP_ACCEPT_HEADER = 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1'; + /** * @var array Raw data * @access private @@ -1690,7 +1696,7 @@ class SimplePie else { $headers = array( - 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', + 'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER, ); if (isset($this->data['headers']['last-modified'])) { @@ -1754,7 +1760,7 @@ class SimplePie else { $headers = array( - 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', + 'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER, ); $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options, $this->syslog_enabled)); } diff --git a/lib/SimplePie/SimplePie/Locator.php b/lib/SimplePie/SimplePie/Locator.php index c5fae0579..10b50cadf 100644 --- a/lib/SimplePie/SimplePie/Locator.php +++ b/lib/SimplePie/SimplePie/Locator.php @@ -256,7 +256,7 @@ class SimplePie_Locator { $this->checked_feeds++; $headers = array( - 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', + 'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER, ); $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed, true)) @@ -386,7 +386,7 @@ class SimplePie_Locator $this->checked_feeds++; $headers = array( - 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', + 'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER, ); $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) @@ -414,9 +414,9 @@ class SimplePie_Locator { $this->checked_feeds++; $headers = array( - 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', + 'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER, ); - $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen, $this->curl_options)); + $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) { return array($feed); -- cgit v1.2.3