]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/OStatus.php
OStatus: Avoid a notice
[friendica.git] / src / Protocol / OStatus.php
index afd406f972f27cc154771e0d3cf3e78c5d99e02d..bf3a6ef9d597021227c21bd57b6096dbd592c842 100644 (file)
@@ -1,31 +1,44 @@
 <?php
 /**
- * @file src/Protocol/OStatus.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Protocol;
 
 use DOMDocument;
 use DOMXPath;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Core\Cache;
-use Friendica\Core\Config;
-use Friendica\Core\PConfig;
-use Friendica\Core\L10n;
+use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
-use Friendica\Core\Lock;
 use Friendica\Core\Protocol;
-use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\GContact;
-use Friendica\Model\APContact;
 use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
-use Friendica\Object\Image;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
@@ -35,7 +48,7 @@ require_once 'mod/share.php';
 require_once 'include/api.php';
 
 /**
- * @brief This class contain functions for the OStatus protocol
+ * This class contain functions for the OStatus protocol
  */
 class OStatus
 {
@@ -43,7 +56,7 @@ class OStatus
        private static $conv_list = [];
 
        /**
-        * @brief Fetches author data
+        * Fetches author data
         *
         * @param DOMXPath $xpath     The xpath object
         * @param object   $context   The xml context of the author details
@@ -234,7 +247,7 @@ class OStatus
                        $gcid = GContact::update($contact);
 
                        GContact::link($gcid, $contact["uid"], $contact["id"]);
-               } elseif ($contact["network"] != Protocol::DFRN) {
+               } elseif (empty($contact["network"]) || ($contact["network"] != Protocol::DFRN)) {
                        $contact = [];
                }
 
@@ -242,7 +255,7 @@ class OStatus
        }
 
        /**
-        * @brief Fetches author data from a given XML string
+        * Fetches author data from a given XML string
         *
         * @param string $xml      The XML
         * @param array  $importer user record of the importing user
@@ -261,14 +274,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];
 
@@ -279,7 +292,7 @@ class OStatus
        }
 
        /**
-        * @brief Read attributes from element
+        * Read attributes from element
         *
         * @param object $element Element object
         *
@@ -297,7 +310,7 @@ class OStatus
        }
 
        /**
-        * @brief Imports an XML string containing OStatus elements
+        * Imports an XML string containing OStatus elements
         *
         * @param string $xml      The XML
         * @param array  $importer user record of the importing user
@@ -313,7 +326,7 @@ class OStatus
        }
 
        /**
-        * @brief Internal feed processing
+        * Internal feed processing
         *
         * @param string  $xml        The XML
         * @param array   $importer   user record of the importing user
@@ -342,14 +355,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);
@@ -428,12 +441,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;
@@ -447,7 +460,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;
@@ -459,29 +472,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);
                        }
 
@@ -494,7 +507,7 @@ class OStatus
 
                                        if (!$valid) {
                                                // If not, then it depends on this setting
-                                               $valid = ((self::$itemlist[0]['uid'] == 0) || !PConfig::get(self::$itemlist[0]['uid'], 'system', 'accept_only_sharer', false));
+                                               $valid = ((self::$itemlist[0]['uid'] == 0) || !DI::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);
                                                }
@@ -504,7 +517,7 @@ 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 (in_array($item['verb'], $verbs) && Contact::isSharingByURL($item['author-link'], $item['uid'])) {
                                                                $valid = true;
@@ -539,9 +552,9 @@ class OStatus
                                                        Logger::log("Item with uri ".$item["uri"]." is from a blocked contact.", Logger::DEBUG);
                                                } else {
                                                        // We are having duplicated entries. Hopefully this solves it.
-                                                       if (Lock::acquire('ostatus_process_item_insert')) {
+                                                       if (DI::lock()->acquire('ostatus_process_item_insert')) {
                                                                $ret = Item::insert($item);
-                                                               Lock::release('ostatus_process_item_insert');
+                                                               DI::lock()->release('ostatus_process_item_insert');
                                                                Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret);
                                                        } else {
                                                                $ret = Item::insert($item);
@@ -572,13 +585,13 @@ class OStatus
                        return;
                }
 
-               Item::delete($condition);
+               Item::markForDeletion($condition);
 
                Logger::log('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
        }
 
        /**
-        * @brief Processes the XML for a post
+        * Processes the XML for a post
         *
         * @param DOMXPath $xpath    The xpath object
         * @param object   $entry    The xml entry that is processed
@@ -592,10 +605,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);
                }
 
@@ -646,7 +659,7 @@ class OStatus
                                                        $item['tag'] = '';
                                                }
 
-                                               $item['tag'] .= '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']' . $term . '[/url]';
+                                               $item['tag'] .= '#[url=' . DI::baseUrl() . '/search?tag=' . $term . ']' . $term . '[/url]';
                                        }
                                }
                        }
@@ -676,7 +689,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'];
@@ -691,7 +704,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);
@@ -727,7 +740,7 @@ class OStatus
        }
 
        /**
-        * @brief Fetch the conversation for posts
+        * Fetch the conversation for posts
         *
         * @param string $conversation     The link to the conversation
         * @param string $conversation_uri The conversation in "uri" format
@@ -789,7 +802,7 @@ class OStatus
        }
 
        /**
-        * @brief Store a feed in several conversation entries
+        * Store a feed in several conversation entries
         *
         * @param string $xml              The feed
         * @param string $conversation     conversation
@@ -803,9 +816,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');
 
@@ -870,7 +883,7 @@ class OStatus
        }
 
        /**
-        * @brief Fetch the own post so that it can be stored later
+        * Fetch the own post so that it can be stored later
         *
         * We want to store the original data for later processing.
         * This function is meant for cases where we process a feed with multiple entries.
@@ -909,7 +922,7 @@ class OStatus
        }
 
        /**
-        * @brief Fetch related posts and processes them
+        * Fetch related posts and processes them
         *
         * @param string $related     The link to the related item
         * @param string $related_uri The related item in "uri" format
@@ -1018,7 +1031,7 @@ class OStatus
        }
 
        /**
-        * @brief Processes the XML for a repeated post
+        * Processes the XML for a repeated post
         *
         * @param DOMXPath $xpath    The xpath object
         * @param object   $entry    The xml entry that is processed
@@ -1067,7 +1080,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);
@@ -1087,7 +1100,7 @@ class OStatus
        }
 
        /**
-        * @brief Processes links in the XML
+        * Processes links in the XML
         *
         * @param object $links The xml data that contain links
         * @param array  $item  The item array
@@ -1105,8 +1118,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']);
                                                }
@@ -1135,7 +1148,7 @@ class OStatus
                                                }
                                                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'];
                                                        }
@@ -1157,7 +1170,7 @@ class OStatus
        }
 
        /**
-        * @brief Create an url out of an uri
+        * Create an url out of an uri
         *
         * @param string $href URI in the format "parameter1:parameter1:..."
         *
@@ -1189,7 +1202,7 @@ class OStatus
        }
 
        /**
-        * @brief Checks if the current post is a reshare
+        * Checks if the current post is a reshare
         *
         * @param array $item The item array of thw post
         *
@@ -1197,41 +1210,16 @@ 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'];
        }
 
        /**
-        * @brief Cleans the body of a post if it contains picture links
+        * Cleans the body of a post if it contains picture links
         *
         * @param string $body The body
         *
@@ -1269,7 +1257,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds the header elements to the XML document
+        * Adds the header elements to the XML document
         *
         * @param DOMDocument $doc       XML document
         * @param array       $owner     Contact data of the poster
@@ -1281,30 +1269,30 @@ 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"] . '/';
                switch ($filter) {
                        case 'activity':
-                               $title = L10n::t('%s\'s timeline', $owner['name']);
+                               $title = DI::l10n()->t('%s\'s timeline', $owner['name']);
                                $selfUri .= $filter;
                                break;
                        case 'posts':
-                               $title = L10n::t('%s\'s posts', $owner['name']);
+                               $title = DI::l10n()->t('%s\'s posts', $owner['name']);
                                break;
                        case 'comments':
-                               $title = L10n::t('%s\'s comments', $owner['name']);
+                               $title = DI::l10n()->t('%s\'s comments', $owner['name']);
                                $selfUri .= $filter;
                                break;
                }
@@ -1315,9 +1303,9 @@ class OStatus
 
                $attributes = ["uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION];
                XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
-               XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]);
+               XML::addElement($doc, $root, "id", DI::baseUrl() . "/profile/" . $owner["nick"]);
                XML::addElement($doc, $root, "title", $title);
-               XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], Config::get('config', 'sitename')));
+               XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], DI::config()->get('config', 'sitename')));
                XML::addElement($doc, $root, "logo", $owner["photo"]);
                XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
 
@@ -1328,23 +1316,23 @@ class OStatus
                XML::addElement($doc, $root, "link", "", $attributes);
 
                /// @TODO We have to find out what this is
-               /// $attributes = array("href" => System::baseUrl()."/sup",
+               /// $attributes = array("href" => DI::baseUrl()."/sup",
                ///             "rel" => "http://api.friendfeed.com/2008/03#sup",
                ///             "type" => "application/json");
                /// XML::addElement($doc, $root, "link", "", $attributes);
 
                self::hublinks($doc, $root, $owner["nick"]);
 
-               $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "salmon"];
+               $attributes = ["href" => DI::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "salmon"];
                XML::addElement($doc, $root, "link", "", $attributes);
 
-               $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies"];
+               $attributes = ["href" => DI::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies"];
                XML::addElement($doc, $root, "link", "", $attributes);
 
-               $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"];
+               $attributes = ["href" => DI::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"];
                XML::addElement($doc, $root, "link", "", $attributes);
 
-               $attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"];
+               $attributes = ["href" => DI::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"];
                XML::addElement($doc, $root, "link", "", $attributes);
 
                if ($owner['account-type'] == Contact::TYPE_COMMUNITY) {
@@ -1358,7 +1346,7 @@ class OStatus
        }
 
        /**
-        * @brief Add the link to the push hubs to the XML document
+        * Add the link to the push hubs to the XML document
         *
         * @param DOMDocument $doc  XML document
         * @param object      $root XML root element where the hub links are added
@@ -1368,12 +1356,12 @@ class OStatus
         */
        public static function hublinks(DOMDocument $doc, $root, $nick)
        {
-               $h = System::baseUrl() . '/pubsubhubbub/'.$nick;
+               $h = DI::baseUrl() . '/pubsubhubbub/'.$nick;
                XML::addElement($doc, $root, "link", "", ["href" => $h, "rel" => "hub"]);
        }
 
        /**
-        * @brief Adds attachment data to the XML document
+        * Adds attachment data to the XML document
         *
         * @param DOMDocument $doc  XML document
         * @param object      $root XML root element where the hub links are added
@@ -1388,7 +1376,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"],
@@ -1411,8 +1399,8 @@ class OStatus
                                break;
                }
 
-               if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
-                       $imgdata = Image::getInfoFromURL($siteinfo["image"]);
+               if (!DI::config()->get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
+                       $imgdata = Images::getInfoFromURLCached($siteinfo["image"]);
                        if ($imgdata) {
                                $attributes = ["rel" => "enclosure",
                                                "href" => $siteinfo["image"],
@@ -1446,7 +1434,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds the author element to the XML document
+        * Adds the author element to the XML document
         *
         * @param DOMDocument $doc          XML document
         * @param array       $owner        Contact data of the poster
@@ -1457,13 +1445,13 @@ class OStatus
         */
        private static function addAuthor(DOMDocument $doc, array $owner, $show_profile = true)
        {
-               $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
+               $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid']]);
                $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"]);
@@ -1514,7 +1502,7 @@ class OStatus
                                $author->appendChild($urls);
                        }
 
-                       XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl() . "/profile/" . $owner["nick"] . "/contacts/followers"]);
+                       XML::addElement($doc, $author, "followers", "", ["url" => DI::baseUrl() . "/profile/" . $owner["nick"] . "/contacts/followers"]);
                        XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]);
 
                        if ($profile["publish"]) {
@@ -1532,7 +1520,7 @@ class OStatus
         */
 
        /**
-        * @brief Returns the given activity if present - otherwise returns the "post" activity
+        * Returns the given activity if present - otherwise returns the "post" activity
         *
         * @param array $item Data of the item that is to be posted
         *
@@ -1544,11 +1532,11 @@ class OStatus
                        return $item['verb'];
                }
 
-               return ACTIVITY_POST;
+               return Activity::POST;
        }
 
        /**
-        * @brief Returns the given object type if present - otherwise returns the "note" object type
+        * Returns the given object type if present - otherwise returns the "note" object type
         *
         * @param array $item Data of the item that is to be posted
         *
@@ -1556,15 +1544,15 @@ 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;
        }
 
        /**
-        * @brief Adds an entry element to the XML document
+        * Adds an entry element to the XML document
         *
         * @param DOMDocument $doc       XML document
         * @param array       $item      Data of the item that is to be posted
@@ -1589,9 +1577,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);
@@ -1599,7 +1587,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds a source entry to the XML document
+        * Adds a source entry to the XML document
         *
         * @param DOMDocument $doc     XML document
         * @param array       $contact Array of the contact that is added
@@ -1621,7 +1609,7 @@ class OStatus
        }
 
        /**
-        * @brief Fetches contact data from the contact or the gcontact table
+        * Fetches contact data from the contact or the gcontact table
         *
         * @param string $url   URL of the contact
         * @param array  $owner Contact data of the poster
@@ -1674,7 +1662,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds an entry element with reshared content
+        * Adds an entry element with reshared content
         *
         * @param DOMDocument $doc           XML document
         * @param array       $item          Data of the item that is to be posted
@@ -1694,7 +1682,7 @@ class OStatus
 
                $entry = self::entryHeader($doc, $owner, $item, $toplevel);
 
-               $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false,
+               $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]];
                $repeated_item = Item::selectFirst([], $condition);
                if (!DBA::isResult($repeated_item)) {
@@ -1705,11 +1693,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);
 
@@ -1740,7 +1728,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds an entry element with a "like"
+        * Adds an entry element with a "like"
         *
         * @param DOMDocument $doc      XML document
         * @param array       $item     Data of the item that is to be posted
@@ -1759,7 +1747,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"]]);
@@ -1779,7 +1767,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds the person object element to the XML document
+        * Adds the person object element to the XML document
         *
         * @param DOMDocument $doc     XML document
         * @param array       $owner   Contact data of the poster
@@ -1790,7 +1778,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']);
@@ -1824,7 +1812,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds a follow/unfollow entry element
+        * Adds a follow/unfollow entry element
         *
         * @param DOMDocument $doc      XML document
         * @param array       $item     Data of the follow/unfollow message
@@ -1839,7 +1827,7 @@ class OStatus
        {
                $item["id"] = $item["parent"] = 0;
                $item["created"] = $item["edited"] = date("c");
-               $item["private"] = true;
+               $item["private"] = Item::PRIVATE;
 
                $contact = Probe::uri($item['follow']);
 
@@ -1858,18 +1846,18 @@ class OStatus
                        $connect_id = 0;
                }
 
-               if ($item['verb'] == ACTIVITY_FOLLOW) {
-                       $message = L10n::t('%s is now following %s.');
-                       $title = L10n::t('following');
+               if ($item['verb'] == Activity::FOLLOW) {
+                       $message = DI::l10n()->t('%s is now following %s.');
+                       $title = DI::l10n()->t('following');
                        $action = "subscription";
                } else {
-                       $message = L10n::t('%s stopped following %s.');
-                       $title = L10n::t('stopped following');
+                       $message = DI::l10n()->t('%s stopped following %s.');
+                       $title = DI::l10n()->t('stopped following');
                        $action = "unfollow";
                }
 
                $item["uri"] = $item['parent-uri'] = $item['thr-parent']
-                               = 'tag:'.get_app()->getHostName().
+                               = 'tag:' . DI::baseUrl()->getHostname().
                                ','.date('Y-m-d').':'.$action.':'.$owner['uid'].
                                ':person:'.$connect_id.':'.$item['created'];
 
@@ -1888,7 +1876,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds a regular entry element
+        * Adds a regular entry element
         *
         * @param DOMDocument $doc       XML document
         * @param array       $item      Data of the item that is to be posted
@@ -1918,7 +1906,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);
 
@@ -1928,7 +1916,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds a header element to the XML document
+        * Adds a header element to the XML document
         *
         * @param DOMDocument $doc      XML document
         * @param array       $owner    Contact data of the poster
@@ -1950,16 +1938,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);
@@ -1969,7 +1957,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds elements to the XML document
+        * Adds elements to the XML document
         *
         * @param DOMDocument $doc       XML document
         * @param \DOMElement $entry     Entry element where the content is added
@@ -2002,7 +1990,7 @@ class OStatus
                XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
 
                XML::addElement($doc, $entry, "link", "", ["rel" => "alternate", "type" => "text/html",
-                                                               "href" => System::baseUrl()."/display/".$item["guid"]]
+                                                               "href" => DI::baseUrl()."/display/".$item["guid"]]
                );
 
                if (!$feed_mode && $complete && ($item["id"] > 0)) {
@@ -2018,7 +2006,7 @@ class OStatus
        }
 
        /**
-        * @brief Adds the elements at the foot of an entry to the XML document
+        * Adds the elements at the foot of an entry to the XML document
         *
         * @param DOMDocument $doc       XML document
         * @param object      $entry     The entry element where the elements are added
@@ -2046,7 +2034,7 @@ class OStatus
                        } else {
                                $mentioned[$parent["author-link"]] = $parent["author-link"];
                                $mentioned[$parent["owner-link"]] = $parent["owner-link"];
-                               $parent_plink = System::baseUrl()."/display/".$parent["guid"];
+                               $parent_plink = DI::baseUrl()."/display/".$parent["guid"];
                        }
 
                        $attributes = [
@@ -2111,14 +2099,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]
                                );
                        }
@@ -2132,7 +2120,7 @@ class OStatus
                        ]);
                }
 
-               if (!$item["private"] && !$feed_mode) {
+               if (($item['private'] != Item::PRIVATE) && !$feed_mode) {
                        XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:attention",
                                                                        "href" => "http://activityschema.org/collection/public"]);
                        XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
@@ -2182,8 +2170,6 @@ class OStatus
         * Updates the provided last_update parameter if the result comes from the
         * cache or it is empty
         *
-        * @brief Creates the XML feed for a given nickname
-        *
         * @param string  $owner_nick  Nickname of the feed owner
         * @param string  $last_update Date of the last update
         * @param integer $max_items   Number of maximum items to fetch
@@ -2210,7 +2196,7 @@ class OStatus
 
                // Don't cache when the last item was posted less then 15 minutes ago (Cache duration)
                if ((time() - strtotime($owner['last-item'])) < 15*60) {
-                       $result = Cache::get($cachekey);
+                       $result = DI::cache()->get($cachekey);
                        if (!$nocache && !is_null($result)) {
                                Logger::log('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', Logger::DEBUG);
                                $last_update = $result['last_update'];
@@ -2226,12 +2212,12 @@ class OStatus
                $authorid = Contact::getIdForURL($owner["url"], 0, true);
 
                $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];
+                       AND `private` != ? AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
+                       $owner["uid"], $check_date, Item::PRIVATE, 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) {
@@ -2256,7 +2242,7 @@ class OStatus
                $root = self::addHeader($doc, $owner, $filter, $feed_mode);
 
                foreach ($items as $item) {
-                       if (Config::get('system', 'ostatus_debug')) {
+                       if (DI::config()->get('system', 'ostatus_debug')) {
                                $item['body'] .= '🍼';
                        }
 
@@ -2271,7 +2257,7 @@ class OStatus
                $feeddata = trim($doc->saveXML());
 
                $msg = ['feed' => $feeddata, 'last_update' => $last_update];
-               Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
+               DI::cache()->set($cachekey, $msg, Duration::QUARTER_HOUR);
 
                Logger::log('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, Logger::DEBUG);
 
@@ -2279,7 +2265,7 @@ class OStatus
        }
 
        /**
-        * @brief Creates the XML for a salmon message
+        * Creates the XML for a salmon message
         *
         * @param array $item  Data of the item that is to be posted
         * @param array $owner Contact data of the poster
@@ -2293,7 +2279,7 @@ class OStatus
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
 
-               if (Config::get('system', 'ostatus_debug')) {
+               if (DI::config()->get('system', 'ostatus_debug')) {
                        $item['body'] .= '🐟';
                }