aboutsummaryrefslogtreecommitdiffstats
path: root/include/follow.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/follow.php')
-rw-r--r--include/follow.php55
1 files changed, 26 insertions, 29 deletions
diff --git a/include/follow.php b/include/follow.php
index 97be82da7..70e717cfc 100644
--- a/include/follow.php
+++ b/include/follow.php
@@ -122,6 +122,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
else
$permissions = $j['permissions'];
+
foreach($permissions as $k => $v) {
if($v) {
$their_perms = $their_perms | intval($global_perms[$k][1]);
@@ -133,26 +134,29 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
$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)) {
- $d = discover_by_webbie($url);
- }
- elseif($is_http) {
- if(get_config('system','feed_contacts'))
+
+ $d = discover_by_webbie($url);
+
+ if((! $d) && ($is_http)) {
+
+ // try RSS discovery
+
+ if(get_config('system','feed_contacts')) {
$d = discover_by_url($url);
+ }
else {
$result['message'] = t('Protocol disabled.');
return $result;
}
}
+
if($d) {
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1",
dbesc($url),
@@ -160,6 +164,9 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
);
}
}
+
+ // if discovery was a success we should have an xchan record in $r
+
if($r) {
$xchan = $r[0];
$xchan_hash = $r[0]['xchan_hash'];
@@ -167,13 +174,16 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
}
}
+
if(! $xchan_hash) {
$result['message'] = t('Channel discovery failed.');
logger('follow: ' . $result['message']);
return $result;
}
- $x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => 1, 'singleton' => 0);
+ $allowed = (($is_red || $r[0]['xchan_network'] === 'rss') ? 1 : 0);
+
+ $x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => $allowed, 'singleton' => 0);
call_hooks('follow_allow',$x);
@@ -183,27 +193,13 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
}
$singleton = intval($x['singleton']);
- if((local_channel()) && $uid == local_channel()) {
- $aid = get_account_id();
- $hash = get_observer_hash();
- $ch = $a->get_channel();
- $default_group = $ch['channel_default_group'];
- }
- else {
- $r = q("select * from channel where channel_id = %d limit 1",
- intval($uid)
- );
- if(! $r) {
- $result['message'] = t('local account not found.');
- return $result;
- }
- $aid = $r[0]['channel_account_id'];
- $hash = $r[0]['channel_hash'];
- $default_group = $r[0]['channel_default_group'];
- }
+ $aid = $channel['channel_account_id'];
+ $hash = get_observer_hash();
+ $default_group = $channel['channel_default_group'];
- if($is_http) {
+ if($xchan['xchan_network'] === 'rss') {
+ // check service class feed limits
$r = q("select count(*) as total from abook where abook_account = %d and abook_feed = 1 ",
intval($aid)
@@ -226,6 +222,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
dbesc($xchan_hash),
intval($uid)
);
+
if($r) {
$abook_instance = $r[0]['abook_instance'];
@@ -242,7 +239,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
);
}
else {
-
$closeness = get_pconfig($uid,'system','new_abook_closeness');
if($closeness === false)
$closeness = 80;
@@ -270,12 +266,13 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
dbesc($xchan_hash),
intval($uid)
);
+
if($r) {
$result['abook'] = $r[0];
proc_run('php', 'include/notifier.php', 'permission_create', $result['abook']['abook_id']);
}
- $arr = array('channel_id' => $uid, 'abook' => $result['abook']);
+ $arr = array('channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook']);
call_hooks('follow', $arr);