summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwn_ <[email protected]>2024-01-20 17:37:10 +0000
committerwn_ <[email protected]>2024-01-20 17:37:10 +0000
commit21aebd8ff10952963acb4f736e0a14e89425eb07 (patch)
tree88ad5e7a8b851261cd7e7fee9c03e6edb98fe623
parenta86df7eac8307b8aa1a253459d8504c7abfa2de4 (diff)
Use FeedEnclosure throughout RSSUtils.
-rw-r--r--classes/RSSUtils.php62
1 files changed, 28 insertions, 34 deletions
diff --git a/classes/RSSUtils.php b/classes/RSSUtils.php
index 751e1d9c7..742d96b2f 100644
--- a/classes/RSSUtils.php
+++ b/classes/RSSUtils.php
@@ -806,35 +806,35 @@ class RSSUtils {
// enclosures
+ /** @var array<int, FeedEnclosure> */
$enclosures = array();
$encs = $item->get_enclosures();
- if (is_array($encs)) {
- foreach ($encs as $e) {
-
- $pluginhost->chain_hooks_callback(PluginHost::HOOK_ENCLOSURE_IMPORTED,
- function ($result) use (&$e) {
- $e = $result;
- },
- $e, $feed);
-
- // TODO: Just use FeedEnclosure (and modify it to cover whatever justified this)?
- $e_item = array(
- UrlHelper::rewrite_relative($feed_obj->site_url, $e->link, "", "", $e->type),
- $e->type, $e->length, $e->title, $e->width, $e->height);
-
- // Yet another episode of "mysql utf8_general_ci is gimped"
- if (Config::get(Config::DB_TYPE) == "mysql" && Config::get(Config::MYSQL_CHARSET) != "UTF8MB4") {
- for ($i = 0; $i < count($e_item); $i++) {
- if (is_string($e_item[$i])) {
- $e_item[$i] = self::strip_utf8mb4($e_item[$i]);
- }
+ foreach ($encs as $e) {
+ $pluginhost->chain_hooks_callback(PluginHost::HOOK_ENCLOSURE_IMPORTED,
+ function ($result) use (&$e) {
+ $e = $result;
+ },
+ $e, $feed);
+
+ $e->link = UrlHelper::rewrite_relative($feed_obj->site_url, $e->link, "", "", $e->type);
+
+ if (!$e->link) {
+ Debug::log('Skipping enclosure whose link failed validation.', Debug::LOG_VERBOSE);
+ continue;
+ }
+
+ // Yet another episode of "mysql utf8_general_ci is gimped"
+ if (Config::get(Config::DB_TYPE) == "mysql" && Config::get(Config::MYSQL_CHARSET) != "UTF8MB4") {
+ foreach ((array)$e as $prop => $val) {
+ if (is_string($val)) {
+ $e->$prop = self::strip_utf8mb4($val);
}
}
-
- array_push($enclosures, $e_item);
}
+
+ array_push($enclosures, $e);
}
$article = array("owner_uid" => $feed_obj->owner_uid, // read only
@@ -1000,6 +1000,7 @@ class RSSUtils {
$entry_language = $article["language"];
$entry_timestamp = $article["timestamp"];
$num_comments = $article["num_comments"];
+ /** @var array<int, FeedEnclosure> */
$enclosures = $article["enclosures"];
if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) {
@@ -1235,17 +1236,10 @@ class RSSUtils {
(?, ?, ?, ?, ?, ?, ?)");
foreach ($enclosures as $enc) {
- $enc_url = $enc[0];
- $enc_type = $enc[1];
- $enc_dur = (int)$enc[2];
- $enc_title = $enc[3];
- $enc_width = intval($enc[4]);
- $enc_height = intval($enc[5]);
-
- $esth->execute([$enc_url, $enc_type, $entry_ref_id]);
+ $esth->execute([$enc->link, $enc->type, $entry_ref_id]);
if (!$esth->fetch()) {
- $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
+ $usth->execute([$enc->link, $enc->type, (string)$enc->title, (int)$enc->length, $entry_ref_id, (int)$enc->width, (int)$enc->height]);
}
}
@@ -1360,7 +1354,7 @@ class RSSUtils {
/**
* TODO: move to DiskCache?
*
- * @param array<int, array<string>> $enclosures An array of "enclosure arrays" [string $link, string $type, string $length, string, $title, string $width, string $height]
+ * @param array<int, FeedEnclosure> $enclosures
* @see RSSUtils::update_rss_feed()
* @see FeedEnclosure
*/
@@ -1370,8 +1364,8 @@ class RSSUtils {
if ($cache->is_writable()) {
foreach ($enclosures as $enc) {
- if (preg_match("/(image|audio|video)/", $enc[1])) {
- $src = UrlHelper::rewrite_relative($site_url, $enc[0]);
+ if (preg_match("/(image|audio|video)/", $enc->type)) {
+ $src = UrlHelper::rewrite_relative($site_url, $enc->link);
$local_filename = sha1($src);