]> git.mxchange.org Git - friendica.git/blobdiff - include/diaspora.php
Fix wrong class name case
[friendica.git] / include / diaspora.php
index b8eff62b1130f2a25ecd1503d043d130240b8704..21081dd6a7250d7e4891984c47889ad633e4b065 100644 (file)
@@ -8,7 +8,8 @@
  * This will change in the future.
  */
 
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
 
 require_once 'include/items.php';
 require_once 'include/bb2diaspora.php';
@@ -347,15 +348,10 @@ class Diaspora {
                                self::dispatch($rr,$msg);
                        }
                } else {
-                       $social_relay = (bool)Config::get('system', 'relay_subscribe', false);
-
                        // Use a dummy importer to import the data for the public copy
-                       if ($social_relay) {
-                               $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
-                               $message_id = self::dispatch($importer,$msg);
-                       } else {
-                               logger("Unwanted message from ".$msg["author"]." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG);
-                       }
+                       // or for comments from unknown people
+                       $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
+                       $message_id = self::dispatch($importer,$msg);
                }
 
                return $message_id;
@@ -382,6 +378,11 @@ class Diaspora {
 
                $type = $fields->getName();
 
+               $social_relay = Config::get('system', 'relay_subscribe', false);
+               if (!$social_relay AND ($type == 'message')) {
+                       logger("Unwanted message from ".$sender." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG);
+               }
+
                logger("Received message type ".$type." from ".$sender." for user ".$importer["uid"], LOGGER_DEBUG);
 
                switch ($type) {
@@ -1227,6 +1228,27 @@ class Diaspora {
                }
        }
 
+       /**
+        * @brief Find the best importer for a comment
+        *
+        * @param array $importer Array of the importer user
+        * @param string $guid The guid of the item
+        *
+        * @return array the importer that fits the best
+        */
+       private static function importer_for_comment($importer, $guid) {
+               $item = dba::fetch_first("SELECT `uid` FROM `item` WHERE `origin` AND `guid` = ? LIMIT 1", $guid);
+
+               if (dbm::is_result($item)) {
+                       logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG);
+                       $contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']);
+                       if (dbm::is_result($contact)) {
+                               $importer = $contact;
+                       }
+               }
+               return $importer;
+       }
+
        /**
         * @brief Processes an incoming comment
         *
@@ -1256,6 +1278,11 @@ class Diaspora {
                        $thr_uri = "";
                }
 
+               // Find the best importer when there was no importer found
+               if ($importer["uid"] == 0) {
+                       $importer = self::importer_for_comment($importer, $parent_guid);
+               }
+
                $contact = self::allowed_contact_by_handle($importer, $sender, true);
                if (!$contact) {
                        return false;
@@ -1308,7 +1335,9 @@ class Diaspora {
                }
 
                $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
-               $datarray["object"] = $xml;
+
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+               $datarray["source"] = $xml;
 
                $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
 
@@ -1628,6 +1657,8 @@ class Diaspora {
 
                $datarray = array();
 
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+
                $datarray["uid"] = $importer["uid"];
                $datarray["contact-id"] = $author_contact["cid"];
                $datarray["network"]  = $author_contact["network"];
@@ -1919,6 +1950,7 @@ class Diaspora {
                        if ($self && $contact["rel"] == CONTACT_IS_FOLLOWER) {
 
                                $arr = array();
+                               $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"];
@@ -2278,7 +2310,8 @@ class Diaspora {
                $datarray["verb"] = ACTIVITY_POST;
                $datarray["gravity"] = GRAVITY_PARENT;
 
-               $datarray["object"] = $xml;
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+               $datarray["source"] = $xml;
 
                $prefix = share_header($original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"],
                                        $original_item["guid"], $original_item["created"], $orig_url);
@@ -2481,7 +2514,8 @@ class Diaspora {
                $datarray["verb"] = ACTIVITY_POST;
                $datarray["gravity"] = GRAVITY_PARENT;
 
-               $datarray["object"] = $xml;
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+               $datarray["source"] = $xml;
 
                $datarray["body"] = self::replace_people_guid($body, $contact["url"]);