X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FOStatus.php;h=127773f3c6ce1a15dd7ee61a76f191544c0dbf6d;hb=6bb418c5a7cdd71d28a8a572059efb14401b70bd;hp=6860665fc200c43f58eb207c4580e568094ee8e0;hpb=7f2dc4060119f49eaaefb01ce3f32907e4c7761d;p=friendica.git diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 6860665fc2..127773f3c6 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -53,7 +53,7 @@ class OStatus * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function fetchAuthor(DOMXPath $xpath, $context, array $importer, array &$contact, $onlyfetch) + private static function fetchAuthor(DOMXPath $xpath, $context, array $importer, array &$contact = null, $onlyfetch) { $author = []; $author["author-link"] = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context); @@ -72,9 +72,9 @@ class OStatus } $author["author-id"] = Contact::getIdForURL($author["author-link"]); - $author["contact-id"] = $contact["id"]; + $author['contact-id'] = defaults($contact, 'id', $author['author-id']); - $contact = null; + $contact = []; /* This here would be better, but we would get problems with contacts from the statusnet addon @@ -231,7 +231,7 @@ class OStatus GContact::link($gcid, $contact["uid"], $contact["id"]); } elseif ($contact["network"] != Protocol::DFRN) { - $contact = null; + $contact = []; } return $author; @@ -322,7 +322,7 @@ class OStatus * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function process($xml, array $importer, array &$contact, &$hub, $stored = false, $initialize = true) + private static function process($xml, array $importer, array &$contact = null, &$hub, $stored = false, $initialize = true) { if ($initialize) { self::$itemlist = []; @@ -417,13 +417,6 @@ class OStatus $author = self::fetchAuthor($xpath, $entry, $importer, $contact, $stored); } - $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()', $entry); - if ($value != "") { - $nickname = $value; - } else { - $nickname = $author["author-name"]; - } - $item = array_merge($header, $author); $item["uri"] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry); @@ -463,7 +456,7 @@ class OStatus } if ($item["verb"] == ACTIVITY_FOLLOW) { - Contact::addRelationship($importer, $contact, $item, $nickname); + Contact::addRelationship($importer, $contact, $item); continue; } @@ -745,7 +738,7 @@ class OStatus self::$conv_list[$conversation] = true; - $curlResult = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -938,7 +931,7 @@ class OStatus } $stored = false; - $curlResult = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -1453,7 +1446,7 @@ class OStatus * @param array $owner Contact data of the poster * @param bool $show_profile Whether to show profile * - * @return object author element + * @return \DOMElement author element * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ private static function addAuthor(DOMDocument $doc, array $owner, $show_profile = true) @@ -1515,7 +1508,7 @@ class OStatus $author->appendChild($urls); } - XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]); + XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl() . "/profile/" . $owner["nick"] . "/contacts/followers"]); XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]); if ($profile["publish"]) { @@ -1573,7 +1566,7 @@ class OStatus * @param bool $toplevel optional default false * @param bool $feed_mode Behave like a regular feed for users if true * - * @return object Entry element + * @return \DOMElement Entry element * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1605,7 +1598,7 @@ class OStatus * @param DOMDocument $doc XML document * @param array $contact Array of the contact that is added * - * @return object Source element + * @return \DOMElement Source element * @throws \Exception */ private static function sourceEntry(DOMDocument $doc, array $contact) @@ -1653,7 +1646,7 @@ class OStatus } if (!DBA::isResult($r)) { - $contact = owner; + $contact = $owner; } if (!isset($contact["poll"])) { @@ -1693,7 +1686,7 @@ class OStatus Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } - self::entryHeader($doc, $entry, $owner, $item, $toplevel); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]]; @@ -1748,7 +1741,7 @@ class OStatus * @param array $owner Contact data of the poster * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * - * @return object Entry element with "like" + * @return \DOMElement Entry element with "like" * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1758,24 +1751,21 @@ class OStatus Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } - self::entryHeader($doc, $entry, $owner, $item, $toplevel); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); $verb = NAMESPACE_ACTIVITY_SCHEMA."favorite"; self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false); - $as_object = $doc->createElement("activity:object"); - $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]); + if (DBA::isResult($parent)) { + $as_object = $doc->createElement("activity:object"); - if (!$parent) { - $parent = []; - } + XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent)); - XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent)); + self::entryContent($doc, $as_object, $parent, $owner, "New entry"); - self::entryContent($doc, $as_object, $parent, $owner, "New entry"); - - $entry->appendChild($as_object); + $entry->appendChild($as_object); + } self::entryFooter($doc, $entry, $item, $owner); @@ -1835,7 +1825,7 @@ class OStatus * @param array $owner Contact data of the poster * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * - * @return object Entry element + * @return \DOMElement Entry element * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1879,7 +1869,7 @@ class OStatus $item["body"] = sprintf($message, $owner["nick"], $contact["nick"]); - self::entryHeader($doc, $entry, $owner, $item, $toplevel); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); self::entryContent($doc, $entry, $item, $owner, $title); @@ -1900,7 +1890,7 @@ class OStatus * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * @param bool $feed_mode Behave like a regular feed for users if true * - * @return object Entry element + * @return \DOMElement Entry element * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1910,7 +1900,17 @@ class OStatus Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } - $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel); + if (!$toplevel) { + if (!empty($item['title'])) { + $title = BBCode::convert($item['title'], false, 7); + } else { + $title = sprintf("New note by %s", $owner["nick"]); + } + } else { + $title = sprintf("New comment by %s", $owner["nick"]); + } + + $entry = self::entryHeader($doc, $owner, $item, $toplevel); XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); @@ -1925,25 +1925,18 @@ class OStatus * @brief Adds a header element to the XML document * * @param DOMDocument $doc XML document - * @param object $entry The entry element where the elements are added * @param array $owner Contact data of the poster * @param array $item * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * - * @return string The title for the element + * @return \DOMElement The entry element where the elements are added * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function entryHeader(DOMDocument $doc, &$entry, array $owner, array $item, $toplevel) + private static function entryHeader(DOMDocument $doc, array $owner, array $item, $toplevel) { - /// @todo Check if this title stuff is really needed (I guess not) if (!$toplevel) { $entry = $doc->createElement("entry"); - if (!empty($item['title'])) { - $title = BBCode::convert($item['title'], false, 7); - } else { - $title = sprintf("New note by %s", $owner["nick"]); - } if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) { $contact = self::contactEntry($item['author-link'], $owner); @@ -1964,17 +1957,16 @@ class OStatus $author = self::addAuthor($doc, $owner); $entry->appendChild($author); - - $title = sprintf("New comment by %s", $owner["nick"]); } - return $title; + + return $entry; } /** * @brief Adds elements to the XML document * * @param DOMDocument $doc XML document - * @param object $entry Entry element where the content is added + * @param \DOMElement $entry Entry element where the content is added * @param array $item Data of the item that is to be posted * @param array $owner Contact data of the poster * @param string $title Title for the post @@ -1984,7 +1976,7 @@ class OStatus * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private static function entryContent(DOMDocument $doc, $entry, array $item, array $owner, $title, $verb = "", $complete = true, $feed_mode = false) + private static function entryContent(DOMDocument $doc, \DOMElement $entry, array $item, array $owner, $title, $verb = "", $complete = true, $feed_mode = false) { if ($verb == "") { $verb = self::constructVerb($item); @@ -2227,7 +2219,7 @@ class OStatus $check_date = DateTimeFormat::utc($last_update); $authorid = Contact::getIdForURL($owner["url"], 0, true); - $condition = ["`uid` = ? AND `created` > ? AND NOT `deleted` + $condition = ["`uid` = ? AND `received` > ? AND NOT `deleted` AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)", $owner["uid"], $check_date, Protocol::OSTATUS, Protocol::DFRN]; @@ -2242,7 +2234,7 @@ class OStatus $condition[] = $authorid; } - $params = ['order' => ['created' => true], 'limit' => $max_items]; + $params = ['order' => ['received' => true], 'limit' => $max_items]; if ($filter === 'posts') { $ret = Item::selectThread([], $condition, $params);