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.
 
 
 
 
 
 

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