mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 05:35:12 +00:00
when following, allow [network]follow_address syntax to connect with a specific network for multi-protocol services
This commit is contained in:
parent
5686901869
commit
6c55e44f4c
2 changed files with 20 additions and 7 deletions
|
@ -17,6 +17,17 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||||
|
|
||||||
$my_perms = false;
|
$my_perms = false;
|
||||||
$is_zot = false;
|
$is_zot = false;
|
||||||
|
$protocol = '';
|
||||||
|
|
||||||
|
|
||||||
|
if(substr($url,0,1) === '[') {
|
||||||
|
$x = strpos($url,']');
|
||||||
|
if($x) {
|
||||||
|
$protocol = substr($url,1,$x-1);
|
||||||
|
$url = substr($url,$x+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$is_http = ((strpos($url,'://') !== false) ? true : false);
|
$is_http = ((strpos($url,'://') !== false) ? true : false);
|
||||||
|
|
||||||
if($is_http && substr($url,-1,1) === '/')
|
if($is_http && substr($url,-1,1) === '/')
|
||||||
|
@ -47,13 +58,13 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$arr = array('url' => $url, 'channel' => array());
|
$arr = array('url' => $url, 'protocol', 'channel' => array());
|
||||||
|
|
||||||
call_hooks('follow_init', $arr);
|
call_hooks('follow_init', $arr);
|
||||||
|
|
||||||
if($arr['channel']['success'])
|
if($arr['channel']['success'])
|
||||||
$ret = $arr['channel'];
|
$ret = $arr['channel'];
|
||||||
elseif(! $is_http)
|
elseif((! $is_http) && ((! $protocol) || (strtolower($protocol) === 'zot')))
|
||||||
$ret = Zotlabs\Zot\Finger::run($url,$channel);
|
$ret = Zotlabs\Zot\Finger::run($url,$channel);
|
||||||
|
|
||||||
if($ret && is_array($ret) && $ret['success']) {
|
if($ret && is_array($ret) && $ret['success']) {
|
||||||
|
@ -118,8 +129,10 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$xchan_hash = '';
|
$xchan_hash = '';
|
||||||
|
$sql_options = (($protocol) ? " and xchan_network = '" . dbesc($protocol) . "' " : '');
|
||||||
|
|
||||||
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1",
|
|
||||||
|
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' $sql_options limit 1",
|
||||||
dbesc($url),
|
dbesc($url),
|
||||||
dbesc($url)
|
dbesc($url)
|
||||||
);
|
);
|
||||||
|
@ -127,7 +140,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||||
if(! $r) {
|
if(! $r) {
|
||||||
// attempt network auto-discovery
|
// attempt network auto-discovery
|
||||||
|
|
||||||
$d = discover_by_webbie($url);
|
$d = discover_by_webbie($url,$protocol);
|
||||||
|
|
||||||
if((! $d) && ($is_http)) {
|
if((! $d) && ($is_http)) {
|
||||||
|
|
||||||
|
|
|
@ -1137,7 +1137,7 @@ function discover_by_url($url, $arr = null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function discover_by_webbie($webbie) {
|
function discover_by_webbie($webbie,$protocol = '') {
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
|
@ -1153,7 +1153,7 @@ function discover_by_webbie($webbie) {
|
||||||
// If we discover zot - don't search further; grab the info and get out of
|
// If we discover zot - don't search further; grab the info and get out of
|
||||||
// here.
|
// here.
|
||||||
|
|
||||||
if($link['rel'] === PROTOCOL_ZOT) {
|
if($link['rel'] === PROTOCOL_ZOT && ((! $protocol) || (strtolower($protocol) === 'zot'))) {
|
||||||
logger('discover_by_webbie: zot found for ' . $webbie, LOGGER_DEBUG);
|
logger('discover_by_webbie: zot found for ' . $webbie, LOGGER_DEBUG);
|
||||||
if(array_key_exists('zot',$x) && $x['zot']['success']) {
|
if(array_key_exists('zot',$x) && $x['zot']['success']) {
|
||||||
$i = import_xchan($x['zot']);
|
$i = import_xchan($x['zot']);
|
||||||
|
@ -1174,7 +1174,7 @@ function discover_by_webbie($webbie) {
|
||||||
|
|
||||||
logger('webfinger: ' . print_r($x,true), LOGGER_DATA, LOG_INFO);
|
logger('webfinger: ' . print_r($x,true), LOGGER_DATA, LOG_INFO);
|
||||||
|
|
||||||
$arr = array('address' => $webbie, 'success' => false, 'webfinger' => $x);
|
$arr = array('address' => $webbie, 'protocol' => $protocol, 'success' => false, 'webfinger' => $x);
|
||||||
call_hooks('discover_channel_webfinger', $arr);
|
call_hooks('discover_channel_webfinger', $arr);
|
||||||
if($arr['success'])
|
if($arr['success'])
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue