<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Email;
use Friendica\Protocol\Feed;
+use Friendica\Protocol\Salmon;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
*/
class Probe
{
+ const HOST_META = '/.well-known/host-meta';
const WEBFINGER = '/.well-known/webfinger?resource={uri}';
+ /**
+ * @var string Base URL
+ */
private static $baseurl;
- private static $istimeout;
+
+ /**
+ * @var boolean Whether a timeout has occurred
+ */
+ private static $isTimeout;
+
+ /**
+ * Checks if the provided network can be probed
+ *
+ * @param string $network
+ *
+ * @return boolean
+ */
+ public static function isProbable(string $network): bool
+ {
+ return (in_array($network, array_merge(Protocol::FEDERATED, [Protocol::ZOT, Protocol::PHANTOM])));
+ }
/**
* Remove stuff from an URI that doesn't belong there
public static function cleanURI(string $rawUri): string
{
// At first remove leading and trailing junk
- $rawUri = trim($rawUri, "@#?:/ \t\n\r\0\x0B");
+ $rawUri = trim($rawUri, "@#?: \t\n\r\0\x0B");
$rawUri = Network::convertToIdn($rawUri);
*/
private static function rearrangeData(array $data): array
{
- $fields = ['name', 'nick', 'guid', 'url', 'addr', 'alias', 'photo', 'header',
+ $fields = ['name', 'given_name', 'family_name', 'nick', 'guid', 'url', 'addr', 'alias',
+ 'photo', 'photo_medium', 'photo_small', 'header',
'account-type', 'community', 'keywords', 'location', 'about', 'xmpp', 'matrix',
'hide', 'batch', 'notify', 'poll', 'request', 'confirm', 'subscribe', 'poco',
'following', 'followers', 'inbox', 'outbox', 'sharedinbox',
$numeric_fields = ['gsid', 'hide', 'account-type', 'manually-approve'];
+ if (!empty($data['photo'])) {
+ $data['photo'] = Network::addBasePath($data['photo'], $data['url']);
+
+ if (!Network::isValidHttpUrl($data['photo'])) {
+ Logger::warning('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]);
+ unset($data['photo']);
+ }
+ }
+
$newdata = [];
foreach ($fields as $field) {
if (isset($data[$field])) {
if (in_array($field, $numeric_fields)) {
$newdata[$field] = (int)$data[$field];
} else {
- $newdata[$field] = $data[$field];
+ $newdata[$field] = trim($data[$field]);
}
} elseif (!in_array($field, $numeric_fields)) {
$newdata[$field] = '';
}
}
+ $newdata['networks'] = [];
+ foreach ([Protocol::DIASPORA, Protocol::OSTATUS] as $network) {
+ if (!empty($data['networks'][$network])) {
+ $data['networks'][$network]['subscribe'] = $newdata['subscribe'] ?? '';
+ if (empty($data['networks'][$network]['baseurl'])) {
+ $data['networks'][$network]['baseurl'] = $newdata['baseurl'] ?? '';
+ } else {
+ $newdata['baseurl'] = $data['networks'][$network]['baseurl'];
+ }
+ if (!empty($newdata['baseurl'])) {
+ $newdata['gsid'] = $data['networks'][$network]['gsid'] = GServer::getID($newdata['baseurl']);
+ } else {
+ $newdata['gsid'] = $data['networks'][$network]['gsid'] = null;
+ }
+
+ $newdata['networks'][$network] = self::rearrangeData($data['networks'][$network]);
+ unset($newdata['networks'][$network]['networks']);
+ }
+ }
+
// We don't use the "priority" field anymore and replace it with a dummy.
$newdata['priority'] = 0;
*/
private static function ownHost(string $host): bool
{
- $own_host = DI::baseUrl()->getHostname();
+ $own_host = DI::baseUrl()->getHost();
$parts = parse_url($host);
if (!isset($parts['scheme'])) {
- $parts = parse_url('http://'.$host);
+ $parts = parse_url('http://' . $host);
}
if (!isset($parts['host'])) {
* It seems as if it was dropped from the standard.
*
* @param string $host The host part of an url
+ *
* @return array with template and type of the webfinger template for JSON or XML
* @throws HTTPException\InternalServerErrorException
*/
// Handles the case when the hostname contains the scheme
if (!parse_url($host, PHP_URL_SCHEME)) {
- $ssl_url = 'https://' . $host . '/.well-known/host-meta';
- $url = 'http://' . $host . '/.well-known/host-meta';
+ $ssl_url = 'https://' . $host . self::HOST_META;
+ $url = 'http://' . $host . self::HOST_META;
} else {
- $ssl_url = $host . '/.well-known/host-meta';
+ $ssl_url = $host . self::HOST_META;
$url = '';
}
}
} elseif ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $ssl_url]);
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url]);
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
} elseif ($connection_error && $ssl_connection_error) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
* @param string $uri Address that should be probed
* @param string $network Test for this specific network
* @param integer $uid User ID for the probe (only used for mails)
- * @param boolean $cache Use cached values?
*
* @return array uri data
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function uri($uri, $network = '', $uid = -1)
+ public static function uri(string $uri, string $network = '', int $uid = -1): array
{
// Local profiles aren't probed via network
if (empty($network) && Contact::isLocal($uri)) {
}
if ($uid == -1) {
- $uid = local_user();
+ $uid = DI::userSession()->getLocalUserId();
}
if (empty($network) || ($network == Protocol::ACTIVITYPUB)) {
$ap_profile = [];
}
- self::$istimeout = false;
+ self::$isTimeout = false;
if ($network != Protocol::ACTIVITYPUB) {
$data = self::detect($uri, $network, $uid, $ap_profile);
$data = [];
}
if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) {
+ $networks = $data['networks'] ?? [];
+ unset($data['networks']);
+ if (!empty($data['network'])) {
+ $networks[$data['network']] = $data;
+ }
$data = $ap_profile;
+ $data['networks'] = $networks;
} elseif (!empty($ap_profile)) {
$ap_profile['batch'] = '';
$data = array_merge($ap_profile, $data);
*
* @param array $result Result array
* @param array $webfinger Webfinger data
+ *
* @return array result Altered/unaltered result array
*/
private static function getSubscribeLink(array $result, array $webfinger): array
* Get webfinger data from a given URI
*
* @param string $uri URI
+ *
* @return array Webfinger data
* @throws HTTPException\InternalServerErrorException
*/
- private static function getWebfingerArray(string $uri): array
+ public static function getWebfingerArray(string $uri): array
{
$parts = parse_url($uri);
$addr = $uri;
$webfinger = self::getWebfinger('https://' . $host . self::WEBFINGER, HttpClientAccept::JRD_JSON, $uri, $addr);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
if (empty($webfinger)) {
$webfinger = self::getWebfinger('http://' . $host . self::WEBFINGER, HttpClientAccept::JRD_JSON, $uri, $addr);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
} else {
if (empty($webfinger)) {
$lrdd = self::hostMeta($host);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
$baseurl = self::$baseurl;
* @param string $type
* @param string $uri
* @param string $addr
+ *
* @return array webfinger results
*/
private static function getWebfinger(string $template, string $type, string $uri, string $addr): array
$detected = $addr;
$path = str_replace('{uri}', urlencode('acct:' . $addr), $template);
$webfinger = self::webfinger($path, $type);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
}
$detected = $uri;
$path = str_replace('{uri}', urlencode($uri), $template);
$webfinger = self::webfinger($path, $type);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
}
}
$parts = parse_url($uri);
- if (empty($parts['scheme']) && empty($parts['host']) && !strstr($parts['path'], '@')) {
+ if (empty($parts['scheme']) && empty($parts['host']) && (empty($parts['path']) || strpos($parts['path'], '@') === false)) {
Logger::info('URI was not detectable', ['uri' => $uri]);
return [];
}
$result = [];
- if (in_array($network, ["", Protocol::DFRN])) {
+ if (in_array($network, ['', Protocol::DFRN])) {
$result = self::dfrn($webfinger);
}
- if ((!$result && ($network == "")) || ($network == Protocol::DIASPORA)) {
+ if ((!$result && ($network == '')) || ($network == Protocol::DIASPORA)) {
$result = self::diaspora($webfinger);
+ } else {
+ $result['networks'][Protocol::DIASPORA] = self::diaspora($webfinger);
}
- if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) {
+ if ((!$result && ($network == '')) || ($network == Protocol::OSTATUS)) {
$result = self::ostatus($webfinger);
+ } else {
+ $result['networks'][Protocol::OSTATUS] = self::ostatus($webfinger);
}
if (in_array($network, ['', Protocol::ZOT])) {
$result = self::zot($webfinger, $result, $baseurl);
}
if ((!$result && ($network == '')) || ($network == Protocol::PUMPIO)) {
- $result = self::pumpio($webfinger, $addr);
+ $result = self::pumpio($webfinger, $addr, $baseurl);
}
if (empty($result['network']) && empty($ap_profile['network']) || ($network == Protocol::FEED)) {
$result = self::feed($uri);
} else {
- // We overwrite the detected nick with our try if the previois routines hadn't detected it.
- // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
+ // We overwrite the detected nick with our try if the previous routines hadn't detected it.
+ // Additionally, it is overwritten when the nickname doesn't make sense (contains spaces).
if ((empty($result['nick']) || (strstr($result['nick'], ' '))) && ($nick != '')) {
$result['nick'] = $nick;
}
* @param array $webfinger Webfinger data
* @param array $data previously probed data
* @param string $baseUrl Base URL
+ *
* @return array Zot data
* @throws HTTPException\InternalServerErrorException
*/
*
* @param string $url Address that should be probed
* @param string $type type
+ *
* @return array webfinger data
* @throws HTTPException\InternalServerErrorException
*/
public static function webfinger(string $url, string $type): array
{
- $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
+ try {
+ $curlResult = DI::httpClient()->get(
+ $url,
+ $type,
+ [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout', 20)]
+ );
+ } catch (\Throwable $e) {
+ Logger::notice($e->getMessage(), ['url' => $url, 'type' => $type, 'class' => get_class($e)]);
+ return [];
+ }
- $curlResult = DI::httpClient()->get($url, $type, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$data = $curlResult->getBody();
*
* @param string $noscrape_url Link to the noscrape page
* @param array $data The already fetched data
+ *
* @return array noscrape data
* @throws HTTPException\InternalServerErrorException
*/
{
$curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return $data;
}
$content = $curlResult->getBody();
*
* @return int Number of errors
*/
- public static function validDfrn($data)
+ public static function validDfrn(array $data): int
{
$errors = 0;
if (!isset($data['key'])) {
$data = self::pollHcard($profile_link, $data, true);
}
- $prof_data = [];
if (empty($data['addr']) || empty($data['nick'])) {
$probe_data = self::uri($profile_link);
$data['nick'] = ($data['nick'] ?? '') ?: $probe_data['nick'];
}
- $prof_data['addr'] = $data['addr'];
- $prof_data['nick'] = $data['nick'];
- $prof_data['dfrn-request'] = $data['request'] ?? null;
- $prof_data['dfrn-confirm'] = $data['confirm'] ?? null;
- $prof_data['dfrn-notify'] = $data['notify'] ?? null;
- $prof_data['dfrn-poll'] = $data['poll'] ?? null;
- $prof_data['photo'] = $data['photo'] ?? null;
- $prof_data['fn'] = $data['name'] ?? null;
- $prof_data['key'] = $data['pubkey'] ?? null;
+ $prof_data = [
+ 'addr' => $data['addr'],
+ 'nick' => $data['nick'],
+ 'dfrn-request' => $data['request'] ?? null,
+ 'dfrn-confirm' => $data['confirm'] ?? null,
+ 'dfrn-notify' => $data['notify'] ?? null,
+ 'dfrn-poll' => $data['poll'] ?? null,
+ 'photo' => $data['photo'] ?? null,
+ 'fn' => $data['name'] ?? null,
+ 'key' => $data['pubkey'] ?? null,
+ ];
Logger::debug('Result', ['link' => $profile_link, 'data' => $prof_data]);
{
$curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$content = $curlResult->getBody();
return [];
}
- if (!isset($data["baseurl"])) {
- $data["baseurl"] = "";
+ if (!isset($data['baseurl'])) {
+ $data['baseurl'] = '';
}
if ($vcards->length > 0) {
// We have to discard the guid from the hcard in favour of the guid from lrdd
// Reason: Hubzilla doesn't use the value "uid" in the hcard like Diaspora does.
$search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' uid ')]", $vcard); // */
- if (($search->length > 0) && empty($data["guid"])) {
- $data["guid"] = $search->item(0)->nodeValue;
+ if (($search->length > 0) && empty($data['guid'])) {
+ $data['guid'] = $search->item(0)->nodeValue;
}
$search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' nickname ')]", $vcard); // */
if ($search->length > 0) {
- $data["nick"] = $search->item(0)->nodeValue;
+ $data['nick'] = $search->item(0)->nodeValue;
}
$search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' fn ')]", $vcard); // */
if ($search->length > 0) {
- $data["name"] = $search->item(0)->nodeValue;
+ $data['name'] = $search->item(0)->nodeValue;
+ }
+
+ $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' given_name ')]", $vcard); // */
+ if ($search->length > 0) {
+ $data["given_name"] = $search->item(0)->nodeValue;
+ }
+
+ $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' family_name ')]", $vcard); // */
+ if ($search->length > 0) {
+ $data["family_name"] = $search->item(0)->nodeValue;
}
$search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' searchable ')]", $vcard); // */
if ($search->length > 0) {
- $data["searchable"] = $search->item(0)->nodeValue;
+ $data['hide'] = (strtolower($search->item(0)->nodeValue) != 'true');
}
$search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' key ')]", $vcard); // */
}
}
- $avatar = [];
+ $avatars = [];
if (!empty($vcard)) {
$photos = $xpath->query("//*[contains(concat(' ', @class, ' '), ' photo ') or contains(concat(' ', @class, ' '), ' avatar ')]", $vcard); // */
foreach ($photos as $photo) {
}
if (isset($attr['src']) && isset($attr['width'])) {
- $avatar[$attr['width']] = $attr['src'];
+ $avatars[$attr['width']] = self::fixAvatar($attr['src'], $data['baseurl']);
}
// We don't have a width. So we just take everything that we got.
// This is a Hubzilla workaround which doesn't send a width.
- if ((sizeof($avatar) == 0) && !empty($attr['src'])) {
- $avatar[] = $attr['src'];
+ if (!$avatars && !empty($attr['src'])) {
+ $avatars[] = self::fixAvatar($attr['src'], $data['baseurl']);
}
}
}
- if (sizeof($avatar)) {
- ksort($avatar);
- $data['photo'] = self::fixAvatar(array_pop($avatar), $data['baseurl']);
+ if ($avatars) {
+ ksort($avatars);
+ $data['photo'] = array_pop($avatars);
+ if ($avatars) {
+ $data['photo_medium'] = array_pop($avatars);
+ }
+
+ if ($avatars) {
+ $data['photo_small'] = array_pop($avatars);
+ }
}
if ($dfrn) {
}
}
-
return $data;
}
* Check for Diaspora contact
*
* @param array $webfinger Webfinger data
+ *
* @return array Diaspora data
* @throws HTTPException\InternalServerErrorException
*/
*
* @param array $webfinger Webfinger data
* @param bool $short Short detection mode
+ *
* @return array|bool OStatus data or "false" on error or "true" on short mode
* @throws HTTPException\InternalServerErrorException
*/
} elseif (Strings::normaliseLink($pubkey) == 'http://') {
$curlResult = DI::httpClient()->get($pubkey, HttpClientAccept::MAGIC_KEY);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return $short ? false : [];
}
Logger::debug('Fetched public key', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $pubkey]);
$pubkey = $curlResult->getBody();
}
- $key = explode('.', $pubkey);
+ try {
+ $data['pubkey'] = Salmon::magicKeyToPem($pubkey);
+ } catch (\Throwable $e) {
- if (sizeof($key) >= 3) {
- $m = Strings::base64UrlDecode($key[1]);
- $e = Strings::base64UrlDecode($key[2]);
- $data['pubkey'] = Crypto::meToPem($m, $e);
}
}
}
// Fetch all additional data from the feed
$curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$feed = $curlResult->getBody();
if (!empty($feed_data['header']['author-about'])) {
$data['about'] = $feed_data['header']['author-about'];
}
- // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
+ // OStatus has serious issues when the url doesn't fit (ssl vs. non ssl)
// So we take the value that we just fetched, although the other one worked as well
if (!empty($feed_data['header']['author-link'])) {
$data['url'] = $feed_data['header']['author-link'];
* Fetch data from a pump.io profile page
*
* @param string $profile_link Link to the profile page
+ *
* @return array Profile data
*/
- private static function pumpioProfileData(string $profile_link): array
+ private static function pumpioProfileData(string $profile_link, string $baseurl): array
{
$curlResult = DI::httpClient()->get($profile_link, HttpClientAccept::HTML);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
}
if ($avatar) {
foreach ($avatar->attributes as $attribute) {
- if ($attribute->name == 'src') {
- $data['photo'] = trim($attribute->value);
+ if (($attribute->name == 'src') && !empty($attribute->value)) {
+ $data['photo'] = Network::addBasePath($attribute->value, $baseurl);
}
}
}
*
* @param array $webfinger Webfinger data
* @param string $addr
+ *
* @return array pump.io data
*/
- private static function pumpio(array $webfinger, string $addr): array
+ private static function pumpio(array $webfinger, string $addr, string $baseurl): array
{
$data = [];
// The array is reversed to take into account the order of preference for same-rel links
return [];
}
- $profile_data = self::pumpioProfileData($data['url']);
+ $profile_data = self::pumpioProfileData($data['url'], $baseurl);
if (!$profile_data) {
return [];
*
* @param string $url Page link
* @param string $body Page body string
+ *
* @return string|false Feed link or false if body was invalid HTML document
*/
public static function getFeedLink(string $url, string $body)
$xpath = new DOMXPath($doc);
$feedUrl = $xpath->evaluate('string(/html/head/link[@type="application/rss+xml" and @rel="alternate"]/@href)');
+ $feedUrl = $feedUrl ?: $xpath->evaluate('string(/html/head/link[@type="application/atom+xml" and @rel="alternate"]/@href)');
$feedUrl = $feedUrl ? self::ensureAbsoluteLinkFromHTMLDoc($feedUrl, $url, $xpath) : '';
* @param string $href The potential relative href found in the HTML document
* @param string $base The HTML document URL
* @param DOMXPath $xpath The HTML document XPath
+ *
* @return string Absolute URL
*/
private static function ensureAbsoluteLinkFromHTMLDoc(string $href, string $base, DOMXPath $xpath): string
// Resolve arbitrary relative path
// Lifted from https://www.php.net/manual/en/function.realpath.php#84012
$parts = array_filter(explode('/', $path), 'strlen');
- $absolutes = array();
+ $absolutes = [];
foreach ($parts as $part) {
if ('.' == $part) continue;
if ('..' == $part) {
* @return array feed data
* @throws HTTPException\InternalServerErrorException
*/
- private static function feed($url, $probe = true)
+ private static function feed(string $url, bool $probe = true): array
{
- $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML);
+ try {
+ $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML);
+ } catch(\Throwable $e) {
+ DI::logger()->info('Error requesting feed URL', ['url' => $url, 'exception' => $e]);
+ return [];
+ }
+
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
+
$feed = $curlResult->getBody();
$feed_data = Feed::import($feed);
*
* @param string $uri Profile link
* @param integer $uid User ID
+ *
* @return array mail data
* @throws \Exception
*/
$phost = substr($uri, strpos($uri, '@') + 1);
- $data = [];
- $data['addr'] = $uri;
- $data['network'] = Protocol::MAIL;
- $data['name'] = substr($uri, 0, strpos($uri, '@'));
+ $data = [
+ 'addr' => $uri,
+ 'network' => Protocol::MAIL,
+ 'name' => substr($uri, 0, strpos($uri, '@')),
+ 'photo' => Network::lookupAvatarByEmail($uri),
+ 'url' => 'mailto:' . $uri,
+ 'notify' => 'smtp ' . Strings::getRandomHex(),
+ 'poll' => 'email ' . Strings::getRandomHex(),
+ ];
+
$data['nick'] = $data['name'];
- $data['photo'] = Network::lookupAvatarByEmail($uri);
- $data['url'] = 'mailto:'.$uri;
- $data['notify'] = 'smtp ' . Strings::getRandomHex();
- $data['poll'] = 'email ' . Strings::getRandomHex();
$x = Email::messageMeta($mbox, $msgs[0]);
+
if (stristr($x[0]->from, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->from, '');
} elseif (stristr($x[0]->to, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->to, '');
}
+
if (isset($adr)) {
foreach ($adr as $feadr) {
if ((strcasecmp($feadr->mailbox, $data['name']) == 0)
}
}
}
+
if (!empty($mbox)) {
imap_close($mbox);
}
+
return $data;
}
*
* @param string $avatar Path to the avatar
* @param string $base Another path that is hopefully complete
+ *
* @return string fixed avatar path
* @throws \Exception
*/
* Fetch the last date that the contact had posted something (publically)
*
* @param array $data probing result
+ *
* @return string last activity
*/
public static function getLastUpdate(array $data): string
* Fetch the last activity date from the "noscrape" endpoint
*
* @param array $data Probing result
+ *
* @return string last activity or true if update was successful or the server was unreachable
*/
- private static function updateFromNoScrape(array $data)
+ private static function updateFromNoScrape(array $data): string
{
if (empty($data['baseurl'])) {
return '';
*
* @param string $feed
* @param array $data Probing result
+ *
* @return string last activity
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
* Probe data from local profiles without network traffic
*
* @param string $url
+ *
* @return array probed data
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\NotFoundException
$owner = User::getOwnerDataById($uid);
$approfile = ActivityPub\Transmitter::getProfile($uid);
+ $split_name = Diaspora::splitName($owner['name']);
+
if (empty($owner['gsid'])) {
$owner['gsid'] = GServer::getID($approfile['generator']['url']);
}
$data = [
- 'name' => $owner['name'], 'nick' => $owner['nick'], 'guid' => $approfile['diaspora:guid'] ?? '',
- 'url' => $owner['url'], 'addr' => $owner['addr'], 'alias' => $owner['alias'],
- 'photo' => User::getAvatarUrl($owner),
- 'header' => $owner['header'] ? Contact::getHeaderUrlForId($owner['id'], $owner['updated']) : '',
- 'account-type' => $owner['contact-type'], 'community' => ($owner['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
- 'keywords' => $owner['keywords'], 'location' => $owner['location'], 'about' => $owner['about'],
- 'xmpp' => $owner['xmpp'], 'matrix' => $owner['matrix'],
- 'hide' => !$owner['net-publish'], 'batch' => '', 'notify' => $owner['notify'],
- 'poll' => $owner['poll'], 'request' => $owner['request'], 'confirm' => $owner['confirm'],
- 'subscribe' => $approfile['generator']['url'] . '/follow?url={uri}', 'poco' => $owner['poco'],
- 'following' => $approfile['following'], 'followers' => $approfile['followers'],
- 'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'],
- 'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN,
- 'pubkey' => $owner['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $owner['gsid'],
- 'manually-approve' => in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])
+ 'name' => $owner['name'], 'nick' => $owner['nick'], 'guid' => $approfile['diaspora:guid'] ?? '',
+ 'url' => $owner['url'], 'addr' => $owner['addr'], 'alias' => $owner['alias'],
+ 'photo' => User::getAvatarUrl($owner),
+ 'header' => $owner['header'] ? Contact::getHeaderUrlForId($owner['id'], $owner['updated']) : '',
+ 'account-type' => $owner['contact-type'], 'community' => ($owner['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
+ 'keywords' => $owner['keywords'], 'location' => $owner['location'], 'about' => $owner['about'],
+ 'xmpp' => $owner['xmpp'], 'matrix' => $owner['matrix'],
+ 'hide' => !$owner['net-publish'], 'batch' => '', 'notify' => $owner['notify'],
+ 'poll' => $owner['poll'], 'request' => $owner['request'], 'confirm' => $owner['confirm'],
+ 'subscribe' => $approfile['generator']['url'] . '/contact/follow?url={uri}', 'poco' => $owner['poco'],
+ 'following' => $approfile['following'], 'followers' => $approfile['followers'],
+ 'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'],
+ 'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN,
+ 'pubkey' => $owner['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $owner['gsid'],
+ 'manually-approve' => in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]),
+ 'networks' => [
+ Protocol::DIASPORA => [
+ 'name' => $owner['name'],
+ 'given_name' => $split_name['first'],
+ 'family_name' => $split_name['last'],
+ 'nick' => $owner['nick'],
+ 'guid' => $approfile['diaspora:guid'],
+ 'url' => $owner['url'],
+ 'addr' => $owner['addr'],
+ 'alias' => $owner['alias'],
+ 'photo' => $owner['photo'],
+ 'photo_medium' => $owner['thumb'],
+ 'photo_small' => $owner['micro'],
+ 'batch' => $approfile['generator']['url'] . '/receive/public',
+ 'notify' => $owner['notify'],
+ 'poll' => $owner['poll'],
+ 'poco' => $owner['poco'],
+ 'network' => Protocol::DIASPORA,
+ 'pubkey' => $owner['upubkey'],
+ ]
+ ]
];
} catch (Exception $e) {
- // Default values for non existing targets
+ // Default values for nonexistent targets
$data = [
'name' => $url, 'nick' => $url, 'url' => $url, 'network' => Protocol::PHANTOM,
'photo' => DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO