diff options
Diffstat (limited to 'include/group.php')
-rw-r--r-- | include/group.php | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/include/group.php b/include/group.php index 6042acbb4..7ba14a49d 100644 --- a/include/group.php +++ b/include/group.php @@ -1,7 +1,7 @@ -<?php +<?php /** @file */ -function group_add($uid,$name) { +function group_add($uid,$name,$public = 0) { $ret = false; if(x($uid) && x($name)) { @@ -37,10 +37,11 @@ function group_add($uid,$name) { } while($dups == true); - $r = q("INSERT INTO `group` ( hash, uid, name ) - VALUES( '%s', %d, '%s' ) ", + $r = q("INSERT INTO `group` ( hash, uid, visible, name ) + VALUES( '%s', %d, %d, '%s' ) ", dbesc($hash), intval($uid), + intval($public), dbesc($name) ); $ret = $r; @@ -52,40 +53,43 @@ function group_add($uid,$name) { function group_rmv($uid,$name) { $ret = false; if(x($uid) && x($name)) { - $r = q("SELECT id FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", + $r = q("SELECT id, hash FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", intval($uid), dbesc($name) ); - if(count($r)) + if($r) { $group_id = $r[0]['id']; + $group_hash = $r[0]['hash']; + } + if(! $group_id) return false; // remove group from default posting lists - $r = q("SELECT channel_default_gid, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1", + $r = q("SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1", intval($uid) ); if($r) { $user_info = $r[0]; $change = false; - if($user_info['channel_default_gid'] == $group_id) { - $user_info['channel_default_gid'] = 0; + if($user_info['channel_default_group'] == $group_hash) { + $user_info['channel_default_group'] = ''; $change = true; } if(strpos($user_info['channel_allow_gid'], '<' . $group_id . '>') !== false) { - $user_info['channel_allow_gid'] = str_replace('<' . $group_id . '>', '', $user_info['channel_allow_gid']); + $user_info['channel_allow_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_allow_gid']); $change = true; } if(strpos($user_info['channel_deny_gid'], '<' . $group_id . '>') !== false) { - $user_info['channel_deny_gid'] = str_replace('<' . $group_id . '>', '', $user_info['channel_deny_gid']); + $user_info['channel_deny_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_deny_gid']); $change = true; } if($change) { - q("UPDATE channel SET channel_default_gid = %d, channel_allow_gid = '%s', channel_deny_gid = '%s' + q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s' WHERE channel_id = %d", - intval($user_info['channel_default_gid']), + intval($user_info['channel_default_group']), dbesc($user_info['channel_allow_gid']), dbesc($user_info['channel_deny_gid']), intval($uid) @@ -124,6 +128,19 @@ function group_byname($uid,$name) { return false; } + +function group_rec_byhash($uid,$hash) { + if((! $uid) || (! strlen($hash))) + return false; + $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `hash` = '%s' LIMIT 1", + intval($uid), + dbesc($hash) + ); + if($r) + return $r[0]; + return false; +} + function group_rmv_member($uid,$name,$member) { $gid = group_byname($uid,$name); if(! $gid) @@ -171,9 +188,10 @@ function group_get_members($gid) { if(intval($gid)) { $r = q("SELECT * FROM `group_member` LEFT JOIN abook ON abook_xchan = `group_member`.`xchan` left join xchan on xchan_hash = abook_xchan - WHERE `gid` = %d AND `group_member`.`uid` = %d and not ( abook_flags & %d ) and not ( abook_flags & %d ) and not ( abook_flags & %d ) ORDER BY xchan_name ASC ", + WHERE `gid` = %d AND abook_channel = %d and `group_member`.`uid` = %d and not ( abook_flags & %d ) and not ( abook_flags & %d ) and not ( abook_flags & %d ) ORDER BY xchan_name ASC ", intval($gid), intval(local_user()), + intval(local_user()), intval(ABOOK_FLAG_SELF), intval(ABOOK_FLAG_BLOCKED), intval(ABOOK_FLAG_PENDING) @@ -221,7 +239,7 @@ function group_side($every="contacts",$each="group",$edit = false, $group_id = 0 $groups = array(); $groups[] = array( - 'text' => t('All Connections'), + 'text' => t('All Channels'), 'id' => 0, 'selected' => (($group_id == 0) ? 'group-selected' : ''), 'href' => $every, @@ -279,12 +297,14 @@ function group_side($every="contacts",$each="group",$edit = false, $group_id = 0 function expand_groups($a) { if(! (is_array($a) && count($a))) return array(); - stringify_array_elms($groups); - $groups = implode(',', $a); + $x = $a; + stringify_array_elms($x); + $groups = implode(',', $x); $groups = dbesc($groups); - $r = q("SELECT xchan FROM `group_member` WHERE `gid` IN ( $groups )"); + if($groups) + $r = q("SELECT xchan FROM group_member WHERE gid IN ( $groups )"); $ret = array(); - if(count($r)) + if($r) foreach($r as $rr) $ret[] = $rr['xchan']; return $ret; |