]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge branch 'master' into develop
[friendica.git] / src / Protocol / DFRN.php
index 00bb91f8deb926ce75edbb211a1349a236ebe875..6b9ff3de50e886fda0a672d2647f5fef4406adf9 100644 (file)
@@ -50,9 +50,9 @@ require_once "include/text.php";
 class DFRN
 {
 
-       const DFRN_TOP_LEVEL = 0;       // Top level posting
-       const DFRN_REPLY = 1;           // Regular reply that is stored locally
-       const DFRN_REPLY_RC = 2;        // Reply that will be relayed
+       const TOP_LEVEL = 0;    // Top level posting
+       const REPLY = 1;                // Regular reply that is stored locally
+       const REPLY_RC = 2;     // Reply that will be relayed
 
        /**
         * @brief Generates the atom entries for delivery.php
@@ -81,7 +81,7 @@ class DFRN
                        $root->appendChild($entry);
                }
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -96,7 +96,6 @@ class DFRN
         * @param boolean $onlyheader  Output only the header without content? (Default is "no")
         *
         * @return string DFRN feed entries
-        * @todo Find proper type-hints
         */
        public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0, $onlyheader = false)
        {
@@ -222,10 +221,8 @@ class DFRN
                        //$sql_extra .= file_tag_file_query('item',$category,'category');
                }
 
-               if ($public_feed) {
-                       if (! $converse) {
-                               $sql_extra .= " AND `contact`.`self` = 1 ";
-                       }
+               if ($public_feed && ! $converse) {
+                       $sql_extra .= " AND `contact`.`self` = 1 ";
                }
 
                $check_date = DateTimeFormat::utc($last_update);
@@ -426,7 +423,7 @@ class DFRN
 
                $root->appendChild($mail);
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -455,7 +452,7 @@ class DFRN
 
                $root->appendChild($suggest);
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -490,7 +487,6 @@ class DFRN
                        $photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
                }
 
-               unset($rp, $ext);
 
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
@@ -514,7 +510,7 @@ class DFRN
 
                $root->appendChild($relocate);
 
-               return(trim($doc->saveXML()));
+               return trim($doc->saveXML());
        }
 
        /**
@@ -896,7 +892,7 @@ class DFRN
         * @return object XML entry object
         * @todo Find proper type-hints
         */
-       private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0, $single = false)
+       private static function entry($doc, $type, array $item, array $owner, $comment = false, $cid = 0, $single = false)
        {
                $mentioned = [];
 
@@ -940,7 +936,7 @@ class DFRN
                        $htmlbody = $body;
 
                        if ($item['title'] != "") {
-                               $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
+                               $htmlbody = "[b]" . $item['title'] . "[/b]\n\n" . $htmlbody;
                        }
 
                        $htmlbody = BBCode::convert($htmlbody, false, 7);
@@ -1067,6 +1063,7 @@ class DFRN
 
                $tags = Item::getFeedTags($item);
 
+               /// @TODO Combine this with similar below if() block?
                if (count($tags)) {
                        foreach ($tags as $t) {
                                if (($type != 'html') || ($t[0] != "@")) {
@@ -1576,7 +1573,7 @@ class DFRN
                // Until now we aren't serving different sizes - but maybe later
                $avatarlist = [];
                /// @todo check if "avatar" or "photo" would be the best field in the specification
-               $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context);
+               $avatars = $xpath->query($element . "/atom:link[@rel='avatar']", $context);
                foreach ($avatars as $avatar) {
                        $href = "";
                        $width = 0;
@@ -1596,6 +1593,7 @@ class DFRN
                                $avatarlist[$width] = $href;
                        }
                }
+
                if (count($avatarlist) > 0) {
                        krsort($avatarlist);
                        $author["avatar"] = current($avatarlist);
@@ -2098,6 +2096,9 @@ class DFRN
                $condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], normalise_link($old["url"])];
                dba::update('contact', $fields, $condition);
 
+               // @TODO No dba:update here?
+               dba::update('contact', $fields, $condition);
+
                Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
 
                logger('Contacts are updated.');
@@ -2145,10 +2146,6 @@ class DFRN
                        Item::update($fields, $condition);
 
                        $changed = true;
-
-                       if ($entrytype == DFRN_REPLY_RC) {
-                               Worker::add(PRIORITY_HIGH, "Notifier", "comment-import", $current["id"]);
-                       }
                }
                return $changed;
        }
@@ -2216,12 +2213,12 @@ class DFRN
                        }
 
                        if ($is_a_remote_action) {
-                               return DFRN_REPLY_RC;
+                               return DFRN::REPLY_RC;
                        } else {
-                               return DFRN_REPLY;
+                               return DFRN::REPLY;
                        }
                } else {
-                       return DFRN_TOP_LEVEL;
+                       return DFRN::TOP_LEVEL;
                }
        }
 
@@ -2295,7 +2292,7 @@ class DFRN
        {
                logger("Process verb ".$item["verb"]." and object-type ".$item["object-type"]." for entrytype ".$entrytype, LOGGER_DEBUG);
 
-               if (($entrytype == DFRN_TOP_LEVEL)) {
+               if (($entrytype == DFRN::TOP_LEVEL)) {
                        // The filling of the the "contact" variable is done for legcy reasons
                        // The functions below are partly used by ostatus.php as well - where we have this variable
                        $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($importer["id"]));
@@ -2639,7 +2636,7 @@ class DFRN
                $entrytype = self::getEntryType($importer, $item);
 
                // Now assign the rest of the values that depend on the type of the message
-               if (in_array($entrytype, [DFRN_REPLY, DFRN_REPLY_RC])) {
+               if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
                        if (!isset($item["object-type"])) {
                                $item["object-type"] = ACTIVITY_OBJ_COMMENT;
                        }
@@ -2661,10 +2658,10 @@ class DFRN
                        }
                }
 
-               if ($entrytype == DFRN_REPLY_RC) {
+               if ($entrytype == DFRN::REPLY_RC) {
                        $item["type"] = "remote-comment";
                        $item["wall"] = 1;
-               } elseif ($entrytype == DFRN_TOP_LEVEL) {
+               } elseif ($entrytype == DFRN::TOP_LEVEL) {
                        if (!isset($item["object-type"])) {
                                $item["object-type"] = ACTIVITY_OBJ_NOTE;
                        }
@@ -2708,12 +2705,12 @@ class DFRN
                        if (self::updateContent($current, $item, $importer, $entrytype)) {
                                logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG);
                        } else {
-                               logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
+                               logger("Item " . $item["uri"] . " already existed.", LOGGER_DEBUG);
                        }
                        return;
                }
 
-               if (in_array($entrytype, [DFRN_REPLY, DFRN_REPLY_RC])) {
+               if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
                        $posted_id = Item::insert($item);
                        $parent = 0;
 
@@ -2724,26 +2721,9 @@ class DFRN
                                        Item::distribute($posted_id);
                                }
 
-                               $item["id"] = $posted_id;
-
-                               $r = q(
-                                       "SELECT `parent`, `parent-uri` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                                       intval($posted_id),
-                                       intval($importer["importer_uid"])
-                               );
-                               if (DBM::is_result($r)) {
-                                       $parent = $r[0]["parent"];
-                                       $parent_uri = $r[0]["parent-uri"];
-                               }
-
-                               if ($posted_id && $parent && ($entrytype == DFRN_REPLY_RC)) {
-                                       logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG);
-                                       Worker::add(PRIORITY_HIGH, "Notifier", "comment-import", $posted_id);
-                               }
-
                                return true;
                        }
-               } else { // $entrytype == DFRN_TOP_LEVEL
+               } else { // $entrytype == DFRN::TOP_LEVEL
                        if (($importer["uid"] == 0) && ($importer["importer_uid"] != 0)) {
                                logger("Contact ".$importer["id"]." isn't known to user ".$importer["importer_uid"].". The post will be ignored.", LOGGER_DEBUG);
                                return;
@@ -2834,23 +2814,13 @@ class DFRN
                        }
                }
 
-               $entrytype = self::getEntryType($importer, $item);
-
-               if (!$item["deleted"]) {
-                       logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG);
-               } else {
+               if ($item["deleted"]) {
                        return;
                }
 
-               Item::deleteById($item["id"]);
+               logger('deleting item '.$item['id'].' uri='.$uri, LOGGER_DEBUG);
 
-               if ($entrytype != DFRN_TOP_LEVEL) {
-                       // if this is a relayed delete, propagate it to other recipients
-                       if ($entrytype == DFRN_REPLY_RC) {
-                               logger("Notifying followers about deletion of post " . $item["id"], LOGGER_DEBUG);
-                               Worker::add(PRIORITY_HIGH, "Notifier", "drop", $item["id"]);
-                       }
-               }
+               Item::delete(['id' => $item['id']]);
        }
 
        /**