X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FFeed.php;h=a9e50d532ca9cdf749b668ef1dffc24bcf75440b;hb=24ee87224f5ca8bdce7adc4d571d5ece36b72471;hp=a32b460d5ac8dfa19ee1de7919774a8f0a8bbb2f;hpb=2a8826273269524e90acd920a084bffc8acda0e4;p=friendica.git diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index a32b460d5a..a9e50d532c 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -26,7 +26,7 @@ use DOMXPath; use Friendica\Content\PageInfo; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Cache\Duration; +use Friendica\Core\Cache\Enum\Duration; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Database\DBA; @@ -69,6 +69,8 @@ class Feed Logger::info("Import Atom/RSS feed '" . $contact["name"] . "' (Contact " . $contact["id"] . ") for user " . $importer["uid"]); } + $xml = trim($xml); + if (empty($xml)) { Logger::info('XML is empty.'); return []; @@ -83,7 +85,7 @@ class Feed } $doc = new DOMDocument(); - @$doc->loadXML(trim($xml)); + @$doc->loadXML($xml); $xpath = new DOMXPath($doc); $xpath->registerNamespace('atom', ActivityNamespace::ATOM1); $xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/"); @@ -111,7 +113,7 @@ class Feed if ($xpath->query('/atom:feed')->length > 0) { $alternate = XML::getFirstAttributes($xpath, "atom:link[@rel='alternate']"); if (is_object($alternate)) { - foreach ($alternate AS $attribute) { + foreach ($alternate as $attribute) { if ($attribute->name == "href") { $author["author-link"] = $attribute->textContent; } @@ -121,7 +123,7 @@ class Feed if (empty($author["author-link"])) { $self = XML::getFirstAttributes($xpath, "atom:link[@rel='self']"); if (is_object($self)) { - foreach ($self AS $attribute) { + foreach ($self as $attribute) { if ($attribute->name == "href") { $author["author-link"] = $attribute->textContent; } @@ -175,7 +177,7 @@ class Feed $avatar = XML::getFirstAttributes($xpath, "atom:author/atom:link[@rel='avatar']"); if (is_object($avatar)) { - foreach ($avatar AS $attribute) { + foreach ($avatar as $attribute) { if ($attribute->name == "href") { $author["author-avatar"] = $attribute->textContent; } @@ -267,7 +269,7 @@ class Feed $alternate = XML::getFirstAttributes($xpath, "atom:link", $entry); } if (is_object($alternate)) { - foreach ($alternate AS $attribute) { + foreach ($alternate as $attribute) { if ($attribute->name == "href") { $item["plink"] = $attribute->textContent; } @@ -383,12 +385,12 @@ class Feed $attachments = []; $enclosures = $xpath->query("enclosure|atom:link[@rel='enclosure']", $entry); - foreach ($enclosures AS $enclosure) { + foreach ($enclosures as $enclosure) { $href = ""; $length = null; $type = null; - foreach ($enclosure->attributes AS $attribute) { + foreach ($enclosure->attributes as $attribute) { if (in_array($attribute->name, ["url", "href"])) { $href = $attribute->textContent; } elseif ($attribute->name == "length") { @@ -405,7 +407,7 @@ class Feed $taglist = []; $categories = $xpath->query("category", $entry); - foreach ($categories AS $category) { + foreach ($categories as $category) { $taglist[] = $category->nodeValue; } @@ -459,7 +461,7 @@ class Feed $preview = ''; if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] < 3)) { // Handle enclosures and treat them as preview picture - foreach ($attachments AS $attachment) { + foreach ($attachments as $attachment) { if ($attachment["mimetype"] == "image/jpeg") { $preview = $attachment["url"]; } @@ -732,7 +734,7 @@ class Feed if ($contact['rating'] != $priority) { Logger::notice('Adjusting priority', ['old' => $contact['rating'], 'new' => $priority, 'id' => $contact['id'], 'uid' => $contact['uid'], 'url' => $contact['url']]); - DBA::update('contact', ['rating' => $priority], ['id' => $contact['id']]); + Contact::update(['rating' => $priority], ['id' => $contact['id']]); } } @@ -911,7 +913,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']) { @@ -965,7 +967,7 @@ class Feed XML::addElement($doc, $root, "id", DI::baseUrl() . "/profile/" . $owner["nick"]); XML::addElement($doc, $root, "title", $title); XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], DI::config()->get('config', 'sitename'))); - XML::addElement($doc, $root, "logo", User::getAvatarUrlForId($owner['uid'], Proxy::SIZE_SMALL)); + XML::addElement($doc, $root, "logo", User::getAvatarUrl($owner, Proxy::SIZE_SMALL)); XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM)); $author = self::addAuthor($doc, $owner); @@ -1001,69 +1003,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 *