]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Remove deprecated code
[friendica.git] / src / Protocol / Diaspora.php
index f0fcddc9a8a6287936f712a40c0ef5c7c20fce2a..bff56d5af39bbe9864bde864364758432709bdde 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * @file src/Protocol/diaspora.php
- * @brief The implementation of the diaspora protocol
+ * The implementation of the diaspora protocol
  *
  * The new protocol is described here: http://diaspora.github.io/diaspora_federation/index.html
  * This implementation here interprets the old and the new protocol and sends the new one.
@@ -13,19 +13,16 @@ namespace Friendica\Protocol;
 use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\Markdown;
-use Friendica\Core\Cache;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
+use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
-use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\GContact;
-use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\ItemDeliveryData;
 use Friendica\Model\Mail;
@@ -42,7 +39,7 @@ use Friendica\Worker\Delivery;
 use SimpleXMLElement;
 
 /**
- * @brief This class contain functions to create and send Diaspora XML files
+ * This class contain functions to create and send Diaspora XML files
  *
  */
 class Diaspora
@@ -78,7 +75,7 @@ class Diaspora
        }
 
        /**
-        * @brief Return a list of relay servers
+        * Return a list of relay servers
         *
         * The list contains not only the official relays but also servers that we serve directly
         *
@@ -93,7 +90,7 @@ class Diaspora
                $serverlist = [];
 
                // Fetching relay servers
-               $serverdata = Config::get("system", "relay_server");
+               $serverdata = DI::config()->get("system", "relay_server");
 
                if (!empty($serverdata)) {
                        $servers = explode(",", $serverdata);
@@ -102,7 +99,7 @@ class Diaspora
                        }
                }
 
-               if (Config::get("system", "relay_directly", false)) {
+               if (DI::config()->get("system", "relay_directly", false)) {
                        // We distribute our stuff based on the parent to ensure that the thread will be complete
                        $parent = Item::selectFirst(['parent'], ['id' => $item_id]);
                        if (!DBA::isResult($parent)) {
@@ -144,7 +141,7 @@ class Diaspora
                // Now we are collecting all relay contacts
                foreach ($serverlist as $server_url) {
                        // We don't send messages to ourselves
-                       if (Strings::compareLink($server_url, System::baseUrl())) {
+                       if (Strings::compareLink($server_url, DI::baseUrl())) {
                                continue;
                        }
                        $contact = self::getRelayContact($server_url);
@@ -168,14 +165,14 @@ class Diaspora
        }
 
        /**
-        * @brief Return a contact for a given server address or creates a dummy entry
+        * Return a contact for a given server address or creates a dummy entry
         *
         * @param string $server_url The url of the server
         * @param array $fields Fieldlist
         * @return array with the contact
         * @throws \Exception
         */
-       private static function getRelayContact(string $server_url, array $fields = ['batch', 'id', 'name', 'network', 'protocol', 'archive', 'blocked'])
+       private static function getRelayContact(string $server_url, array $fields = ['batch', 'id', 'url', 'name', 'network', 'protocol', 'archive', 'blocked'])
        {
                // Fetch the relay contact
                $condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
@@ -201,7 +198,7 @@ class Diaspora
        }
 
        /**
-        * @brief Update or insert a relay contact
+        * Update or insert a relay contact
         *
         * @param string $server_url     The url of the server
         * @param array  $network_fields Optional network specific fields
@@ -235,7 +232,7 @@ class Diaspora
        }
 
        /**
-        * @brief Return a list of participating contacts for a thread
+        * Return a list of participating contacts for a thread
         *
         * This is used for the participation feature.
         * One of the parameters is a contact array.
@@ -249,7 +246,7 @@ class Diaspora
         */
        public static function participantsForThread($thread, array $contacts)
        {
-               $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`,
+               $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`,
                                `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
                                INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid`
                                INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`
@@ -287,7 +284,7 @@ class Diaspora
        }
 
        /**
-        * @brief repairs a signature that was double encoded
+        * repairs a signature that was double encoded
         *
         * The function is unused at the moment. It was copied from the old implementation.
         *
@@ -318,7 +315,7 @@ class Diaspora
        }
 
        /**
-        * @brief verify the envelope and return the verified data
+        * verify the envelope and return the verified data
         *
         * @param string $envelope The magic envelope
         *
@@ -383,7 +380,7 @@ class Diaspora
        }
 
        /**
-        * @brief encrypts data via AES
+        * encrypts data via AES
         *
         * @param string $key  The AES key
         * @param string $iv   The IV (is used for CBC encoding)
@@ -397,7 +394,7 @@ class Diaspora
        }
 
        /**
-        * @brief decrypts data via AES
+        * decrypts data via AES
         *
         * @param string $key       The AES key
         * @param string $iv        The IV (is used for CBC encoding)
@@ -411,10 +408,10 @@ class Diaspora
        }
 
        /**
-        * @brief: Decodes incoming Diaspora message in the new format
+        * Decodes incoming Diaspora message in the new format
         *
-        * @param array   $importer Array of the importer user
         * @param string  $raw      raw post message
+        * @param string  $privKey   The private key of the importer
         * @param boolean $no_exit  Don't do an http exit on error
         *
         * @return array
@@ -424,7 +421,7 @@ class Diaspora
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function decodeRaw(array $importer, $raw, $no_exit = false)
+       public static function decodeRaw(string $raw, string $privKey = '', bool $no_exit = false)
        {
                $data = json_decode($raw);
 
@@ -434,7 +431,7 @@ class Diaspora
                        $ciphertext = base64_decode($data->encrypted_magic_envelope);
 
                        $outer_key_bundle = '';
-                       @openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $importer['prvkey']);
+                       @openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $privKey);
                        $j_outer_key_bundle = json_decode($outer_key_bundle);
 
                        if (!is_object($j_outer_key_bundle)) {
@@ -465,7 +462,7 @@ class Diaspora
                        }
                }
 
-               $base = $basedom->children(NAMESPACE_SALMON_ME);
+               $base = $basedom->children(ActivityNamespace::SALMON_ME);
 
                // Not sure if this cleaning is needed
                $data = str_replace([" ", "\t", "\r", "\n"], ["", "", "", ""], $base->data);
@@ -517,10 +514,10 @@ class Diaspora
        }
 
        /**
-        * @brief: Decodes incoming Diaspora message in the deprecated format
+        * Decodes incoming Diaspora message in the deprecated format
         *
-        * @param array  $importer Array of the importer user
         * @param string $xml      urldecoded Diaspora salmon
+        * @param string $privKey  The private key of the importer
         *
         * @return array
         * 'message' -> decoded Diaspora XML message
@@ -529,7 +526,7 @@ class Diaspora
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function decode(array $importer, $xml)
+       public static function decode(string $xml, string $privKey = '')
        {
                $public = false;
                $basedom = XML::parseString($xml);
@@ -548,7 +545,7 @@ class Diaspora
                        $author_link = str_replace('acct:', '', $children->header->author_id);
                } else {
                        // This happens with posts from a relais
-                       if (!$importer) {
+                       if (empty($privKey)) {
                                Logger::log("This is no private post in the old format", Logger::DEBUG);
                                return false;
                        }
@@ -559,7 +556,7 @@ class Diaspora
                        $ciphertext = base64_decode($encrypted_header->ciphertext);
 
                        $outer_key_bundle = '';
-                       openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $importer['prvkey']);
+                       openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $privKey);
 
                        $j_outer_key_bundle = json_decode($outer_key_bundle);
 
@@ -577,7 +574,7 @@ class Diaspora
                        $author_link = str_replace('acct:', '', $idom->author_id);
                }
 
-               $dom = $basedom->children(NAMESPACE_SALMON_ME);
+               $dom = $basedom->children(ActivityNamespace::SALMON_ME);
 
                // figure out where in the DOM tree our data is hiding
 
@@ -660,7 +657,7 @@ class Diaspora
 
 
        /**
-        * @brief Dispatches public messages and find the fitting receivers
+        * Dispatches public messages and find the fitting receivers
         *
         * @param array $msg The post that will be dispatched
         *
@@ -670,7 +667,7 @@ class Diaspora
         */
        public static function dispatchPublic($msg)
        {
-               $enabled = intval(Config::get("system", "diaspora_enabled"));
+               $enabled = intval(DI::config()->get("system", "diaspora_enabled"));
                if (!$enabled) {
                        Logger::log("diaspora is disabled");
                        return false;
@@ -688,7 +685,7 @@ class Diaspora
        }
 
        /**
-        * @brief Dispatches the different message types to the different functions
+        * Dispatches the different message types to the different functions
         *
         * @param array            $importer Array of the importer user
         * @param array            $msg      The post that will be dispatched
@@ -793,7 +790,7 @@ class Diaspora
        }
 
        /**
-        * @brief Checks if a posting is valid and fetches the data fields.
+        * Checks if a posting is valid and fetches the data fields.
         *
         * This function does not only check the signature.
         * It also does the conversion between the old and the new diaspora format.
@@ -946,7 +943,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches the public key for a given handle
+        * Fetches the public key for a given handle
         *
         * @param string $handle The handle
         *
@@ -969,7 +966,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches data for a given handle
+        * Fetches data for a given handle
         *
         * @param string $handle The handle
         * @param boolean $update true = always update, false = never update, null = update when not found or outdated
@@ -1023,7 +1020,7 @@ class Diaspora
        }
 
        /**
-        * @brief Updates the fcontact table
+        * Updates the fcontact table
         *
         * @param array $arr The fcontact data
         * @throws \Exception
@@ -1044,7 +1041,7 @@ class Diaspora
        }
 
        /**
-        * @brief get a handle (user@domain.tld) from a given contact id
+        * get a handle (user@domain.tld) from a given contact id
         *
         * @param int $contact_id  The id in the contact table
         * @param int $pcontact_id The id in the contact table (Used for the public contact)
@@ -1091,7 +1088,7 @@ class Diaspora
        }
 
        /**
-        * @brief get a url (scheme://domain.tld/u/user) from a given Diaspora*
+        * get a url (scheme://domain.tld/u/user) from a given Diaspora*
         * fcontact guid
         *
         * @param mixed $fcontact_guid Hexadecimal string guid
@@ -1117,7 +1114,7 @@ class Diaspora
        }
 
        /**
-        * @brief Get a contact id for a given handle
+        * Get a contact id for a given handle
         *
         * @todo  Move to Friendica\Model\Contact
         *
@@ -1131,12 +1128,6 @@ class Diaspora
        private static function contactByHandle($uid, $handle)
        {
                $cid = Contact::getIdForURL($handle, $uid);
-               if (!$cid) {
-                       $handle_parts = explode("@", $handle);
-                       $nurl_sql = "%%://" . $handle_parts[1] . "%%/profile/" . $handle_parts[0];
-                       $cid = Contact::getIdForURL($nurl_sql, $uid);
-               }
-
                if (!$cid) {
                        Logger::log("Haven't found a contact for user " . $uid . " and handle " . $handle, Logger::DEBUG);
                        return false;
@@ -1167,7 +1158,7 @@ class Diaspora
        }
 
        /**
-        * @brief Check if posting is allowed for this contact
+        * Check if posting is allowed for this contact
         *
         * @param array $importer   Array of the importer user
         * @param array $contact    The contact that is checked
@@ -1220,7 +1211,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches the contact id for a handle and checks if posting is allowed
+        * Fetches the contact id for a handle and checks if posting is allowed
         *
         * @param array  $importer   Array of the importer user
         * @param string $handle     The checked handle in the format user@domain.tld
@@ -1252,7 +1243,7 @@ class Diaspora
        }
 
        /**
-        * @brief Does the message already exists on the system?
+        * Does the message already exists on the system?
         *
         * @param int    $uid  The user id
         * @param string $guid The guid of the message
@@ -1272,7 +1263,7 @@ class Diaspora
        }
 
        /**
-        * @brief Checks for links to posts in a message
+        * Checks for links to posts in a message
         *
         * @param array $item The item array
         * @return void
@@ -1298,7 +1289,7 @@ class Diaspora
        }
 
        /**
-        * @brief Checks for relative /people/* links in an item body to match local
+        * Checks for relative /people/* links in an item body to match local
         * contacts or prepends the remote host taken from the author link.
         *
         * @param string $body        The item body to replace links from
@@ -1334,7 +1325,7 @@ class Diaspora
        }
 
        /**
-        * @brief sub function of "fetchGuid" which checks for links in messages
+        * sub function of "fetchGuid" which checks for links in messages
         *
         * @param array $match array containing a link that has to be checked for a message link
         * @param array $item  The item array
@@ -1350,7 +1341,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches an item with a given guid from a given server
+        * Fetches an item with a given guid from a given server
         *
         * @param string $guid   the message guid
         * @param string $server The server address
@@ -1385,7 +1376,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches a message from a server
+        * Fetches a message from a server
         *
         * @param string $guid   message guid
         * @param string $server The url of the server
@@ -1464,7 +1455,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches an item with a given URL
+        * Fetches an item with a given URL
         *
         * @param string $url the message url
         *
@@ -1497,7 +1488,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches the item record of a given guid
+        * Fetches the item record of a given guid
         *
         * @param int    $uid     The user id
         * @param string $guid    message guid
@@ -1541,7 +1532,7 @@ class Diaspora
        }
 
        /**
-        * @brief returns contact details
+        * returns contact details
         *
         * @param array $def_contact The default contact if the person isn't found
         * @param array $person      The record of the person
@@ -1568,7 +1559,7 @@ class Diaspora
        }
 
        /**
-        * @brief Is the profile a hubzilla profile?
+        * Is the profile a hubzilla profile?
         *
         * @param string $url The profile link
         *
@@ -1580,7 +1571,7 @@ class Diaspora
        }
 
        /**
-        * @brief Generate a post link with a given handle and message guid
+        * Generate a post link with a given handle and message guid
         *
         * @param string $addr        The user handle
         * @param string $guid        message guid
@@ -1608,7 +1599,7 @@ class Diaspora
                }
 
                if (self::isRedmatrix($contact["url"])) {
-                       return $contact["url"] . "/?f=&mid=" . $guid;
+                       return $contact["url"] . "/?mid=" . $guid;
                }
 
                if ($parent_guid != '') {
@@ -1619,7 +1610,7 @@ class Diaspora
        }
 
        /**
-        * @brief Receives account migration
+        * Receives account migration
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -1682,7 +1673,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes an account deletion
+        * Processes an account deletion
         *
         * @param object $data The message object
         *
@@ -1706,7 +1697,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetch the uri from our database if we already have this item (maybe from ourselves)
+        * Fetch the uri from our database if we already have this item (maybe from ourselves)
         *
         * @param string  $author    Author handle
         * @param string  $guid      Message guid
@@ -1735,7 +1726,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetch the guid from our database with a given uri
+        * Fetch the guid from our database with a given uri
         *
         * @param string $uri Message uri
         * @param string $uid Author handle
@@ -1754,7 +1745,7 @@ class Diaspora
        }
 
        /**
-        * @brief Find the best importer for a comment, like, ...
+        * Find the best importer for a comment, like, ...
         *
         * @param string $guid The guid of the item
         *
@@ -1775,7 +1766,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes an incoming comment
+        * Processes an incoming comment
         *
         * @param array  $importer Array of the importer user
         * @param string $sender   The sender of the message
@@ -1845,7 +1836,7 @@ class Diaspora
                $datarray["guid"] = $guid;
                $datarray["uri"] = self::getUriFromGuid($author, $guid);
 
-               $datarray["verb"] = ACTIVITY_POST;
+               $datarray["verb"] = Activity::POST;
                $datarray["gravity"] = GRAVITY_COMMENT;
 
                if ($thr_uri != "") {
@@ -1854,7 +1845,7 @@ class Diaspora
                        $datarray["parent-uri"] = $parent_item["uri"];
                }
 
-               $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
+               $datarray["object-type"] = Activity\ObjectType::COMMENT;
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
                $datarray["source"] = $xml;
@@ -1892,7 +1883,7 @@ class Diaspora
        }
 
        /**
-        * @brief processes and stores private messages
+        * processes and stores private messages
         *
         * @param array  $importer     Array of the importer user
         * @param array  $contact      The contact of the message
@@ -1952,7 +1943,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes new private messages (answers to private messages are processed elsewhere)
+        * Processes new private messages (answers to private messages are processed elsewhere)
         *
         * @param array  $importer Array of the importer user
         * @param array  $msg      Array of the processed message, author handle and key
@@ -2011,7 +2002,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes "like" messages
+        * Processes "like" messages
         *
         * @param array  $importer Array of the importer user
         * @param string $sender   The sender of the message
@@ -2062,9 +2053,9 @@ class Diaspora
                // "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
                // We would accept this anyhow.
                if ($positive == "true") {
-                       $verb = ACTIVITY_LIKE;
+                       $verb = Activity::LIKE;
                } else {
-                       $verb = ACTIVITY_DISLIKE;
+                       $verb = Activity::DISLIKE;
                }
 
                $datarray = [];
@@ -2085,7 +2076,7 @@ class Diaspora
                $datarray["gravity"] = GRAVITY_ACTIVITY;
                $datarray["parent-uri"] = $parent_item["uri"];
 
-               $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
+               $datarray["object-type"] = Activity\ObjectType::NOTE;
 
                $datarray["body"] = $verb;
 
@@ -2123,7 +2114,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes private messages
+        * Processes private messages
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2184,7 +2175,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes participations - unsupported by now
+        * Processes participations - unsupported by now
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2248,7 +2239,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes photos - unneeded
+        * Processes photos - unneeded
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2263,7 +2254,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes poll participations - unssupported
+        * Processes poll participations - unssupported
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2277,7 +2268,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes incoming profile updates
+        * Processes incoming profile updates
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2375,7 +2366,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes incoming friend requests
+        * Processes incoming friend requests
         *
         * @param array $importer Array of the importer user
         * @param array $contact  The contact that send the request
@@ -2394,7 +2385,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes incoming sharing notification
+        * Processes incoming sharing notification
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2475,101 +2466,30 @@ class Diaspora
                        return false;
                }
 
-               $batch = (($ret["batch"]) ? $ret["batch"] : implode("/", array_slice(explode("/", $ret["url"]), 0, 3))."/receive/public");
-
-               q(
-                       "INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
-                       VALUES (%d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d)",
-                       intval($importer["uid"]),
-                       DBA::escape($ret["network"]),
-                       DBA::escape($ret["addr"]),
-                       DateTimeFormat::utcNow(),
-                       DBA::escape($ret["url"]),
-                       DBA::escape(Strings::normaliseLink($ret["url"])),
-                       DBA::escape($batch),
-                       DBA::escape($ret["name"]),
-                       DBA::escape($ret["nick"]),
-                       DBA::escape($ret["photo"]),
-                       DBA::escape($ret["pubkey"]),
-                       DBA::escape($ret["notify"]),
-                       DBA::escape($ret["poll"]),
-                       1,
-                       2
-               );
-
-               // find the contact record we just created
-
-               $contact_record = self::contactByHandle($importer["uid"], $author);
-
-               if (!$contact_record) {
-                       Logger::log("unable to locate newly created contact record.");
-                       return;
-               }
-
-               Logger::log("Author ".$author." was added as contact number ".$contact_record["id"].".", Logger::DEBUG);
-
-               Group::addMember(User::getDefaultGroup($importer['uid'], $ret["network"]), $contact_record['id']);
-
-               Contact::updateAvatar($ret["photo"], $importer['uid'], $contact_record["id"], true);
-
-               if (in_array($importer["page-flags"], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])) {
-                       Logger::log("Sending intra message for author ".$author.".", Logger::DEBUG);
-
-                       $hash = Strings::getRandomHex().(string)time();   // Generate a confirm_key
-
-                       q(
-                               "INSERT INTO `intro` (`uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
-                               VALUES (%d, %d, %d, %d, '%s', '%s', '%s')",
-                               intval($importer["uid"]),
-                               intval($contact_record["id"]),
-                               0,
-                               0,
-                               DBA::escape(L10n::t("Sharing notification from Diaspora network")),
-                               DBA::escape($hash),
-                               DBA::escape(DateTimeFormat::utcNow())
-                       );
+               $cid = Contact::getIdForURL($ret['url'], $importer['uid']);
+               if (!empty($cid)) {
+                       $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
                } else {
-                       // automatic friend approval
-
-                       Logger::log("Does an automatic friend approval for author ".$author.".", Logger::DEBUG);
+                       $contact = [];
+               }
 
-                       Contact::updateAvatar($contact_record["photo"], $importer["uid"], $contact_record["id"]);
+               $item = ['author-id' => Contact::getIdForURL($ret['url']),
+                       'author-link' => $ret['url']];
 
-                       /*
-                        * technically they are sharing with us (Contact::SHARING),
-                        * but if our page-type is Profile::PAGE_COMMUNITY or Profile::PAGE_SOAPBOX
-                        * we are going to change the relationship and make them a follower.
-                        */
-                       if (($importer["page-flags"] == User::PAGE_FLAGS_FREELOVE) && $sharing && $following) {
-                               $new_relation = Contact::FRIEND;
-                       } elseif (($importer["page-flags"] == User::PAGE_FLAGS_FREELOVE) && $sharing) {
-                               $new_relation = Contact::SHARING;
-                       } else {
-                               $new_relation = Contact::FOLLOWER;
+               $result = Contact::addRelationship($importer, $contact, $item, false);
+               if ($result === true) {
+                       $contact_record = self::contactByHandle($importer['uid'], $author);
+                       if (!$contact_record) {
+                               Logger::info('unable to locate newly created contact record.');
+                               return;
                        }
 
-                       q(
-                               "UPDATE `contact` SET `rel` = %d,
-                               `name-date` = '%s',
-                               `uri-date` = '%s',
-                               `blocked` = 0,
-                               `pending` = 0,
-                               `writable` = 1
-                               WHERE `id` = %d
-                               ",
-                               intval($new_relation),
-                               DBA::escape(DateTimeFormat::utcNow()),
-                               DBA::escape(DateTimeFormat::utcNow()),
-                               intval($contact_record["id"])
-                       );
-
-                       $user = DBA::selectFirst('user', [], ['uid' => $importer["uid"]]);
+                       $user = DBA::selectFirst('user', [], ['uid' => $importer['uid']]);
                        if (DBA::isResult($user)) {
-                               Logger::log("Sending share message (Relation: ".$new_relation.") to author ".$author." - Contact: ".$contact_record["id"]." - User: ".$importer["uid"], Logger::DEBUG);
                                self::sendShare($user, $contact_record);
 
                                // Send the profile data, maybe it weren't transmitted before
-                               self::sendProfile($importer["uid"], [$contact_record]);
+                               self::sendProfile($importer['uid'], [$contact_record]);
                        }
                }
 
@@ -2577,7 +2497,7 @@ class Diaspora
        }
 
        /**
-        * @brief Fetches a message with a given guid
+        * Fetches a message with a given guid
         *
         * @param string $guid        message guid
         * @param string $orig_author handle of the original post
@@ -2593,7 +2513,7 @@ class Diaspora
                }
 
                // Do we already have this item?
-               $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+               $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
                        'author-name', 'author-link', 'author-avatar'];
                $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
                $item = Item::selectFirst($fields, $condition);
@@ -2637,7 +2557,7 @@ class Diaspora
                        }
 
                        if ($stored) {
-                               $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+                               $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
                                        'author-name', 'author-link', 'author-avatar'];
                                $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
                                $item = Item::selectFirst($fields, $condition);
@@ -2657,7 +2577,7 @@ class Diaspora
        }
 
        /**
-        * @brief Stores a reshare activity
+        * Stores a reshare activity
         *
         * @param array   $item              Array of reshare post
         * @param integer $parent_message_id Id of the parent post
@@ -2684,9 +2604,9 @@ class Diaspora
                $datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
                $datarray['parent-uri'] = $parent['uri'];
 
-               $datarray['verb'] = $datarray['body'] = ACTIVITY2_ANNOUNCE;
+               $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
                $datarray['gravity'] = GRAVITY_ACTIVITY;
-               $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
+               $datarray['object-type'] = Activity\ObjectType::NOTE;
 
                $datarray['protocol'] = $item['protocol'];
 
@@ -2705,7 +2625,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes a reshare message
+        * Processes a reshare message
         *
         * @param array  $importer Array of the importer user
         * @param object $data     The message object
@@ -2740,7 +2660,7 @@ class Diaspora
                        return false;
                }
 
-               $orig_url = System::baseUrl()."/display/".$original_item["guid"];
+               $orig_url = DI::baseUrl()."/display/".$original_item["guid"];
 
                $datarray = [];
 
@@ -2757,7 +2677,7 @@ class Diaspora
                $datarray["guid"] = $guid;
                $datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
 
-               $datarray["verb"] = ACTIVITY_POST;
+               $datarray["verb"] = Activity::POST;
                $datarray["gravity"] = GRAVITY_PARENT;
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
@@ -2771,9 +2691,15 @@ class Diaspora
                        $original_item["created"],
                        $orig_url
                );
+
+               if (!empty($original_item['title'])) {
+                       $prefix .= '[h3]' . $original_item['title'] . "[/h3]\n";
+               }
+
                $datarray["body"] = $prefix.$original_item["body"]."[/share]";
 
                $datarray["tag"] = $original_item["tag"];
+               $datarray["attach"] = $original_item["attach"];
                $datarray["app"]  = $original_item["app"];
 
                $datarray["plink"] = self::plink($author, $guid);
@@ -2804,7 +2730,7 @@ class Diaspora
        }
 
        /**
-        * @brief Processes retractions
+        * Processes retractions
         *
         * @param array  $importer Array of the importer user
         * @param array  $contact  The contact of the item owner
@@ -2869,7 +2795,7 @@ class Diaspora
        }
 
        /**
-        * @brief Receives retraction messages
+        * Receives retraction messages
         *
         * @param array  $importer Array of the importer user
         * @param string $sender   The sender of the message
@@ -2915,7 +2841,7 @@ class Diaspora
        }
 
        /**
-        * @brief Receives status messages
+        * Receives status messages
         *
         * @param array            $importer Array of the importer user
         * @param SimpleXMLElement $data     The message object
@@ -2962,9 +2888,9 @@ class Diaspora
                                        XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
                        }
 
-                       $datarray["object-type"] = ACTIVITY_OBJ_IMAGE;
+                       $datarray["object-type"] = Activity\ObjectType::IMAGE;
                } else {
-                       $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
+                       $datarray["object-type"] = Activity\ObjectType::NOTE;
 
                        // Add OEmbed and other information to the body
                        if (!self::isRedmatrix($contact["url"])) {
@@ -2994,7 +2920,7 @@ class Diaspora
                $datarray["guid"] = $guid;
                $datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
 
-               $datarray["verb"] = ACTIVITY_POST;
+               $datarray["verb"] = Activity::POST;
                $datarray["gravity"] = GRAVITY_PARENT;
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
@@ -3039,7 +2965,7 @@ class Diaspora
         * ************************************************************************************** */
 
        /**
-        * @brief returnes the handle of a contact
+        * returnes the handle of a contact
         *
         * @param array $contact contact array
         *
@@ -3060,12 +2986,12 @@ class Diaspora
                        $nick = $contact["nick"];
                }
 
-               return $nick . "@" . substr(System::baseUrl(), strpos(System::baseUrl(), "://") + 3);
+               return $nick . "@" . substr(DI::baseUrl(), strpos(DI::baseUrl(), "://") + 3);
        }
 
 
        /**
-        * @brief Creates the data for a private message in the new format
+        * Creates the data for a private message in the new format
         *
         * @param string $msg     The message that is to be transmitted
         * @param array  $user    The record of the sender
@@ -3107,7 +3033,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates the envelope for the "fetch" endpoint and for the new format
+        * Creates the envelope for the "fetch" endpoint and for the new format
         *
         * @param string $msg  The message that is to be transmitted
         * @param array  $user The record of the sender
@@ -3147,7 +3073,7 @@ class Diaspora
        }
 
        /**
-        * @brief Create the envelope for a message
+        * Create the envelope for a message
         *
         * @param string $msg     The message that is to be transmitted
         * @param array  $user    The record of the sender
@@ -3173,7 +3099,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates a signature for a message
+        * Creates a signature for a message
         *
         * @param array $owner   the array of the owner of the message
         * @param array $message The message that is to be signed
@@ -3192,7 +3118,7 @@ class Diaspora
        }
 
        /**
-        * @brief Transmit a message to a target server
+        * Transmit a message to a target server
         *
         * @param array  $owner        the array of the item owner
         * @param array  $contact      Target of the communication
@@ -3206,7 +3132,7 @@ class Diaspora
         */
        private static function transmit(array $owner, array $contact, $envelope, $public_batch, $guid = "")
        {
-               $enabled = intval(Config::get("system", "diaspora_enabled"));
+               $enabled = intval(DI::config()->get("system", "diaspora_enabled"));
                if (!$enabled) {
                        return 200;
                }
@@ -3233,7 +3159,7 @@ class Diaspora
 
                Logger::log("transmit: ".$logid."-".$guid." ".$dest_url);
 
-               if (!intval(Config::get("system", "diaspora_test"))) {
+               if (!intval(DI::config()->get("system", "diaspora_test"))) {
                        $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
 
                        $postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
@@ -3250,7 +3176,7 @@ class Diaspora
 
 
        /**
-        * @brief Build the post xml
+        * Build the post xml
         *
         * @param string $type    The message type
         * @param array  $message The message data
@@ -3265,7 +3191,7 @@ class Diaspora
        }
 
        /**
-        * @brief Builds and transmit messages
+        * Builds and transmit messages
         *
         * @param array  $owner        the array of the item owner
         * @param array  $contact      Target of the communication
@@ -3300,7 +3226,7 @@ class Diaspora
        }
 
        /**
-        * @brief sends a participation (Used to get all further updates)
+        * sends a participation (Used to get all further updates)
         *
         * @param array $contact Target of the communication
         * @param array $item    Item array
@@ -3317,7 +3243,7 @@ class Diaspora
 
                $cachekey = "diaspora:sendParticipation:".$item['guid'];
 
-               $result = Cache::get($cachekey);
+               $result = DI::cache()->get($cachekey);
                if (!is_null($result)) {
                        return;
                }
@@ -3343,13 +3269,13 @@ class Diaspora
                Logger::log("Send participation for ".$item["guid"]." by ".$author, Logger::DEBUG);
 
                // It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
-               Cache::set($cachekey, $item["guid"], Cache::QUARTER_HOUR);
+               DI::cache()->set($cachekey, $item["guid"], Duration::QUARTER_HOUR);
 
                return self::buildAndTransmit($owner, $contact, "participation", $message);
        }
 
        /**
-        * @brief sends an account migration
+        * sends an account migration
         *
         * @param array $owner   the array of the item owner
         * @param array $contact Target of the communication
@@ -3361,7 +3287,7 @@ class Diaspora
         */
        public static function sendAccountMigration(array $owner, array $contact, $uid)
        {
-               $old_handle = PConfig::get($uid, 'system', 'previous_addr');
+               $old_handle = DI::pConfig()->get($uid, 'system', 'previous_addr');
                $profile = self::createProfileData($uid);
 
                $signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author'];
@@ -3377,7 +3303,7 @@ class Diaspora
        }
 
        /**
-        * @brief Sends a "share" message
+        * Sends a "share" message
         *
         * @param array $owner   the array of the item owner
         * @param array $contact Target of the communication
@@ -3421,7 +3347,7 @@ class Diaspora
        }
 
        /**
-        * @brief sends an "unshare"
+        * sends an "unshare"
         *
         * @param array $owner   the array of the item owner
         * @param array $contact Target of the communication
@@ -3442,7 +3368,7 @@ class Diaspora
        }
 
        /**
-        * @brief Checks a message body if it is a reshare
+        * Checks a message body if it is a reshare
         *
         * @param string $body     The message body that is to be check
         * @param bool   $complete Should it be a complete check or a simple check?
@@ -3455,72 +3381,40 @@ class Diaspora
        {
                $body = trim($body);
 
-               // Skip if it isn't a pure repeated messages
-               // Does it start with a share?
-               if ((strpos($body, "[share") > 0) && $complete) {
+               $reshared = Item::getShareArray(['body' => $body]);
+               if (empty($reshared)) {
                        return false;
                }
 
-               // Does it end with a share?
-               if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
-                       return false;
-               }
-
-               $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
-               // Skip if there is no shared message in there
-               if ($body == $attributes) {
+               // Skip if it isn't a pure repeated messages
+               // Does it start with a share?
+               if (!empty($reshared['comment']) && $complete) {
                        return false;
                }
 
-               // If we don't do the complete check we quit here
-
-               $guid = "";
-               preg_match("/guid='(.*?)'/ism", $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $guid = $matches[1];
-               }
-
-               preg_match('/guid="(.*?)"/ism', $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $guid = $matches[1];
-               }
-
-               if (($guid != "") && $complete) {
-                       $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
+               if (!empty($reshared['guid']) && $complete) {
+                       $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
                        $item = Item::selectFirst(['contact-id'], $condition);
                        if (DBA::isResult($item)) {
-                               $ret= [];
+                               $ret = [];
                                $ret["root_handle"] = self::handleFromContact($item["contact-id"]);
-                               $ret["root_guid"] = $guid;
+                               $ret["root_guid"] = $reshared['guid'];
                                return $ret;
                        } elseif ($complete) {
                                // We are resharing something that isn't a DFRN or Diaspora post.
                                // So we have to return "false" on "$complete" to not trigger a reshare.
                                return false;
                        }
-               } elseif (($guid == "") && $complete) {
+               } elseif (empty($reshared['guid']) && $complete) {
                        return false;
                }
 
-               $ret["root_guid"] = $guid;
-
-               $profile = "";
-               preg_match("/profile='(.*?)'/ism", $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $profile = $matches[1];
-               }
-
-               preg_match('/profile="(.*?)"/ism', $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $profile = $matches[1];
-               }
+               $ret = [];
 
-               $ret= [];
-
-               if ($profile != "") {
-                       if (Contact::getIdForURL($profile)) {
-                               $author = Contact::getDetailsByURL($profile);
-                               $ret["root_handle"] = $author['addr'];
+               if (!empty($reshared['profile']) && ($cid = Contact::getIdForURL($reshared['profile']))) {
+                       $contact = DBA::selectFirst('contact', ['addr'], ['id' => $cid]);
+                       if (!empty($contact['addr'])) {
+                               $ret['root_handle'] = $contact['addr'];
                        }
                }
 
@@ -3532,7 +3426,7 @@ class Diaspora
        }
 
        /**
-        * @brief Create an event array
+        * Create an event array
         *
         * @param integer $event_id The id of the event
         *
@@ -3612,7 +3506,7 @@ class Diaspora
        }
 
        /**
-        * @brief Create a post (status message or reshare)
+        * Create a post (status message or reshare)
         *
         * @param array $item  The item that will be exported
         * @param array $owner the array of the item owner
@@ -3627,7 +3521,7 @@ class Diaspora
        {
                $cachekey = "diaspora:buildStatus:".$item['guid'];
 
-               $result = Cache::get($cachekey);
+               $result = DI::cache()->get($cachekey);
                if (!is_null($result)) {
                        return $result;
                }
@@ -3635,8 +3529,7 @@ class Diaspora
                $myaddr = self::myHandle($owner);
 
                $public = ($item["private"] ? "false" : "true");
-
-               $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
+               $created = DateTimeFormat::utc($item['received'], DateTimeFormat::ATOM);
                $edited = DateTimeFormat::utc($item["edited"] ?? $item["created"], DateTimeFormat::ATOM);
 
                // Detect a share element and do a reshare
@@ -3654,6 +3547,14 @@ class Diaspora
                        $title = $item["title"];
                        $body = $item["body"];
 
+                       // Fetch the title from an attached link - if there is one
+                       if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
+                               $page_data = BBCode::getAttachmentData($item['body']);
+                               if (!empty($page_data['type']) && !empty($page_data['title']) && ($page_data['type'] == 'link')) {
+                                       $title = $page_data['title'];
+                               }
+                       }
+
                        if ($item['author-link'] != $item['owner-link']) {
                                require_once 'mod/share.php';
                                $body = share_header($item['author-name'], $item['author-link'], $item['author-avatar'],
@@ -3665,13 +3566,13 @@ class Diaspora
 
                        // Adding the title
                        if (strlen($title)) {
-                               $body = "## ".html_entity_decode($title)."\n\n".$body;
+                               $body = "### ".html_entity_decode($title)."\n\n".$body;
                        }
 
                        if ($item["attach"]) {
                                $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item["attach"], $matches, PREG_SET_ORDER);
                                if ($cnt) {
-                                       $body .= "\n".L10n::t("Attachments:")."\n";
+                                       $body .= "\n".DI::l10n()->t("Attachments:")."\n";
                                        foreach ($matches as $mtch) {
                                                $body .= "[".$mtch[3]."](".$mtch[1].")\n";
                                        }
@@ -3724,7 +3625,7 @@ class Diaspora
 
                $msg = ["type" => $type, "message" => $message];
 
-               Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
+               DI::cache()->set($cachekey, $msg, Duration::QUARTER_HOUR);
 
                return $msg;
        }
@@ -3744,7 +3645,7 @@ class Diaspora
        }
 
        /**
-        * @brief Sends a post
+        * Sends a post
         *
         * @param array $item         The item that will be exported
         * @param array $owner        the array of the item owner
@@ -3763,7 +3664,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates a "like" object
+        * Creates a "like" object
         *
         * @param array $item  The item that will be exported
         * @param array $owner the array of the item owner
@@ -3780,9 +3681,9 @@ class Diaspora
 
                $target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
                $positive = null;
-               if ($item['verb'] === ACTIVITY_LIKE) {
+               if ($item['verb'] === Activity::LIKE) {
                        $positive = "true";
-               } elseif ($item['verb'] === ACTIVITY_DISLIKE) {
+               } elseif ($item['verb'] === Activity::DISLIKE) {
                        $positive = "false";
                }
 
@@ -3795,7 +3696,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates an "EventParticipation" object
+        * Creates an "EventParticipation" object
         *
         * @param array $item  The item that will be exported
         * @param array $owner the array of the item owner
@@ -3811,13 +3712,13 @@ class Diaspora
                }
 
                switch ($item['verb']) {
-                       case ACTIVITY_ATTEND:
+                       case Activity::ATTEND:
                                $attend_answer = 'accepted';
                                break;
-                       case ACTIVITY_ATTENDNO:
+                       case Activity::ATTENDNO:
                                $attend_answer = 'declined';
                                break;
-                       case ACTIVITY_ATTENDMAYBE:
+                       case Activity::ATTENDMAYBE:
                                $attend_answer = 'tentative';
                                break;
                        default:
@@ -3833,7 +3734,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates the object for a comment
+        * Creates the object for a comment
         *
         * @param array $item  The item that will be exported
         * @param array $owner the array of the item owner
@@ -3845,12 +3746,12 @@ class Diaspora
        {
                $cachekey = "diaspora:constructComment:".$item['guid'];
 
-               $result = Cache::get($cachekey);
+               $result = DI::cache()->get($cachekey);
                if (!is_null($result)) {
                        return $result;
                }
 
-               $toplevel_item = Item::selectFirst(['guid', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
+               $toplevel_item = Item::selectFirst(['guid', 'author-id', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
                if (!DBA::isResult($toplevel_item)) {
                        Logger::error('Missing parent conversation item', ['parent' => $item["parent"]]);
                        return false;
@@ -3858,13 +3759,19 @@ class Diaspora
 
                $thread_parent_item = $toplevel_item;
                if ($item['thr-parent'] != $item['parent-uri']) {
-                       $thread_parent_item = Item::selectFirst(['guid', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
+                       $thread_parent_item = Item::selectFirst(['guid', 'author-id', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
                }
 
                $body = $item["body"];
 
-               if ((empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
-                       && !Config::get('system', 'disable_implicit_mentions')
+               // The replied to autor mention is prepended for clarity if:
+               // - Item replied isn't yours
+               // - Item is public or explicit mentions are disabled
+               // - Implicit mentions are enabled
+               if (
+                       $item['author-id'] != $thread_parent_item['author-id']
+                       && (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
+                       && !DI::config()->get('system', 'disable_implicit_mentions')
                ) {
                        $body = self::prependParentAuthorMention($body, $thread_parent_item['author-link']);
                }
@@ -3888,13 +3795,13 @@ class Diaspora
                        $comment['thread_parent_guid'] = $thread_parent_item['guid'];
                }
 
-               Cache::set($cachekey, $comment, Cache::QUARTER_HOUR);
+               DI::cache()->set($cachekey, $comment, Duration::QUARTER_HOUR);
 
                return($comment);
        }
 
        /**
-        * @brief Send a like or a comment
+        * Send a like or a comment
         *
         * @param array $item         The item that will be exported
         * @param array $owner        the array of the item owner
@@ -3907,13 +3814,13 @@ class Diaspora
         */
        public static function sendFollowup(array $item, array $owner, array $contact, $public_batch = false)
        {
-               if (in_array($item['verb'], [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE])) {
+               if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
                        $message = self::constructAttend($item, $owner);
                        $type = "event_participation";
-               } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+               } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
                        $message = self::constructLike($item, $owner);
                        $type = "like";
-               } elseif (!in_array($item["verb"], [ACTIVITY_FOLLOW, ACTIVITY_TAG])) {
+               } elseif (!in_array($item["verb"], [Activity::FOLLOW, Activity::TAG])) {
                        $message = self::constructComment($item, $owner);
                        $type = "comment";
                }
@@ -3928,7 +3835,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates a message from a signature record entry
+        * Creates a message from a signature record entry
         *
         * @param array $item The item that will be exported
         * @return array The message
@@ -3942,7 +3849,7 @@ class Diaspora
                        $message = ["author" => $item['signer'],
                                        "target_guid" => $signed_parts[0],
                                        "target_type" => $signed_parts[1]];
-               } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+               } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
                        $message = ["author" => $signed_parts[4],
                                        "guid" => $signed_parts[1],
                                        "parent_guid" => $signed_parts[3],
@@ -3973,7 +3880,7 @@ class Diaspora
        }
 
        /**
-        * @brief Relays messages (like, comment, retraction) to other servers if we are the thread owner
+        * Relays messages (like, comment, retraction) to other servers if we are the thread owner
         *
         * @param array $item         The item that will be exported
         * @param array $owner        the array of the item owner
@@ -3987,7 +3894,7 @@ class Diaspora
        {
                if ($item["deleted"]) {
                        return self::sendRetraction($item, $owner, $contact, $public_batch, true);
-               } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+               } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
                        $type = "like";
                } else {
                        $type = "comment";
@@ -4029,7 +3936,7 @@ class Diaspora
        }
 
        /**
-        * @brief Sends a retraction (deletion) of a message, like or comment
+        * Sends a retraction (deletion) of a message, like or comment
         *
         * @param array $item         The item that will be exported
         * @param array $owner        the array of the item owner
@@ -4048,7 +3955,7 @@ class Diaspora
 
                if ($item['id'] == $item['parent']) {
                        $target_type = "Post";
-               } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+               } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
                        $target_type = "Like";
                } else {
                        $target_type = "Comment";
@@ -4064,7 +3971,7 @@ class Diaspora
        }
 
        /**
-        * @brief Sends a mail
+        * Sends a mail
         *
         * @param array $item    The item that will be exported
         * @param array $owner   The owner
@@ -4115,7 +4022,7 @@ class Diaspora
        }
 
        /**
-        * @brief Split a name into first name and last name
+        * Split a name into first name and last name
         *
         * @param string $name The name
         *
@@ -4171,7 +4078,7 @@ class Diaspora
        }
 
        /**
-        * @brief Create profile data
+        * Create profile data
         *
         * @param int $uid The user id
         *
@@ -4185,7 +4092,7 @@ class Diaspora
                        FROM `profile`
                        INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
                        INNER JOIN `contact` ON `profile`.`uid` = `contact`.`uid`
-                       WHERE `user`.`uid` = %d AND `profile`.`is-default` AND `contact`.`self` LIMIT 1",
+                       WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
                        intval($uid)
                );
 
@@ -4200,9 +4107,9 @@ class Diaspora
                $first = $split_name['first'];
                $last = $split_name['last'];
 
-               $large = System::baseUrl().'/photo/custom/300/'.$profile['uid'].'.jpg';
-               $medium = System::baseUrl().'/photo/custom/100/'.$profile['uid'].'.jpg';
-               $small = System::baseUrl().'/photo/custom/50/'  .$profile['uid'].'.jpg';
+               $large = DI::baseUrl().'/photo/custom/300/'.$profile['uid'].'.jpg';
+               $medium = DI::baseUrl().'/photo/custom/100/'.$profile['uid'].'.jpg';
+               $small = DI::baseUrl().'/photo/custom/50/'  .$profile['uid'].'.jpg';
                $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false');
 
                $dob = null;
@@ -4256,7 +4163,7 @@ class Diaspora
        }
 
        /**
-        * @brief Sends profile data
+        * Sends profile data
         *
         * @param int  $uid    The user id
         * @param bool $recips optional, default false
@@ -4298,7 +4205,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates the signature for likes that are created on our system
+        * Creates the signature for likes that are created on our system
         *
         * @param integer $uid  The user of that comment
         * @param array   $item Item array
@@ -4314,7 +4221,7 @@ class Diaspora
                        return false;
                }
 
-               if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+               if (!in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
                        return false;
                }
 
@@ -4329,7 +4236,7 @@ class Diaspora
        }
 
        /**
-        * @brief Creates the signature for Comments that are created on our system
+        * Creates the signature for Comments that are created on our system
         *
         * @param integer $uid  The user of that comment
         * @param array   $item Item array