Merge pull request #7420 from annando/reshare-contact

Fix contact issues with fake reshares from Twitter
This commit is contained in:
Hypolite Petovan 2019-07-23 05:05:44 -04:00 committed by GitHub
commit 64b10205bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 4 deletions

View 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']));

View 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;

View 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
*