]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
API: fix sender/recipient of PMs: check api_user before get user info.
[friendica.git] / src / Protocol / Diaspora.php
index bae2eb6a2a2091372642e16f8e3d224248eec370..20d1d74fea12ad99133019a3b72f537815e24181 100644 (file)
@@ -1602,11 +1602,21 @@ class Diaspora
         */
        private static function getUriFromGuid($author, $guid, $onlyfound = false)
        {
-               $r = q("SELECT `uri` FROM `item` WHERE `guid` = '%s' LIMIT 1", dbesc($guid));
-               if (DBM::is_result($r)) {
-                       return $r[0]["uri"];
+               $item = dba::selectFirst('item', ['uri'], ['guid' => $guid]);
+               if (DBM::is_result($item)) {
+                       return $item["uri"];
                } elseif (!$onlyfound) {
-                       return $author.":".$guid;
+                       $contact = Contact::getDetailsByAddr($author, 0);
+                       if (!empty($contact['network'])) {
+                               $prefix = 'urn:X-' . $contact['network'] . ':';
+                       } else {
+                               // This fallback should happen most unlikely
+                               $prefix = 'urn:X-dspr:';
+                       }
+
+                       $author_parts = explode('@', $author);
+
+                       return $prefix . $author_parts[1] . ':' . $author_parts[0] . ':'. $guid;
                }
 
                return "";
@@ -2386,78 +2396,6 @@ class Diaspora
                                ['id' => $contact["id"], 'uid' => $importer["uid"]]
                        );
                }
-               // send notification
-
-               $r = q(
-                       "SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
-                       intval($importer["uid"])
-               );
-
-               if ($r && !$r[0]["hide-friends"] && !$contact["hidden"] && intval(PConfig::get($importer["uid"], "system", "post_newfriend"))) {
-                       $self = q(
-                               "SELECT * FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1",
-                               intval($importer["uid"])
-                       );
-
-                       // they are not CONTACT_IS_FOLLOWER anymore but that's what we have in the array
-
-                       if ($self && $contact["rel"] == CONTACT_IS_FOLLOWER) {
-                               $arr = [];
-                               $arr["protocol"] = PROTOCOL_DIASPORA;
-                               $arr["uri"] = $arr["parent-uri"] = item_new_uri($a->get_hostname(), $importer["uid"]);
-                               $arr["uid"] = $importer["uid"];
-                               $arr["contact-id"] = $self[0]["id"];
-                               $arr["wall"] = 1;
-                               $arr["type"] = 'wall';
-                               $arr["gravity"] = 0;
-                               $arr["origin"] = 1;
-                               $arr["author-name"] = $arr["owner-name"] = $self[0]["name"];
-                               $arr["author-link"] = $arr["owner-link"] = $self[0]["url"];
-                               $arr["author-avatar"] = $arr["owner-avatar"] = $self[0]["thumb"];
-                               $arr["verb"] = ACTIVITY_FRIEND;
-                               $arr["object-type"] = ACTIVITY_OBJ_PERSON;
-
-                               $A = "[url=".$self[0]["url"]."]".$self[0]["name"]."[/url]";
-                               $B = "[url=".$contact["url"]."]".$contact["name"]."[/url]";
-                               $BPhoto = "[url=".$contact["url"]."][img]".$contact["thumb"]."[/img][/url]";
-                               $arr["body"] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$BPhoto;
-
-                               $arr["object"] = self::constructNewFriendObject($contact);
-
-                               $user = dba::selectFirst('user', ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['uid' => $importer["uid"]]);
-
-                               $arr["allow_cid"] = $user["allow_cid"];
-                               $arr["allow_gid"] = $user["allow_gid"];
-                               $arr["deny_cid"]  = $user["deny_cid"];
-                               $arr["deny_gid"]  = $user["deny_gid"];
-
-                               $i = Item::insert($arr);
-                               if ($i) {
-                                       Worker::add(PRIORITY_HIGH, "Notifier", "activity", $i);
-                               }
-                       }
-               }
-       }
-
-       /**
-        * @brief Creates a XML object for a "new friend" message
-        *
-        * @param array $contact Array of the contact
-        *
-        * @return string The XML
-        */
-       private static function constructNewFriendObject($contact)
-       {
-               $objtype = ACTIVITY_OBJ_PERSON;
-               $link = '<link rel="alternate" type="text/html" href="'.$contact["url"].'" />'."\n".
-                       '<link rel="photo" type="image/jpeg" href="'.$contact["thumb"].'" />'."\n";
-
-               $xmldata = ["object" => ["type" => $objtype,
-                                               "title" => $contact["name"],
-                                               "id" => $contact["url"]."/".$contact["name"],
-                                               "link" => $link]];
-
-               return XML::fromArray($xmldata, $xml, true);
        }
 
        /**
@@ -2857,7 +2795,7 @@ class Diaspora
 
                while ($item = dba::fetch($r)) {
                        // Fetch the parent item
-                       $parent = dba::selectFirst('item', ['author-link', 'origin'], ['id' => $item["parent"]]);
+                       $parent = dba::selectFirst('item', ['author-link'], ['id' => $item["parent"]]);
 
                        // Only delete it if the parent author really fits
                        if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
@@ -2865,7 +2803,7 @@ class Diaspora
                                continue;
                        }
 
-                       Item::deleteById($item["id"]);
+                       Item::delete(['id' => $item['id']]);
 
                        logger("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], LOGGER_DEBUG);
                }