From ca086b880b0f3be4793fab06e66fab62eb23a24e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Mar 2022 15:29:07 +0000 Subject: [PATCH] Some small improvements for importing feeds --- src/Protocol/Feed.php | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 048e9974ce..d74d26f489 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -197,7 +197,6 @@ class Feed $author["author-link"] = XML::getFirstNodeValue($xpath, '/rss/channel/link/text()'); $author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/title/text()'); - $author["author-avatar"] = XML::getFirstNodeValue($xpath, '/rss/channel/image/url/text()'); if (empty($author["author-name"])) { $author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/copyright/text()'); @@ -207,6 +206,25 @@ class Feed $author["author-name"] = XML::getFirstNodeValue($xpath, '/rss/channel/description/text()'); } + $author["author-avatar"] = XML::getFirstNodeValue($xpath, '/rss/channel/image/url/text()'); + + if (empty($author["author-avatar"])) { + $avatar = XML::getFirstAttributes($xpath, "/rss/channel/itunes:image"); + if (is_object($avatar)) { + foreach ($avatar as $attribute) { + if ($attribute->name == "href") { + $author["author-avatar"] = $attribute->textContent; + } + } + } + } + + $author["author-about"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, '/rss/channel/description/text()'), $basepath); + + if (empty($author["author-about"])) { + $author["author-about"] = XML::getFirstNodeValue($xpath, '/rss/channel/itunes:summary/text()'); + } + $author["edited"] = $author["created"] = XML::getFirstNodeValue($xpath, '/rss/channel/pubDate/text()'); $author["app"] = XML::getFirstNodeValue($xpath, '/rss/channel/generator/text()'); @@ -284,20 +302,21 @@ class Feed $item["plink"] = XML::getFirstNodeValue($xpath, 'rss:link/text()', $entry); } + // Add the base path if missing + $item["plink"] = Network::addBasePath($item["plink"], $basepath); + $item["uri"] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry); - if (empty($item["uri"])) { - $item["uri"] = XML::getFirstNodeValue($xpath, 'guid/text()', $entry); + $guid = XML::getFirstNodeValue($xpath, 'guid/text()', $entry); + if (!empty($guid)) { + $item["uri"] = $guid; + $item["guid"] = $guid; } if (empty($item["uri"])) { $item["uri"] = $item["plink"]; } - // Add the base path if missing - $item["uri"] = Network::addBasePath($item["uri"], $basepath); - $item["plink"] = Network::addBasePath($item["plink"], $basepath); - $orig_plink = $item["plink"]; try { @@ -311,10 +330,15 @@ class Feed if (empty($item["title"])) { $item["title"] = XML::getFirstNodeValue($xpath, 'title/text()', $entry); } + if (empty($item["title"])) { $item["title"] = XML::getFirstNodeValue($xpath, 'rss:title/text()', $entry); } + if (empty($item["title"])) { + $item["title"] = XML::getFirstNodeValue($xpath, 'itunes:title/text()', $entry); + } + $item["title"] = html_entity_decode($item["title"], ENT_QUOTES, 'UTF-8'); $published = XML::getFirstNodeValue($xpath, 'atom:published/text()', $entry); @@ -457,6 +481,7 @@ class Feed } if ($dryRun) { + $item['attachments'] = $attachments; $items[] = $item; break; } elseif (!Item::isValid($item)) { -- 2.39.5