From 2a213c215e7e9bcb32b991a5c290ab1d42822f71 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 23 Jul 2019 04:26:20 +0000 Subject: [PATCH] Fix contact issues with fake reshares from Twitter --- src/Content/Text/BBCode.php | 12 +++++++++++- src/Model/Contact.php | 2 +- src/Network/Probe.php | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index da09e13dd9..e2a4fa603c 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -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'])); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 559236001e..398acc2d7d 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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; diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 7a8e8de350..15235c7c26 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -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 * -- 2.39.5