diff options
Diffstat (limited to 'include/follow.php')
-rw-r--r-- | include/follow.php | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/include/follow.php b/include/follow.php index 54e16703d..40ad2c299 100644 --- a/include/follow.php +++ b/include/follow.php @@ -37,9 +37,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) // check service class limits - $r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d)>0 ", - intval($uid), - intval(ABOOK_FLAG_SELF) + $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", + intval($uid) ); if($r) $total_channels = $r[0]['total']; @@ -130,39 +129,31 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } } else { - if(! ($is_http)) { - if(! intval(get_config('system','diaspora_enabled'))) { - $result['message'] = t('Protocol disabled.'); - return $result; - } - - $allowed = get_pconfig($uid,'system','diaspora_allowed'); - if($allowed === false) - $allowed = 1; - - if(! intval($allowed)) { - $result['message'] = t('Protocol blocked for this channel.'); - return $result; - } - } $their_perms = 0; $xchan_hash = ''; + $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url) ); + if(! $r) { // attempt network auto-discovery if(strpos($url,'@') && (! $is_http)) { - $r = discover_by_webbie($url); + $d = discover_by_webbie($url); } elseif($is_http) { - $r = discover_by_url($url); + if(get_config('system','feed_contacts')) + $d = discover_by_url($url); + else { + $result['message'] = t('Protocol disabled.'); + return $result; + } } - if($r) { + if($d) { $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url) @@ -181,6 +172,16 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) return $result; } + $x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => 1); + + call_hooks('follow_allow',$x); + + if(! $x['allowed']) { + $result['message'] = t('Protocol disabled.'); + return $result; + } + + if((local_channel()) && $uid == local_channel()) { $aid = get_account_id(); $hash = get_observer_hash(); @@ -202,14 +203,9 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($is_http) { - if(! intval(get_config('system','feed_contacts'))) { - $result['message'] = t('Protocol disabled.'); - return $result; - } - $r = q("select count(*) as total from abook where abook_account = %d and ( abook_flags & %d )>0", - intval($aid), - intval(ABOOK_FLAG_FEED) + $r = q("select count(*) as total from abook where abook_account = %d and abook_feed = 1 ", + intval($aid) ); if($r) $total_feeds = $r[0]['total']; @@ -241,13 +237,13 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($closeness === false) $closeness = 80; - $r = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_flags, abook_their_perms, abook_my_perms, abook_created, abook_updated ) + $r = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_feed, abook_their_perms, abook_my_perms, abook_created, abook_updated ) values( %d, %d, %d, '%s', %d, %d, %d, '%s', '%s' ) ", intval($aid), intval($uid), intval($closeness), dbesc($xchan_hash), - intval(($is_http) ? ABOOK_FLAG_FEED : 0), + intval(($is_http) ? 1 : 0), intval(($is_http) ? $their_perms|PERMS_R_STREAM|PERMS_A_REPUBLISH : $their_perms), intval($my_perms), dbesc(datetime_convert()), @@ -265,7 +261,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) ); if($r) { $result['abook'] = $r[0]; - proc_run('php', 'include/notifier.php', 'permission_update', $result['abook']['abook_id']); + proc_run('php', 'include/notifier.php', 'permission_create', $result['abook']['abook_id']); } $arr = array('channel_id' => $uid, 'abook' => $result['abook']); |