Merge pull request #9029 from annando/local-probing
Don't probe on local profiles via network
This commit is contained in:
commit
5651874fc5
|
@ -162,14 +162,24 @@ class User
|
||||||
* @return integer user id
|
* @return integer user id
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function getIdForURL($url)
|
public static function getIdForURL(string $url)
|
||||||
{
|
{
|
||||||
$self = DBA::selectFirst('contact', ['uid'], ['nurl' => Strings::normaliseLink($url), 'self' => true]);
|
$self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]);
|
||||||
if (!DBA::isResult($self)) {
|
if (!empty($self['uid'])) {
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return $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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace Friendica\Network;
|
||||||
|
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DomXPath;
|
use DomXPath;
|
||||||
use Friendica\Core\Cache\Duration;
|
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
|
@ -330,6 +329,14 @@ class Probe
|
||||||
*/
|
*/
|
||||||
public static function uri($uri, $network = '', $uid = -1)
|
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) {
|
if ($uid == -1) {
|
||||||
$uid = local_user();
|
$uid = local_user();
|
||||||
}
|
}
|
||||||
|
@ -2156,4 +2163,46 @@ class Probe
|
||||||
|
|
||||||
return '';
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue