]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #6446 from annando/approve
[friendica.git] / src / Protocol / DFRN.php
index b67b7c021fc76d5a10f85e00202db00fee54b3c6..d6b0a482ec94c439734b6b49436913346d7a07df 100644 (file)
@@ -37,12 +37,6 @@ use Friendica\Util\XML;
 use HTMLPurifier;
 use HTMLPurifier_Config;
 
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once "include/enotify.php";
-require_once "include/items.php";
-require_once "include/text.php";
-
 /**
  * @brief This class contain functions to create and send DFRN XML files
  */
@@ -143,7 +137,7 @@ class DFRN
         */
        public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0, $onlyheader = false)
        {
-               $a = get_app();
+               $a = \get_app();
 
                $sitefeed    = ((strlen($owner_nick)) ? false : true); // not yet implemented, need to rewrite huge chunks of following logic
                $public_feed = (($dfrn_id) ? false : true);
@@ -1166,7 +1160,7 @@ class DFRN
         */
        public static function deliver($owner, $contact, $atom, $dissolve = false, $legacy_transport = false)
        {
-               $a = get_app();
+               $a = \get_app();
 
                // At first try the Diaspora transport layer
                if (!$dissolve && !$legacy_transport) {
@@ -1426,7 +1420,7 @@ class DFRN
         */
        public static function transmit($owner, $contact, $atom, $public_batch = false)
        {
-               $a = get_app();
+               $a = \get_app();
 
                if (!$public_batch) {
                        if (empty($contact['addr'])) {
@@ -1876,6 +1870,7 @@ class DFRN
                        "to_email" => $importer["email"],
                        "uid" => $importer["importer_uid"],
                        "item" => $msg,
+                       "parent" => $msg["parent-uri"],
                        "source_name" => $msg["from-name"],
                        "source_link" => $importer["url"],
                        "source_photo" => $importer["thumb"],
@@ -1899,7 +1894,7 @@ class DFRN
         */
        private static function processSuggestion($xpath, $suggestion, $importer)
        {
-               $a = get_app();
+               $a = \get_app();
 
                Logger::log("Processing suggestions");
 
@@ -2462,7 +2457,7 @@ class DFRN
 
                /// @todo Do we really need this check for HTML elements? (It was copied from the old function)
                if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) {
-                       $base_url = get_app()->getBaseURL();
+                       $base_url = \get_app()->getBaseURL();
                        $item['body'] = HTML::relToAbs($item['body'], $base_url);
 
                        $item['body'] = HTML::toBBCodeVideo($item['body']);
@@ -2637,7 +2632,7 @@ class DFRN
                        if (($item["object-type"] == ACTIVITY_OBJ_EVENT) && !$owner_unknown) {
                                Logger::log("Item ".$item["uri"]." seems to contain an event.", Logger::DEBUG);
                                $ev = Event::fromBBCode($item["body"]);
-                               if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) {
+                               if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
                                        Logger::log("Event in item ".$item["uri"]." was found.", Logger::DEBUG);
                                        $ev["cid"]     = $importer["id"];
                                        $ev["uid"]     = $importer["importer_uid"];
@@ -2855,19 +2850,41 @@ class DFRN
 
                // The account type is new since 3.5.1
                if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) {
+                       // Hint: We are using separate update calls for uid=0 and uid!=0 since a combined call is bad for the database performance
+
                        $accounttype = intval(XML::getFirstNodeValue($xpath, "/atom:feed/dfrn:account_type/text()"));
 
                        if ($accounttype != $importer["contact-type"]) {
-                               DBA::update('contact', ['contact-type' => $accounttype], ['id' => $importer["id"]]);
+                               DBA::update('contact', ['contact-type' => $accounttype], ['id' => $importer['id']]);
+
+                               // Updating the public contact as well
+                               DBA::update('contact', ['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]);
                        }
                        // A forum contact can either have set "forum" or "prv" - but not both
-                       if (($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) && (($forum != $importer["forum"]) || ($forum == $importer["prv"]))) {
-                               $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer["id"]];
+                       if ($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) {
+                               // It's a forum, so either set the public or private forum flag
+                               $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']];
+                               DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);
+
+                               // Updating the public contact as well
+                               $condition = ['(`forum` != ? OR `prv` != ?) AND `uid` = 0 AND `nurl` = ?', $forum, !$forum, $importer['nurl']];
                                DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);
+                       } else {
+                               // It's not a forum, so remove the flags
+                               $condition = ['(`forum` OR `prv`) AND `id` = ?', $importer['id']];
+                               DBA::update('contact', ['forum' => false, 'prv' => false], $condition);
+
+                               // Updating the public contact as well
+                               $condition = ['(`forum` OR `prv`) AND `uid` = 0 AND `nurl` = ?', $importer['nurl']];
+                               DBA::update('contact', ['forum' => false, 'prv' => false], $condition);
                        }
                } elseif ($forum != $importer["forum"]) { // Deprecated since 3.5.1
                        $condition = ['`forum` != ? AND `id` = ?', $forum, $importer["id"]];
                        DBA::update('contact', ['forum' => $forum], $condition);
+
+                       // Updating the public contact as well
+                       $condition = ['`forum` != ? AND `uid` = 0 AND `nurl` = ?', $forum, $importer['nurl']];
+                       DBA::update('contact', ['forum' => $forum], $condition);
                }
 
 
@@ -2925,7 +2942,7 @@ class DFRN
        public static function autoRedir(App $a, $contact_nick)
        {
                // prevent looping
-               if (x($_REQUEST, 'redir') && intval($_REQUEST['redir'])) {
+               if (!empty($_REQUEST['redir'])) {
                        return;
                }
 
@@ -3077,10 +3094,10 @@ class DFRN
         */
        private static function isEditedTimestampNewer($existing, $update)
        {
-               if (!x($existing, 'edited') || !$existing['edited']) {
+               if (empty($existing['edited'])) {
                        return true;
                }
-               if (!x($update, 'edited') || !$update['edited']) {
+               if (empty($update['edited'])) {
                        return false;
                }