more work on permcats and consolidating calls that try to discover connect permissions, also create lowlevel store functions for abook and profile - since these currently may have issues with sql strict mode.
This commit is contained in:
@@ -336,17 +336,18 @@ function create_identity($arr) {
|
||||
// Not checking return value.
|
||||
// It's ok for this to fail if it's an imported channel, and therefore the hash is a duplicate
|
||||
|
||||
$r = q("INSERT INTO profile ( aid, uid, profile_guid, profile_name, is_default, publish, fullname, photo, thumb)
|
||||
VALUES ( %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s') ",
|
||||
intval($ret['channel']['channel_account_id']),
|
||||
intval($newuid),
|
||||
dbesc(random_string()),
|
||||
t('Default Profile'),
|
||||
1,
|
||||
$publish,
|
||||
dbesc($ret['channel']['channel_name']),
|
||||
dbesc(z_root() . "/photo/profile/l/{$newuid}"),
|
||||
dbesc(z_root() . "/photo/profile/m/{$newuid}")
|
||||
$r = profile_store_lowlevel(
|
||||
[
|
||||
'aid' => intval($ret['channel']['channel_account_id']),
|
||||
'uid' => intval($newuid),
|
||||
'profile_guid' => random_string(),
|
||||
'profile_name' => t('Default Profile'),
|
||||
'is_default' => 1,
|
||||
'publish' => $publish,
|
||||
'fullname' => $ret['channel']['channel_name'],
|
||||
'photo' => z_root() . "/photo/profile/l/{$newuid}",
|
||||
'thumb' => z_root() . "/photo/profile/m/{$newuid}"
|
||||
]
|
||||
);
|
||||
|
||||
if($role_permissions) {
|
||||
@@ -357,15 +358,16 @@ function create_identity($arr) {
|
||||
$myperms = $x['perms_connect'];
|
||||
}
|
||||
|
||||
$r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_closeness, abook_created, abook_updated, abook_self )
|
||||
values ( %d, %d, '%s', %d, '%s', '%s', %d ) ",
|
||||
intval($ret['channel']['channel_account_id']),
|
||||
intval($newuid),
|
||||
dbesc($hash),
|
||||
intval(0),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval(1)
|
||||
$r = abook_store_lowlevel(
|
||||
[
|
||||
'abook_account' => intval($ret['channel']['channel_account_id']),
|
||||
'abook_channel' => intval($newuid),
|
||||
'abook_xchan' => $hash,
|
||||
'abook_closeness' => 0,
|
||||
'abook_created' => datetime_convert(),
|
||||
'abook_updated' => datetime_convert(),
|
||||
'abook_self' => 1
|
||||
]
|
||||
);
|
||||
|
||||
$x = \Zotlabs\Access\Permissions::FilledPerms($myperms);
|
||||
@@ -390,6 +392,7 @@ function create_identity($arr) {
|
||||
set_pconfig($newuid,'autoperms',$k,$v);
|
||||
}
|
||||
}
|
||||
// as this is a new channel, this shouldn't do anything and probaby is not needed
|
||||
else {
|
||||
$r = q("delete from pconfig where uid = %d and cat = 'autoperms'",
|
||||
intval($newuid)
|
||||
@@ -462,6 +465,7 @@ function create_identity($arr) {
|
||||
* if true, set this default unconditionally
|
||||
* if $force is false only do this if there is no existing default
|
||||
*/
|
||||
|
||||
function set_default_login_identity($account_id, $channel_id, $force = true) {
|
||||
$r = q("select account_default_channel from account where account_id = %d limit 1",
|
||||
intval($account_id)
|
||||
@@ -499,6 +503,7 @@ function get_default_export_sections() {
|
||||
* @returns array
|
||||
* See function for details
|
||||
*/
|
||||
|
||||
function identity_basic_export($channel_id, $sections = null) {
|
||||
|
||||
/*
|
||||
@@ -1989,6 +1994,58 @@ function remote_login() {
|
||||
));
|
||||
return $o;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function profile_store_lowlevel($arr) {
|
||||
|
||||
$store = [
|
||||
'profile_guid' => ((array_key_exists('profile_guid',$arr)) ? $arr['profile_guid'] : ''),
|
||||
'aid' => ((array_key_exists('aid',$arr)) ? $arr['aid'] : 0),
|
||||
'uid' => ((array_key_exists('uid',$arr)) ? $arr['uid'] : 0),
|
||||
'profile_name' => ((array_key_exists('profile_name',$arr)) ? $arr['profile_name'] : ''),
|
||||
'is_default' => ((array_key_exists('is_default',$arr)) ? $arr['is_default'] : 0),
|
||||
'hide_friends' => ((array_key_exists('hide_friends',$arr)) ? $arr['hide_friends'] : 0),
|
||||
'fullname' => ((array_key_exists('fullname',$arr)) ? $arr['fullname'] : ''),
|
||||
'pdesc' => ((array_key_exists('pdesc',$arr)) ? $arr['pdesc'] : ''),
|
||||
'chandesc' => ((array_key_exists('chandesc',$arr)) ? $arr['chandesc'] : ''),
|
||||
'dob' => ((array_key_exists('dob',$arr)) ? $arr['dob'] : ''),
|
||||
'dob_tz' => ((array_key_exists('dob_tz',$arr)) ? $arr['dob_tz'] : ''),
|
||||
'address' => ((array_key_exists('address',$arr)) ? $arr['address'] : ''),
|
||||
'locality' => ((array_key_exists('locality',$arr)) ? $arr['locality'] : ''),
|
||||
'region' => ((array_key_exists('region',$arr)) ? $arr['region'] : ''),
|
||||
'postal_code' => ((array_key_exists('postal_code',$arr)) ? $arr['postal_code'] : ''),
|
||||
'country_name' => ((array_key_exists('country_name',$arr)) ? $arr['country_name'] : ''),
|
||||
'hometown' => ((array_key_exists('hometown',$arr)) ? $arr['hometown'] : ''),
|
||||
'gender' => ((array_key_exists('gender',$arr)) ? $arr['gender'] : ''),
|
||||
'marital' => ((array_key_exists('marital',$arr)) ? $arr['marital'] : ''),
|
||||
'partner' => ((array_key_exists('partner',$arr)) ? $arr['partner'] : ''),
|
||||
'howlong' => ((array_key_exists('howlong',$arr)) ? $arr['howlong'] : NULL_DATE),
|
||||
'sexual' => ((array_key_exists('sexual',$arr)) ? $arr['sexual'] : ''),
|
||||
'politic' => ((array_key_exists('politic',$arr)) ? $arr['politic'] : ''),
|
||||
'religion' => ((array_key_exists('religion',$arr)) ? $arr['religion'] : ''),
|
||||
'keywords' => ((array_key_exists('keywords',$arr)) ? $arr['keywords'] : ''),
|
||||
'likes' => ((array_key_exists('likes',$arr)) ? $arr['likes'] : ''),
|
||||
'dislikes' => ((array_key_exists('dislikes',$arr)) ? $arr['dislikes'] : ''),
|
||||
'about' => ((array_key_exists('about',$arr)) ? $arr['about'] : ''),
|
||||
'summary' => ((array_key_exists('summary',$arr)) ? $arr['summary'] : ''),
|
||||
'music' => ((array_key_exists('music',$arr)) ? $arr['music'] : ''),
|
||||
'book' => ((array_key_exists('book',$arr)) ? $arr['book'] : ''),
|
||||
'tv' => ((array_key_exists('tv',$arr)) ? $arr['tv'] : ''),
|
||||
'film' => ((array_key_exists('film',$arr)) ? $arr['film'] : ''),
|
||||
'interest' => ((array_key_exists('interest',$arr)) ? $arr['interest'] : ''),
|
||||
'romance' => ((array_key_exists('romance',$arr)) ? $arr['romance'] : ''),
|
||||
'employment' => ((array_key_exists('employment',$arr)) ? $arr['employment'] : ''),
|
||||
'education' => ((array_key_exists('education',$arr)) ? $arr['education'] : ''),
|
||||
'contact' => ((array_key_exists('contact',$arr)) ? $arr['contact'] : ''),
|
||||
'channels' => ((array_key_exists('channels',$arr)) ? $arr['channels'] : ''),
|
||||
'homepage' => ((array_key_exists('homepage',$arr)) ? $arr['homepage'] : ''),
|
||||
'photo' => ((array_key_exists('photo',$arr)) ? $arr['photo'] : ''),
|
||||
'thumb' => ((array_key_exists('thumb',$arr)) ? $arr['thumb'] : ''),
|
||||
'publish' => ((array_key_exists('publish',$arr)) ? $arr['publish'] : 0),
|
||||
'profile_vcard' => ((array_key_exists('profile_vcard',$arr)) ? $arr['profile_vcard'] : '')
|
||||
];
|
||||
|
||||
return create_table_from_array('profile',$store);
|
||||
}
|
||||
@@ -1,6 +1,38 @@
|
||||
<?php /** @file */
|
||||
|
||||
|
||||
function abook_store_lowlevel($arr) {
|
||||
|
||||
$store = [
|
||||
'abook_account' => ((array_key_exists('abook_account',$arr)) ? $arr['abook_account'] : 0),
|
||||
'abook_channel' => ((array_key_exists('abook_channel',$arr)) ? $arr['abook_channel'] : 0),
|
||||
'abook_xchan' => ((array_key_exists('abook_xchan',$arr)) ? $arr['abook_xchan'] : ''),
|
||||
'abook_my_perms' => ((array_key_exists('abook_my_perms',$arr)) ? $arr['abook_my_perms'] : 0),
|
||||
'abook_their_perms' => ((array_key_exists('abook_their_perms',$arr)) ? $arr['abook_their_perms'] : 0),
|
||||
'abook_closeness' => ((array_key_exists('abook_closeness',$arr)) ? $arr['abook_closeness'] : 99),
|
||||
'abook_created' => ((array_key_exists('abook_created',$arr)) ? $arr['abook_created'] : NULL_DATE),
|
||||
'abook_updated' => ((array_key_exists('abook_updated',$arr)) ? $arr['abook_updated'] : NULL_DATE),
|
||||
'abook_connected' => ((array_key_exists('abook_connected',$arr)) ? $arr['abook_connected'] : NULL_DATE),
|
||||
'abook_dob' => ((array_key_exists('abook_dob',$arr)) ? $arr['abook_dob'] : NULL_DATE),
|
||||
'abook_flags' => ((array_key_exists('abook_flags',$arr)) ? $arr['abook_flags'] : 0),
|
||||
'abook_blocked' => ((array_key_exists('abook_blocked',$arr)) ? $arr['abook_blocked'] : 0),
|
||||
'abook_ignored' => ((array_key_exists('abook_ignored',$arr)) ? $arr['abook_ignored'] : 0),
|
||||
'abook_hidden' => ((array_key_exists('abook_hidden',$arr)) ? $arr['abook_hidden'] : 0),
|
||||
'abook_archived' => ((array_key_exists('abook_archived',$arr)) ? $arr['abook_archived'] : 0),
|
||||
'abook_pending' => ((array_key_exists('abook_pending',$arr)) ? $arr['abook_pending'] : 0),
|
||||
'abook_unconnected' => ((array_key_exists('abook_unconnected',$arr)) ? $arr['abook_unconnected'] : 0),
|
||||
'abook_self' => ((array_key_exists('abook_self',$arr)) ? $arr['abook_self'] : 0),
|
||||
'abook_feed' => ((array_key_exists('abook_feed',$arr)) ? $arr['abook_feed'] : 0),
|
||||
'abook_profile' => ((array_key_exists('abook_profile',$arr)) ? $arr['abook_profile'] : ''),
|
||||
'abook_incl' => ((array_key_exists('abook_incl',$arr)) ? $arr['abook_incl'] : ''),
|
||||
'abook_excl' => ((array_key_exists('abook_excl',$arr)) ? $arr['abook_excl'] : ''),
|
||||
'abook_instance' => ((array_key_exists('abook_instance',$arr)) ? $arr['abook_instance'] : '')
|
||||
];
|
||||
|
||||
return create_table_from_array('abook',$store);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function rconnect_url($channel_id,$xchan) {
|
||||
|
||||
|
||||
@@ -13,12 +13,11 @@ require_once('include/zot.php');
|
||||
|
||||
function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) {
|
||||
|
||||
$result = [ 'success' => false, 'message' => '' ];
|
||||
|
||||
|
||||
$result = array('success' => false,'message' => '');
|
||||
|
||||
$is_red = false;
|
||||
$is_http = ((strpos($url,'://') !== false) ? true : false);
|
||||
$my_perms = false;
|
||||
$is_zot = false;
|
||||
$is_http = ((strpos($url,'://') !== false) ? true : false);
|
||||
|
||||
if($is_http && substr($url,-1,1) === '/')
|
||||
$url = substr($url,0,-1);
|
||||
@@ -58,20 +57,14 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
$ret = Zotlabs\Zot\Finger::run($url,$channel);
|
||||
|
||||
if($ret && is_array($ret) && $ret['success']) {
|
||||
$is_red = true;
|
||||
$is_zot = true;
|
||||
$j = $ret;
|
||||
}
|
||||
|
||||
$my_perms = get_channel_default_perms($uid);
|
||||
$p = \Zotlabs\Access\Permissions::connect_perms($uid);
|
||||
$my_perms = $p['perms'];
|
||||
|
||||
$role = get_pconfig($uid,'system','permissions_role');
|
||||
if($role) {
|
||||
$x = \Zotlabs\Access\PermissionRoles::role_perms($role);
|
||||
if($x['perms_connect'])
|
||||
$my_perms = $x['perms_connect'];
|
||||
}
|
||||
|
||||
if($is_red && $j) {
|
||||
if($is_zot && $j) {
|
||||
|
||||
logger('follow: ' . $url . ' ' . print_r($j,true), LOGGER_DEBUG);
|
||||
|
||||
@@ -166,14 +159,13 @@ 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;
|
||||
}
|
||||
|
||||
$allowed = (($is_red || $r[0]['xchan_network'] === 'rss') ? 1 : 0);
|
||||
$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);
|
||||
|
||||
@@ -211,7 +203,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
return $result;
|
||||
}
|
||||
|
||||
$r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook where abook_xchan = '%s' and abook_channel = %d limit 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)
|
||||
);
|
||||
@@ -226,6 +219,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
}
|
||||
|
||||
if($r) {
|
||||
|
||||
$abook_instance = $r[0]['abook_instance'];
|
||||
|
||||
if(($singleton) && strpos($abook_instance,z_root()) === false) {
|
||||
@@ -240,21 +234,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
);
|
||||
|
||||
if(intval($r[0]['abook_pending'])) {
|
||||
|
||||
$abook_my_perms = get_channel_default_perms($uid);
|
||||
$role = get_pconfig($uid,'system','permissions_role');
|
||||
if($role) {
|
||||
$x = \Zotlabs\Access\PermissionRoles::role_perms($role);
|
||||
if($x['perms_connect']) {
|
||||
$abook_my_perms = $x['perms_connect'];
|
||||
}
|
||||
}
|
||||
|
||||
$filled_perms = \Zotlabs\Access\Permissions::FilledPerms($abook_my_perms);
|
||||
foreach($filled_perms as $k => $v) {
|
||||
set_abconfig($uid,$r[0]['abook_xchan'],'my_perms',$k,$v);
|
||||
}
|
||||
|
||||
$x = q("update abook set abook_pending = 0 where abook_id = %d",
|
||||
intval($r[0]['abook_id'])
|
||||
);
|
||||
@@ -265,29 +244,26 @@ 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_feed, abook_created, abook_updated, abook_instance )
|
||||
values( %d, %d, %d, '%s', %d, '%s', '%s', '%s' ) ",
|
||||
intval($aid),
|
||||
intval($uid),
|
||||
intval($closeness),
|
||||
dbesc($xchan_hash),
|
||||
intval(($is_http) ? 1 : 0),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(($singleton) ? z_root() : '')
|
||||
$r = abook_store_lowlevel(
|
||||
[
|
||||
'abook_account' => intval($aid),
|
||||
'abook_channel' => intval($uid),
|
||||
'abook_closeness' => intval($closeness),
|
||||
'abook_xchan' => $xchan_hash,
|
||||
'abook_feed' => intval(($is_http) ? 1 : 0),
|
||||
'abook_created' => datetime_convert(),
|
||||
'abook_updated' => datetime_convert(),
|
||||
'abook_instance' => (($singleton) ? z_root() : '')
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if(! $r)
|
||||
logger('mod_follow: abook creation failed');
|
||||
|
||||
$all_perms = \Zotlabs\Access\Permissions::Perms();
|
||||
if($all_perms) {
|
||||
foreach($all_perms as $k => $v) {
|
||||
if(in_array($k,$my_perms))
|
||||
set_abconfig($uid,$xchan_hash,'my_perms',$k,1);
|
||||
else
|
||||
set_abconfig($uid,$xchan_hash,'my_perms',$k,0);
|
||||
if($my_perms) {
|
||||
foreach($my_perms as $k => $v) {
|
||||
set_abconfig($uid,$xchan_hash,'my_perms',$k,$v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -417,29 +417,13 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
}
|
||||
else {
|
||||
|
||||
$p = \Zotlabs\Access\Permissions::connect_perms($channel['channel_id']);
|
||||
|
||||
$my_perms = $p['perms'];
|
||||
$automatic = $p['automatic'];
|
||||
|
||||
// new connection
|
||||
|
||||
$my_perms = null;
|
||||
$automatic = false;
|
||||
|
||||
$role = get_pconfig($channel['channel_id'],'system','permissions_role');
|
||||
if($role) {
|
||||
$xx = \Zotlabs\Access\PermissionRoles::role_perms($role);
|
||||
if($xx['perms_auto']) {
|
||||
$automatic = true;
|
||||
$default_perms = $xx['perms_connect'];
|
||||
$my_perms = \Zotlabs\Access\Permissions::FilledPerms($default_perms);
|
||||
}
|
||||
}
|
||||
|
||||
if(! $my_perms) {
|
||||
$m = \Zotlabs\Access\Permissions::FilledAutoperms($channel['channel_id']);
|
||||
if($m) {
|
||||
$automatic = true;
|
||||
$my_perms = $m;
|
||||
}
|
||||
}
|
||||
|
||||
if($my_perms) {
|
||||
foreach($my_perms as $k => $v) {
|
||||
set_abconfig($channel['channel_id'],$x['hash'],'my_perms',$k,$v);
|
||||
@@ -450,15 +434,17 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
if($closeness === false)
|
||||
$closeness = 80;
|
||||
|
||||
$y = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_created, abook_updated, abook_dob, abook_pending ) values ( %d, %d, %d, '%s', '%s', '%s', '%s', %d )",
|
||||
intval($channel['channel_account_id']),
|
||||
intval($channel['channel_id']),
|
||||
intval($closeness),
|
||||
dbesc($x['hash']),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($next_birthday),
|
||||
intval(($automatic) ? 0 : 1)
|
||||
$y = abook_store_lowlevel(
|
||||
[
|
||||
'abook_account' => intval($channel['channel_account_id']),
|
||||
'abook_channel' => intval($channel['channel_id']),
|
||||
'abook_closeness' => intval($closeness),
|
||||
'abook_xchan' => $x['hash'],
|
||||
'abook_created' => datetime_convert(),
|
||||
'abook_updated' => datetime_convert(),
|
||||
'abook_dob' => $next_birthday,
|
||||
'abook_pending' => intval(($automatic) ? 0 : 1)
|
||||
]
|
||||
);
|
||||
|
||||
if($y) {
|
||||
@@ -3323,10 +3309,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
||||
logger('process_channel_sync_delivery: total_feeds service class limit exceeded');
|
||||
continue;
|
||||
}
|
||||
q("insert into abook ( abook_xchan, abook_account, abook_channel ) values ('%s', %d, %d ) ",
|
||||
dbesc($clean['abook_xchan']),
|
||||
intval($channel['channel_account_id']),
|
||||
intval($channel['channel_id'])
|
||||
abook_store_lowlevel(
|
||||
[
|
||||
'abook_xchan' => $clean['abook_xchan'],
|
||||
'abook_account' => $channel['channel_account_id'],
|
||||
'abook_channel' => $channel['channel_id']
|
||||
]
|
||||
);
|
||||
$total_friends ++;
|
||||
if(intval($clean['abook_feed']))
|
||||
|
||||
Reference in New Issue
Block a user