]> git.mxchange.org Git - friendica.git/commitdiff
Fix contact issues with fake reshares from Twitter
authorMichael <heluecht@pirati.ca>
Tue, 23 Jul 2019 04:26:20 +0000 (04:26 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 23 Jul 2019 04:26:20 +0000 (04:26 +0000)
src/Content/Text/BBCode.php
src/Model/Contact.php
src/Network/Probe.php

index da09e13dd9b8dfc5a243a9480d4b3de5b9207186..e2a4fa603cf42dc959fe95fcfb5efbc5d186cc87 100644 (file)
@@ -905,7 +905,17 @@ class BBCode extends BaseObject
                                // We only call this so that a previously unknown contact can be added.
                                // This is important for the function "Model\Contact::getDetailsByURL()".
                                // This function then can fetch an entry from the contact table.
-                               Contact::getIdForURL($attributes['profile'], 0, true);
+                               $default['url'] = $attributes['profile'];
+
+                               if (!empty($attributes['author'])) {
+                                       $default['name'] = $attributes['author'];
+                               }
+
+                               if (!empty($attributes['avatar'])) {
+                                       $default['photo'] = $attributes['avatar'];
+                               }
+
+                               Contact::getIdForURL($attributes['profile'], 0, true, $default);
 
                                $author_contact = Contact::getDetailsByURL($attributes['profile']);
                                $author_contact['addr'] = defaults($author_contact, 'addr' , Protocol::getAddrFromProfileUrl($attributes['profile']));
index 559236001eee0da25d74a62875b4c38fff0c1128..398acc2d7d06e65ce4cda577d4c74c035204ade9 100644 (file)
@@ -1419,7 +1419,7 @@ class Contact extends BaseObject
                        // When we don't want to update, we look if we know this contact in any way
                        $data = self::getProbeDataFromDatabase($url, $contact_id);
                        $background_update = true;
-               } elseif ($no_update && !empty($default)) {
+               } elseif ($no_update && !empty($default['network'])) {
                        // If there are default values, take these
                        $data = $default;
                        $background_update = false;
index 7a8e8de3502356782b22c5a36c9778378665059f..15235c7c26d5969f2bc58caa67721e3e560474b1 100644 (file)
@@ -471,7 +471,7 @@ class Probe
                        }
 
                        if ($host == 'twitter.com') {
-                               return ["network" => Protocol::TWITTER];
+                               return self::twitter($uri);
                        }
                        $lrdd = self::hostMeta($host);
 
@@ -512,7 +512,7 @@ class Probe
                        $nick = substr($uri, 0, strpos($uri, '@'));
 
                        if (strpos($uri, '@twitter.com')) {
-                               return ["network" => Protocol::TWITTER];
+                               return self::twitter($uri);
                        }
                        $lrdd = self::hostMeta($host);
 
@@ -1411,6 +1411,37 @@ class Probe
                return $data;
        }
 
+       /**
+        * @brief Check for twitter contact
+        *
+        * @param string $uri
+        *
+        * @return array twitter data
+        */
+       private static function twitter($uri)
+       {
+               if (preg_match('=(.*)@twitter.com=i', $uri, $matches)) {
+                       $nick = $matches[1];
+               } elseif (preg_match('=https?://twitter.com/(.*)=i', $uri, $matches)) {
+                       $nick = $matches[1];
+               } else {
+                       return [];
+               }
+
+               $data = [];
+               $data['url'] = 'https://twitter.com/' . $nick;
+               $data['addr'] = $nick . '@twitter.com';
+               $data['nick'] = $data['name'] = $nick;
+               $data['network'] = Protocol::TWITTER;
+               $data['baseurl'] = 'https://twitter.com';
+
+               $curlResult = Network::curl($data['url'], false);
+               if ($curlResult->isSuccess()) {
+                       return $data;
+               }
+               return [];
+       }
+
        /**
         * @brief Check page for feed link
         *