]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/OStatus.php
"FetchPoCo" added
[friendica.git] / src / Protocol / OStatus.php
index 180ef4e37293acc4d9df9df72dc8159a64623b8c..a63b12731dd3556cb56dcf3650b3cd76d7aca244 100644 (file)
@@ -11,11 +11,13 @@ use Friendica\Content\Text\HTML;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Core\Logger;
 use Friendica\Core\Lock;
+use Friendica\Core\Logger;
+use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\GContact;
@@ -23,7 +25,9 @@ use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
+use Friendica\Protocol\ActivityNamespace;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
@@ -72,7 +76,7 @@ class OStatus
                }
                $author["author-id"] = Contact::getIdForURL($author["author-link"]);
 
-               $author['contact-id'] = defaults($contact, 'id', $author['author-id']);
+               $author['contact-id'] = ($contact['id'] ?? 0) ?: $author['author-id'];
 
                $contact = [];
 
@@ -113,6 +117,8 @@ class OStatus
                if (DBA::isResult($contact)) {
                        if ($contact['blocked']) {
                                $contact['id'] = -1;
+                       } elseif (!empty(APContact::getByURL($contact['url'], false))) {
+                               ActivityPub\Receiver::switchContact($contact['id'], $importer['uid'], $contact['url']);
                        }
                        $author["contact-id"] = $contact["id"];
                }
@@ -257,14 +263,14 @@ class OStatus
                @$doc->loadXML($xml);
 
                $xpath = new DOMXPath($doc);
-               $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
-               $xpath->registerNamespace('thr', NAMESPACE_THREAD);
-               $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
-               $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
-               $xpath->registerNamespace('media', NAMESPACE_MEDIA);
-               $xpath->registerNamespace('poco', NAMESPACE_POCO);
-               $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
-               $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
+               $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
+               $xpath->registerNamespace('thr', ActivityNamespace::THREAD);
+               $xpath->registerNamespace('georss', ActivityNamespace::GEORSS);
+               $xpath->registerNamespace('activity', ActivityNamespace::ACTIVITY);
+               $xpath->registerNamespace('media', ActivityNamespace::MEDIA);
+               $xpath->registerNamespace('poco', ActivityNamespace::POCO);
+               $xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
+               $xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
 
                $contact = ["id" => 0];
 
@@ -338,14 +344,14 @@ class OStatus
                @$doc->loadXML($xml);
 
                $xpath = new DOMXPath($doc);
-               $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
-               $xpath->registerNamespace('thr', NAMESPACE_THREAD);
-               $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
-               $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
-               $xpath->registerNamespace('media', NAMESPACE_MEDIA);
-               $xpath->registerNamespace('poco', NAMESPACE_POCO);
-               $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
-               $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
+               $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
+               $xpath->registerNamespace('thr', ActivityNamespace::THREAD);
+               $xpath->registerNamespace('georss', ActivityNamespace::GEORSS);
+               $xpath->registerNamespace('activity', ActivityNamespace::ACTIVITY);
+               $xpath->registerNamespace('media', ActivityNamespace::MEDIA);
+               $xpath->registerNamespace('poco', ActivityNamespace::POCO);
+               $xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
+               $xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
 
                $hub = "";
                $hub_items = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0);
@@ -424,12 +430,12 @@ class OStatus
                        $item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $entry);
 
                        // Delete a message
-                       if (in_array($item["verb"], ['qvitter-delete-notice', ACTIVITY_DELETE, 'delete'])) {
+                       if (in_array($item["verb"], ['qvitter-delete-notice', Activity::DELETE, 'delete'])) {
                                self::deleteNotice($item);
                                continue;
                        }
 
-                       if (in_array($item["verb"], [NAMESPACE_OSTATUS."/unfavorite", ACTIVITY_UNFAVORITE])) {
+                       if (in_array($item["verb"], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) {
                                // Ignore "Unfavorite" message
                                Logger::log("Ignore unfavorite message ".print_r($item, true), Logger::DEBUG);
                                continue;
@@ -443,7 +449,7 @@ class OStatus
                                Logger::log('Processing post with URI '.$item["uri"].' for user '.$importer["uid"].'.', Logger::DEBUG);
                        }
 
-                       if ($item["verb"] == ACTIVITY_JOIN) {
+                       if ($item["verb"] == Activity::JOIN) {
                                // ignore "Join" messages
                                Logger::log("Ignore join message ".print_r($item, true), Logger::DEBUG);
                                continue;
@@ -455,29 +461,29 @@ class OStatus
                                continue;
                        }
 
-                       if ($item["verb"] == ACTIVITY_FOLLOW) {
+                       if ($item["verb"] == Activity::FOLLOW) {
                                Contact::addRelationship($importer, $contact, $item);
                                continue;
                        }
 
-                       if ($item["verb"] == NAMESPACE_OSTATUS."/unfollow") {
+                       if ($item["verb"] == Activity::O_UNFOLLOW) {
                                $dummy = null;
                                Contact::removeFollower($importer, $contact, $item, $dummy);
                                continue;
                        }
 
-                       if ($item["verb"] == ACTIVITY_FAVORITE) {
+                       if ($item["verb"] == Activity::FAVORITE) {
                                $orig_uri = $xpath->query("activity:object/atom:id", $entry)->item(0)->nodeValue;
                                Logger::log("Favorite ".$orig_uri." ".print_r($item, true));
 
-                               $item["verb"] = ACTIVITY_LIKE;
+                               $item["verb"] = Activity::LIKE;
                                $item["parent-uri"] = $orig_uri;
                                $item["gravity"] = GRAVITY_ACTIVITY;
-                               $item["object-type"] = ACTIVITY_OBJ_NOTE;
+                               $item["object-type"] = Activity\ObjectType::NOTE;
                        }
 
                        // http://activitystrea.ms/schema/1.0/rsvp-yes
-                       if (!in_array($item["verb"], [ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE])) {
+                       if (!in_array($item["verb"], [Activity::POST, Activity::LIKE, Activity::SHARE])) {
                                Logger::log("Unhandled verb ".$item["verb"]." ".print_r($item, true), Logger::DEBUG);
                        }
 
@@ -486,10 +492,11 @@ class OStatus
                        if ($initialize && (count(self::$itemlist) > 0)) {
                                if (self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']) {
                                        // We will import it everytime, when it is started by our contacts
-                                       $valid = !empty(self::$itemlist[0]['contact-id']);
+                                       $valid = Contact::isSharingByURL(self::$itemlist[0]['author-link'], self::$itemlist[0]['uid']);
+
                                        if (!$valid) {
                                                // If not, then it depends on this setting
-                                               $valid = !Config::get('system', 'ostatus_full_threads');
+                                               $valid = ((self::$itemlist[0]['uid'] == 0) || !PConfig::get(self::$itemlist[0]['uid'], 'system', 'accept_only_sharer', false));
                                                if ($valid) {
                                                        Logger::log("Item with uri ".self::$itemlist[0]['uri']." will be imported due to the system settings.", Logger::DEBUG);
                                                }
@@ -499,9 +506,9 @@ class OStatus
                                        if ($valid) {
                                                // Never post a thread when the only interaction by our contact was a like
                                                $valid = false;
-                                               $verbs = [ACTIVITY_POST, ACTIVITY_SHARE];
+                                               $verbs = [Activity::POST, Activity::SHARE];
                                                foreach (self::$itemlist as $item) {
-                                                       if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
+                                                       if (in_array($item['verb'], $verbs) && Contact::isSharingByURL($item['author-link'], $item['uid'])) {
                                                                $valid = true;
                                                        }
                                                }
@@ -587,10 +594,10 @@ class OStatus
        {
                $item["body"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
                $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry);
-               if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
+               if (($item["object-type"] == Activity\ObjectType::BOOKMARK) || ($item["object-type"] == Activity\ObjectType::EVENT)) {
                        $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
                        $item["body"] = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
-               } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
+               } elseif ($item["object-type"] == Activity\ObjectType::QUESTION) {
                        $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
                }
 
@@ -671,7 +678,7 @@ class OStatus
                        }
                }
                // Is it a repeated post?
-               if (($repeat_of != "") || ($item["verb"] == ACTIVITY_SHARE)) {
+               if (($repeat_of != "") || ($item["verb"] == Activity::SHARE)) {
                        $link_data = self::processRepeatedItem($xpath, $entry, $item, $importer);
                        if (!empty($link_data['add_body'])) {
                                $add_body .= $link_data['add_body'];
@@ -686,7 +693,7 @@ class OStatus
                }
 
                // Mastodon Content Warning
-               if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
+               if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
                        $clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
                        if (!empty($clear_text)) {
                                $item['content-warning'] = HTML::toBBCode($clear_text);
@@ -738,7 +745,7 @@ class OStatus
 
                self::$conv_list[$conversation] = true;
 
-               $curlResult = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
@@ -798,9 +805,9 @@ class OStatus
                @$doc->loadXML($xml);
 
                $xpath = new DOMXPath($doc);
-               $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
-               $xpath->registerNamespace('thr', NAMESPACE_THREAD);
-               $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
+               $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
+               $xpath->registerNamespace('thr', ActivityNamespace::THREAD);
+               $xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
 
                $entries = $xpath->query('/atom:feed/atom:entry');
 
@@ -931,7 +938,7 @@ class OStatus
                }
 
                $stored = false;
-               $curlResult = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
@@ -1062,7 +1069,7 @@ class OStatus
                $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $activityobject);
 
                // Mastodon Content Warning
-               if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $activityobject)) {
+               if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $activityobject)) {
                        $clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $activityobject);
                        if (!empty($clear_text)) {
                                $item['content-warning'] = HTML::toBBCode($clear_text);
@@ -1100,8 +1107,8 @@ class OStatus
                                switch ($attribute['rel']) {
                                        case "alternate":
                                                $item["plink"] = $attribute['href'];
-                                               if (($item["object-type"] == ACTIVITY_OBJ_QUESTION)
-                                                       || ($item["object-type"] == ACTIVITY_OBJ_EVENT)
+                                               if (($item["object-type"] == Activity\ObjectType::QUESTION)
+                                                       || ($item["object-type"] == Activity\ObjectType::EVENT)
                                                ) {
                                                        $item["body"] .= add_page_info($attribute['href']);
                                                }
@@ -1126,11 +1133,11 @@ class OStatus
                                                        if (!isset($attribute['length'])) {
                                                                $attribute['length'] = "0";
                                                        }
-                                                       $item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.defaults($attribute, 'title', '').'"[/attach]';
+                                                       $item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.($attribute['title'] ?? '') .'"[/attach]';
                                                }
                                                break;
                                        case "related":
-                                               if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
+                                               if ($item["object-type"] != Activity\ObjectType::BOOKMARK) {
                                                        if (!isset($item["parent-uri"])) {
                                                                $item["parent-uri"] = $attribute['href'];
                                                        }
@@ -1192,37 +1199,12 @@ class OStatus
         */
        private static function getResharedGuid(array $item)
        {
-               $body = trim($item["body"]);
-
-               // Skip if it isn't a pure repeated messages
-               // Does it start with a share?
-               if (strpos($body, "[share") > 0) {
-                       return "";
-               }
-
-               // Does it end with a share?
-               if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
-                       return "";
-               }
-
-               $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
-               // Skip if there is no shared message in there
-               if ($body == $attributes) {
-                       return false;
-               }
-
-               $guid = "";
-               preg_match("/guid='(.*?)'/ism", $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $guid = $matches[1];
+               $reshared = Item::getShareArray($item);
+               if (empty($reshared['guid']) || !empty($reshared['comment'])) {
+                       return '';
                }
 
-               preg_match('/guid="(.*?)"/ism', $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $guid = $matches[1];
-               }
-
-               return $guid;
+               return $reshared['guid'];
        }
 
        /**
@@ -1276,17 +1258,17 @@ class OStatus
         */
        private static function addHeader(DOMDocument $doc, array $owner, $filter, $feed_mode = false)
        {
-               $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
+               $root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
                $doc->appendChild($root);
 
-               $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
-               $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
-               $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
-               $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
-               $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
-               $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
-               $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
-               $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
+               $root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+               $root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+               $root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+               $root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+               $root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+               $root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+               $root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
+               $root->setAttribute("xmlns:mastodon", ActivityNamespace::MASTODON);
 
                $title = '';
                $selfUri = '/feed/' . $owner["nick"] . '/';
@@ -1383,7 +1365,7 @@ class OStatus
                switch ($siteinfo["type"]) {
                        case 'photo':
                                if (!empty($siteinfo["image"])) {
-                                       $imgdata = Image::getInfoFromURL($siteinfo["image"]);
+                                       $imgdata = Images::getInfoFromURLCached($siteinfo["image"]);
                                        if ($imgdata) {
                                                $attributes = ["rel" => "enclosure",
                                                                "href" => $siteinfo["image"],
@@ -1398,7 +1380,8 @@ class OStatus
                                                "href" => $siteinfo["url"],
                                                "type" => "text/html; charset=UTF-8",
                                                "length" => "",
-                                               "title" => defaults($siteinfo, "title", $siteinfo["url"])];
+                                               "title" => ($siteinfo["title"] ?? '') ?: $siteinfo["url"],
+                               ];
                                XML::addElement($doc, $root, "link", "", $attributes);
                                break;
                        default:
@@ -1406,7 +1389,7 @@ class OStatus
                }
 
                if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
-                       $imgdata = Image::getInfoFromURL($siteinfo["image"]);
+                       $imgdata = Images::getInfoFromURLCached($siteinfo["image"]);
                        if ($imgdata) {
                                $attributes = ["rel" => "enclosure",
                                                "href" => $siteinfo["image"],
@@ -1455,9 +1438,9 @@ class OStatus
                $author = $doc->createElement("author");
                XML::addElement($doc, $author, "id", $owner["url"]);
                if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
-                       XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
+                       XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::GROUP);
                } else {
-                       XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
+                       XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::PERSON);
                }
                XML::addElement($doc, $author, "uri", $owner["url"]);
                XML::addElement($doc, $author, "name", $owner["nick"]);
@@ -1508,7 +1491,7 @@ class OStatus
                                $author->appendChild($urls);
                        }
 
-                       XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]);
+                       XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl() . "/profile/" . $owner["nick"] . "/contacts/followers"]);
                        XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]);
 
                        if ($profile["publish"]) {
@@ -1538,7 +1521,7 @@ class OStatus
                        return $item['verb'];
                }
 
-               return ACTIVITY_POST;
+               return Activity::POST;
        }
 
        /**
@@ -1550,11 +1533,11 @@ class OStatus
         */
        private static function constructObjecttype(array $item)
        {
-               if (!empty($item['object-type']) && in_array($item['object-type'], [ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT])) {
+               if (!empty($item['object-type']) && in_array($item['object-type'], [Activity\ObjectType::NOTE, Activity\ObjectType::COMMENT])) {
                        return $item['object-type'];
                }
 
-               return ACTIVITY_OBJ_NOTE;
+               return Activity\ObjectType::NOTE;
        }
 
        /**
@@ -1583,9 +1566,9 @@ class OStatus
                        return $xml;
                }
 
-               if ($item["verb"] == ACTIVITY_LIKE) {
+               if ($item["verb"] == Activity::LIKE) {
                        return self::likeEntry($doc, $item, $owner, $toplevel);
-               } elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
+               } elseif (in_array($item["verb"], [Activity::FOLLOW, Activity::O_UNFOLLOW])) {
                        return self::followEntry($doc, $item, $owner, $toplevel);
                } else {
                        return self::noteEntry($doc, $item, $owner, $toplevel, $feed_mode);
@@ -1699,11 +1682,11 @@ class OStatus
 
                $title = $owner["nick"]." repeated a notice by ".$contact["nick"];
 
-               self::entryContent($doc, $entry, $item, $owner, $title, ACTIVITY_SHARE, false);
+               self::entryContent($doc, $entry, $item, $owner, $title, Activity::SHARE, false);
 
                $as_object = $doc->createElement("activity:object");
 
-               XML::addElement($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
+               XML::addElement($doc, $as_object, "activity:object-type", ActivityNamespace::ACTIVITY_SCHEMA . "activity");
 
                self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
 
@@ -1753,7 +1736,7 @@ class OStatus
 
                $entry = self::entryHeader($doc, $owner, $item, $toplevel);
 
-               $verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
+               $verb = ActivityNamespace::ACTIVITY_SCHEMA . "favorite";
                self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
 
                $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
@@ -1784,7 +1767,7 @@ class OStatus
        private static function addPersonObject(DOMDocument $doc, array $owner, array $contact)
        {
                $object = $doc->createElement("activity:object");
-               XML::addElement($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
+               XML::addElement($doc, $object, "activity:object-type", Activity\ObjectType::PERSON);
 
                if ($contact['network'] == Protocol::PHANTOM) {
                        XML::addElement($doc, $object, "id", $contact['url']);
@@ -1852,7 +1835,7 @@ class OStatus
                        $connect_id = 0;
                }
 
-               if ($item['verb'] == ACTIVITY_FOLLOW) {
+               if ($item['verb'] == Activity::FOLLOW) {
                        $message = L10n::t('%s is now following %s.');
                        $title = L10n::t('following');
                        $action = "subscription";
@@ -1912,7 +1895,7 @@ class OStatus
 
                $entry = self::entryHeader($doc, $owner, $item, $toplevel);
 
-               XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
+               XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE);
 
                self::entryContent($doc, $entry, $item, $owner, $title, '', true, $feed_mode);
 
@@ -1944,16 +1927,16 @@ class OStatus
                                $entry->appendChild($author);
                        }
                } else {
-                       $entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
+                       $entry = $doc->createElementNS(ActivityNamespace::ATOM1, "entry");
 
-                       $entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
-                       $entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
-                       $entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
-                       $entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
-                       $entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
-                       $entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
-                       $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
-                       $entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
+                       $entry->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+                       $entry->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+                       $entry->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+                       $entry->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+                       $entry->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+                       $entry->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+                       $entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
+                       $entry->setAttribute("xmlns:mastodon", ActivityNamespace::MASTODON);
 
                        $author = self::addAuthor($doc, $owner);
                        $entry->appendChild($author);
@@ -2105,14 +2088,14 @@ class OStatus
                                XML::addElement($doc, $entry, "link", "",
                                        [
                                                "rel" => "mentioned",
-                                               "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
+                                               "ostatus:object-type" => Activity\ObjectType::GROUP,
                                                "href" => $mention]
                                );
                        } else {
                                XML::addElement($doc, $entry, "link", "",
                                        [
                                                "rel" => "mentioned",
-                                               "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
+                                               "ostatus:object-type" => Activity\ObjectType::PERSON,
                                                "href" => $mention]
                                );
                        }
@@ -2219,13 +2202,13 @@ class OStatus
                $check_date = DateTimeFormat::utc($last_update);
                $authorid = Contact::getIdForURL($owner["url"], 0, true);
 
-               $condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
+               $condition = ["`uid` = ? AND `received` > ? AND NOT `deleted`
                        AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
                        $owner["uid"], $check_date, Protocol::OSTATUS, Protocol::DFRN];
 
                if ($filter === 'comments') {
                        $condition[0] .= " AND `object-type` = ? ";
-                       $condition[] = ACTIVITY_OBJ_COMMENT;
+                       $condition[] = Activity\ObjectType::COMMENT;
                }
 
                if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
@@ -2234,7 +2217,7 @@ class OStatus
                        $condition[] = $authorid;
                }
 
-               $params = ['order' => ['created' => true], 'limit' => $max_items];
+               $params = ['order' => ['received' => true], 'limit' => $max_items];
 
                if ($filter === 'posts') {
                        $ret = Item::selectThread([], $condition, $params);
@@ -2297,4 +2280,19 @@ class OStatus
 
                return trim($doc->saveXML());
        }
+
+       /**
+        * Checks if the given contact url does support OStatus
+        *
+        * @param string  $url    profile url
+        * @param boolean $update Update the profile
+        * @return boolean
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function isSupportedByContactUrl($url, $update = false)
+       {
+               $probe = Probe::uri($url, Protocol::OSTATUS, 0, !$update);
+               return $probe['network'] == Protocol::OSTATUS;
+       }
 }