]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #9400 from nupplaphil/task/guzzle_http
[friendica.git] / src / Protocol / DFRN.php
index cfbf12c784e79b5593016223c396d98411df4c25..f718e0a741e8ad87f2dbda9516dcf94647d9005a 100644 (file)
@@ -1358,7 +1358,7 @@ class DFRN
                        return -9; // timed out
                }
 
-               if (($curl_stat == 503) && stristr($postResult->getHeader(), 'retry-after')) {
+               if (($curl_stat == 503) && $postResult->inHeader('retry-after')) {
                        return -10;
                }
 
@@ -1453,7 +1453,7 @@ class DFRN
                        return -9; // timed out
                }
 
-               if (($curl_stat == 503) && (stristr($postResult->getHeader(), 'retry-after'))) {
+               if (($curl_stat == 503) && $postResult->inHeader('retry-after')) {
                        return -10;
                }
 
@@ -1795,9 +1795,9 @@ class DFRN
        {
                Logger::notice('Processing suggestions');
 
-               $url = $xpath->query('dfrn:url/text()', $suggestion)->item(0)->nodeValue;
+               $url = $xpath->evaluate('string(dfrn:url[1]/text())', $suggestion);
                $cid = Contact::getIdForURL($url);
-               $note = $xpath->query('dfrn:note/text()', $suggestion)->item(0)->nodeValue;
+               $note = $xpath->evaluate('string(dfrn:note[1]/text())', $suggestion);
 
                return FContact::addSuggestion($importer['importer_uid'], $cid, $importer['id'], $note);
        }
@@ -2183,6 +2183,25 @@ class DFRN
                }
        }
 
+       /**
+        * Checks if an incoming message is wanted
+        *
+        * @param array $item
+        * @return boolean Is the message wanted?
+        */
+       private static function isSolicitedMessage(array $item)
+       {
+               if (DBA::exists('contact', ["`nurl` = ? AND `uid` != ? AND `rel` IN (?, ?)",
+                       Strings::normaliseLink($item["author-link"]), 0, Contact::FRIEND, Contact::SHARING])) {
+                       Logger::info('Author has got followers - accepted', ['uri' => $item['uri'], 'author' => $item["author-link"]]);
+                       return true;
+               }
+
+               $taglist = Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]);
+               $tags = array_column($taglist, 'name');
+               return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::DFRN);
+       }
+
        /**
         * Processes the entry elements which contain the items and comments
         *
@@ -2372,6 +2391,14 @@ class DFRN
                        }
                }
 
+               // Check if the message is wanted
+               if (($importer["importer_uid"] == 0) && ($item['uri'] == $item['parent-uri'])) {
+                       if (!self::isSolicitedMessage($item)) {
+                               DBA::delete('item-uri', ['uri' => $item['uri']]);
+                               return 403;
+                       }
+               }
+                               
                // Get the type of the item (Top level post, reply or remote reply)
                $entrytype = self::getEntryType($importer, $item);