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.

98 lines
2.2 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. $sql_extra2 = "AND (`name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
  13. }
  14. // count groups and contacts
  15. $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
  16. intval(local_user())
  17. );
  18. $group_count = (int)$r[0]['g'];
  19. $r = q("SELECT COUNT(`id`) AS c FROM `contact`
  20. WHERE `uid` = %d AND `self` = 0
  21. AND `blocked` = 0 AND `pending` = 0
  22. AND `notify` != '' $sql_extra" ,
  23. intval(local_user())
  24. );
  25. $contact_count = (int)$r[0]['c'];
  26. $tot = $group_count+$contact_count;
  27. $groups = array();
  28. $contacts = array();
  29. $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
  30. FROM `group`,`group_member`
  31. WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
  32. AND `group_member`.`gid`=`group`.`id`
  33. $sql_extra
  34. GROUP BY `group`.`id`
  35. ORDER BY `group`.`name`
  36. LIMIT %d,%d",
  37. intval(local_user()),
  38. intval($start),
  39. intval($count)
  40. );
  41. foreach($r as $g){
  42. $groups[] = array(
  43. "type" => "g",
  44. "photo" => "images/default-group-mm.png",
  45. "name" => $g['name'],
  46. "id" => intval($g['id']),
  47. "uids" => array_map("intval", explode(",",$g['uids'])),
  48. "link" => ''
  49. );
  50. }
  51. $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url` FROM `contact`
  52. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
  53. $sql_extra2
  54. ORDER BY `name` ASC ",
  55. intval(local_user())
  56. );
  57. foreach($r as $g){
  58. $contacts[] = array(
  59. "type" => "c",
  60. "photo" => $g['micro'],
  61. "name" => $g['name'],
  62. "id" => intval($g['id']),
  63. "network" => $g['network'],
  64. "link" => $g['url'],
  65. "nick" => $g['nick'],
  66. );
  67. }
  68. $items = array_merge($groups, $contacts);
  69. $o = array(
  70. 'tot' => $tot,
  71. 'start' => $start,
  72. 'count' => $count,
  73. 'items' => $items,
  74. );
  75. echo json_encode($o);
  76. killme();
  77. }