X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FFeed.php;h=cde81394d3c0f0acce4354f3c46accd3b26c52ea;hb=065d73f860e40e5e3c0646a39edd30997d34f72e;hp=907479776c37f6745e1d57ed0ae188328cd53d4a;hpb=a4706e9521be2719d96ceeb7800c06371316a684;p=friendica.git diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 907479776c..cde81394d3 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -1,6 +1,6 @@ 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,23 @@ 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; + + // Don't use the GUID value directly but instead use it as a basis for the GUID + $item["guid"] = Item::guidFromUri($guid, parse_url($guid, PHP_URL_HOST) ?? parse_url($item["plink"], PHP_URL_HOST)); } 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 +332,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); @@ -401,7 +427,16 @@ class Feed } if (!empty($href)) { - $attachments[] = ['type' => Post\Media::DOCUMENT, 'url' => $href, 'mimetype' => $type, 'size' => $length]; + $attachment = ['type' => Post\Media::UNKNOWN, 'url' => $href, 'mimetype' => $type, 'size' => $length]; + + $attachment = Post\Media::fetchAdditionalData($attachment); + + // By now we separate the visible media types (audio, video, image) from the rest + // In the future we should try to avoid the DOCUMENT type and only use the real one - but not in the RC phase. + if (!in_array($attachment['type'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO])) { + $attachment['type'] = Post\Media::DOCUMENT; + } + $attachments[] = $attachment; } } @@ -448,6 +483,7 @@ class Feed } if ($dryRun) { + $item['attachments'] = $attachments; $items[] = $item; break; } elseif (!Item::isValid($item)) { @@ -525,6 +561,29 @@ class Feed $taglist = $contact["fetch_further_information"] == 2 ? PageInfo::getTagsFromUrl($item["plink"], $preview, $contact["ffi_keyword_denylist"] ?? '') : []; $item["object-type"] = Activity\ObjectType::BOOKMARK; $attachments = []; + + foreach (['audio', 'video'] as $elementname) { + if (!empty($data[$elementname])) { + foreach ($data[$elementname] as $element) { + if (!empty($element['src'])) { + $src = $element['src']; + } elseif (!empty($element['content'])) { + $src = $element['content']; + } else { + continue; + } + + $attachments[] = [ + 'type' => ($elementname == 'audio') ? Post\Media::AUDIO : Post\Media::VIDEO, + 'url' => $src, + 'preview' => $element['image'] ?? null, + 'mimetype' => $element['contenttype'] ?? null, + 'name' => $element['name'] ?? null, + 'description' => $element['description'] ?? null, + ]; + } + } + } } } else { if (!empty($summary)) { @@ -541,7 +600,7 @@ class Feed } // Add the link to the original feed entry if not present in feed - if (($item['plink'] != '') && !strstr($item["body"], $item['plink'])) { + if (($item['plink'] != '') && !strstr($item["body"], $item['plink']) && !in_array($item['plink'], array_column($attachments, 'url'))) { $item["body"] .= "[hr][url]" . $item['plink'] . "[/url]"; } } @@ -866,6 +925,11 @@ class Feed $cachekey = "feed:feed:" . $owner_nick . ":" . $filter . ":" . $last_update; + // Display events in the users's timezone + if (strlen($owner['timezone'])) { + DI::app()->setTimeZone($owner['timezone']); + } + $previous_created = $last_update; // Don't cache when the last item was posted less then 15 minutes ago (Cache duration) @@ -913,7 +977,7 @@ class Feed $root = self::addHeader($doc, $owner, $filter); foreach ($items as $item) { - $entry = self::entry($doc, $item, $owner); + $entry = self::noteEntry($doc, $item, $owner); $root->appendChild($entry); if ($last_update < $item['created']) { @@ -1003,69 +1067,6 @@ class Feed return $author; } - /** - * Adds an entry element to the XML document - * - * @param DOMDocument $doc XML document - * @param array $item Data of the item that is to be posted - * @param array $owner Contact data of the poster - * @param bool $toplevel optional default false - * - * @return \DOMElement Entry element - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - * @throws \ImagickException - */ - private static function entry(DOMDocument $doc, array $item, array $owner) - { - $xml = null; - - $repeated_guid = OStatus::getResharedGuid($item); - if ($repeated_guid != "") { - $xml = self::reshareEntry($doc, $item, $owner, $repeated_guid); - } - - if ($xml) { - return $xml; - } - - return self::noteEntry($doc, $item, $owner); - } - - /** - * Adds an entry element with reshared content - * - * @param DOMDocument $doc XML document - * @param array $item Data of the item that is to be posted - * @param array $owner Contact data of the poster - * @param string $repeated_guid guid - * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? - * - * @return bool Entry element - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - * @throws \ImagickException - */ - private static function reshareEntry(DOMDocument $doc, array $item, array $owner, $repeated_guid) - { - if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { - Logger::info('Feed entry author does not match feed owner', ['owner' => $owner["url"], 'author' => $item["author-link"]]); - } - - $entry = OStatus::entryHeader($doc, $owner, $item, false); - - $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED], - 'network' => Protocol::FEDERATED]; - $repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition); - if (!DBA::isResult($repeated_item)) { - return false; - } - - self::entryContent($doc, $entry, $item, self::getTitle($repeated_item), Activity::SHARE, false); - - self::entryFooter($doc, $entry, $item, $owner); - - return $entry; - } - /** * Adds a regular entry element *