diff options
Diffstat (limited to 'include/follow.php')
-rw-r--r-- | include/follow.php | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/include/follow.php b/include/follow.php index 751d86db1..56d8294c5 100644 --- a/include/follow.php +++ b/include/follow.php @@ -17,6 +17,17 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $my_perms = 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); 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', $arr); + call_hooks('follow_init', $arr); if($arr['channel']['success']) $ret = $arr['channel']; - elseif(! $is_http) + elseif((! $is_http) && ((! $protocol) || (strtolower($protocol) === 'zot'))) $ret = Zotlabs\Zot\Finger::run($url,$channel); if($ret && is_array($ret) && $ret['success']) { @@ -118,26 +129,31 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) else { $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) ); if(! $r) { + // attempt network auto-discovery - $d = discover_by_webbie($url); + $d = discover_by_webbie($url,$protocol); if((! $d) && ($is_http)) { // try RSS discovery - if(get_config('system','feed_contacts')) { + $feeds = get_config('system','feed_contacts'); + + if(($feeds) && ($protocol === '' || $protocol === 'feed')) { $d = discover_by_url($url); } else { - $result['message'] = t('Protocol disabled.'); + $result['message'] = t('Remote channel or protocol unavailable.'); return $result; } } @@ -182,6 +198,11 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $hash = get_observer_hash(); $default_group = $channel['channel_default_group']; + if($hash == $xchan_hash) { + $result['message'] = t('Cannot connect to yourself.'); + return $result; + } + if($xchan['xchan_network'] === 'rss') { // check service class feed limits @@ -196,28 +217,22 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $result['message'] = upgrade_message(); return $result; } - } - if($hash == $xchan_hash) { - $result['message'] = t('Cannot connect to yourself.'); - return $result; + // Always set these "remote" permissions for feeds since we cannot interact with them + // to negotiate a suitable permission response + + set_abconfig($uid,$xchan_hash,'their_perms','view_stream',1); + set_abconfig($uid,$xchan_hash,'their_perms','republish',1); + } + $r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook where abook_xchan = '%s' and abook_channel = %d limit 1", dbesc($xchan_hash), intval($uid) ); - if($is_http) { - - // Always set these "remote" permissions for feeds since we cannot interact with them - // to negotiate a suitable permission response - - set_abconfig($uid,$xchan_hash,'their_perms','view_stream',1); - set_abconfig($uid,$xchan_hash,'their_perms','republish',1); - } - if($r) { $abook_instance = $r[0]['abook_instance']; @@ -226,12 +241,12 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($abook_instance) $abook_instance .= ','; $abook_instance .= z_root(); - } - $x = q("update abook set abook_instance = '%s' where abook_id = %d", - dbesc($abook_instance), - intval($r[0]['abook_id']) - ); + $x = q("update abook set abook_instance = '%s', abook_not_here = 0 where abook_id = %d", + dbesc($abook_instance), + intval($r[0]['abook_id']) + ); + } if(intval($r[0]['abook_pending'])) { $x = q("update abook set abook_pending = 0 where abook_id = %d", @@ -250,7 +265,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) 'abook_channel' => intval($uid), 'abook_closeness' => intval($closeness), 'abook_xchan' => $xchan_hash, - 'abook_feed' => intval(($is_http) ? 1 : 0), + 'abook_feed' => intval(($xchan['xchan_network'] === 'rss') ? 1 : 0), 'abook_created' => datetime_convert(), 'abook_updated' => datetime_convert(), 'abook_instance' => (($singleton) ? z_root() : '') |