Merge pull request #7434 from annando/contact-protocol
New functions to check if a contact supports that protocol
This commit is contained in:
commit
8b344141da
|
@ -194,4 +194,18 @@ class ActivityPub
|
|||
ActivityPub\Receiver::processActivity($ldactivity, '', $uid, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given contact url does support ActivityPub
|
||||
*
|
||||
* @param string $url profile url
|
||||
* @param boolean $update true = always update, false = never update, null = update when not found or outdated
|
||||
* @return boolean
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isSupportedByContactUrl($url, $update = null)
|
||||
{
|
||||
return !empty(APContact::getByURL($url, $update));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ use Friendica\Model\Mail;
|
|||
use Friendica\Model\PermissionSet;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Util\BaseURL;
|
||||
use Friendica\Util\Crypto;
|
||||
|
@ -3041,4 +3042,19 @@ class DFRN
|
|||
|
||||
return (strcmp($existing_edited, $update_edited) < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given contact url does support DFRN
|
||||
*
|
||||
* @param string $url profile url
|
||||
* @param boolean $update Update the profile
|
||||
* @return boolean
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isSupportedByContactUrl($url, $update = false)
|
||||
{
|
||||
$probe = Probe::uri($url, Protocol::DFRN, 0, !$update);
|
||||
return $probe['network'] == Protocol::DFRN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -942,19 +942,24 @@ class Diaspora
|
|||
* @brief Fetches data for a given handle
|
||||
*
|
||||
* @param string $handle The handle
|
||||
* @param boolean $update true = always update, false = never update, null = update when not found or outdated
|
||||
*
|
||||
* @return array the queried data
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function personByHandle($handle)
|
||||
public static function personByHandle($handle, $update = null)
|
||||
{
|
||||
$update = false;
|
||||
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
|
||||
if (!DBA::isResult($person)) {
|
||||
$urls = [$handle, str_replace('http://', 'https://', $handle), Strings::normaliseLink($handle)];
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'url' => $urls]);
|
||||
}
|
||||
|
||||
if (DBA::isResult($person)) {
|
||||
Logger::debug("In cache " . print_r($person, true));
|
||||
|
||||
if (is_null($update)) {
|
||||
// update record occasionally so it doesn't get stale
|
||||
$d = strtotime($person["updated"]." +00:00");
|
||||
if ($d < strtotime("now - 14 days")) {
|
||||
|
@ -965,8 +970,13 @@ class Diaspora
|
|||
$update = true;
|
||||
}
|
||||
}
|
||||
} elseif (is_null($update)) {
|
||||
$update = !DBA::isResult($person);
|
||||
} else {
|
||||
$person = [];
|
||||
}
|
||||
|
||||
if (!DBA::isResult($person) || $update) {
|
||||
if ($update) {
|
||||
Logger::log("create or refresh", Logger::DEBUG);
|
||||
$r = Probe::uri($handle, Protocol::DIASPORA);
|
||||
|
||||
|
@ -975,12 +985,7 @@ class Diaspora
|
|||
if ($r && ($r["network"] === Protocol::DIASPORA)) {
|
||||
self::updateFContact($r);
|
||||
|
||||
// Fetch the updated or added contact
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
|
||||
if (!DBA::isResult($person)) {
|
||||
$person = $r;
|
||||
$person['id'] = 0;
|
||||
}
|
||||
$person = self::personByHandle($handle, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1117,6 +1122,20 @@ class Diaspora
|
|||
return $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given contact url does support ActivityPub
|
||||
*
|
||||
* @param string $url profile url
|
||||
* @param boolean $update true = always update, false = never update, null = update when not found or outdated
|
||||
* @return boolean
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isSupportedByContactUrl($url, $update = null)
|
||||
{
|
||||
return !empty(self::personByHandle($url, $update));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if posting is allowed for this contact
|
||||
*
|
||||
|
|
|
@ -2302,4 +2302,19 @@ class OStatus
|
|||
|
||||
return trim($doc->saveXML());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given contact url does support OStatus
|
||||
*
|
||||
* @param string $url profile url
|
||||
* @param boolean $update Update the profile
|
||||
* @return boolean
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isSupportedByContactUrl($url, $update = false)
|
||||
{
|
||||
$probe = Probe::uri($url, Protocol::OSTATUS, 0, !$update);
|
||||
return $probe['network'] == Protocol::OSTATUS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue