aboutsummaryrefslogtreecommitdiffstats
path: root/include/identity.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/identity.php')
-rw-r--r--include/identity.php101
1 files changed, 89 insertions, 12 deletions
diff --git a/include/identity.php b/include/identity.php
index d8f59e56c..50c5d13b9 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -215,18 +215,38 @@ function create_identity($arr) {
if(array_key_exists('primary', $arr))
$primary = intval($arr['primary']);
+
$perms_sql = '';
- $defperms = site_default_perms();
+ $role_permissions = null;
$global_perms = get_perms();
- foreach($defperms as $p => $v) {
- $perms_keys .= ', ' . $global_perms[$p][0];
- $perms_vals .= ', ' . intval($v);
+
+ if(array_key_exists('permissions_role',$arr) && $arr['permissions_role']) {
+ $role_permissions = get_role_perms($arr['permissions_role']);
+
+ if($role_permissions) {
+ foreach($role_permissions as $p => $v) {
+ if(strpos($p,'channel_') !== false) {
+ $perms_keys .= ', ' . $p;
+ $perms_vals .= ', ' . intval($v);
+ }
+ if($p === 'directory_publish')
+ $publish = intval($v);
+ }
+ }
}
+ else {
+ $defperms = site_default_perms();
+ foreach($defperms as $p => $v) {
+ $perms_keys .= ', ' . $global_perms[$p][0];
+ $perms_vals .= ', ' . intval($v);
+ }
+ }
+
$expire = get_config('system', 'default_expire_days');
$expire = (($expire===false)? '0': $expire);
-
+
$r = q("insert into channel ( channel_account_id, channel_primary,
channel_name, channel_address, channel_guid, channel_guid_sig,
channel_hash, channel_prvkey, channel_pubkey, channel_pageflags, channel_expire_days $perms_keys )
@@ -246,8 +266,6 @@ function create_identity($arr) {
);
-
-
$r = q("select * from channel where channel_account_id = %d
and channel_guid = '%s' limit 1",
intval($arr['account_id']),
@@ -322,24 +340,55 @@ function create_identity($arr) {
dbesc($a->get_baseurl() . "/photo/profile/m/{$newuid}")
);
- $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_closeness, abook_created, abook_updated, abook_flags )
- values ( %d, %d, '%s', %d, '%s', '%s', %d ) ",
+ $myperms = 0;
+ if($role_permissions) {
+ $myperms = ((array_key_exists('perms_auto',$role_permissions) && $role_permissions['perms_auto']) ? intval($role_permissions['perms_accept']) : 0);
+ }
+
+ $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_closeness, abook_created, abook_updated, abook_flags, abook_my_perms )
+ values ( %d, %d, '%s', %d, '%s', '%s', %d, %d ) ",
intval($ret['channel']['channel_account_id']),
intval($newuid),
dbesc($hash),
intval(0),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
- intval(ABOOK_FLAG_SELF)
+ intval(ABOOK_FLAG_SELF),
+ intval($myperms)
);
if(intval($ret['channel']['channel_account_id'])) {
- // Create a group with no members. This allows somebody to use it
+ // Save our permissions role so we can perhaps call it up and modify it later.
+
+ if($role_permissions) {
+ set_pconfig($newuid,'system','permissions_role',$arr['permissions_role']);
+ if(array_key_exists('online',$role_permissions))
+ set_pconfig('system','hide_presence',1-intval($role_permissions['online']));
+ }
+
+ // Create a group with yourself as a member. This allows somebody to use it
// right away as a default group for new contacts.
require_once('include/group.php');
group_add($newuid, t('Friends'));
+ group_add_member($newuid,t('Friends'),$ret['channel']['channel_hash']);
+
+ // if our role_permissions indicate that we're using a default collection ACL, add it.
+
+ if(is_array($role_permissions) && $role_permissions['default_collection']) {
+ $r = q("select hash from groups where uid = %d and name = '%s' limit 1",
+ intval($newuid),
+ dbesc( t('Friends') )
+ );
+ if($r) {
+ q("update channel set channel_allow_gid = '%s' where channel_id = %d limit 1",
+ dbesc('<' . $r[0]['hash'] . '>'),
+ intval($newuid)
+ );
+ }
+ }
+
call_hooks('register_account', $newuid);
@@ -396,7 +445,7 @@ function set_default_login_identity($account_id,$channel_id,$force = true) {
*
*/
-function identity_basic_export($channel_id) {
+function identity_basic_export($channel_id, $items = false) {
/*
* Red basic channel export
@@ -468,8 +517,36 @@ function identity_basic_export($channel_id) {
$ret['photo'] = array('type' => $r[0]['type'], 'data' => base64url_encode($r[0]['data']));
}
+ if(! $items)
+ return $ret;
+
+
+ $r = q("select * from item_id where uid = %d",
+ intval($channel_id)
+ );
+
+ if($r)
+ $ret['item_id'] = $r;
+
+ $key = get_config('system','prvkey');
+
+ // warning: this may run into memory limits on smaller systems
+
+ $r = q("select * from item where (item_flags & %d) and not (item_restrict & %d) and uid = %d",
+ intval(ITEM_WALL),
+ intval(ITEM_DELETED),
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['item'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rr)
+ $ret['item'][] = encode_item($rr,true);
+ }
return $ret;
+
}