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\Model\Contact;
18 use Friendica\Model\Conversation;
19 use Friendica\Model\GContact;
20 use Friendica\Model\Item;
21 use Friendica\Model\User;
22 use Friendica\Network\Probe;
23 use Friendica\Object\Image;
24 use Friendica\Util\DateTimeFormat;
25 use Friendica\Util\Network;
26 use Friendica\Util\XML;
28 require_once 'include/dba.php';
29 require_once 'include/items.php';
30 require_once 'mod/share.php';
31 require_once 'include/enotify.php';
32 require_once 'include/api.php';
33 require_once 'mod/proxy.php';
36 * @brief This class contain functions for the OStatus protocol
40 private static $itemlist;
41 private static $conv_list = [];
44 * @brief Fetches author data
46 * @param object $xpath The xpath object
47 * @param object $context The xml context of the author details
48 * @param array $importer user record of the importing user
49 * @param array $contact Called by reference, will contain the fetched contact
50 * @param bool $onlyfetch Only fetch the header without updating the contact entries
52 * @return array Array of author related entries for the item
54 private static function fetchAuthor(DOMXPath $xpath, $context, array $importer, array &$contact = null, $onlyfetch)
57 $author["author-link"] = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context);
58 $author["author-name"] = XML::getFirstNodeValue($xpath, 'atom:author/atom:name/text()', $context);
59 $addr = XML::getFirstNodeValue($xpath, 'atom:author/atom:email/text()', $context);
61 $aliaslink = $author["author-link"];
63 $alternate_item = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0);
64 if (is_object($alternate_item)) {
65 foreach ($alternate_item->attributes as $attributes) {
66 if (($attributes->name == "href") && ($attributes->textContent != "")) {
67 $author["author-link"] = $attributes->textContent;
71 $author["author-id"] = Contact::getIdForURL($author["author-link"]);
73 $author["contact-id"] = $contact["id"];
76 if ($aliaslink != '') {
77 $condition = ["`uid` = ? AND `alias` = ? AND `network` != ? AND `rel` IN (?, ?)",
78 $importer["uid"], $aliaslink, NETWORK_STATUSNET,
79 Contact::SHARING, Contact::FRIEND];
80 $contact = DBA::selectFirst('contact', [], $condition);
83 if (!DBA::isResult($contact) && $author["author-link"] != '') {
84 if ($aliaslink == "") {
85 $aliaslink = $author["author-link"];
88 $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ? AND `rel` IN (?, ?)",
89 $importer["uid"], normalise_link($author["author-link"]), normalise_link($aliaslink),
90 NETWORK_STATUSNET, Contact::SHARING, Contact::FRIEND];
91 $contact = DBA::selectFirst('contact', [], $condition);
94 if (!DBA::isResult($contact) && ($addr != '')) {
95 $condition = ["`uid` = ? AND `addr` = ? AND `network` != ? AND `rel` IN (?, ?)",
96 $importer["uid"], $addr, NETWORK_STATUSNET,
97 Contact::SHARING, Contact::FRIEND];
98 $contact = DBA::selectFirst('contact', [], $condition);
101 if (DBA::isResult($contact)) {
102 if ($contact['blocked']) {
105 $author["contact-id"] = $contact["id"];
109 $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context);
110 foreach ($avatars as $avatar) {
113 foreach ($avatar->attributes as $attributes) {
114 if ($attributes->name == "href") {
115 $href = $attributes->textContent;
117 if ($attributes->name == "width") {
118 $width = $attributes->textContent;
122 $avatarlist[$width] = $href;
125 if (count($avatarlist) > 0) {
127 $author["author-avatar"] = Probe::fixAvatar(current($avatarlist), $author["author-link"]);
130 $displayname = XML::getFirstNodeValue($xpath, 'atom:author/poco:displayName/text()', $context);
131 if ($displayname != "") {
132 $author["author-name"] = $displayname;
135 $author["owner-id"] = $author["author-id"];
137 // Only update the contacts if it is an OStatus contact
138 if (DBA::isResult($contact) && ($contact['id'] > 0) && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
140 // Update contact data
142 unset($current['name-date']);
144 // This query doesn't seem to work
145 // $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
147 // $contact["notify"] = $value;
149 // This query doesn't seem to work as well - I hate these queries
150 // $value = $xpath->query("atom:link[@rel='self' and @type='application/atom+xml']", $context)->item(0)->nodeValue;
152 // $contact["poll"] = $value;
154 $contact['url'] = $author["author-link"];
155 $contact['nurl'] = normalise_link($contact['url']);
157 $value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context);
159 $contact["alias"] = $value;
162 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:displayName/text()', $context);
164 $contact["name"] = $value;
167 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()', $context);
169 $contact["nick"] = $value;
172 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:note/text()', $context);
174 $contact["about"] = HTML::toBBCode($value);
177 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:address/poco:formatted/text()', $context);
179 $contact["location"] = $value;
182 $contact['name-date'] = DateTimeFormat::utcNow();
184 DBA::update('contact', $contact, ['id' => $contact["id"]], $current);
186 if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
187 logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
188 Contact::updateAvatar($author["author-avatar"], $importer["uid"], $contact["id"]);
191 // Ensure that we are having this contact (with uid=0)
192 $cid = Contact::getIdForURL($aliaslink, 0, true);
195 $fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
196 $old_contact = DBA::selectFirst('contact', $fields, ['id' => $cid]);
198 // Update it with the current values
199 $fields = ['url' => $author["author-link"], 'name' => $contact["name"],
200 'nurl' => normalise_link($author["author-link"]),
201 'nick' => $contact["nick"], 'alias' => $contact["alias"],
202 'about' => $contact["about"], 'location' => $contact["location"],
203 'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()];
205 DBA::update('contact', $fields, ['id' => $cid], $old_contact);
208 if (!empty($author["author-avatar"])) {
209 Contact::updateAvatar($author["author-avatar"], 0, $cid);
213 $contact["generation"] = 2;
214 $contact["hide"] = false; // OStatus contacts are never hidden
215 if (!empty($author["author-avatar"])) {
216 $contact["photo"] = $author["author-avatar"];
218 $gcid = GContact::update($contact);
220 GContact::link($gcid, $contact["uid"], $contact["id"]);
229 * @brief Fetches author data from a given XML string
231 * @param string $xml The XML
232 * @param array $importer user record of the importing user
234 * @return array Array of author related entries for the item
236 public static function salmonAuthor($xml, array $importer)
242 $doc = new DOMDocument();
243 @$doc->loadXML($xml);
245 $xpath = new DOMXPath($doc);
246 $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
247 $xpath->registerNamespace('thr', NAMESPACE_THREAD);
248 $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
249 $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
250 $xpath->registerNamespace('media', NAMESPACE_MEDIA);
251 $xpath->registerNamespace('poco', NAMESPACE_POCO);
252 $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
253 $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
255 $contact = ["id" => 0];
257 // Fetch the first author
258 $authordata = $xpath->query('//author')->item(0);
259 $author = self::fetchAuthor($xpath, $authordata, $importer, $contact, true);
264 * @brief Read attributes from element
266 * @param object $element Element object
268 * @return array attributes
270 private static function readAttributes($element)
274 foreach ($element->attributes as $attributes) {
275 $attribute[$attributes->name] = $attributes->textContent;
282 * @brief Imports an XML string containing OStatus elements
284 * @param string $xml The XML
285 * @param array $importer user record of the importing user
286 * @param array $contact contact
287 * @param string $hub Called by reference, returns the fetched hub data
290 public static function import($xml, array $importer, array &$contact = null, &$hub)
292 self::process($xml, $importer, $contact, $hub);
296 * @brief Internal feed processing
298 * @param string $xml The XML
299 * @param array $importer user record of the importing user
300 * @param array $contact contact
301 * @param string $hub Called by reference, returns the fetched hub data
302 * @param boolean $stored Is the post fresh imported or from the database?
303 * @param boolean $initialize Is it the leading post so that data has to be initialized?
305 * @return boolean Could the XML be processed?
307 private static function process($xml, array $importer, array &$contact = null, &$hub, $stored = false, $initialize = true)
310 self::$itemlist = [];
311 self::$conv_list = [];
314 logger("Import OStatus message", LOGGER_DEBUG);
319 $doc = new DOMDocument();
320 @$doc->loadXML($xml);
322 $xpath = new DOMXPath($doc);
323 $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
324 $xpath->registerNamespace('thr', NAMESPACE_THREAD);
325 $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
326 $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
327 $xpath->registerNamespace('media', NAMESPACE_MEDIA);
328 $xpath->registerNamespace('poco', NAMESPACE_POCO);
329 $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
330 $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
333 $hub_items = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0);
334 if (is_object($hub_items)) {
335 $hub_attributes = $hub_items->attributes;
336 if (is_object($hub_attributes)) {
337 foreach ($hub_attributes as $hub_attribute) {
338 if ($hub_attribute->name == "href") {
339 $hub = $hub_attribute->textContent;
340 logger("Found hub ".$hub, LOGGER_DEBUG);
347 $header["uid"] = $importer["uid"];
348 $header["network"] = NETWORK_OSTATUS;
350 $header["origin"] = 0;
351 $header["gravity"] = GRAVITY_COMMENT;
353 $first_child = $doc->firstChild->tagName;
355 if ($first_child == "feed") {
356 $entries = $xpath->query('/atom:feed/atom:entry');
358 $entries = $xpath->query('/atom:entry');
361 if ($entries->length == 1) {
362 // We reformat the XML to make it better readable
363 $doc2 = new DOMDocument();
364 $doc2->loadXML($xml);
365 $doc2->preserveWhiteSpace = false;
366 $doc2->formatOutput = true;
367 $xml2 = $doc2->saveXML();
369 $header["protocol"] = PROTOCOL_OSTATUS_SALMON;
370 $header["source"] = $xml2;
371 } elseif (!$initialize) {
375 // Fetch the first author
376 $authordata = $xpath->query('//author')->item(0);
377 $author = self::fetchAuthor($xpath, $authordata, $importer, $contact, $stored);
379 $entry = $xpath->query('/atom:entry');
381 // Reverse the order of the entries
384 foreach ($entries as $entry) {
385 $entrylist[] = $entry;
388 foreach (array_reverse($entrylist) as $entry) {
390 $authorelement = $xpath->query('/atom:entry/atom:author', $entry);
392 if ($authorelement->length == 0) {
393 $authorelement = $xpath->query('atom:author', $entry);
396 if ($authorelement->length > 0) {
397 $author = self::fetchAuthor($xpath, $entry, $importer, $contact, $stored);
400 $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()', $entry);
404 $nickname = $author["author-name"];
407 $item = array_merge($header, $author);
409 $item["uri"] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
411 $item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $entry);
414 if (in_array($item["verb"], ['qvitter-delete-notice', ACTIVITY_DELETE, 'delete'])) {
415 self::deleteNotice($item);
419 if (in_array($item["verb"], [NAMESPACE_OSTATUS."/unfavorite", ACTIVITY_UNFAVORITE])) {
420 // Ignore "Unfavorite" message
421 logger("Ignore unfavorite message ".print_r($item, true), LOGGER_DEBUG);
425 // Deletions come with the same uri, so we check for duplicates after processing deletions
426 if (Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]])) {
427 logger('Post with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', LOGGER_DEBUG);
430 logger('Processing post with URI '.$item["uri"].' for user '.$importer["uid"].'.', LOGGER_DEBUG);
433 if ($item["verb"] == ACTIVITY_JOIN) {
434 // ignore "Join" messages
435 logger("Ignore join message ".print_r($item, true), LOGGER_DEBUG);
439 if ($item["verb"] == "http://mastodon.social/schema/1.0/block") {
440 // ignore mastodon "block" messages
441 logger("Ignore block message ".print_r($item, true), LOGGER_DEBUG);
445 if ($item["verb"] == ACTIVITY_FOLLOW) {
446 Contact::addRelationship($importer, $contact, $item, $nickname);
450 if ($item["verb"] == NAMESPACE_OSTATUS."/unfollow") {
452 Contact::removeFollower($importer, $contact, $item, $dummy);
456 if ($item["verb"] == ACTIVITY_FAVORITE) {
457 $orig_uri = $xpath->query("activity:object/atom:id", $entry)->item(0)->nodeValue;
458 logger("Favorite ".$orig_uri." ".print_r($item, true));
460 $item["verb"] = ACTIVITY_LIKE;
461 $item["parent-uri"] = $orig_uri;
462 $item["gravity"] = GRAVITY_ACTIVITY;
463 $item["object-type"] = ACTIVITY_OBJ_NOTE;
466 // http://activitystrea.ms/schema/1.0/rsvp-yes
467 if (!in_array($item["verb"], [ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE])) {
468 logger("Unhandled verb ".$item["verb"]." ".print_r($item, true), LOGGER_DEBUG);
471 self::processPost($xpath, $entry, $item, $importer);
473 if ($initialize && (count(self::$itemlist) > 0)) {
474 if (self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']) {
475 // We will import it everytime, when it is started by our contacts
476 $valid = !empty(self::$itemlist[0]['contact-id']);
478 // If not, then it depends on this setting
479 $valid = !Config::get('system', 'ostatus_full_threads');
481 logger("Item with uri ".self::$itemlist[0]['uri']." will be imported due to the system settings.", LOGGER_DEBUG);
484 logger("Item with uri ".self::$itemlist[0]['uri']." belongs to a contact (".self::$itemlist[0]['contact-id']."). It will be imported.", LOGGER_DEBUG);
487 // Never post a thread when the only interaction by our contact was a like
489 $verbs = [ACTIVITY_POST, ACTIVITY_SHARE];
490 foreach (self::$itemlist as $item) {
491 if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
496 logger("Item with uri ".self::$itemlist[0]['uri']." will be imported since the thread contains posts or shares.", LOGGER_DEBUG);
500 // But we will only import complete threads
501 $valid = Item::exists(['uid' => $importer["uid"], 'uri' => self::$itemlist[0]['parent-uri']]);
503 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);
508 $default_contact = 0;
509 $key = count(self::$itemlist);
510 for ($key = count(self::$itemlist) - 1; $key >= 0; $key--) {
511 if (empty(self::$itemlist[$key]['contact-id'])) {
512 self::$itemlist[$key]['contact-id'] = $default_contact;
514 $default_contact = $item['contact-id'];
517 foreach (self::$itemlist as $item) {
518 $found = Item::exists(['uid' => $importer["uid"], 'uri' => $item["uri"]]);
520 logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", LOGGER_DEBUG);
521 } elseif ($item['contact-id'] < 0) {
522 logger("Item with uri ".$item["uri"]." is from a blocked contact.", LOGGER_DEBUG);
524 // We are having duplicated entries. Hopefully this solves it.
525 if (Lock::acquire('ostatus_process_item_insert')) {
526 $ret = Item::insert($item);
527 Lock::release('ostatus_process_item_insert');
528 logger("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret);
530 $ret = Item::insert($item);
531 logger("We couldn't lock - but tried to store the item anyway. Return value is ".$ret);
536 self::$itemlist = [];
538 logger('Processing done for post with URI '.$item["uri"].' for user '.$importer["uid"].'.', LOGGER_DEBUG);
544 * Removes notice item from database
545 * @param array $item item
548 private static function deleteNotice(array $item)
550 $condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'uri' => $item['uri']];
551 if (!Item::exists($condition)) {
552 logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it.");
556 Item::delete($condition);
558 logger('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
562 * @brief Processes the XML for a post
564 * @param object $xpath The xpath object
565 * @param object $entry The xml entry that is processed
566 * @param array $item The item array
567 * @param array $importer user record of the importing user
570 private static function processPost(DOMXPath $xpath, $entry, array &$item, array $importer)
572 $item["body"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
573 $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry);
574 if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
575 $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
576 $item["body"] = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
577 } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
578 $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
581 $item["created"] = XML::getFirstNodeValue($xpath, 'atom:published/text()', $entry);
582 $item["edited"] = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry);
583 $item['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
585 $conv = $xpath->query('ostatus:conversation', $entry);
586 if (is_object($conv->item(0))) {
587 foreach ($conv->item(0)->attributes as $attributes) {
588 if ($attributes->name == "ref") {
589 $item['conversation-uri'] = $attributes->textContent;
591 if ($attributes->name == "href") {
592 $item['conversation-href'] = $attributes->textContent;
599 $inreplyto = $xpath->query('thr:in-reply-to', $entry);
600 if (is_object($inreplyto->item(0))) {
601 foreach ($inreplyto->item(0)->attributes as $attributes) {
602 if ($attributes->name == "ref") {
603 $item["parent-uri"] = $attributes->textContent;
605 if ($attributes->name == "href") {
606 $related = $attributes->textContent;
611 $georsspoint = $xpath->query('georss:point', $entry);
612 if (!empty($georsspoint) && ($georsspoint->length > 0)) {
613 $item["coord"] = $georsspoint->item(0)->nodeValue;
616 $categories = $xpath->query('atom:category', $entry);
618 foreach ($categories as $category) {
619 foreach ($category->attributes as $attributes) {
620 if ($attributes->name == "term") {
621 $term = $attributes->textContent;
622 if (!empty($item["tag"])) {
628 $item["tag"] .= "#[url=".System::baseUrl()."/search?tag=".$term."]".$term."[/url]";
637 $links = $xpath->query('atom:link', $entry);
639 $link_data = self::processLinks($links, $item);
640 $self = $link_data['self'];
641 $add_body = $link_data['add_body'];
646 $notice_info = $xpath->query('statusnet:notice_info', $entry);
647 if ($notice_info && ($notice_info->length > 0)) {
648 foreach ($notice_info->item(0)->attributes as $attributes) {
649 if ($attributes->name == "source") {
650 $item["app"] = strip_tags($attributes->textContent);
652 if ($attributes->name == "repeat_of") {
653 $repeat_of = $attributes->textContent;
657 // Is it a repeated post?
658 if (($repeat_of != "") || ($item["verb"] == ACTIVITY_SHARE)) {
659 $link_data = self::processRepeatedItem($xpath, $entry, $item, $importer);
660 if (!empty($link_data['add_body'])) {
661 $add_body .= $link_data['add_body'];
665 $item["body"] .= $add_body;
667 // Only add additional data when there is no picture in the post
668 if (!strstr($item["body"], '[/img]')) {
669 $item["body"] = add_page_info_to_body($item["body"]);
672 // Mastodon Content Warning
673 if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
674 $clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
675 if (!empty($clear_text)) {
676 $item['content-warning'] = HTML::toBBCode($clear_text);
680 if (($self != '') && empty($item['protocol'])) {
681 self::fetchSelf($self, $item);
684 if (!empty($item["conversation-href"])) {
685 self::fetchConversation($item['conversation-href'], $item['conversation-uri']);
688 if (isset($item["parent-uri"])) {
689 if (!Item::exists(['uid' => $importer["uid"], 'uri' => $item['parent-uri']])) {
690 if ($related != '') {
691 self::fetchRelated($related, $item["parent-uri"], $importer);
694 logger('Reply with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', LOGGER_DEBUG);
697 $item["parent-uri"] = $item["uri"];
698 $item["gravity"] = GRAVITY_PARENT;
701 if (($item['author-link'] != '') && !empty($item['protocol'])) {
702 $item = Conversation::insert($item);
705 self::$itemlist[] = $item;
709 * @brief Fetch the conversation for posts
711 * @param string $conversation The link to the conversation
712 * @param string $conversation_uri The conversation in "uri" format
715 private static function fetchConversation($conversation, $conversation_uri)
717 // Ensure that we only store a conversation once in a process
718 if (isset(self::$conv_list[$conversation])) {
722 self::$conv_list[$conversation] = true;
724 $conversation_data = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
726 if (!$conversation_data['success']) {
732 if (stristr($conversation_data['header'], 'Content-Type: application/atom+xml')) {
733 $xml = $conversation_data['body'];
737 $doc = new DOMDocument();
738 if (!@$doc->loadHTML($conversation_data['body'])) {
741 $xpath = new DOMXPath($doc);
743 $links = $xpath->query('//link');
746 foreach ($links as $link) {
747 $attribute = self::readAttributes($link);
748 if (($attribute['rel'] == 'alternate') && ($attribute['type'] == 'application/atom+xml')) {
749 $file = $attribute['href'];
753 $conversation_atom = Network::curl($attribute['href']);
755 if ($conversation_atom['success']) {
756 $xml = $conversation_atom['body'];
766 self::storeConversation($xml, $conversation, $conversation_uri);
770 * @brief Store a feed in several conversation entries
772 * @param string $xml The feed
773 * @param string $conversation conversation
774 * @param string $conversation_uri conversation uri
777 private static function storeConversation($xml, $conversation = '', $conversation_uri = '')
779 $doc = new DOMDocument();
780 @$doc->loadXML($xml);
782 $xpath = new DOMXPath($doc);
783 $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
784 $xpath->registerNamespace('thr', NAMESPACE_THREAD);
785 $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
787 $entries = $xpath->query('/atom:feed/atom:entry');
789 // Now store the entries
790 foreach ($entries as $entry) {
791 $doc2 = new DOMDocument();
792 $doc2->preserveWhiteSpace = false;
793 $doc2->formatOutput = true;
797 $conv_data['protocol'] = PROTOCOL_SPLITTED_CONV;
798 $conv_data['network'] = NETWORK_OSTATUS;
799 $conv_data['uri'] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
801 $inreplyto = $xpath->query('thr:in-reply-to', $entry);
802 if (is_object($inreplyto->item(0))) {
803 foreach ($inreplyto->item(0)->attributes as $attributes) {
804 if ($attributes->name == "ref") {
805 $conv_data['reply-to-uri'] = $attributes->textContent;
810 $conv_data['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
812 $conv = $xpath->query('ostatus:conversation', $entry);
813 if (is_object($conv->item(0))) {
814 foreach ($conv->item(0)->attributes as $attributes) {
815 if ($attributes->name == "ref") {
816 $conv_data['conversation-uri'] = $attributes->textContent;
818 if ($attributes->name == "href") {
819 $conv_data['conversation-href'] = $attributes->textContent;
824 if ($conversation != '') {
825 $conv_data['conversation-uri'] = $conversation;
828 if ($conversation_uri != '') {
829 $conv_data['conversation-uri'] = $conversation_uri;
832 $entry = $doc2->importNode($entry, true);
834 $doc2->appendChild($entry);
836 $conv_data['source'] = $doc2->saveXML();
838 $condition = ['item-uri' => $conv_data['uri'],'protocol' => PROTOCOL_OSTATUS_FEED];
839 if (DBA::exists('conversation', $condition)) {
840 logger('Delete deprecated entry for URI '.$conv_data['uri'], LOGGER_DEBUG);
841 DBA::delete('conversation', ['item-uri' => $conv_data['uri']]);
844 logger('Store conversation data for uri '.$conv_data['uri'], LOGGER_DEBUG);
845 Conversation::insert($conv_data);
850 * @brief Fetch the own post so that it can be stored later
852 * We want to store the original data for later processing.
853 * This function is meant for cases where we process a feed with multiple entries.
854 * In that case we need to fetch the single posts here.
856 * @param string $self The link to the self item
857 * @param array $item The item array
860 private static function fetchSelf($self, array &$item)
862 $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $self, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
863 if (DBA::exists('conversation', $condition)) {
864 logger('Conversation '.$item['uri'].' is already stored.', LOGGER_DEBUG);
868 $self_data = Network::curl($self);
870 if (!$self_data['success']) {
874 // We reformat the XML to make it better readable
875 $doc = new DOMDocument();
876 $doc->loadXML($self_data['body']);
877 $doc->preserveWhiteSpace = false;
878 $doc->formatOutput = true;
879 $xml = $doc->saveXML();
881 $item["protocol"] = PROTOCOL_OSTATUS_SALMON;
882 $item["source"] = $xml;
884 logger('Conversation '.$item['uri'].' is now fetched.', LOGGER_DEBUG);
888 * @brief Fetch related posts and processes them
890 * @param string $related The link to the related item
891 * @param string $related_uri The related item in "uri" format
892 * @param array $importer user record of the importing user
895 private static function fetchRelated($related, $related_uri, $importer)
897 $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
898 $conversation = DBA::selectFirst('conversation', ['source', 'protocol'], $condition);
899 if (DBA::isResult($conversation)) {
901 $xml = $conversation['source'];
902 if (self::process($xml, $importer, $contact, $hub, $stored, false)) {
903 logger('Got valid cached XML for URI '.$related_uri, LOGGER_DEBUG);
906 if ($conversation['protocol'] == PROTOCOL_OSTATUS_SALMON) {
907 logger('Delete invalid cached XML for URI '.$related_uri, LOGGER_DEBUG);
908 DBA::delete('conversation', ['item-uri' => $related_uri]);
913 $related_data = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
915 if (!$related_data['success']) {
921 if (stristr($related_data['header'], 'Content-Type: application/atom+xml')) {
922 logger('Directly fetched XML for URI '.$related_uri, LOGGER_DEBUG);
923 $xml = $related_data['body'];
927 $doc = new DOMDocument();
928 if (!@$doc->loadHTML($related_data['body'])) {
931 $xpath = new DOMXPath($doc);
935 $links = $xpath->query('//link');
937 foreach ($links as $link) {
938 $attribute = self::readAttributes($link);
939 if (($attribute['rel'] == 'alternate') && ($attribute['type'] == 'application/atom+xml')) {
940 $atom_file = $attribute['href'];
943 if ($atom_file != '') {
944 $related_atom = Network::curl($atom_file);
946 if ($related_atom['success']) {
947 logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG);
948 $xml = $related_atom['body'];
954 // Workaround for older GNU Social servers
955 if (($xml == '') && strstr($related, '/notice/')) {
956 $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related).'.atom');
958 if ($related_atom['success']) {
959 logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
960 $xml = $related_atom['body'];
964 // Even more worse workaround for GNU Social ;-)
966 $related_guess = OStatus::convertHref($related_uri);
967 $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom');
969 if ($related_atom['success']) {
970 logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
971 $xml = $related_atom['body'];
975 // Finally we take the data that we fetched from "ostatus:conversation"
977 $condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
978 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
979 if (DBA::isResult($conversation)) {
981 logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
982 $xml = $conversation['source'];
987 self::process($xml, $importer, $contact, $hub, $stored, false);
989 logger("XML couldn't be fetched for URI: ".$related_uri." - href: ".$related, LOGGER_DEBUG);
995 * @brief Processes the XML for a repeated post
997 * @param object $xpath The xpath object
998 * @param object $entry The xml entry that is processed
999 * @param array $item The item array
1000 * @param array $importer user record of the importing user
1002 * @return array with data from links
1004 private static function processRepeatedItem(DOMXPath $xpath, $entry, array &$item, array $importer)
1006 $activityobjects = $xpath->query('activity:object', $entry)->item(0);
1008 if (!is_object($activityobjects)) {
1014 $orig_uri = XML::getFirstNodeValue($xpath, 'atom:id/text()', $activityobjects);
1016 $links = $xpath->query("atom:link", $activityobjects);
1018 $link_data = self::processLinks($links, $item);
1021 $orig_body = XML::getFirstNodeValue($xpath, 'atom:content/text()', $activityobjects);
1022 $orig_created = XML::getFirstNodeValue($xpath, 'atom:published/text()', $activityobjects);
1023 $orig_edited = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $activityobjects);
1025 $orig_author = self::fetchAuthor($xpath, $activityobjects, $importer, $dummy, false);
1027 $item["author-name"] = $orig_author["author-name"];
1028 $item["author-link"] = $orig_author["author-link"];
1029 $item["author-id"] = $orig_author["author-id"];
1031 $item["body"] = HTML::toBBCode($orig_body);
1032 $item["created"] = $orig_created;
1033 $item["edited"] = $orig_edited;
1035 $item["uri"] = $orig_uri;
1037 $item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $activityobjects);
1039 $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $activityobjects);
1041 $inreplyto = $xpath->query('thr:in-reply-to', $activityobjects);
1042 if (is_object($inreplyto->item(0))) {
1043 foreach ($inreplyto->item(0)->attributes as $attributes) {
1044 if ($attributes->name == "ref") {
1045 $item["parent-uri"] = $attributes->textContent;
1054 * @brief Processes links in the XML
1056 * @param object $links The xml data that contain links
1057 * @param array $item The item array
1059 * @return array with data from the links
1061 private static function processLinks($links, array &$item)
1063 $link_data = ['add_body' => '', 'self' => ''];
1065 foreach ($links as $link) {
1066 $attribute = self::readAttributes($link);
1068 if (!empty($attribute['rel']) && !empty($attribute['href'])) {
1069 switch ($attribute['rel']) {
1071 $item["plink"] = $attribute['href'];
1072 if (($item["object-type"] == ACTIVITY_OBJ_QUESTION)
1073 || ($item["object-type"] == ACTIVITY_OBJ_EVENT)
1075 $item["body"] .= add_page_info($attribute['href']);
1078 case "ostatus:conversation":
1079 $link_data['conversation'] = $attribute['href'];
1080 $item['conversation-href'] = $link_data['conversation'];
1081 if (!isset($item['conversation-uri'])) {
1082 $item['conversation-uri'] = $item['conversation-href'];
1086 $filetype = strtolower(substr($attribute['type'], 0, strpos($attribute['type'], '/')));
1087 if ($filetype == 'image') {
1088 $link_data['add_body'] .= "\n[img]".$attribute['href'].'[/img]';
1090 if (!empty($item["attach"])) {
1091 $item["attach"] .= ',';
1093 $item["attach"] = '';
1095 if (!isset($attribute['length'])) {
1096 $attribute['length'] = "0";
1098 $item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.defaults($attribute, 'title', '').'"[/attach]';
1102 if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
1103 if (!isset($item["parent-uri"])) {
1104 $item["parent-uri"] = $attribute['href'];
1106 $link_data['related'] = $attribute['href'];
1108 $item["body"] .= add_page_info($attribute['href']);
1112 if (empty($item["plink"])) {
1113 $item["plink"] = $attribute['href'];
1115 $link_data['self'] = $attribute['href'];
1124 * @brief Create an url out of an uri
1126 * @param string $href URI in the format "parameter1:parameter1:..."
1128 * @return string URL in the format http(s)://....
1130 public static function convertHref($href)
1132 $elements = explode(":", $href);
1134 if ((count($elements) <= 2) || ($elements[0] != "tag")) {
1138 $server = explode(",", $elements[1]);
1139 $conversation = explode("=", $elements[2]);
1141 if ((count($elements) == 4) && ($elements[2] == "post")) {
1142 return "http://".$server[0]."/notice/".$elements[3];
1145 if ((count($conversation) != 2) || ($conversation[1] =="")) {
1148 if ($elements[3] == "objectType=thread") {
1149 return "http://".$server[0]."/conversation/".$conversation[1];
1151 return "http://".$server[0]."/notice/".$conversation[1];
1157 * @brief Checks if the current post is a reshare
1159 * @param array $item The item array of thw post
1161 * @return string The guid if the post is a reshare
1163 private static function getResharedGuid(array $item)
1165 $body = trim($item["body"]);
1167 // Skip if it isn't a pure repeated messages
1168 // Does it start with a share?
1169 if (strpos($body, "[share") > 0) {
1173 // Does it end with a share?
1174 if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
1178 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
1179 // Skip if there is no shared message in there
1180 if ($body == $attributes) {
1185 preg_match("/guid='(.*?)'/ism", $attributes, $matches);
1186 if (!empty($matches[1])) {
1187 $guid = $matches[1];
1190 preg_match('/guid="(.*?)"/ism', $attributes, $matches);
1191 if (!empty($matches[1])) {
1192 $guid = $matches[1];
1199 * @brief Cleans the body of a post if it contains picture links
1201 * @param string $body The body
1203 * @return string The cleaned body
1205 private static function formatPicturePost($body)
1207 $siteinfo = BBCode::getAttachedData($body);
1209 if (($siteinfo["type"] == "photo")) {
1210 if (isset($siteinfo["preview"])) {
1211 $preview = $siteinfo["preview"];
1213 $preview = $siteinfo["image"];
1216 // Is it a remote picture? Then make a smaller preview here
1217 $preview = proxy_url($preview, false, PROXY_SIZE_SMALL);
1219 // Is it a local picture? Then make it smaller here
1220 $preview = str_replace(["-0.jpg", "-0.png"], ["-2.jpg", "-2.png"], $preview);
1221 $preview = str_replace(["-1.jpg", "-1.png"], ["-2.jpg", "-2.png"], $preview);
1223 if (isset($siteinfo["url"])) {
1224 $url = $siteinfo["url"];
1226 $url = $siteinfo["image"];
1229 $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]";
1236 * @brief Adds the header elements to the XML document
1238 * @param object $doc XML document
1239 * @param array $owner Contact data of the poster
1240 * @param string $filter The related feed filter (activity, posts or comments)
1242 * @return object header root element
1244 private static function addHeader(DOMDocument $doc, array $owner, $filter)
1248 $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
1249 $doc->appendChild($root);
1251 $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
1252 $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
1253 $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
1254 $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
1255 $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
1256 $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
1257 $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
1258 $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
1262 case 'activity': $title = L10n::t('%s\'s timeline', $owner['name']); break;
1263 case 'posts' : $title = L10n::t('%s\'s posts' , $owner['name']); break;
1264 case 'comments': $title = L10n::t('%s\'s comments', $owner['name']); break;
1267 $attributes = ["uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION];
1268 XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
1269 XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]);
1270 XML::addElement($doc, $root, "title", $title);
1271 XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], Config::get('config', 'sitename')));
1272 XML::addElement($doc, $root, "logo", $owner["photo"]);
1273 XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
1275 $author = self::addAuthor($doc, $owner);
1276 $root->appendChild($author);
1278 $attributes = ["href" => $owner["url"], "rel" => "alternate", "type" => "text/html"];
1279 XML::addElement($doc, $root, "link", "", $attributes);
1281 /// @TODO We have to find out what this is
1282 /// $attributes = array("href" => System::baseUrl()."/sup",
1283 /// "rel" => "http://api.friendfeed.com/2008/03#sup",
1284 /// "type" => "application/json");
1285 /// XML::addElement($doc, $root, "link", "", $attributes);
1287 self::hublinks($doc, $root, $owner["nick"]);
1289 $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "salmon"];
1290 XML::addElement($doc, $root, "link", "", $attributes);
1292 $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies"];
1293 XML::addElement($doc, $root, "link", "", $attributes);
1295 $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"];
1296 XML::addElement($doc, $root, "link", "", $attributes);
1298 $attributes = ["href" => System::baseUrl() . "/api/statuses/user_timeline/" . $owner["nick"] . ".atom",
1299 "rel" => "self", "type" => "application/atom+xml"];
1300 XML::addElement($doc, $root, "link", "", $attributes);
1302 if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
1303 $condition = ['uid' => $owner['uid'], 'self' => false, 'pending' => false,
1304 'archive' => false, 'hidden' => false, 'blocked' => false];
1305 $members = DBA::count('contact', $condition);
1306 XML::addElement($doc, $root, "statusnet:group_info", "", ["member_count" => $members]);
1313 * @brief Add the link to the push hubs to the XML document
1315 * @param object $doc XML document
1316 * @param object $root XML root element where the hub links are added
1317 * @param object $nick nick
1320 public static function hublinks(DOMDocument $doc, $root, $nick)
1322 $h = System::baseUrl() . '/pubsubhubbub/'.$nick;
1323 XML::addElement($doc, $root, "link", "", ["href" => $h, "rel" => "hub"]);
1327 * @brief Adds attachment data to the XML document
1329 * @param object $doc XML document
1330 * @param object $root XML root element where the hub links are added
1331 * @param array $item Data of the item that is to be posted
1334 private static function getAttachment(DOMDocument $doc, $root, $item)
1337 $siteinfo = BBCode::getAttachedData($item["body"]);
1339 switch ($siteinfo["type"]) {
1341 $imgdata = Image::getInfoFromURL($siteinfo["image"]);
1343 $attributes = ["rel" => "enclosure",
1344 "href" => $siteinfo["image"],
1345 "type" => $imgdata["mime"],
1346 "length" => intval($imgdata["size"])];
1347 XML::addElement($doc, $root, "link", "", $attributes);
1351 $attributes = ["rel" => "enclosure",
1352 "href" => $siteinfo["url"],
1353 "type" => "text/html; charset=UTF-8",
1355 "title" => $siteinfo["title"]];
1356 XML::addElement($doc, $root, "link", "", $attributes);
1362 if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
1363 $imgdata = Image::getInfoFromURL($siteinfo["image"]);
1365 $attributes = ["rel" => "enclosure",
1366 "href" => $siteinfo["image"],
1367 "type" => $imgdata["mime"],
1368 "length" => intval($imgdata["size"])];
1370 XML::addElement($doc, $root, "link", "", $attributes);
1374 $arr = explode('[/attach],', $item['attach']);
1376 foreach ($arr as $r) {
1378 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
1380 $attributes = ["rel" => "enclosure",
1381 "href" => $matches[1],
1382 "type" => $matches[3]];
1384 if (intval($matches[2])) {
1385 $attributes["length"] = intval($matches[2]);
1387 if (trim($matches[4]) != "") {
1388 $attributes["title"] = trim($matches[4]);
1390 XML::addElement($doc, $root, "link", "", $attributes);
1397 * @brief Adds the author element to the XML document
1399 * @param object $doc XML document
1400 * @param array $owner Contact data of the poster
1401 * @param bool $show_profile Whether to show profile
1403 * @return object author element
1405 private static function addAuthor(DOMDocument $doc, array $owner, $show_profile = true)
1407 $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
1408 $author = $doc->createElement("author");
1409 XML::addElement($doc, $author, "id", $owner["url"]);
1410 if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
1411 XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
1413 XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
1415 XML::addElement($doc, $author, "uri", $owner["url"]);
1416 XML::addElement($doc, $author, "name", $owner["nick"]);
1417 XML::addElement($doc, $author, "email", $owner["addr"]);
1418 if ($show_profile) {
1419 XML::addElement($doc, $author, "summary", BBCode::convert($owner["about"], false, 7));
1422 $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $owner["url"]];
1423 XML::addElement($doc, $author, "link", "", $attributes);
1427 "type" => "image/jpeg", // To-Do?
1428 "media:width" => 175,
1429 "media:height" => 175,
1430 "href" => $owner["photo"]];
1431 XML::addElement($doc, $author, "link", "", $attributes);
1433 if (isset($owner["thumb"])) {
1436 "type" => "image/jpeg", // To-Do?
1437 "media:width" => 80,
1438 "media:height" => 80,
1439 "href" => $owner["thumb"]];
1440 XML::addElement($doc, $author, "link", "", $attributes);
1443 XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
1444 XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
1445 if ($show_profile) {
1446 XML::addElement($doc, $author, "poco:note", BBCode::convert($owner["about"], false, 7));
1448 if (trim($owner["location"]) != "") {
1449 $element = $doc->createElement("poco:address");
1450 XML::addElement($doc, $element, "poco:formatted", $owner["location"]);
1451 $author->appendChild($element);
1455 if (DBA::isResult($profile) && !$show_profile) {
1456 if (trim($profile["homepage"]) != "") {
1457 $urls = $doc->createElement("poco:urls");
1458 XML::addElement($doc, $urls, "poco:type", "homepage");
1459 XML::addElement($doc, $urls, "poco:value", $profile["homepage"]);
1460 XML::addElement($doc, $urls, "poco:primary", "true");
1461 $author->appendChild($urls);
1464 XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]);
1465 XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]);
1467 if ($profile["publish"]) {
1468 XML::addElement($doc, $author, "mastodon:scope", "public");
1476 * @TODO Picture attachments should look like this:
1477 * <a href="https://status.pirati.ca/attachment/572819" title="https://status.pirati.ca/file/heluecht-20151202T222602-rd3u49p.gif"
1478 * class="attachment thumbnail" id="attachment-572819" rel="nofollow external">https://status.pirati.ca/attachment/572819</a>
1482 * @brief Returns the given activity if present - otherwise returns the "post" activity
1484 * @param array $item Data of the item that is to be posted
1486 * @return string activity
1488 private static function constructVerb(array $item)
1490 if (!empty($item['verb'])) {
1491 return $item['verb'];
1494 return ACTIVITY_POST;
1498 * @brief Returns the given object type if present - otherwise returns the "note" object type
1500 * @param array $item Data of the item that is to be posted
1502 * @return string Object type
1504 private static function constructObjecttype(array $item)
1506 if (in_array($item['object-type'], [ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT]))
1507 return $item['object-type'];
1508 return ACTIVITY_OBJ_NOTE;
1512 * @brief Adds an entry element to the XML document
1514 * @param object $doc XML document
1515 * @param array $item Data of the item that is to be posted
1516 * @param array $owner Contact data of the poster
1517 * @param bool $toplevel optional default false
1519 * @return object Entry element
1521 private static function entry(DOMDocument $doc, array $item, array $owner, $toplevel = false)
1525 $repeated_guid = self::getResharedGuid($item);
1526 if ($repeated_guid != "") {
1527 $xml = self::reshareEntry($doc, $item, $owner, $repeated_guid, $toplevel);
1534 if ($item["verb"] == ACTIVITY_LIKE) {
1535 return self::likeEntry($doc, $item, $owner, $toplevel);
1536 } elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
1537 return self::followEntry($doc, $item, $owner, $toplevel);
1539 return self::noteEntry($doc, $item, $owner, $toplevel);
1544 * @brief Adds a source entry to the XML document
1546 * @param object $doc XML document
1547 * @param array $contact Array of the contact that is added
1549 * @return object Source element
1551 private static function sourceEntry(DOMDocument $doc, array $contact)
1553 $source = $doc->createElement("source");
1554 XML::addElement($doc, $source, "id", $contact["poll"]);
1555 XML::addElement($doc, $source, "title", $contact["name"]);
1556 XML::addElement($doc, $source, "link", "", ["rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]]);
1557 XML::addElement($doc, $source, "link", "", ["rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]]);
1558 XML::addElement($doc, $source, "icon", $contact["photo"]);
1559 XML::addElement($doc, $source, "updated", DateTimeFormat::utc($contact["success_update"]."+00:00", DateTimeFormat::ATOM));
1565 * @brief Fetches contact data from the contact or the gcontact table
1567 * @param string $url URL of the contact
1568 * @param array $owner Contact data of the poster
1570 * @return array Contact array
1572 private static function contactEntry($url, array $owner)
1575 "SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1",
1576 DBA::escape(normalise_link($url)),
1577 intval($owner["uid"])
1579 if (DBA::isResult($r)) {
1581 $contact["uid"] = -1;
1584 if (!DBA::isResult($r)) {
1586 "SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
1587 DBA::escape(normalise_link($url))
1589 if (DBA::isResult($r)) {
1591 $contact["uid"] = -1;
1592 $contact["success_update"] = $contact["updated"];
1596 if (!DBA::isResult($r)) {
1600 if (!isset($contact["poll"])) {
1601 $data = Probe::uri($url);
1602 $contact["poll"] = $data["poll"];
1604 if (!$contact["alias"]) {
1605 $contact["alias"] = $data["alias"];
1609 if (!isset($contact["alias"])) {
1610 $contact["alias"] = $contact["url"];
1613 $contact['account-type'] = $owner['account-type'];
1619 * @brief Adds an entry element with reshared content
1621 * @param object $doc XML document
1622 * @param array $item Data of the item that is to be posted
1623 * @param array $owner Contact data of the poster
1624 * @param string $repeated_guid guid
1625 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1627 * @return object Entry element
1629 private static function reshareEntry(DOMDocument $doc, array $item, array $owner, $repeated_guid, $toplevel)
1631 if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
1632 logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
1635 $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1637 $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false,
1638 'network' => [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS]];
1639 $repeated_item = Item::selectFirst([], $condition);
1640 if (!DBA::isResult($repeated_item)) {
1644 $contact = self::contactEntry($repeated_item['author-link'], $owner);
1646 $title = $owner["nick"]." repeated a notice by ".$contact["nick"];
1648 self::entryContent($doc, $entry, $item, $owner, $title, ACTIVITY_SHARE, false);
1650 $as_object = $doc->createElement("activity:object");
1652 XML::addElement($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
1654 self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
1656 $author = self::addAuthor($doc, $contact, false);
1657 $as_object->appendChild($author);
1659 $as_object2 = $doc->createElement("activity:object");
1661 XML::addElement($doc, $as_object2, "activity:object-type", self::constructObjecttype($repeated_item));
1663 $title = sprintf("New comment by %s", $contact["nick"]);
1665 self::entryContent($doc, $as_object2, $repeated_item, $owner, $title);
1667 $as_object->appendChild($as_object2);
1669 self::entryFooter($doc, $as_object, $item, $owner, false);
1671 $source = self::sourceEntry($doc, $contact);
1673 $as_object->appendChild($source);
1675 $entry->appendChild($as_object);
1677 self::entryFooter($doc, $entry, $item, $owner);
1683 * @brief Adds an entry element with a "like"
1685 * @param object $doc XML document
1686 * @param array $item Data of the item that is to be posted
1687 * @param array $owner Contact data of the poster
1688 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1690 * @return object Entry element with "like"
1692 private static function likeEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
1694 if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
1695 logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
1698 $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1700 $verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
1701 self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
1703 $as_object = $doc->createElement("activity:object");
1705 $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
1711 XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent));
1713 self::entryContent($doc, $as_object, $parent, $owner, "New entry");
1715 $entry->appendChild($as_object);
1717 self::entryFooter($doc, $entry, $item, $owner);
1723 * @brief Adds the person object element to the XML document
1725 * @param object $doc XML document
1726 * @param array $owner Contact data of the poster
1727 * @param array $contact Contact data of the target
1729 * @return object author element
1731 private static function addPersonObject(DOMDocument $doc, array $owner, array $contact)
1733 $object = $doc->createElement("activity:object");
1734 XML::addElement($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
1736 if ($contact['network'] == NETWORK_PHANTOM) {
1737 XML::addElement($doc, $object, "id", $contact['url']);
1741 XML::addElement($doc, $object, "id", $contact["alias"]);
1742 XML::addElement($doc, $object, "title", $contact["nick"]);
1744 $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $contact["url"]];
1745 XML::addElement($doc, $object, "link", "", $attributes);
1749 "type" => "image/jpeg", // To-Do?
1750 "media:width" => 175,
1751 "media:height" => 175,
1752 "href" => $contact["photo"]];
1753 XML::addElement($doc, $object, "link", "", $attributes);
1755 XML::addElement($doc, $object, "poco:preferredUsername", $contact["nick"]);
1756 XML::addElement($doc, $object, "poco:displayName", $contact["name"]);
1758 if (trim($contact["location"]) != "") {
1759 $element = $doc->createElement("poco:address");
1760 XML::addElement($doc, $element, "poco:formatted", $contact["location"]);
1761 $object->appendChild($element);
1768 * @brief Adds a follow/unfollow entry element
1770 * @param object $doc XML document
1771 * @param array $item Data of the follow/unfollow message
1772 * @param array $owner Contact data of the poster
1773 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1775 * @return object Entry element
1777 private static function followEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
1779 $item["id"] = $item["parent"] = 0;
1780 $item["created"] = $item["edited"] = date("c");
1781 $item["private"] = true;
1783 $contact = Probe::uri($item['follow']);
1785 if ($contact['alias'] == '') {
1786 $contact['alias'] = $contact["url"];
1788 $item['follow'] = $contact['alias'];
1792 "SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
1793 intval($owner['uid']),
1794 DBA::escape(normalise_link($contact["url"]))
1797 if (DBA::isResult($r)) {
1798 $connect_id = $r[0]['id'];
1803 if ($item['verb'] == ACTIVITY_FOLLOW) {
1804 $message = L10n::t('%s is now following %s.');
1805 $title = L10n::t('following');
1806 $action = "subscription";
1808 $message = L10n::t('%s stopped following %s.');
1809 $title = L10n::t('stopped following');
1810 $action = "unfollow";
1813 $item["uri"] = $item['parent-uri'] = $item['thr-parent']
1814 = 'tag:'.get_app()->get_hostname().
1815 ','.date('Y-m-d').':'.$action.':'.$owner['uid'].
1816 ':person:'.$connect_id.':'.$item['created'];
1818 $item["body"] = sprintf($message, $owner["nick"], $contact["nick"]);
1820 self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1822 self::entryContent($doc, $entry, $item, $owner, $title);
1824 $object = self::addPersonObject($doc, $owner, $contact);
1825 $entry->appendChild($object);
1827 self::entryFooter($doc, $entry, $item, $owner);
1833 * @brief Adds a regular entry element
1835 * @param object $doc XML document
1836 * @param array $item Data of the item that is to be posted
1837 * @param array $owner Contact data of the poster
1838 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1840 * @return object Entry element
1842 private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel)
1844 if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
1845 logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
1848 $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
1850 XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
1852 self::entryContent($doc, $entry, $item, $owner, $title);
1854 self::entryFooter($doc, $entry, $item, $owner);
1860 * @brief Adds a header element to the XML document
1862 * @param object $doc XML document
1863 * @param object $entry The entry element where the elements are added
1864 * @param array $owner Contact data of the poster
1865 * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)?
1867 * @return string The title for the element
1869 private static function entryHeader(DOMDocument $doc, &$entry, array $owner, array $item, $toplevel)
1871 /// @todo Check if this title stuff is really needed (I guess not)
1873 $entry = $doc->createElement("entry");
1874 $title = sprintf("New note by %s", $owner["nick"]);
1876 if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
1877 $contact = self::contactEntry($item['author-link'], $owner);
1878 $author = self::addAuthor($doc, $contact, false);
1879 $entry->appendChild($author);
1882 $entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
1884 $entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
1885 $entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
1886 $entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
1887 $entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
1888 $entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
1889 $entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
1890 $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
1891 $entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
1893 $author = self::addAuthor($doc, $owner);
1894 $entry->appendChild($author);
1896 $title = sprintf("New comment by %s", $owner["nick"]);
1902 * @brief Adds elements to the XML document
1904 * @param object $doc XML document
1905 * @param object $entry Entry element where the content is added
1906 * @param array $item Data of the item that is to be posted
1907 * @param array $owner Contact data of the poster
1908 * @param string $title Title for the post
1909 * @param string $verb The activity verb
1910 * @param bool $complete Add the "status_net" element?
1913 private static function entryContent(DOMDocument $doc, $entry, array $item, array $owner, $title, $verb = "", $complete = true)
1916 $verb = self::constructVerb($item);
1919 XML::addElement($doc, $entry, "id", $item["uri"]);
1920 XML::addElement($doc, $entry, "title", $title);
1922 $body = self::formatPicturePost($item['body']);
1924 if ($item['title'] != "") {
1925 $body = "[b]".$item['title']."[/b]\n\n".$body;
1928 $body = BBCode::convert($body, false, 7);
1930 XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
1932 XML::addElement($doc, $entry, "link", "", ["rel" => "alternate", "type" => "text/html",
1933 "href" => System::baseUrl()."/display/".$item["guid"]]
1936 if ($complete && ($item["id"] > 0)) {
1937 XML::addElement($doc, $entry, "status_net", "", ["notice_id" => $item["id"]]);
1940 XML::addElement($doc, $entry, "activity:verb", $verb);
1942 XML::addElement($doc, $entry, "published", DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM));
1943 XML::addElement($doc, $entry, "updated", DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM));
1947 * @brief Adds the elements at the foot of an entry to the XML document
1949 * @param object $doc XML document
1950 * @param object $entry The entry element where the elements are added
1951 * @param array $item Data of the item that is to be posted
1952 * @param array $owner Contact data of the poster
1953 * @param bool $complete default true
1956 private static function entryFooter(DOMDocument $doc, $entry, array $item, array $owner, $complete = true)
1960 if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
1961 $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item["parent"]]);
1962 $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
1964 $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $parent_item]);
1966 if (DBA::isResult($thrparent)) {
1967 $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
1968 $mentioned[$thrparent["owner-link"]] = $thrparent["owner-link"];
1969 $parent_plink = $thrparent["plink"];
1971 $mentioned[$parent["author-link"]] = $parent["author-link"];
1972 $mentioned[$parent["owner-link"]] = $parent["owner-link"];
1973 $parent_plink = System::baseUrl()."/display/".$parent["guid"];
1977 "ref" => $parent_item,
1978 "href" => $parent_plink];
1979 XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
1983 "href" => $parent_plink];
1984 XML::addElement($doc, $entry, "link", "", $attributes);
1987 if (intval($item["parent"]) > 0) {
1988 $conversation_href = System::baseUrl()."/display/".$owner["nick"]."/".$item["parent"];
1989 $conversation_uri = $conversation_href;
1991 if (isset($parent_item)) {
1992 $conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $parent_item]);
1993 if (DBA::isResult($conversation)) {
1994 if ($conversation['conversation-uri'] != '') {
1995 $conversation_uri = $conversation['conversation-uri'];
1997 if ($conversation['conversation-href'] != '') {
1998 $conversation_href = $conversation['conversation-href'];
2003 XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:conversation", "href" => $conversation_href]);
2006 "href" => $conversation_href,
2007 "local_id" => $item["parent"],
2008 "ref" => $conversation_uri];
2010 XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
2013 $tags = item::getFeedTags($item);
2016 foreach ($tags as $t) {
2018 $mentioned[$t[1]] = $t[1];
2023 // Make sure that mentions are accepted (GNU Social has problems with mixing HTTP and HTTPS)
2025 foreach ($mentioned as $mention) {
2026 $newmentions[str_replace("http://", "https://", $mention)] = str_replace("http://", "https://", $mention);
2027 $newmentions[str_replace("https://", "http://", $mention)] = str_replace("https://", "http://", $mention);
2029 $mentioned = $newmentions;
2031 foreach ($mentioned as $mention) {
2032 $condition = ['uid' => $owner['uid'], 'nurl' => normalise_link($mention)];
2033 $contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition);
2034 if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) ||
2035 ($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) {
2036 XML::addElement($doc, $entry, "link", "",
2038 "rel" => "mentioned",
2039 "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
2043 XML::addElement($doc, $entry, "link", "",
2045 "rel" => "mentioned",
2046 "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
2052 if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
2053 XML::addElement($doc, $entry, "link", "", [
2054 "rel" => "mentioned",
2055 "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
2056 "href" => $owner['url']
2060 if (!$item["private"]) {
2061 XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:attention",
2062 "href" => "http://activityschema.org/collection/public"]);
2063 XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
2064 "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
2065 "href" => "http://activityschema.org/collection/public"]);
2066 XML::addElement($doc, $entry, "mastodon:scope", "public");
2070 foreach ($tags as $t) {
2072 XML::addElement($doc, $entry, "category", "", ["term" => $t[2]]);
2077 self::getAttachment($doc, $entry, $item);
2079 if ($complete && ($item["id"] > 0)) {
2080 $app = $item["app"];
2085 $attributes = ["local_id" => $item["id"], "source" => $app];
2087 if (isset($parent["id"])) {
2088 $attributes["repeat_of"] = $parent["id"];
2091 if ($item["coord"] != "") {
2092 XML::addElement($doc, $entry, "georss:point", $item["coord"]);
2095 XML::addElement($doc, $entry, "statusnet:notice_info", "", $attributes);
2100 * Creates the XML feed for a given nickname
2102 * Supported filters:
2103 * - activity (default): all the public posts
2104 * - posts: all the public top-level posts
2105 * - comments: all the public replies
2107 * Updates the provided last_update parameter if the result comes from the
2108 * cache or it is empty
2110 * @brief Creates the XML feed for a given nickname
2112 * @param string $owner_nick Nickname of the feed owner
2113 * @param string $last_update Date of the last update
2114 * @param integer $max_items Number of maximum items to fetch
2115 * @param string $filter Feed items filter (activity, posts or comments)
2116 * @param boolean $nocache Wether to bypass caching
2118 * @return string XML feed
2120 public static function feed($owner_nick, &$last_update, $max_items = 300, $filter = 'activity', $nocache = false)
2122 $stamp = microtime(true);
2124 $owner = User::getOwnerDataByNick($owner_nick);
2129 $cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
2131 $previous_created = $last_update;
2133 // Don't cache when the last item was posted less then 15 minutes ago (Cache duration)
2134 if ((time() - strtotime($owner['last-item'])) < 15*60) {
2135 $result = Cache::get($cachekey);
2136 if (!$nocache && !is_null($result)) {
2137 logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
2138 $last_update = $result['last_update'];
2139 return $result['feed'];
2143 if (!strlen($last_update)) {
2144 $last_update = 'now -30 days';
2147 $check_date = DateTimeFormat::utc($last_update);
2148 $authorid = Contact::getIdForURL($owner["url"], 0, true);
2150 $condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
2151 AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
2152 $owner["uid"], $check_date, NETWORK_OSTATUS, NETWORK_DFRN];
2154 if ($filter === 'comments') {
2155 $condition[0] .= " AND `object-type` = ? ";
2156 $condition[] = ACTIVITY_OBJ_COMMENT;
2159 if ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY) {
2160 $condition[0] .= " AND `contact-id` = ? AND `author-id` = ?";
2161 $condition[] = $owner["id"];
2162 $condition[] = $authorid;
2165 $params = ['order' => ['created' => true], 'limit' => $max_items];
2167 if ($filter === 'posts') {
2168 $ret = Item::selectThread([], $condition, $params);
2170 $ret = Item::select([], $condition, $params);
2173 $items = Item::inArray($ret);
2175 $doc = new DOMDocument('1.0', 'utf-8');
2176 $doc->formatOutput = true;
2178 $root = self::addHeader($doc, $owner, $filter);
2180 foreach ($items as $item) {
2181 if (Config::get('system', 'ostatus_debug')) {
2182 $item['body'] .= '🍼';
2184 $entry = self::entry($doc, $item, $owner);
2185 $root->appendChild($entry);
2187 if ($last_update < $item['created']) {
2188 $last_update = $item['created'];
2192 $feeddata = trim($doc->saveXML());
2194 $msg = ['feed' => $feeddata, 'last_update' => $last_update];
2195 Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
2197 logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
2203 * @brief Creates the XML for a salmon message
2205 * @param array $item Data of the item that is to be posted
2206 * @param array $owner Contact data of the poster
2208 * @return string XML for the salmon
2210 public static function salmon(array $item, array $owner)
2212 $doc = new DOMDocument('1.0', 'utf-8');
2213 $doc->formatOutput = true;
2215 if (Config::get('system', 'ostatus_debug')) {
2216 $item['body'] .= '🐟';
2219 $entry = self::entry($doc, $item, $owner, true);
2221 $doc->appendChild($entry);
2223 return trim($doc->saveXML());