Fetch profile data from different contact tables when we won't or can't probe via network
This commit is contained in:
parent
df0e2c959a
commit
f387d85cdb
|
@ -1114,6 +1114,81 @@ class Contact extends BaseObject
|
||||||
)", intval($uid), intval($uid));
|
)", intval($uid), intval($uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Have a look at all contact tables for a given profile url.
|
||||||
|
* This function works as a replacement for probing the contact.
|
||||||
|
*
|
||||||
|
* @param string $url Contact URL
|
||||||
|
*
|
||||||
|
* @return array Contact array in the "probe" structure
|
||||||
|
*/
|
||||||
|
private static function getProbeDataFromDatabase($url)
|
||||||
|
{
|
||||||
|
// The link could be provided as http although we stored it as https
|
||||||
|
$ssl_url = str_replace('http://', 'https://', $url);
|
||||||
|
|
||||||
|
$fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
|
||||||
|
'photo', 'keywords', 'location', 'about', 'network',
|
||||||
|
'priority', 'batch', 'request', 'confirm', 'poco'];
|
||||||
|
$data = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url)]);
|
||||||
|
|
||||||
|
if (!DBA::isResult($contact)) {
|
||||||
|
$condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
|
||||||
|
$data = DBA::selectFirst('contact', $fields, $condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DBA::isResult($data)) {
|
||||||
|
// For security reasons we don't fetch key data from our users
|
||||||
|
$data["pubkey"] = '';
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = ['url', 'addr', 'alias', 'notify', 'name', 'nick',
|
||||||
|
'photo', 'keywords', 'location', 'about', 'network'];
|
||||||
|
$data = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($url)]);
|
||||||
|
|
||||||
|
if (!DBA::isResult($contact)) {
|
||||||
|
$condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
|
||||||
|
$data = DBA::selectFirst('contact', $fields, $condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DBA::isResult($data)) {
|
||||||
|
$data["pubkey"] = '';
|
||||||
|
$data["poll"] = '';
|
||||||
|
$data["priority"] = 0;
|
||||||
|
$data["batch"] = '';
|
||||||
|
$data["request"] = '';
|
||||||
|
$data["confirm"] = '';
|
||||||
|
$data["poco"] = '';
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = ActivityPub::probeProfile($url, false);
|
||||||
|
if (!empty($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
|
||||||
|
'photo', 'network', 'priority', 'batch', 'request', 'confirm'];
|
||||||
|
$data = DBA::selectFirst('fcontact', $fields, ['url' => $url]);
|
||||||
|
|
||||||
|
if (!DBA::isResult($contact)) {
|
||||||
|
$condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
|
||||||
|
$data = DBA::selectFirst('contact', $fields, $condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DBA::isResult($data)) {
|
||||||
|
$data["pubkey"] = '';
|
||||||
|
$data["keywords"] = '';
|
||||||
|
$data["location"] = '';
|
||||||
|
$data["about"] = '';
|
||||||
|
$data["poco"] = '';
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetch the contact id for a given URL and user
|
* @brief Fetch the contact id for a given URL and user
|
||||||
*
|
*
|
||||||
|
@ -1187,17 +1262,9 @@ class Contact extends BaseObject
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we don't want to update, we look if some of our users already know this contact
|
// When we don't want to update, we look if we know this contact in any way
|
||||||
if ($no_update) {
|
if ($no_update && empty($default)) {
|
||||||
$fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
|
$data = self::getProbeDataFromDatabase($url);
|
||||||
'photo', 'keywords', 'location', 'about', 'network',
|
|
||||||
'priority', 'batch', 'request', 'confirm', 'poco'];
|
|
||||||
$data = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url)]);
|
|
||||||
|
|
||||||
if (DBA::isResult($data)) {
|
|
||||||
// For security reasons we don't fetch key data from our users
|
|
||||||
$data["pubkey"] = '';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$data = [];
|
$data = [];
|
||||||
}
|
}
|
||||||
|
@ -1217,40 +1284,13 @@ class Contact extends BaseObject
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get data from the gcontact table
|
|
||||||
$fields = ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'];
|
|
||||||
$contact = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($url)]);
|
|
||||||
if (!DBA::isResult($contact)) {
|
|
||||||
$contact = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DBA::isResult($contact)) {
|
|
||||||
$fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
|
|
||||||
'photo', 'keywords', 'location', 'about', 'network',
|
|
||||||
'priority', 'batch', 'request', 'confirm', 'poco'];
|
|
||||||
$contact = DBA::selectFirst('contact', $fields, ['addr' => $url]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The link could be provided as http although we stored it as https
|
|
||||||
$ssl_url = str_replace('http://', 'https://', $url);
|
|
||||||
|
|
||||||
if (!DBA::isResult($contact)) {
|
|
||||||
$condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]];
|
|
||||||
$contact = DBA::selectFirst('contact', $fields, $condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DBA::isResult($contact)) {
|
|
||||||
$fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
|
|
||||||
'photo', 'network', 'priority', 'batch', 'request', 'confirm'];
|
|
||||||
$condition = ['url' => [$url, Strings::normaliseLink($url), $ssl_url]];
|
|
||||||
$contact = DBA::selectFirst('fcontact', $fields, $condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($default)) {
|
if (!empty($default)) {
|
||||||
$contact = $default;
|
$contact = $default;
|
||||||
|
} else {
|
||||||
|
$contact = self::getProbeDataFromDatabase($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DBA::isResult($contact)) {
|
if (!empty($contact)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
$data = array_merge($data, $contact);
|
$data = array_merge($data, $contact);
|
||||||
|
|
|
@ -90,13 +90,14 @@ class ActivityPub
|
||||||
* Fetches a profile from the given url into an array that is compatible to Probe::uri
|
* Fetches a profile from the given url into an array that is compatible to Probe::uri
|
||||||
*
|
*
|
||||||
* @param string $url profile url
|
* @param string $url profile url
|
||||||
|
* @param boolean $update Update the profile
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function probeProfile($url)
|
public static function probeProfile($url, $update = true)
|
||||||
{
|
{
|
||||||
$apcontact = APContact::getByURL($url, true);
|
$apcontact = APContact::getByURL($url, $update);
|
||||||
if (empty($apcontact)) {
|
if (empty($apcontact)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user