mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 02:15:19 +00:00
refactor include/follow
This commit is contained in:
parent
d67d26564d
commit
f58c244ba0
2 changed files with 41 additions and 130 deletions
|
@ -22,7 +22,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
$is_zot = false;
|
||||
$protocol = '';
|
||||
|
||||
|
||||
if(substr($url,0,1) === '[') {
|
||||
$x = strpos($url,']');
|
||||
if($x) {
|
||||
|
@ -31,8 +30,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
}
|
||||
}
|
||||
|
||||
$is_http = ((strpos($url,'://') !== false) ? true : false);
|
||||
|
||||
$url = rtrim($url,'/');
|
||||
|
||||
if(! allowed_url($url)) {
|
||||
|
@ -45,7 +42,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
return $result;
|
||||
}
|
||||
|
||||
|
||||
// check service class limits
|
||||
|
||||
$r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ",
|
||||
|
@ -59,86 +55,28 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
return $result;
|
||||
}
|
||||
|
||||
|
||||
$arr = array('url' => $url, 'protocol' => $protocol, 'channel' => array());
|
||||
|
||||
call_hooks('follow_init', $arr);
|
||||
|
||||
if($arr['channel']['success'])
|
||||
$ret = $arr['channel'];
|
||||
else {
|
||||
$href = \Zotlabs\Lib\Webfinger::zot_url(punify($url));
|
||||
if($href) {
|
||||
$zf = \Zotlabs\Lib\Zotfinger::exec($href,$channel);
|
||||
}
|
||||
if(is_array($zf) && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href
|
||||
&& intval($zf['signature']['header_valid']) && array_path_exists('data/permissions',$zf)) {
|
||||
$x = Libzot::import_xchan($zf['data']);
|
||||
$j = $zf['data'];
|
||||
$is_zot = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$p = \Zotlabs\Access\Permissions::connect_perms($uid);
|
||||
$my_perms = \Zotlabs\Access\Permissions::serialise($p['perms']);
|
||||
|
||||
if($x) {
|
||||
|
||||
// Premium channel, set confirm before callback to avoid recursion
|
||||
|
||||
// if(array_key_exists('connect_url',$j) && (! $confirm)) {
|
||||
// if($interactive) {
|
||||
// goaway(zid($j['connect_url']));
|
||||
// }
|
||||
// else {
|
||||
// $result['message'] = t('Premium channel - please visit:') . ' ' . zid($j['connect_url']);
|
||||
// logger('mod_follow: ' . $result['message']);
|
||||
// return $result;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
if(array_key_exists('deleted',$j) && intval($j['deleted'])) {
|
||||
$result['message'] = t('Channel was deleted and no longer exists.');
|
||||
return $result;
|
||||
}
|
||||
|
||||
if(! $x['success'])
|
||||
return $x;
|
||||
|
||||
$xchan_hash = $x['hash'];
|
||||
|
||||
$permissions = $j['permissions'];
|
||||
|
||||
set_abconfig($channel['channel_uid'],$xchan_hash,'system','their_perms',$j['permissions']);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$xchan_hash = '';
|
||||
$sql_options = (($protocol) ? " and xchan_network = '" . dbesc($protocol) . "' " : '');
|
||||
|
||||
|
||||
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' $sql_options limit 1",
|
||||
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' $sql_options limit 1",
|
||||
dbesc($url),
|
||||
dbesc($url),
|
||||
dbesc($url)
|
||||
);
|
||||
|
||||
$singleton = false;
|
||||
$d = false;
|
||||
|
||||
if(! $r) {
|
||||
|
||||
// attempt network auto-discovery
|
||||
// try RSS discovery
|
||||
|
||||
$wf = discover_by_webbie($url,$protocol);
|
||||
|
||||
if((! $wf) && ($is_http)) {
|
||||
|
||||
// try RSS discovery
|
||||
|
||||
$feeds = get_config('system','feed_contacts');
|
||||
|
||||
if(($feeds) && ($protocol === '' || $protocol === 'feed' || $protocol === 'rss')) {
|
||||
$d = discover_by_url($url);
|
||||
$d = discover_feed($url);
|
||||
}
|
||||
else {
|
||||
$result['message'] = t('Remote channel or protocol unavailable.');
|
||||
|
@ -147,12 +85,12 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
}
|
||||
|
||||
if($wf || $d) {
|
||||
$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' or xchan_addr = '%s' limit 1",
|
||||
dbesc(($wf) ? $wf : $url),
|
||||
dbesc($url),
|
||||
dbesc($url)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// if discovery was a success we should have an xchan record in $r
|
||||
|
||||
|
@ -161,7 +99,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
$xchan_hash = $r[0]['xchan_hash'];
|
||||
$their_perms = EMPTY_STR;
|
||||
}
|
||||
}
|
||||
|
||||
if(! $xchan_hash) {
|
||||
$result['message'] = t('Channel discovery failed.');
|
||||
|
@ -169,19 +106,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
return $result;
|
||||
}
|
||||
|
||||
$allowed = (($is_zot || $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);
|
||||
|
||||
if(! $x['allowed']) {
|
||||
$result['message'] = t('Protocol disabled.');
|
||||
return $result;
|
||||
}
|
||||
|
||||
$singleton = intval($x['singleton']);
|
||||
|
||||
$aid = $channel['channel_account_id'];
|
||||
$hash = $channel['channel_hash'];
|
||||
$default_group = $channel['channel_default_group'];
|
||||
|
@ -217,6 +141,9 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
|
||||
}
|
||||
|
||||
$p = \Zotlabs\Access\Permissions::connect_perms($uid);
|
||||
$my_perms = \Zotlabs\Access\Permissions::serialise($p['perms']);
|
||||
|
||||
$profile_assign = get_pconfig($uid,'system','profile_assign','');
|
||||
|
||||
|
||||
|
@ -268,7 +195,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
}
|
||||
|
||||
if(! $r)
|
||||
logger('mod_follow: abook creation failed');
|
||||
logger('abook creation failed');
|
||||
|
||||
if($my_perms) {
|
||||
set_abconfig($uid,$xchan_hash,'system','my_perms',$my_perms);
|
||||
|
@ -282,20 +209,20 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
|||
|
||||
if($r) {
|
||||
$result['abook'] = $r[0];
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier', 'permissions_create', $result['abook']['abook_id']));
|
||||
Zotlabs\Daemon\Master::Summon([ 'Notifier', 'permissions_create', $result['abook']['abook_id'] ]);
|
||||
}
|
||||
|
||||
$arr = array('channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook']);
|
||||
$arr = [ 'channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook'] ];
|
||||
|
||||
call_hooks('follow', $arr);
|
||||
|
||||
/** If there is a default group for this channel, add this connection to it */
|
||||
|
||||
if($default_group) {
|
||||
|
||||
$g = Group::rec_byhash($uid,$default_group);
|
||||
if($g)
|
||||
Group_member_add($uid,'',$xchan_hash,$g['id']);
|
||||
if($g) {
|
||||
Group::member_add($uid,'',$xchan_hash,$g['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$result['success'] = true;
|
||||
|
|
|
@ -1005,7 +1005,7 @@ function email_header_encode($in_str, $charset = 'UTF-8') {
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function discover_by_url($url, $arr = null) {
|
||||
function discover_feed($url, $arr = null) {
|
||||
|
||||
$x = scrape_feed($url);
|
||||
if(! $x) {
|
||||
|
@ -1192,23 +1192,7 @@ function discover_by_webbie($webbie, $protocol = '') {
|
|||
|
||||
$x = Libzot::import_xchan($record['data']);
|
||||
if($x['success']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if($link['rel'] === PROTOCOL_ZOT && ((! $protocol) || (strtolower($protocol) === 'zot'))) {
|
||||
logger('zot found for ' . $webbie, LOGGER_DEBUG);
|
||||
if(array_key_exists('zot',$x) && $x['zot']['success']) {
|
||||
$i = import_xchan($x['zot']);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
$z = z_fetch_url($link['href']);
|
||||
if($z['success']) {
|
||||
$j = json_decode($z['body'],true);
|
||||
$i = import_xchan($j);
|
||||
return true;
|
||||
}
|
||||
return $x['hash'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue