Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
2.0 KiB

  1. <?php
  2. /* ACL selector json backend */
  3. require_once("include/acl_selectors.php");
  4. function acl_init(&$a){
  5. if(!local_user())
  6. return "";
  7. $start = (x($_POST,'start')?$_POST['start']:0);
  8. $count = (x($_POST,'count')?$_POST['count']:100);
  9. $search = (x($_POST,'search')?$_POST['search']:"");
  10. if ($search!=""){
  11. $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
  12. }
  13. // count groups and contacts
  14. $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
  15. intval(local_user())
  16. );
  17. $group_count = (int)$r[0]['g'];
  18. $r = q("SELECT COUNT(`id`) AS c FROM `contact`
  19. WHERE `uid` = %d AND `self` = 0
  20. AND `blocked` = 0 AND `pending` = 0
  21. AND `notify` != '' $sql_extra" ,
  22. intval(local_user())
  23. );
  24. $contact_count = (int)$r[0]['c'];
  25. $tot = $group_count+$contact_count;
  26. $groups = array();
  27. $contacts = array();
  28. $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
  29. FROM `group`,`group_member`
  30. WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
  31. AND `group_member`.`gid`=`group`.`id`
  32. $sql_extra
  33. GROUP BY `group`.`id`
  34. ORDER BY `group`.`name`
  35. LIMIT %d,%d",
  36. intval(local_user()),
  37. intval($start),
  38. intval($count)
  39. );
  40. foreach($r as $g){
  41. $groups[] = array(
  42. "type" => "g",
  43. "photo" => "images/default-group-mm.png",
  44. "name" => $g['name'],
  45. "id" => intval($g['id']),
  46. "uids" => array_map("intval", explode(",",$g['uids']))
  47. );
  48. }
  49. $r = q("SELECT `id`, `name`, `micro`, `network` FROM `contact`
  50. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
  51. $sql_extra
  52. ORDER BY `name` ASC ",
  53. intval(local_user())
  54. );
  55. foreach($r as $g){
  56. $contacts[] = array(
  57. "type" => "c",
  58. "photo" => $g['micro'],
  59. "name" => $g['name'],
  60. "id" => intval($g['id']),
  61. "network" => $g['network']
  62. );
  63. }
  64. $items = array_merge($groups, $contacts);
  65. $o = array(
  66. 'tot' => $tot,
  67. 'start' => $start,
  68. 'count' => $count,
  69. 'items' => $items,
  70. );
  71. echo json_encode($o);
  72. killme();
  73. }