X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FOStatus.php;h=dec5c4c80b021a572da0d951304a7234dcbab6bc;hb=75ec384fc3e42c77727e552751651029cd54a010;hp=84a97c20a3f641b7f932db720cffaa73f157ca8c;hpb=3282ce53894b624893ee2989747a59866ab4b137;p=friendica.git diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 84a97c20a3..dec5c4c80b 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -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; @@ -303,7 +303,7 @@ class OStatus * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function import($xml, array $importer, array &$contact = null, &$hub) + public static function import($xml, array $importer, array &$contact, &$hub) { self::process($xml, $importer, $contact, $hub); } @@ -398,8 +398,6 @@ class OStatus $authordata = $xpath->query('//author')->item(0); $author = self::fetchAuthor($xpath, $authordata, $importer, $contact, $stored); - $entry = $xpath->query('/atom:entry'); - // Reverse the order of the entries $entrylist = []; @@ -528,7 +526,6 @@ class OStatus if ($valid) { $default_contact = 0; - $key = count(self::$itemlist); for ($key = count(self::$itemlist) - 1; $key >= 0; $key--) { if (empty(self::$itemlist[$key]['contact-id'])) { self::$itemlist[$key]['contact-id'] = $default_contact; @@ -1191,7 +1188,6 @@ class OStatus } else { return "http://".$server[0]."/notice/".$conversation[1]; } - return $href; } /** @@ -1287,8 +1283,6 @@ class OStatus */ private static function addHeader(DOMDocument $doc, array $owner, $filter, $feed_mode = false) { - $a = \get_app(); - $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed'); $doc->appendChild($root); @@ -1355,7 +1349,7 @@ class OStatus $attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"]; XML::addElement($doc, $root, "link", "", $attributes); - if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) { + if ($owner['account-type'] == Contact::TYPE_COMMUNITY) { $condition = ['uid' => $owner['uid'], 'self' => false, 'pending' => false, 'archive' => false, 'hidden' => false, 'blocked' => false]; $members = DBA::count('contact', $condition); @@ -1459,7 +1453,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) @@ -1467,7 +1461,7 @@ class OStatus $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]); $author = $doc->createElement("author"); XML::addElement($doc, $author, "id", $owner["url"]); - if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) { + if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) { XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP); } else { XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON); @@ -1579,7 +1573,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 */ @@ -1611,7 +1605,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) @@ -1659,7 +1653,7 @@ class OStatus } if (!DBA::isResult($r)) { - $contact = owner; + $contact = $owner; } if (!isset($contact["poll"])) { @@ -1699,7 +1693,7 @@ 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); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]]; @@ -1754,7 +1748,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 */ @@ -1764,24 +1758,21 @@ 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); + $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); @@ -1841,7 +1832,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 */ @@ -1885,7 +1876,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); @@ -1906,7 +1897,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 */ @@ -1916,7 +1907,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); @@ -1931,27 +1932,20 @@ 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'] == Contact::ACCOUNT_TYPE_COMMUNITY) { + if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) { $contact = self::contactEntry($item['author-link'], $owner); $author = self::addAuthor($doc, $contact, false); $entry->appendChild($author); @@ -1970,17 +1964,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 @@ -1990,7 +1983,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); @@ -2114,8 +2107,8 @@ class OStatus foreach ($mentioned as $mention) { $condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($mention)]; $contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition); - if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) || - ($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) { + if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::TYPE_COMMUNITY) || + ($contact['self'] && ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY))) { XML::addElement($doc, $entry, "link", "", [ "rel" => "mentioned", @@ -2132,7 +2125,7 @@ class OStatus } } - if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) { + if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) { XML::addElement($doc, $entry, "link", "", [ "rel" => "mentioned", "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group", @@ -2242,7 +2235,7 @@ class OStatus $condition[] = ACTIVITY_OBJ_COMMENT; } - if ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY) { + if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) { $condition[0] .= " AND `contact-id` = ? AND `author-id` = ?"; $condition[] = $owner["id"]; $condition[] = $authorid;