Merge pull request #9029 from annando/local-probing

Don't probe on local profiles via network
This commit is contained in:
Hypolite Petovan 2020-08-18 15:58:51 -04:00 committed by GitHub
commit 5651874fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 6 deletions

View File

@ -162,14 +162,24 @@ class User
* @return integer user id
* @throws Exception
*/
public static function getIdForURL($url)
public static function getIdForURL(string $url)
{
$self = DBA::selectFirst('contact', ['uid'], ['nurl' => Strings::normaliseLink($url), 'self' => true]);
if (!DBA::isResult($self)) {
return false;
} else {
$self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]);
if (!empty($self['uid'])) {
return $self['uid'];
}
$self = Contact::selectFirst(['uid'], ['self' => true, 'addr' => $url]);
if (!empty($self['uid'])) {
return $self['uid'];
}
$self = Contact::selectFirst(['uid'], ['self' => true, 'alias' => [$url, Strings::normaliseLink($url)]]);
if (!empty($self['uid'])) {
return $self['uid'];
}
return 0;
}
/**

View File

@ -23,7 +23,6 @@ namespace Friendica\Network;
use DOMDocument;
use DomXPath;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
@ -330,6 +329,14 @@ class Probe
*/
public static function uri($uri, $network = '', $uid = -1)
{
// Local profiles aren't probed via network
if (empty($network) && strpos($uri, DI::baseUrl()->getHostname())) {
$data = self::localProbe($uri);
if (!empty($data)) {
return $data;
}
}
if ($uid == -1) {
$uid = local_user();
}
@ -2156,4 +2163,46 @@ class Probe
return '';
}
/**
* Probe data from local profiles without network traffic
*
* @param string $url
* @return array probed data
*/
private static function localProbe(string $url)
{
$uid = User::getIdForURL($url);
if (empty($uid)) {
return [];
}
$profile = User::getOwnerDataById($uid);
if (empty($profile)) {
return [];
}
$approfile = ActivityPub\Transmitter::getProfile($uid);
if (empty($approfile)) {
return [];
}
if (empty($profile['gsid'])) {
$profile['gsid'] = GServer::getID($approfile['generator']['url']);
}
$data = ['name' => $profile['name'], 'nick' => $profile['nick'], 'guid' => $approfile['diaspora:guid'],
'url' => $profile['url'], 'addr' => $profile['addr'], 'alias' => $profile['alias'],
'photo' => $profile['photo'], 'account-type' => $profile['contact-type'],
'community' => ($profile['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
'keywords' => $profile['keywords'], 'location' => $profile['location'], 'about' => $profile['about'],
'hide' => !$profile['net-publish'], 'batch' => '', 'notify' => $profile['notify'],
'poll' => $profile['poll'], 'request' => $profile['request'], 'confirm' => $profile['confirm'],
'subscribe' => $approfile['generator']['url'] . '/follow?url={uri}', 'poco' => $profile['poco'],
'following' => $approfile['following'], 'followers' => $approfile['followers'],
'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'],
'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN,
'pubkey' => $profile['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $profile['gsid']];
return self::rearrangeData($data);
}
}