3 * @file src/Protocol/OStatus.php
5 namespace Friendica\Protocol;
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Content\Text\HTML;
11 use Friendica\Core\Cache;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Core\Lock;
15 use Friendica\Core\System;
16 use Friendica\Database\DBA;
17 use Friendica\Database\DBM;
18 use Friendica\Model\Contact;
19 use Friendica\Model\Conversation;
20 use Friendica\Model\GContact;
21 use Friendica\Model\Item;
22 use Friendica\Model\User;
23 use Friendica\Network\Probe;
24 use Friendica\Object\Image;
25 use Friendica\Util\DateTimeFormat;
26 use Friendica\Util\Network;
27 use Friendica\Util\XML;
29 require_once 'include/dba.php';
30 require_once 'include/items.php';
31 require_once 'mod/share.php';
32 require_once 'include/enotify.php';
33 require_once 'include/api.php';
34 require_once 'mod/proxy.php';
37 * @brief This class contain functions for the OStatus protocol
41 private static $itemlist;
42 private static $conv_list = [];
45 * @brief Fetches author data
47 * @param object $xpath The xpath object
48 * @param object $context The xml context of the author details
49 * @param array $importer user record of the importing user
50 * @param array $contact Called by reference, will contain the fetched contact
51 * @param bool $onlyfetch Only fetch the header without updating the contact entries
53 * @return array Array of author related entries for the item
55 private static function fetchAuthor(DOMXPath $xpath, $context, array $importer, array &$contact, $onlyfetch)
58 $author["author-link"] = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context);
59 $author["author-name"] = XML::getFirstNodeValue($xpath, 'atom:author/atom:name/text()', $context);
60 $addr = XML::getFirstNodeValue($xpath, 'atom:author/atom:email/text()', $context);
62 $aliaslink = $author["author-link"];
64 $alternate_item = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0);
65 if (is_object($alternate_item)) {
66 foreach ($alternate_item->attributes as $attributes) {
67 if (($attributes->name == "href") && ($attributes->textContent != "")) {
68 $author["author-link"] = $attributes->textContent;
72 $author["author-id"] = Contact::getIdForURL($author["author-link"]);
74 $author["contact-id"] = $contact["id"];
77 if ($aliaslink != '') {
78 $condition = ["`uid` = ? AND `alias` = ? AND `network` != ? AND `rel` IN (?, ?)",
79 $importer["uid"], $aliaslink, NETWORK_STATUSNET,
80 CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
81 $contact = DBA::selectFirst('contact', [], $condition);
84 if (!DBM::is_result($contact) && $author["author-link"] != '') {
85 if ($aliaslink == "") {
86 $aliaslink = $author["author-link"];
89 $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ? AND `rel` IN (?, ?)",
90 $importer["uid"], normalise_link($author["author-link"]), normalise_link($aliaslink),
91 NETWORK_STATUSNET, CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
92 $contact = DBA::selectFirst('contact', [], $condition);
95 if (!DBM::is_result($contact) && ($addr != '')) {
96 $condition = ["`uid` = ? AND `addr` = ? AND `network` != ? AND `rel` IN (?, ?)",
97 $importer["uid"], $addr, NETWORK_STATUSNET,
98 CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
99 $contact = DBA::selectFirst('contact', [], $condition);
102 if (DBM::is_result($contact)) {
103 if ($contact['blocked']) {
106 $author["contact-id"] = $contact["id"];
110 $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context);
111 foreach ($avatars as $avatar) {
114 foreach ($avatar->attributes as $attributes) {
115 if ($attributes->name == "href") {
116 $href = $attributes->textContent;
118 if ($attributes->name == "width") {
119 $width = $attributes->textContent;
123 $avatarlist[$width] = $href;
126 if (count($avatarlist) > 0) {
128 $author["author-avatar"] = Probe::fixAvatar(current($avatarlist), $author["author-link"]);
131 $displayname = XML::getFirstNodeValue($xpath, 'atom:author/poco:displayName/text()', $context);
132 if ($displayname != "") {
133 $author["author-name"] = $displayname;
136 $author["owner-id"] = $author["author-id"];
138 // Only update the contacts if it is an OStatus contact
139 if (DBM::is_result($contact) && ($contact['id'] > 0) && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
141 // Update contact data
143 unset($current['name-date']);
145 // This query doesn't seem to work
146 // $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
148 // $contact["notify"] = $value;
150 // This query doesn't seem to work as well - I hate these queries
151 // $value = $xpath->query("atom:link[@rel='self' and @type='application/atom+xml']", $context)->item(0)->nodeValue;
153 // $contact["poll"] = $value;
155 $contact['url'] = $author["author-link"];
156 $contact['nurl'] = normalise_link($contact['url']);
158 $value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context);
160 $contact["alias"] = $value;
163 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:displayName/text()', $context);
165 $contact["name"] = $value;
168 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()', $context);
170 $contact["nick"] = $value;
173 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:note/text()', $context);
175 $contact["about"] = HTML::toBBCode($value);
178 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:address/poco:formatted/text()', $context);
180 $contact["location"] = $value;
183 $contact['name-date'] = DateTimeFormat::utcNow();
185 DBA::update('contact', $contact, ['id' => $contact["id"]], $current);
187 if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
188 logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
189 Contact::updateAvatar($author["author-avatar"], $importer["uid"], $contact["id"]);
192 // Ensure that we are having this contact (with uid=0)
193 $cid = Contact::getIdForURL($aliaslink, 0, true);
196 $fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
197 $old_contact = DBA::selectFirst('contact', $fields, ['id' => $cid]);
199 // Update it with the current values
200 $fields = ['url' => $author["author-link"], 'name' => $contact["name"],
201 'nurl' => normalise_link($author["author-link"]),
202 'nick' => $contact["nick"], 'alias' => $contact["alias"],
203 'about' => $contact["about"], 'location' => $contact["location"],
204 'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()];
206 DBA::update('contact', $fields, ['id' => $cid], $old_contact);
209 if (!empty($author["author-avatar"])) {
210 Contact::updateAvatar($author["author-avatar"], 0, $cid);
214 $contact["generation"] = 2;
215 $contact["hide"] = false; // OStatus contacts are never hidden
216 if (!empty($author["author-avatar"])) {
217 $contact["photo"] = $author["author-avatar"];
219 $gcid = GContact::update($contact);
221 GContact::link($gcid, $contact["uid"], $contact["id"]);
228 * @brief Fetches author data from a given XML string
230 * @param string $xml The XML
231 * @param array $importer user record of the importing user
233 * @return array Array of author related entries for the item
235 public static function salmonAuthor($xml, array $importer)
241 $doc = new DOMDocument();
242 @$doc->loadXML($xml);
244 $xpath = new DOMXPath($doc);
245 $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
246 $xpath->registerNamespace('thr', NAMESPACE_THREAD);
247 $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
248 $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
249 $xpath->registerNamespace('media', NAMESPACE_MEDIA);
250 $xpath->registerNamespace('poco', NAMESPACE_POCO);
251 $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
252 $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
254 $contact = ["id" => 0];
256 // Fetch the first author
257 $authordata = $xpath->query('//author')->item(0);
258 $author = self::fetchAuthor($xpath, $authordata, $importer, $contact, true);
263 * @brief Read attributes from element
265 * @param object $element Element object
267 * @return array attributes
269 private static function readAttributes($element)
273 foreach ($element->attributes as $attributes) {
274 $attribute[$attributes->name] = $attributes->textContent;
281 * @brief Imports an XML string containing OStatus elements
283 * @param string $xml The XML
284 * @param array $importer user record of the importing user
285 * @param array $contact contact
286 * @param string $hub Called by reference, returns the fetched hub data
289 public static function import($xml, array $importer, array &$contact, &$hub)
291 self::process($xml, $importer, $contact, $hub);
295 * @brief Internal feed processing
297 * @param string $xml The XML
298 * @param array $importer user record of the importing user
299 * @param array $contact contact
300 * @param string $hub Called by reference, returns the fetched hub data
301 * @param boolean $stored Is the post fresh imported or from the database?
302 * @param boolean $initialize Is it the leading post so that data has to be initialized?
304 * @return boolean Could the XML be processed?
306 private static function process($xml, array $importer, array &$contact = null, &$hub, $stored = false, $initialize = true)
309 self::$itemlist = [];
310 self::$conv_list = [];
313 logger("Import OStatus message", LOGGER_DEBUG);
318 $doc = new DOMDocument();
319 @$doc->loadXML($xml);
321 $xpath = new DOMXPath($doc);
322 $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
323 $xpath->registerNamespace('thr', NAMESPACE_THREAD);
324 $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
325 $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
326 $xpath->registerNamespace('media', NAMESPACE_MEDIA);
327 $xpath->registerNamespace('poco', NAMESPACE_POCO);
328 $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
329 $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
332 $hub_items = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0);
333 if (is_object($hub_items)) {
334 $hub_attributes = $hub_items->attributes;
335 if (is_object($hub_attributes)) {
336 foreach ($hub_attributes as $hub_attribute) {
337 if ($hub_attribute->name == "href") {
338 $hub = $hub_attribute->textContent;
339 logger("Found hub ".$hub, LOGGER_DEBUG);
346 $header["uid"] = $importer["uid"];
347 $header["network"] = NETWORK_OSTATUS;
349 $header["origin"] = 0;
350 $header["gravity"] = GRAVITY_COMMENT;
352 $first_child = $doc->firstChild->tagName;
354 if ($first_child == "feed") {
355 $entries = $xpath->query('/atom:feed/atom:entry');
357 $entries = $xpath->query('/atom:entry');
360 if ($entries->length == 1) {
361 // We reformat the XML to make it better readable
362 $doc2 = new DOMDocument();
363 $doc2->loadXML($xml);
364 $doc2->preserveWhiteSpace = false;
365 $doc2->formatOutput = true;
366 $xml2 = $doc2->saveXML();
368 $header["protocol"] = PROTOCOL_OSTATUS_SALMON;
369 $header["source"] = $xml2;
370 } elseif (!$initialize) {
374 // Fetch the first author
375 $authordata = $xpath->query('//author')->item(0);
376 $author = self::fetchAuthor($xpath, $authordata, $importer, $contact, $stored);
378 $entry = $xpath->query('/atom:entry');
380 // Reverse the order of the entries
383 foreach ($entries as $entry) {
384 $entrylist[] = $entry;
387 foreach (array_reverse($entrylist) as $entry) {
389 $authorelement = $xpath->query('/atom:entry/atom:author', $entry);
391 if ($authorelement->length == 0) {
392 $authorelement = $xpath->query('atom:author', $entry);
395 if ($authorelement->length > 0) {
396 $author = self::fetchAuthor($xpath, $entry, $importer, $contact, $stored);
399 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()', $entry);
403 $nickname = $author["author-name"];
406 $item = array_merge($header, $author);
408 $item["uri"] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
410 $item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $entry);
413 if (in_array($item["verb"], ['qvitter-delete-notice', ACTIVITY_DELETE, 'delete'])) {
414 self::deleteNotice($item);
418 if (in_array($item["verb"], [NAMESPACE_OSTATUS."/unfavorite", ACTIVITY_UNFAVORITE])) {
419 // Ignore "Unfavorite" message
420 logger("Ignore unfavorite message ".print_r($item, true), LOGGER_DEBUG);
424 // Deletions come with the same uri, so we check for duplicates after processing deletions
425 if (Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]])) {
426 logger('Post with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', LOGGER_DEBUG);
429 logger('Processing post with URI '.$item["uri"].' for user '.$importer["uid"].'.', LOGGER_DEBUG);
432 if ($item["verb"] == ACTIVITY_JOIN) {
433 // ignore "Join" messages
434 logger("Ignore join message ".print_r($item, true), LOGGER_DEBUG);
438 if ($item["verb"] == "http://mastodon.social/schema/1.0/block") {
439 // ignore mastodon "block" messages
440 logger("Ignore block message ".print_r($item, true), LOGGER_DEBUG);
444 if ($item["verb"] == ACTIVITY_FOLLOW) {
445 Contact::addRelationship($importer, $contact, $item, $nickname);
449 if ($item["verb"] == NAMESPACE_OSTATUS."/unfollow") {
451 Contact::removeFollower($importer, $contact, $item, $dummy);
455 if ($item["verb"] == ACTIVITY_FAVORITE) {
456 $orig_uri = $xpath->query("activity:object/atom:id", $entry)->item(0)->nodeValue;
457 logger("Favorite ".$orig_uri." ".print_r($item, true));
459 $item["verb"] = ACTIVITY_LIKE;
460 $item["parent-uri"] = $orig_uri;
461 $item["gravity"] = GRAVITY_ACTIVITY;
462 $item["object-type"] = ACTIVITY_OBJ_NOTE;
465 // http://activitystrea.ms/schema/1.0/rsvp-yes
466 if (!in_array($item["verb"], [ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE])) {
467 logger("Unhandled verb ".$item["verb"]." ".print_r($item, true), LOGGER_DEBUG);
470 self::processPost($xpath, $entry, $item, $importer);
472 if ($initialize && (count(self::$itemlist) > 0)) {
473 if (self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']) {
474 // We will import it everytime, when it is started by our contacts
475 $valid = !empty(self::$itemlist[0]['contact-id']);
477 // If not, then it depends on this setting
478 $valid = !Config::get('system', 'ostatus_full_threads');
480 logger("Item with uri ".self::$itemlist[0]['uri']." will be imported due to the system settings.", LOGGER_DEBUG);
483 logger("Item with uri ".self::$itemlist[0]['uri']." belongs to a contact (".self::$itemlist[0]['contact-id']."). It will be imported.", LOGGER_DEBUG);
486 // Never post a thread when the only interaction by our contact was a like
488 $verbs = [ACTIVITY_POST, ACTIVITY_SHARE];
489 foreach (self::$itemlist as $item) {
490 if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
495 logger("Item with uri ".self::$itemlist[0]['uri']." will be imported since the thread contains posts or shares.", LOGGER_DEBUG);
499 // But we will only import complete threads
500 $valid = Item::exists(['uid' => $importer["uid"], 'uri' => self::$itemlist[0]['parent-uri']]);
502 logger("Item with uri ".self::$itemlist[0]["uri"]." belongs to parent ".self::$itemlist[0]['parent-uri']." of user ".$importer["uid"].". It will be imported.", LOGGER_DEBUG);
507 $default_contact = 0;
508 $key = count(self::$itemlist);
509 for ($key = count(self::$itemlist) - 1; $key >= 0; $key--) {
510 if (empty(self::$itemlist[$key]['contact-id'])) {
511 self::$itemlist[$key]['contact-id'] = $default_contact;
513 $default_contact = $item['contact-id'];
516 foreach (self::$itemlist as $item) {
517 $found = Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]]);
519 logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", LOGGER_DEBUG);
520 } elseif ($item['contact-id'] < 0) {
521 logger("Item with uri ".$item["uri"]." is from a blocked contact.", LOGGER_DEBUG);
523 // We are having duplicated entries. Hopefully this solves it.
524 if (Lock::acquire('ostatus_process_item_insert')) {
525 $ret = Item::insert($item);
526 Lock::release('ostatus_process_item_insert');
527 logger("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret);
529 $ret = Item::insert($item);
530 logger("We couldn't lock - but tried to store the item anyway. Return value is ".$ret);
535 self::$itemlist = [];
537 logger('Processing done for post with URI '.$item["uri"].' for user '.$importer["uid"].'.', LOGGER_DEBUG);
543 * Removes notice item from database
544 * @param array $item item
547 private static function deleteNotice(array $item)
549 $condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'uri' => $item['uri']];
550 if (!Item::exists($condition)) {
551 logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it.");
555 Item::delete($condition);
557 logger('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
561 * @brief Processes the XML for a post
563 * @param object $xpath The xpath object
564 * @param object $entry The xml entry that is processed
565 * @param array $item The item array
566 * @param array $importer user record of the importing user
569 private static function processPost(DOMXPath $xpath, $entry, array &$item, array $importer)
571 $item["body"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
572 $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry);
573 if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
574 $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
575 $item["body"] = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
576 } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
577 $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
580 $item["created"] = XML::getFirstNodeValue($xpath, 'atom:published/text()', $entry);
581 $item["edited"] = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry);
582 $item['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
584 $conv = $xpath->query('ostatus:conversation', $entry);
585 if (is_object($conv->item(0))) {
586 foreach ($conv->item(0)->attributes as $attributes) {
587 if ($attributes->name == "ref") {
588 $item['conversation-uri'] = $attributes->textContent;
590 if ($attributes->name == "href") {
591 $item['conversation-href'] = $attributes->textContent;
598 $inreplyto = $xpath->query('thr:in-reply-to', $entry);
599 if (is_object($inreplyto->item(0))) {
600 foreach ($inreplyto->item(0)->attributes as $attributes) {
601 if ($attributes->name == "ref") {
602 $item["parent-uri"] = $attributes->textContent;
604 if ($attributes->name == "href") {
605 $related = $attributes->textContent;
610 $georsspoint = $xpath->query('georss:point', $entry);
611 if (!empty($georsspoint) && ($georsspoint->length > 0)) {
612 $item["coord"] = $georsspoint->item(0)->nodeValue;
615 $categories = $xpath->query('atom:category', $entry);
617 foreach ($categories as $category) {
618 foreach ($category->attributes as $attributes) {
619 if ($attributes->name == "term") {
620 $term = $attributes->textContent;
621 if (!empty($item["tag"])) {
627 $item["tag"] .= "#[url=".System::baseUrl()."/search?tag=".$term."]".$term."[/url]";
636 $links = $xpath->query('atom:link', $entry);
638 $link_data = self::processLinks($links, $item);
639 $self = $link_data['self'];
640 $add_body = $link_data['add_body'];
645 $notice_info = $xpath->query('statusnet:notice_info', $entry);
646 if ($notice_info && ($notice_info->length > 0)) {
647 foreach ($notice_info->item(0)->attributes as $attributes) {
648 if ($attributes->name == "source") {
649 $item["app"] = strip_tags($attributes->textContent);
651 if ($attributes->name == "repeat_of") {
652 $repeat_of = $attributes->textContent;
656 // Is it a repeated post?
657 if (($repeat_of != "") || ($item["verb"] == ACTIVITY_SHARE)) {
658 $link_data = self::processRepeatedItem($xpath, $entry, $item, $importer);
659 if (!empty($link_data['add_body'])) {
660 $add_body .= $link_data['add_body'];
664 $item["body"] .= $add_body;
666 // Only add additional data when there is no picture in the post
667 if (!strstr($item["body"], '[/img]')) {
668 $item["body"] = add_page_info_to_body($item["body"]);
671 // Mastodon Content Warning
672 if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
673 $clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
674 if (!empty($clear_text)) {
675 $item['content-warning'] = HTML::toBBCode($clear_text);
679 if (($self != '') && empty($item['protocol'])) {
680 self::fetchSelf($self, $item);
683 if (!empty($item["conversation-href"])) {
684 self::fetchConversation($item['conversation-href'], $item['conversation-uri']);
687 if (isset($item["parent-uri"])) {
688 if (!Item::exists(['uid' => $importer["uid"], 'uri' => $item['parent-uri']])) {
689 if ($related != '') {
690 self::fetchRelated($related, $item["parent-uri"], $importer);
693 logger('Reply with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', LOGGER_DEBUG);
696 $item["parent-uri"] = $item["uri"];
697 $item["gravity"] = GRAVITY_PARENT;
700 if (($item['author-link'] != '') && !empty($item['protocol'])) {
701 $item = Conversation::insert($item);
704 self::$itemlist[] = $item;
708 * @brief Fetch the conversation for posts
710 * @param string $conversation The link to the conversation
711 * @param string $conversation_uri The conversation in "uri" format
714 private static function fetchConversation($conversation, $conversation_uri)
716 // Ensure that we only store a conversation once in a process
717 if (isset(self::$conv_list[$conversation])) {
721 self::$conv_list[$conversation] = true;
723 $conversation_data = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
725 if (!$conversation_data['success']) {
731 if (stristr($conversation_data['header'], 'Content-Type: application/atom+xml')) {
732 $xml = $conversation_data['body'];
736 $doc = new DOMDocument();
737 if (!@$doc->loadHTML($conversation_data['body'])) {
740 $xpath = new DOMXPath($doc);
742 $links = $xpath->query('//link');
745 foreach ($links as $link) {
746 $attribute = self::readAttributes($link);
747 if (($attribute['rel'] == 'alternate') && ($attribute['type'] == 'application/atom+xml')) {
748 $file = $attribute['href'];
752 $conversation_atom = Network::curl($attribute['href']);
754 if ($conversation_atom['success']) {
755 $xml = $conversation_atom['body'];
765 self::storeConversation($xml, $conversation, $conversation_uri);
769 * @brief Store a feed in several conversation entries
771 * @param string $xml The feed
772 * @param string $conversation conversation
773 * @param string $conversation_uri conversation uri
776 private static function storeConversation($xml, $conversation = '', $conversation_uri = '')
778 $doc = new DOMDocument();
779 @$doc->loadXML($xml);
781 $xpath = new DOMXPath($doc);
782 $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
783 $xpath->registerNamespace('thr', NAMESPACE_THREAD);
784 $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
786 $entries = $xpath->query('/atom:feed/atom:entry');
788 // Now store the entries
789 foreach ($entries as $entry) {
790 $doc2 = new DOMDocument();
791 $doc2->preserveWhiteSpace = false;
792 $doc2->formatOutput = true;
796 $conv_data['protocol'] = PROTOCOL_SPLITTED_CONV;
797 $conv_data['network'] = NETWORK_OSTATUS;
798 $conv_data['uri'] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
800 $inreplyto = $xpath->query('thr:in-reply-to', $entry);
801 if (is_object($inreplyto->item(0))) {
802 foreach ($inreplyto->item(0)->attributes as $attributes) {
803 if ($attributes->name == "ref") {
804 $conv_data['reply-to-uri'] = $attributes->textContent;
809 $conv_data['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
811 $conv = $xpath->query('ostatus:conversation', $entry);
812 if (is_object($conv->item(0))) {
813 foreach ($conv->item(0)->attributes as $attributes) {
814 if ($attributes->name == "ref") {
815 $conv_data['conversation-uri'] = $attributes->textContent;
817 if ($attributes->name == "href") {
818 $conv_data['conversation-href'] = $attributes->textContent;
823 if ($conversation != '') {
824 $conv_data['conversation-uri'] = $conversation;
827 if ($conversation_uri != '') {
828 $conv_data['conversation-uri'] = $conversation_uri;
831 $entry = $doc2->importNode($entry, true);
833 $doc2->appendChild($entry);
835 $conv_data['source'] = $doc2->saveXML();
837 $condition = ['item-uri' => $conv_data['uri'],'protocol' => PROTOCOL_OSTATUS_FEED];
838 if (DBA::exists('conversation', $condition)) {
839 logger('Delete deprecated entry for URI '.$conv_data['uri'], LOGGER_DEBUG);
840 DBA::delete('conversation', ['item-uri' => $conv_data['uri']]);
843 logger('Store conversation data for uri '.$conv_data['uri'], LOGGER_DEBUG);
844 Conversation::insert($conv_data);
849 * @brief Fetch the own post so that it can be stored later
851 * We want to store the original data for later processing.
852 * This function is meant for cases where we process a feed with multiple entries.
853 * In that case we need to fetch the single posts here.
855 * @param string $self The link to the self item
856 * @param array $item The item array
859 private static function fetchSelf($self, array &$item)
861 $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $self, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
862 if (DBA::exists('conversation', $condition)) {
863 logger('Conversation '.$item['uri'].' is already stored.', LOGGER_DEBUG);
867 $self_data = Network::curl($self);
869 if (!$self_data['success']) {
873 // We reformat the XML to make it better readable
874 $doc = new DOMDocument();
875 $doc->loadXML($self_data['body']);
876 $doc->preserveWhiteSpace = false;
877 $doc->formatOutput = true;
878 $xml = $doc->saveXML();
880 $item["protocol"] = PROTOCOL_OSTATUS_SALMON;
881 $item["source"] = $xml;
883 logger('Conversation '.$item['uri'].' is now fetched.', LOGGER_DEBUG);
887 * @brief Fetch related posts and processes them
889 * @param string $related The link to the related item
890 * @param string $related_uri The related item in "uri" format
891 * @param array $importer user record of the importing user
894 private static function fetchRelated($related, $related_uri, $importer)
896 $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
897 $conversation = DBA::selectFirst('conversation', ['source', 'protocol'], $condition);
898 if (DBM::is_result($conversation)) {
900 $xml = $conversation['source'];
901 if (self::process($xml, $importer, $contact, $hub, $stored, false)) {
902 logger('Got valid cached XML for URI '.$related_uri, LOGGER_DEBUG);
905 if ($conversation['protocol'] == PROTOCOL_OSTATUS_SALMON) {
906 logger('Delete invalid cached XML for URI '.$related_uri, LOGGER_DEBUG);
907 DBA::delete('conversation', ['item-uri' => $related_uri]);
912 $related_data = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
914 if (!$related_data['success']) {
920 if (stristr($related_data['header'], 'Content-Type: application/atom+xml')) {
921 logger('Directly fetched XML for URI '.$related_uri, LOGGER_DEBUG);
922 $xml = $related_data['body'];
926 $doc = new DOMDocument();
927 if (!@$doc->loadHTML($related_data['body'])) {
930 $xpath = new DOMXPath($doc);
934 $links = $xpath->query('//link');
936 foreach ($links as $link) {
937 $attribute = self::readAttributes($link);
938 if (($attribute['rel'] == 'alternate') && ($attribute['type'] == 'application/atom+xml')) {
939 $atom_file = $attribute['href'];
942 if ($atom_file != '') {
943 $related_atom = Network::curl($atom_file);
945 if ($related_atom['success']) {
946 logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG);
947 $xml = $related_atom['body'];
953 // Workaround for older GNU Social servers
954 if (($xml == '') && strstr($related, '/notice/')) {
955 $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related).'.atom');
957 if ($related_atom['success']) {
958 logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
959 $xml = $related_atom['body'];
963 // Even more worse workaround for GNU Social ;-)
965 $related_guess = OStatus::convertHref($related_uri);
966 $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom');
968 if ($related_atom['success']) {
969 logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
970 $xml = $related_atom['body'];
974 // Finally we take the data that we fetched from "ostatus:conversation"
976 $condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
977 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
978 if (DBM::is_result($conversation)) {
980 logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
981 $xml = $conversation['source'];
986 self::process($xml, $importer, $contact, $hub, $stored, false);
988 logger("XML couldn't be fetched for URI: ".$related_uri." - href: ".$related, LOGGER_DEBUG);
994 * @brief Processes the XML for a repeated post
996 * @param object $xpath The xpath object
997 * @param object $entry The xml entry that is processed
998 * @param array $item The item array
999 * @param array $importer user record of the importing user
1001 * @return array with data from links
1003 private static function processRepeatedItem(DOMXPath $xpath, $entry, array &$item, array $importer)
1005 $activityobjects = $xpath->query('activity:object', $entry)->item(0);
1007 if (!is_object($activityobjects)) {
1013 $orig_uri = XML::getFirstNodeValue($xpath, 'atom:id/text()', $activityobjects);
1015 $links = $xpath->query("atom:link", $activityobjects);
1017 $link_data = self::processLinks($links, $item);
1020 $orig_body = XML::getFirstNodeValue($xpath, 'atom:content/text()', $activityobjects);
1021 $orig_created = XML::getFirstNodeValue($xpath, 'atom:published/text()', $activityobjects);
1022 $orig_edited = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $activityobjects);
1024 $orig_author = self::fetchAuthor($xpath, $activityobjects, $importer, $dummy, false);
1026 $item["author-name"] = $orig_author["author-name"];
1027 $item["author-link"] = $orig_author["author-link"];
1028 $item["author-id"] = $orig_author["author-id"];
1030 $item["body"] = HTML::toBBCode($orig_body);
1031 $item["created"] = $orig_created;
1032 $item["edited"] = $orig_edited;
1034 $item["uri"] = $orig_uri;
1036 $item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $activityobjects);
1038 $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $activityobjects);
1040 $inreplyto = $xpath->query('thr:in-reply-to', $activityobjects);
1041 if (is_object($inreplyto->item(0))) {
1042 foreach ($inreplyto->item(0)->attributes as $attributes) {
1043 if ($attributes->name == "ref") {
1044 $item["parent-uri"] = $attributes->textContent;
1053 * @brief Processes links in the XML
1055 * @param object $links The xml data that contain links
1056 * @param array $item The item array
1058 * @return array with data from the links
1060 private static function processLinks($links, array &$item)
1062 $link_data = ['add_body' => '', 'self' => ''];
1064 foreach ($links as $link) {
1065 $attribute = self::readAttributes($link);
1067 if (!empty($attribute['rel']) && !empty($attribute['href'])) {
1068 switch ($attribute['rel']) {
1070 $item["plink"] = $attribute['href'];
1071 if (($item["object-type"] == ACTIVITY_OBJ_QUESTION)
1072 || ($item["object-type"] == ACTIVITY_OBJ_EVENT)
1074 $item["body"] .= add_page_info($attribute['href']);
1077 case "ostatus:conversation":
1078 $link_data['conversation'] = $attribute['href'];
1079 $item['conversation-href'] = $link_data['conversation'];
1080 if (!isset($item['conversation-uri'])) {
1081 $item['conversation-uri'] = $item['conversation-href'];
1085 $filetype = strtolower(substr($attribute['type'], 0, strpos($attribute['type'], '/')));
1086 if ($filetype == 'image') {
1087 $link_data['add_body'] .= "\n[img]".$attribute['href'].'[/img]';
1089 if (!empty($item["attach"])) {
1090 $item["attach"] .= ',';
1092 $item["attach"] = '';
1094 if (!isset($attribute['length'])) {
1095 $attribute['length'] = "0";
1097 $item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.defaults($attribute, 'title', '').'"[/attach]';
1101 if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
1102 if (!isset($item["parent-uri"])) {
1103 $item["parent-uri"] = $attribute['href'];
1105 $link_data['related'] = $attribute['href'];
1107 $item["body"] .= add_page_info($attribute['href']);
1111 if (empty($item["plink"])) {
1112 $item["plink"] = $attribute['href'];
1114 $link_data['self'] = $attribute['href'];
1123 * @brief Create an url out of an uri
1125 * @param string $href URI in the format "parameter1:parameter1:..."
1127 * @return string URL in the format http(s)://....
1129 public static function convertHref($href)
1131 $elements = explode(":", $href);
1133 if ((count($elements) <= 2) || ($elements[0] != "tag")) {
1137 $server = explode(",", $elements[1]);
1138 $conversation = explode("=", $elements[2]);
1140 if ((count($elements) == 4) && ($elements[2] == "post")) {
1141 return "http://".$server[0]."/notice/".$elements[3];
1144 if ((count($conversation) != 2) || ($conversation[1] =="")) {
1147 if ($elements[3] == "objectType=thread") {
1148 return "http://".$server[0]."/conversation/".$conversation[1];
1150 return "http://".$server[0]."/notice/".$conversation[1];
1156 * @brief Checks if the current post is a reshare
1158 * @param array $item The item array of thw post
1160 * @return string The guid if the post is a reshare
1162 private static function getResharedGuid(array $item)
1164 $body = trim($item["body"]);
1166 // Skip if it isn't a pure repeated messages
1167 // Does it start with a share?
1168 if (strpos($body, "[share") > 0) {
1172 // Does it end with a share?
1173 if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
1177 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
1178 // Skip if there is no shared message in there
1179 if ($body == $attributes) {
1184 preg_match("/guid='(.*?)'/ism", $attributes, $matches);
1185 if (!empty($matches[1])) {
1186 $guid = $matches[1];
1189 preg_match('/guid="(.*?)"/ism', $attributes, $matches);
1190 if (!empty($matches[1])) {
1191 $guid = $matches[1];
1198 * @brief Cleans the body of a post if it contains picture links
1200 * @param string $body The body
1202 * @return string The cleaned body
1204 private static function formatPicturePost($body)
1206 $siteinfo = BBCode::getAttachedData($body);
1208 if (($siteinfo["type"] == "photo")) {
1209 if (isset($siteinfo["preview"])) {
1210 $preview = $siteinfo["preview"];
1212 $preview = $siteinfo["image"];
1215 // Is it a remote picture? Then make a smaller preview here
1216 $preview = proxy_url($preview, false, PROXY_SIZE_SMALL);
1218 // Is it a local picture? Then make it smaller here
1219 $preview = str_replace(["-0.jpg", "-0.png"], ["-2.jpg", "-2.png"], $preview);
1220 $preview = str_replace(["-1.jpg", "-1.png"], ["-2.jpg", "-2.png"], $preview);
1222 if (isset($siteinfo["url"])) {
1223 $url = $siteinfo["url"];
1225 $url = $siteinfo["image"];
1228 $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]";
1235 * @brief Adds the header elements to the XML document
1237 * @param object $doc XML document
1238 * @param array $owner Contact data of the poster
1239 * @param string $filter The related feed filter (activity, posts or comments)
1241 * @return object header root element
1243 private static function addHeader(DOMDocument $doc, array $owner, $filter)
1247 $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
1248 $doc->appendChild($root);
1250 $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
1251 $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
1252 $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
1253 $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
1254 $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
1255 $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
1256 $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
1257 $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
1261 case 'activity': $title = L10n::t('%s\'s timeline', $owner['name']); break;
1262 case 'posts' : $title = L10n::t('%s\'s posts' , $owner['name']); break;
1263 case 'comments': $title = L10n::t('%s\'s comments', $owner['name']); break;
1266 $attributes = ["uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION];
1267 XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
1268 XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]);
1269 XML::addElement($doc, $root, "title", $title);
1270 XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], Config::get('config', 'sitename')));
1271 XML::addElement($doc, $root, "logo", $owner["photo"]);
1272 XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
1274 $author = self::addAuthor($doc, $owner);
1275 $root->appendChild($author);
1277 $attributes = ["href" => $owner["url"], "rel" => "alternate", "type" => "text/html"];
1278 XML::addElement($doc, $root, "link", "", $attributes);
1280 /// @TODO We have to find out what this is
1281 /// $attributes = array("href" => System::baseUrl()."/sup",
1282 /// "rel" => "http://api.friendfeed.com/2008/03#sup",
1283 /// "type" => "application/json");
1284 /// XML::addElement($doc, $root, "link", "", $attributes);
1286 self::hublinks($doc, $root, $owner["nick"]);
1288 $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "salmon"];
1289 XML::addElement($doc, $root, "link", "", $attributes);
1291 $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies"];
1292 XML::addElement($doc, $root, "link", "", $attributes);
1294 $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"];
1295 XML::addElement($doc, $root, "link", "", $attributes);
1297 $attributes = ["href" => System::baseUrl() . "/api/statuses/user_timeline/" . $owner["nick"] . ".atom",
1298 "rel" => "self", "type" => "application/atom+xml"];
1299 XML::addElement($doc, $root, "link", "", $attributes);
1301 if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
1302 $condition = ['uid' => $owner['uid'], 'self' => false, 'pending' => false,
1303 'archive' => false, 'hidden' => false, 'blocked' => false];
1304 $members = DBA::count('contact', $condition);
1305 XML::addElement($doc, $root, "statusnet:group_info", "", ["member_count" => $members]);
1312 * @brief Add the link to the push hubs to the XML document
1314 * @param object $doc XML document
1315 * @param object $root XML root element where the hub links are added
1316 * @param object $nick nick
1319 public static function hublinks(DOMDocument $doc, $root, $nick)
1321 $h = System::baseUrl() . '/pubsubhubbub/'.$nick;
1322 XML::addElement($doc, $root, "link", "", ["href" => $h, "rel" => "hub"]);
1326 * @brief Adds attachment data to the XML document
1328 * @param object $doc XML document
1329 * @param object $root XML root element where the hub links are added
1330 * @param array $item Data of the item that is to be posted
1333 private static function getAttachment(DOMDocument $doc, $root, $item)
1336 $siteinfo = BBCode::getAttachedData($item["body"]);
1338 switch ($siteinfo["type"]) {
1340 $imgdata = Image::getInfoFromURL($siteinfo["image"]);
1342 $attributes = ["rel" => "enclosure",
1343 "href" => $siteinfo["image"],
1344 "type" => $imgdata["mime"],
1345 "length" => intval($imgdata["size"])];
1346 XML::addElement($doc, $root, "link", "", $attributes);
1350 $attributes = ["rel" => "enclosure",
1351 "href" => $siteinfo["url"],
1352 "type" => "text/html; charset=UTF-8",
1354 "title" => $siteinfo["title"]];
1355 XML::addElement($doc, $root, "link", "", $attributes);
1361 if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
1362 $imgdata = Image::getInfoFromURL($siteinfo["image"]);
1364 $attributes = ["rel" => "enclosure",
1365 "href" => $siteinfo["image"],
1366 "type" => $imgdata["mime"],
1367 "length" => intval($imgdata["size"])];
1369 XML::addElement($doc, $root, "link", "", $attributes);
1373 $arr = explode('[/attach],', $item['attach']);
1375 foreach ($arr as $r) {
1377 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
1379 $attributes = ["rel" => "enclosure",
1380 "href" => $matches[1],
1381 "type" => $matches[3]];
1383 if (intval($matches[2])) {
1384 $attributes["length"] = intval($matches[2]);
1386 if (trim($matches[4]) != "") {
1387 $attributes["title"] = trim($matches[4]);
1389 XML::addElement($doc, $root, "link", "", $attributes);
1396 * @brief Adds the author element to the XML document
1398 * @param object $doc XML document
1399 * @param array $owner Contact data of the poster
1400 * @param bool $show_profile Whether to show profile
1402 * @return object author element
1404 private static function addAuthor(DOMDocument $doc, array $owner, $show_profile = true)
1406 $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
1407 $author = $doc->createElement("author");
1408 XML::addElement($doc, $author, "id", $owner["url"]);
1409 if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
1410 XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
1412 XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
1414 XML::addElement($doc, $author, "uri", $owner["url"]);
1415 XML::addElement($doc, $author, "name", $owner["nick"]);
1416 XML::addElement($doc, $author, "email", $owner["addr"]);
1417 if ($show_profile) {
1418 XML::addElement($doc, $author, "summary", BBCode::convert($owner["about"], false, 7));
1421 $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $owner["url"]];
1422 XML::addElement($doc, $author, "link", "", $attributes);
1426 "type" => "image/jpeg", // To-Do?
1427 "media:width" => 175,
1428 "media:height" => 175,
1429 "href" => $owner["photo"]];
1430 XML::addElement($doc, $author, "link", "", $attributes);
1432 if (isset($owner["thumb"])) {
1435 "type" => "image/jpeg", // To-Do?
1436 "media:width" => 80,
1437 "media:height" => 80,
1438 "href" => $owner["thumb"]];
1439 XML::addElement($doc, $author, "link", "", $attributes);
1442 XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
1443 XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
1444 if ($show_profile) {
1445 XML::addElement($doc, $author, "poco:note", BBCode::convert($owner["about"], false, 7));
1447 if (trim($owner["location"]) != "") {
1448 $element = $doc->createElement("poco:address");
1449 XML::addElement($doc, $element, "poco:formatted", $owner["location"]);
1450 $author->appendChild($element);
1454 if (DBM::is_result($profile) && !$show_profile) {
1455 if (trim($profile["homepage"]) != "") {
1456 $urls = $doc->createElement("poco:urls");
1457 XML::addElement($doc, $urls, "poco:type", "homepage");
1458 XML::addElement($doc, $urls, "poco:value", $profile["homepage"]);
1459 XML::addElement($doc, $urls, "poco:primary", "true");
1460 $author->appendChild($urls);
1463 XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]);
1464 XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]);
1466 if ($profile["publish"]) {
1467 XML::addElement($doc, $author, "mastodon:scope", "public");
1475 * @TODO Picture attachments should look like this:
1476 * <a href="https://status.pirati.ca/attachment/572819" title="https://status.pirati.ca/file/heluecht-20151202T222602-rd3u49p.gif"
1477 * class="attachment thumbnail" id="attachment-572819" rel="nofollow external">https://status.pirati.ca/attachment/572819</a>
1481 * @brief Returns the given activity if present - otherwise returns the "post" activity
1483 * @param array $item Data of the item that is to be posted
1485 * @return string activity
1487 private static function constructVerb(array $item)
1489 if (!empty($item['verb'])) {
1490 return $item['verb'];
1493 return ACTIVITY_POST;
1497 * @brief Returns the given object type if present - otherwise returns the "note" object type
1499 * @param array $item Data of the item that is to be posted
1501 * @return string Object type
1503 private static function constructObjecttype(array $item)
1505 if (in_array($item['object-type'], [ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT]))
1506 return $item['object-type'];
1507 return ACTIVITY_OBJ_NOTE;
1511 * @brief Adds an entry element to the XML document
1513 * @param object $doc XML document
1514 * @param array $item Data of the item that is to be posted
1515 * @param array $owner Contact data of the poster
1516 * @param bool $toplevel optional default false
1518 * @return object Entry element
1520 private static function entry(DOMDocument $doc, array $item, array $owner, $toplevel = false)
1524 $repeated_guid = self::getResharedGuid($item);
1525 if ($repeated_guid != "") {
1526 $xml = self::reshareEntry($doc, $item, $owner, $repeated_guid, $toplevel);
1533 if ($item["verb"] == ACTIVITY_LIKE) {
1534 return self::likeEntry($doc, $item, $owner, $toplevel);
1535 } elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
1536 return self::followEntry($doc, $item, $owner, $toplevel);
1538 return self::noteEntry($doc, $item, $owner, $toplevel);
1543 * @brief Adds a source entry to the XML document
1545 * @param object $doc XML document
1546 * @param array $contact Array of the contact that is added
1548 * @return object Source element
1550 private static function sourceEntry(DOMDocument $doc, array $contact)
1552 $source = $doc->createElement("source");
1553 XML::addElement($doc, $source, "id", $contact["poll"]);
1554 XML::addElement($doc, $source, "title", $contact["name"]);
1555 XML::addElement($doc, $source, "link", "", ["rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]]);
1556 XML::addElement($doc, $source, "link", "", ["rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]]);
1557 XML::addElement($doc, $source, "icon", $contact["photo"]);
1558 XML::addElement($doc, $source, "updated", DateTimeFormat::utc($contact["success_update"]."+00:00", DateTimeFormat::ATOM));
1564 * @brief Fetches contact data from the contact or the gcontact table
1566 * @param string $url URL of the contact
1567 * @param array $owner Contact data of the poster
1569 * @return array Contact array
1571 private static function contactEntry($url, array $owner)
1574 "SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1",
1575 dbesc(normalise_link($url)),
1576 intval($owner["uid"])
1578 if (DBM::is_result($r)) {
1580 $contact["uid"] = -1;
1583 if (!DBM::is_result($r)) {
1585 "SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
1586 dbesc(normalise_link($url))
1588 if (DBM::is_result($r)) {
1590 $contact["uid"] = -1;
1591 $contact["success_update"] = $contact["updated"];
1595 if (!DBM::is_result($r)) {
1599 if (!isset($contact["poll"])) {
1600 $data = Probe::uri($url);
1601 $contact["poll"] = $data["poll"];
1603 if (!$contact["alias"]) {
1604 $contact["alias"] = $data["alias"];
1608 if (!isset($contact["alias"])) {
1609 $contact["alias"] = $contact["url"];
1616 * @brief Adds an entry element with reshared content
1618 * @param object $doc XML document
1619 * @param array $item Data of the item that is to be posted
1620 * @param array $owner Contact data of the poster
1621 * @param string $repeated_guid guid
1622 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1624 * @return object Entry element
1626 private static function reshareEntry(DOMDocument $doc, array $item, array $owner, $repeated_guid, $toplevel)
1628 if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
1629 logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
1632 $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1634 $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false,
1635 'network' => [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS]];
1636 $repeated_item = Item::selectFirst([], $condition);
1637 if (!DBM::is_result($repeated_item)) {
1641 $contact = self::contactEntry($repeated_item['author-link'], $owner);
1642 $contact['account-type'] = $contact['contact-type'];
1644 $title = $owner["nick"]." repeated a notice by ".$contact["nick"];
1646 self::entryContent($doc, $entry, $item, $owner, $title, ACTIVITY_SHARE, false);
1648 $as_object = $doc->createElement("activity:object");
1650 XML::addElement($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
1652 self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
1654 $author = self::addAuthor($doc, $contact, false);
1655 $as_object->appendChild($author);
1657 $as_object2 = $doc->createElement("activity:object");
1659 XML::addElement($doc, $as_object2, "activity:object-type", self::constructObjecttype($repeated_item));
1661 $title = sprintf("New comment by %s", $contact["nick"]);
1663 self::entryContent($doc, $as_object2, $repeated_item, $owner, $title);
1665 $as_object->appendChild($as_object2);
1667 self::entryFooter($doc, $as_object, $item, $owner, false);
1669 $source = self::sourceEntry($doc, $contact);
1671 $as_object->appendChild($source);
1673 $entry->appendChild($as_object);
1675 self::entryFooter($doc, $entry, $item, $owner);
1681 * @brief Adds an entry element with a "like"
1683 * @param object $doc XML document
1684 * @param array $item Data of the item that is to be posted
1685 * @param array $owner Contact data of the poster
1686 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1688 * @return object Entry element with "like"
1690 private static function likeEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
1692 if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
1693 logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
1696 $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1698 $verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
1699 self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
1701 $as_object = $doc->createElement("activity:object");
1703 $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
1705 XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent));
1707 self::entryContent($doc, $as_object, $parent, $owner, "New entry");
1709 $entry->appendChild($as_object);
1711 self::entryFooter($doc, $entry, $item, $owner);
1717 * @brief Adds the person object element to the XML document
1719 * @param object $doc XML document
1720 * @param array $owner Contact data of the poster
1721 * @param array $contact Contact data of the target
1723 * @return object author element
1725 private static function addPersonObject(DOMDocument $doc, array $owner, array $contact)
1727 $object = $doc->createElement("activity:object");
1728 XML::addElement($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
1730 if ($contact['network'] == NETWORK_PHANTOM) {
1731 XML::addElement($doc, $object, "id", $contact['url']);
1735 XML::addElement($doc, $object, "id", $contact["alias"]);
1736 XML::addElement($doc, $object, "title", $contact["nick"]);
1738 $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $contact["url"]];
1739 XML::addElement($doc, $object, "link", "", $attributes);
1743 "type" => "image/jpeg", // To-Do?
1744 "media:width" => 175,
1745 "media:height" => 175,
1746 "href" => $contact["photo"]];
1747 XML::addElement($doc, $object, "link", "", $attributes);
1749 XML::addElement($doc, $object, "poco:preferredUsername", $contact["nick"]);
1750 XML::addElement($doc, $object, "poco:displayName", $contact["name"]);
1752 if (trim($contact["location"]) != "") {
1753 $element = $doc->createElement("poco:address");
1754 XML::addElement($doc, $element, "poco:formatted", $contact["location"]);
1755 $object->appendChild($element);
1762 * @brief Adds a follow/unfollow entry element
1764 * @param object $doc XML document
1765 * @param array $item Data of the follow/unfollow message
1766 * @param array $owner Contact data of the poster
1767 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1769 * @return object Entry element
1771 private static function followEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
1773 $item["id"] = $item["parent"] = 0;
1774 $item["created"] = $item["edited"] = date("c");
1775 $item["private"] = true;
1777 $contact = Probe::uri($item['follow']);
1779 if ($contact['alias'] == '') {
1780 $contact['alias'] = $contact["url"];
1782 $item['follow'] = $contact['alias'];
1786 "SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
1787 intval($owner['uid']),
1788 dbesc(normalise_link($contact["url"]))
1791 if (DBM::is_result($r)) {
1792 $connect_id = $r[0]['id'];
1797 if ($item['verb'] == ACTIVITY_FOLLOW) {
1798 $message = L10n::t('%s is now following %s.');
1799 $title = L10n::t('following');
1800 $action = "subscription";
1802 $message = L10n::t('%s stopped following %s.');
1803 $title = L10n::t('stopped following');
1804 $action = "unfollow";
1807 $item["uri"] = $item['parent-uri'] = $item['thr-parent']
1808 = 'tag:'.get_app()->get_hostname().
1809 ','.date('Y-m-d').':'.$action.':'.$owner['uid'].
1810 ':person:'.$connect_id.':'.$item['created'];
1812 $item["body"] = sprintf($message, $owner["nick"], $contact["nick"]);
1814 self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1816 self::entryContent($doc, $entry, $item, $owner, $title);
1818 $object = self::addPersonObject($doc, $owner, $contact);
1819 $entry->appendChild($object);
1821 self::entryFooter($doc, $entry, $item, $owner);
1827 * @brief Adds a regular entry element
1829 * @param object $doc XML document
1830 * @param array $item Data of the item that is to be posted
1831 * @param array $owner Contact data of the poster
1832 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1834 * @return object Entry element
1836 private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
1838 if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
1839 logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
1842 $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1844 XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
1846 self::entryContent($doc, $entry, $item, $owner, $title);
1848 self::entryFooter($doc, $entry, $item, $owner);
1854 * @brief Adds a header element to the XML document
1856 * @param object $doc XML document
1857 * @param object $entry The entry element where the elements are added
1858 * @param array $owner Contact data of the poster
1859 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1861 * @return string The title for the element
1863 private static function entryHeader(DOMDocument $doc, &$entry, array $owner, array $item, $toplevel)
1865 /// @todo Check if this title stuff is really needed (I guess not)
1867 $entry = $doc->createElement("entry");
1868 $title = sprintf("New note by %s", $owner["nick"]);
1870 if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
1871 $contact = self::contactEntry($item['author-link'], $owner);
1872 $author = self::addAuthor($doc, $contact, false);
1873 $entry->appendChild($author);
1876 $entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
1878 $entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
1879 $entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
1880 $entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
1881 $entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
1882 $entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
1883 $entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
1884 $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
1885 $entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
1887 $author = self::addAuthor($doc, $owner);
1888 $entry->appendChild($author);
1890 $title = sprintf("New comment by %s", $owner["nick"]);
1896 * @brief Adds elements to the XML document
1898 * @param object $doc XML document
1899 * @param object $entry Entry element where the content is added
1900 * @param array $item Data of the item that is to be posted
1901 * @param array $owner Contact data of the poster
1902 * @param string $title Title for the post
1903 * @param string $verb The activity verb
1904 * @param bool $complete Add the "status_net" element?
1907 private static function entryContent(DOMDocument $doc, $entry, array $item, array $owner, $title, $verb = "", $complete = true)
1910 $verb = self::constructVerb($item);
1913 XML::addElement($doc, $entry, "id", $item["uri"]);
1914 XML::addElement($doc, $entry, "title", $title);
1916 $body = self::formatPicturePost($item['body']);
1918 if ($item['title'] != "") {
1919 $body = "[b]".$item['title']."[/b]\n\n".$body;
1922 $body = BBCode::convert($body, false, 7);
1924 XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
1926 XML::addElement($doc, $entry, "link", "", ["rel" => "alternate", "type" => "text/html",
1927 "href" => System::baseUrl()."/display/".$item["guid"]]
1930 if ($complete && ($item["id"] > 0)) {
1931 XML::addElement($doc, $entry, "status_net", "", ["notice_id" => $item["id"]]);
1934 XML::addElement($doc, $entry, "activity:verb", $verb);
1936 XML::addElement($doc, $entry, "published", DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM));
1937 XML::addElement($doc, $entry, "updated", DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM));
1941 * @brief Adds the elements at the foot of an entry to the XML document
1943 * @param object $doc XML document
1944 * @param object $entry The entry element where the elements are added
1945 * @param array $item Data of the item that is to be posted
1946 * @param array $owner Contact data of the poster
1947 * @param bool $complete default true
1950 private static function entryFooter(DOMDocument $doc, $entry, array $item, array $owner, $complete = true)
1954 if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
1955 $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item["parent"]]);
1956 $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
1958 $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $parent_item]);
1960 if (DBM::is_result($thrparent)) {
1961 $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
1962 $mentioned[$thrparent["owner-link"]] = $thrparent["owner-link"];
1963 $parent_plink = $thrparent["plink"];
1965 $mentioned[$parent["author-link"]] = $parent["author-link"];
1966 $mentioned[$parent["owner-link"]] = $parent["owner-link"];
1967 $parent_plink = System::baseUrl()."/display/".$parent["guid"];
1971 "ref" => $parent_item,
1972 "href" => $parent_plink];
1973 XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
1977 "href" => $parent_plink];
1978 XML::addElement($doc, $entry, "link", "", $attributes);
1981 if (intval($item["parent"]) > 0) {
1982 $conversation_href = System::baseUrl()."/display/".$owner["nick"]."/".$item["parent"];
1983 $conversation_uri = $conversation_href;
1985 if (isset($parent_item)) {
1986 $conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $parent_item]);
1987 if (DBM::is_result($conversation)) {
1988 if ($conversation['conversation-uri'] != '') {
1989 $conversation_uri = $conversation['conversation-uri'];
1991 if ($conversation['conversation-href'] != '') {
1992 $conversation_href = $conversation['conversation-href'];
1997 XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:conversation", "href" => $conversation_href]);
2000 "href" => $conversation_href,
2001 "local_id" => $item["parent"],
2002 "ref" => $conversation_uri];
2004 XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
2007 $tags = item::getFeedTags($item);
2010 foreach ($tags as $t) {
2012 $mentioned[$t[1]] = $t[1];
2017 // Make sure that mentions are accepted (GNU Social has problems with mixing HTTP and HTTPS)
2019 foreach ($mentioned as $mention) {
2020 $newmentions[str_replace("http://", "https://", $mention)] = str_replace("http://", "https://", $mention);
2021 $newmentions[str_replace("https://", "http://", $mention)] = str_replace("https://", "http://", $mention);
2023 $mentioned = $newmentions;
2025 foreach ($mentioned as $mention) {
2026 $condition = ['uid' => $owner['uid'], 'nurl' => normalise_link($mention)];
2027 $contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition);
2028 if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == ACCOUNT_TYPE_COMMUNITY) ||
2029 ($contact['self'] && ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY))) {
2030 XML::addElement($doc, $entry, "link", "",
2032 "rel" => "mentioned",
2033 "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
2037 XML::addElement($doc, $entry, "link", "",
2039 "rel" => "mentioned",
2040 "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
2046 if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
2047 XML::addElement($doc, $entry, "link", "", [
2048 "rel" => "mentioned",
2049 "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
2050 "href" => $owner['url']
2054 if (!$item["private"]) {
2055 XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:attention",
2056 "href" => "http://activityschema.org/collection/public"]);
2057 XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
2058 "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
2059 "href" => "http://activityschema.org/collection/public"]);
2060 XML::addElement($doc, $entry, "mastodon:scope", "public");
2064 foreach ($tags as $t) {
2066 XML::addElement($doc, $entry, "category", "", ["term" => $t[2]]);
2071 self::getAttachment($doc, $entry, $item);
2073 if ($complete && ($item["id"] > 0)) {
2074 $app = $item["app"];
2079 $attributes = ["local_id" => $item["id"], "source" => $app];
2081 if (isset($parent["id"])) {
2082 $attributes["repeat_of"] = $parent["id"];
2085 if ($item["coord"] != "") {
2086 XML::addElement($doc, $entry, "georss:point", $item["coord"]);
2089 XML::addElement($doc, $entry, "statusnet:notice_info", "", $attributes);
2094 * Creates the XML feed for a given nickname
2096 * Supported filters:
2097 * - activity (default): all the public posts
2098 * - posts: all the public top-level posts
2099 * - comments: all the public replies
2101 * Updates the provided last_update parameter if the result comes from the
2102 * cache or it is empty
2104 * @brief Creates the XML feed for a given nickname
2106 * @param string $owner_nick Nickname of the feed owner
2107 * @param string $last_update Date of the last update
2108 * @param integer $max_items Number of maximum items to fetch
2109 * @param string $filter Feed items filter (activity, posts or comments)
2110 * @param boolean $nocache Wether to bypass caching
2112 * @return string XML feed
2114 public static function feed($owner_nick, &$last_update, $max_items = 300, $filter = 'activity', $nocache = false)
2116 $stamp = microtime(true);
2118 $owner = User::getOwnerDataByNick($owner_nick);
2123 $cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
2125 $previous_created = $last_update;
2127 // Don't cache when the last item was posted less then 15 minutes ago (Cache duration)
2128 if ((time() - strtotime($owner['last-item'])) < 15*60) {
2129 $result = Cache::get($cachekey);
2130 if (!$nocache && !is_null($result)) {
2131 logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
2132 $last_update = $result['last_update'];
2133 return $result['feed'];
2137 if (!strlen($last_update)) {
2138 $last_update = 'now -30 days';
2141 $check_date = DateTimeFormat::utc($last_update);
2142 $authorid = Contact::getIdForURL($owner["url"], 0, true);
2144 $condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
2145 AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
2146 $owner["uid"], $check_date, NETWORK_OSTATUS, NETWORK_DFRN];
2148 if ($filter === 'comments') {
2149 $condition[0] .= " AND `object-type` = ? ";
2150 $condition[] = ACTIVITY_OBJ_COMMENT;
2153 if ($owner['account-type'] != ACCOUNT_TYPE_COMMUNITY) {
2154 $condition[0] .= " AND `contact-id` = ? AND `author-id` = ?";
2155 $condition[] = $owner["id"];
2156 $condition[] = $authorid;
2159 $params = ['order' => ['created' => true], 'limit' => $max_items];
2161 if ($filter === 'posts') {
2162 $ret = Item::selectThread([], $condition, $params);
2164 $ret = Item::select([], $condition, $params);
2167 $items = Item::inArray($ret);
2169 $doc = new DOMDocument('1.0', 'utf-8');
2170 $doc->formatOutput = true;
2172 $root = self::addHeader($doc, $owner, $filter);
2174 foreach ($items as $item) {
2175 if (Config::get('system', 'ostatus_debug')) {
2176 $item['body'] .= '🍼';
2178 $entry = self::entry($doc, $item, $owner);
2179 $root->appendChild($entry);
2181 if ($last_update < $item['created']) {
2182 $last_update = $item['created'];
2186 $feeddata = trim($doc->saveXML());
2188 $msg = ['feed' => $feeddata, 'last_update' => $last_update];
2189 Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
2191 logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
2197 * @brief Creates the XML for a salmon message
2199 * @param array $item Data of the item that is to be posted
2200 * @param array $owner Contact data of the poster
2202 * @return string XML for the salmon
2204 public static function salmon(array $item, array $owner)
2206 $doc = new DOMDocument('1.0', 'utf-8');
2207 $doc->formatOutput = true;
2209 if (Config::get('system', 'ostatus_debug')) {
2210 $item['body'] .= '🐟';
2213 $entry = self::entry($doc, $item, $owner, true);
2215 $doc->appendChild($entry);
2217 return trim($doc->saveXML());