2011-07-19 10:17:58 -04:00
|
|
|
<?php
|
|
|
|
/* ACL selector json backend */
|
2012-06-05 23:33:11 -04:00
|
|
|
|
2011-07-19 10:17:58 -04:00
|
|
|
require_once("include/acl_selectors.php");
|
|
|
|
|
|
|
|
function acl_init(&$a){
|
|
|
|
if(!local_user())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
2012-03-27 00:48:04 -04:00
|
|
|
$start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
|
|
|
|
$count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
|
|
|
|
$search = (x($_REQUEST,'search')?$_REQUEST['search']:"");
|
|
|
|
$type = (x($_REQUEST,'type')?$_REQUEST['type']:"");
|
2011-10-25 09:49:53 -04:00
|
|
|
|
2011-07-19 10:17:58 -04:00
|
|
|
|
2012-05-06 22:53:34 -04:00
|
|
|
// For use with jquery.autocomplete for private mail completion
|
|
|
|
|
|
|
|
if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
|
2012-06-05 23:33:11 -04:00
|
|
|
if(! $type)
|
|
|
|
$type = 'm';
|
2012-05-06 22:53:34 -04:00
|
|
|
$search = $_REQUEST['query'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-19 10:17:58 -04:00
|
|
|
if ($search!=""){
|
|
|
|
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
|
2011-10-26 18:14:12 -04:00
|
|
|
$sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
|
2012-02-26 15:40:41 -05:00
|
|
|
} else {
|
|
|
|
$sql_extra = $sql_extra2 = "";
|
2011-07-19 10:17:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// count groups and contacts
|
2011-10-25 09:49:53 -04:00
|
|
|
if ($type=='' || $type=='g'){
|
|
|
|
$r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
|
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
$group_count = (int)$r[0]['g'];
|
|
|
|
} else {
|
|
|
|
$group_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type=='' || $type=='c'){
|
|
|
|
$r = q("SELECT COUNT(`id`) AS c FROM `contact`
|
|
|
|
WHERE `uid` = %d AND `self` = 0
|
2012-04-27 20:17:58 -04:00
|
|
|
AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
|
2012-03-27 00:48:04 -04:00
|
|
|
AND `notify` != '' $sql_extra2" ,
|
2011-10-25 09:49:53 -04:00
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
$contact_count = (int)$r[0]['c'];
|
2012-04-23 21:28:33 -04:00
|
|
|
}
|
|
|
|
elseif ($type == 'm') {
|
|
|
|
|
|
|
|
// autocomplete for Private Messages
|
|
|
|
|
|
|
|
$r = q("SELECT COUNT(`id`) AS c FROM `contact`
|
|
|
|
WHERE `uid` = %d AND `self` = 0
|
2012-04-27 20:17:58 -04:00
|
|
|
AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
|
2012-04-23 21:28:33 -04:00
|
|
|
AND `network` IN ('%s','%s','%s') $sql_extra2" ,
|
|
|
|
intval(local_user()),
|
|
|
|
dbesc(NETWORK_DFRN),
|
|
|
|
dbesc(NETWORK_ZOT),
|
|
|
|
dbesc(NETWORK_DIASPORA)
|
|
|
|
);
|
|
|
|
$contact_count = (int)$r[0]['c'];
|
|
|
|
|
2012-06-05 23:33:11 -04:00
|
|
|
}
|
|
|
|
elseif ($type == 'a') {
|
|
|
|
|
|
|
|
// autocomplete for Contacts
|
|
|
|
|
|
|
|
$r = q("SELECT COUNT(`id`) AS c FROM `contact`
|
|
|
|
WHERE `uid` = %d AND `self` = 0
|
|
|
|
AND `pending` = 0 $sql_extra2" ,
|
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
$contact_count = (int)$r[0]['c'];
|
|
|
|
|
2011-10-25 09:49:53 -04:00
|
|
|
} else {
|
|
|
|
$contact_count = 0;
|
|
|
|
}
|
2011-07-19 10:17:58 -04:00
|
|
|
|
|
|
|
$tot = $group_count+$contact_count;
|
|
|
|
|
|
|
|
$groups = array();
|
|
|
|
$contacts = array();
|
|
|
|
|
2011-10-25 09:49:53 -04:00
|
|
|
if ($type=='' || $type=='g'){
|
|
|
|
|
|
|
|
$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
|
|
|
|
FROM `group`,`group_member`
|
|
|
|
WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
|
|
|
|
AND `group_member`.`gid`=`group`.`id`
|
|
|
|
$sql_extra
|
|
|
|
GROUP BY `group`.`id`
|
|
|
|
ORDER BY `group`.`name`
|
|
|
|
LIMIT %d,%d",
|
|
|
|
intval(local_user()),
|
|
|
|
intval($start),
|
|
|
|
intval($count)
|
2011-07-19 10:17:58 -04:00
|
|
|
);
|
2011-10-25 09:49:53 -04:00
|
|
|
|
|
|
|
foreach($r as $g){
|
2011-12-20 20:01:41 -05:00
|
|
|
// logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
|
2011-10-25 09:49:53 -04:00
|
|
|
$groups[] = array(
|
|
|
|
"type" => "g",
|
2012-01-11 00:09:38 -05:00
|
|
|
"photo" => "images/twopeople.png",
|
2011-10-25 09:49:53 -04:00
|
|
|
"name" => $g['name'],
|
|
|
|
"id" => intval($g['id']),
|
|
|
|
"uids" => array_map("intval", explode(",",$g['uids'])),
|
|
|
|
"link" => ''
|
|
|
|
);
|
|
|
|
}
|
2011-07-19 10:17:58 -04:00
|
|
|
}
|
|
|
|
|
2011-10-25 09:49:53 -04:00
|
|
|
if ($type=='' || $type=='c'){
|
2011-07-19 10:17:58 -04:00
|
|
|
|
2012-02-26 15:40:41 -05:00
|
|
|
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
|
2012-04-27 20:17:58 -04:00
|
|
|
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
|
2011-10-25 09:49:53 -04:00
|
|
|
$sql_extra2
|
|
|
|
ORDER BY `name` ASC ",
|
|
|
|
intval(local_user())
|
2011-07-19 10:17:58 -04:00
|
|
|
);
|
2012-04-23 21:28:33 -04:00
|
|
|
}
|
|
|
|
elseif($type == 'm') {
|
|
|
|
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
|
2012-04-27 20:17:58 -04:00
|
|
|
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
|
2012-04-23 21:28:33 -04:00
|
|
|
AND `network` IN ('%s','%s','%s')
|
|
|
|
$sql_extra2
|
|
|
|
ORDER BY `name` ASC ",
|
|
|
|
intval(local_user()),
|
|
|
|
dbesc(NETWORK_DFRN),
|
|
|
|
dbesc(NETWORK_ZOT),
|
|
|
|
dbesc(NETWORK_DIASPORA)
|
|
|
|
);
|
|
|
|
}
|
2012-06-05 23:33:11 -04:00
|
|
|
elseif($type == 'a') {
|
|
|
|
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
|
|
|
|
WHERE `uid` = %d AND `pending` = 0
|
|
|
|
$sql_extra2
|
|
|
|
ORDER BY `name` ASC ",
|
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
}
|
2012-04-23 21:28:33 -04:00
|
|
|
else
|
|
|
|
$r = array();
|
|
|
|
|
2012-05-06 22:53:34 -04:00
|
|
|
|
2012-06-05 23:33:11 -04:00
|
|
|
if($type == 'm' || $type == 'a') {
|
2012-05-06 22:53:34 -04:00
|
|
|
$x = array();
|
|
|
|
$x['query'] = $search;
|
2012-05-10 22:29:01 -04:00
|
|
|
$x['photos'] = array();
|
|
|
|
$x['links'] = array();
|
2012-05-06 22:53:34 -04:00
|
|
|
$x['suggestions'] = array();
|
|
|
|
$x['data'] = array();
|
|
|
|
if(count($r)) {
|
|
|
|
foreach($r as $g) {
|
2012-05-10 22:29:01 -04:00
|
|
|
$x['photos'][] = $g['micro'];
|
|
|
|
$x['links'][] = $g['url'];
|
2012-05-30 18:50:30 -04:00
|
|
|
$x['suggestions'][] = $g['name'];
|
2012-05-06 22:53:34 -04:00
|
|
|
$x['data'][] = intval($g['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo json_encode($x);
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2012-04-23 21:28:33 -04:00
|
|
|
if(count($r)) {
|
2011-10-25 09:49:53 -04:00
|
|
|
foreach($r as $g){
|
|
|
|
$contacts[] = array(
|
|
|
|
"type" => "c",
|
|
|
|
"photo" => $g['micro'],
|
|
|
|
"name" => $g['name'],
|
|
|
|
"id" => intval($g['id']),
|
|
|
|
"network" => $g['network'],
|
|
|
|
"link" => $g['url'],
|
2011-10-26 18:14:12 -04:00
|
|
|
"nick" => ($g['attag']) ? $g['attag'] : $g['nick'],
|
2011-10-25 09:49:53 -04:00
|
|
|
);
|
2012-04-23 21:28:33 -04:00
|
|
|
}
|
2011-07-19 10:17:58 -04:00
|
|
|
}
|
2012-04-23 21:28:33 -04:00
|
|
|
|
2011-07-19 10:17:58 -04:00
|
|
|
$items = array_merge($groups, $contacts);
|
|
|
|
|
|
|
|
$o = array(
|
|
|
|
'tot' => $tot,
|
|
|
|
'start' => $start,
|
|
|
|
'count' => $count,
|
|
|
|
'items' => $items,
|
|
|
|
);
|
|
|
|
|
|
|
|
echo json_encode($o);
|
|
|
|
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
|