Fixing the acl widget is going to be hard. Here's a start.

This commit is contained in:
friendica 2012-12-06 19:18:38 -08:00
parent 435836b224
commit 8f864ebd19
2 changed files with 33 additions and 23 deletions

View File

@ -26,8 +26,20 @@ function group_add($uid,$name) {
} }
return true; return true;
} }
$r = q("INSERT INTO `group` ( `uid`, `name` )
VALUES( %d, '%s' ) ", do {
$dups = false;
$hash = random_string() . $name;
$r = q("SELECT id FROM group WHERE hash = '%s' LIMIT 1", dbesc($hash));
if(count($r))
$dups = true;
} while($dups == true);
$r = q("INSERT INTO `group` ( hash, uid, name )
VALUES( '%s', %d, '%s' ) ",
dbesc($hash),
intval($uid), intval($uid),
dbesc($name) dbesc($name)
); );

View File

@ -27,8 +27,8 @@ function acl_init(&$a){
if ($search!=""){ if ($search!=""){
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'"; $sql_extra = " AND `name` LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " ";
$sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')"; $sql_extra2 = "AND ( xchan_name LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " OR xchan_addr LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . ") ";
$col = ((strpos($search,'@') !== false) ? 'xchan_addr' : 'xchan_name' ); $col = ((strpos($search,'@') !== false) ? 'xchan_addr' : 'xchan_name' );
$sql_extra3 = "AND $col like " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " "; $sql_extra3 = "AND $col like " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " ";
@ -48,14 +48,14 @@ function acl_init(&$a){
} }
if ($type=='' || $type=='c'){ if ($type=='' || $type=='c'){
$r = q("SELECT COUNT(`id`) AS c FROM `contact` $r = q("SELECT COUNT(abook_id) AS c FROM abook left join xchan on abook_xchan = xchan_hash
WHERE `uid` = %d AND `self` = 0 WHERE abook_channel = %d AND not ( abook_flags & %d ) $sql_extra2" ,
AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 intval(local_user()),
AND `notify` != '' $sql_extra2" , intval(ABOOK_FLAG_SELF|ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVE)
intval(local_user())
); );
$contact_count = (int)$r[0]['c']; $contact_count = (int)$r[0]['c'];
} }
elseif ($type == 'm') { elseif ($type == 'm') {
// autocomplete for Private Messages // autocomplete for Private Messages
@ -94,7 +94,8 @@ function acl_init(&$a){
if ($type=='' || $type=='g'){ if ($type=='' || $type=='g'){
$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`xchan` SEPARATOR ',') as uids $r = q("SELECT `group`.`id`, `group`.`hash`, `group`.`name`,
GROUP_CONCAT(DISTINCT `group_member`.`xchan` SEPARATOR ',') as uids
FROM `group`,`group_member` FROM `group`,`group_member`
WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
AND `group_member`.`gid`=`group`.`id` AND `group_member`.`gid`=`group`.`id`
@ -113,24 +114,23 @@ function acl_init(&$a){
"type" => "g", "type" => "g",
"photo" => "images/twopeople.png", "photo" => "images/twopeople.png",
"name" => $g['name'], "name" => $g['name'],
"id" => intval($g['id']), "id" => $g['hash'],
"uids" => array_map("intval", explode(",",$g['uids'])), "uids" => explode(",",$g['uids']),
"link" => '' "link" => ''
); );
} }
} }
if ($type=='' || $type=='c'){ if ($type=='' || $type=='c') {
$r = q("SELECT xchan_hash as id, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` FROM abook left join xchan on abook_xchan = xchan_hash
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' WHERE abook_channel = %d AND not ( abook_flags & %d ) $sql_extra2 order by xchan_name asc" ,
$sql_extra2 intval(local_user()),
ORDER BY `name` ASC ", intval(ABOOK_FLAG_SELF|ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVE)
intval(local_user())
); );
} }
elseif($type == 'm') { elseif($type == 'm') {
dbg(1);
$r = q("SELECT xchan_hash as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url $r = q("SELECT xchan_hash as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url
FROM abook left join xchan on abook_xchan = xchan_hash FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d and ( (abook_their_perms = null) or (abook_their_perms & %d )) WHERE abook_channel = %d and ( (abook_their_perms = null) or (abook_their_perms & %d ))
@ -139,7 +139,6 @@ dbg(1);
intval(local_user()), intval(local_user()),
intval(PERMS_W_MAIL) intval(PERMS_W_MAIL)
); );
dbg(0);
} }
elseif($type == 'a') { elseif($type == 'a') {
$r = q("SELECT abook_id as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash $r = q("SELECT abook_id as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash
@ -186,8 +185,7 @@ dbg(0);
"type" => "c", "type" => "c",
"photo" => $g['micro'], "photo" => $g['micro'],
"name" => $g['name'], "name" => $g['name'],
"id" => intval($g['id']), "id" => $g['id'],
"network" => $g['network'],
"link" => $g['url'], "link" => $g['url'],
"nick" => $g['nick'], "nick" => $g['nick'],
); );