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.

720 lines
19 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
6 years ago
6 years ago
6 years ago
11 years ago
6 years ago
  1. <?php
  2. /**
  3. * @file include/acl_selectors.php
  4. */
  5. require_once("include/contact_selectors.php");
  6. require_once("include/contact_widgets.php");
  7. require_once("include/DirSearch.php");
  8. require_once("include/features.php");
  9. require_once("mod/proxy.php");
  10. /**
  11. * @package acl_selectors
  12. */
  13. function group_select($selname,$selclass,$preselected = false,$size = 4) {
  14. $a = get_app();
  15. $o = '';
  16. $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
  17. $r = q("SELECT `id`, `name` FROM `group` WHERE NOT `deleted` AND `uid` = %d ORDER BY `name` ASC",
  18. intval(local_user())
  19. );
  20. $arr = array('group' => $r, 'entry' => $o);
  21. // e.g. 'network_pre_group_deny', 'profile_pre_group_allow'
  22. call_hooks($a->module . '_pre_' . $selname, $arr);
  23. if(count($r)) {
  24. foreach($r as $rr) {
  25. if((is_array($preselected)) && in_array($rr['id'], $preselected))
  26. $selected = " selected=\"selected\" ";
  27. else
  28. $selected = '';
  29. $trimmed = mb_substr($rr['name'],0,12);
  30. $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
  31. }
  32. }
  33. $o .= "</select>\r\n";
  34. call_hooks($a->module . '_post_' . $selname, $o);
  35. return $o;
  36. }
  37. function contact_selector($selname, $selclass, $preselected = false, $options) {
  38. $a = get_app();
  39. $mutual = false;
  40. $networks = null;
  41. $single = false;
  42. $exclude = false;
  43. $size = 4;
  44. if(is_array($options)) {
  45. if(x($options,'size'))
  46. $size = $options['size'];
  47. if(x($options,'mutual_friends'))
  48. $mutual = true;
  49. if(x($options,'single'))
  50. $single = true;
  51. if(x($options,'multiple'))
  52. $single = false;
  53. if(x($options,'exclude'))
  54. $exclude = $options['exclude'];
  55. if(x($options,'networks')) {
  56. switch($options['networks']) {
  57. case 'DFRN_ONLY':
  58. $networks = array(NETWORK_DFRN);
  59. break;
  60. case 'PRIVATE':
  61. if(is_array($a->user) && $a->user['prvnets'])
  62. $networks = array(NETWORK_DFRN,NETWORK_MAIL,NETWORK_DIASPORA);
  63. else
  64. $networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL, NETWORK_DIASPORA);
  65. break;
  66. case 'TWO_WAY':
  67. if(is_array($a->user) && $a->user['prvnets'])
  68. $networks = array(NETWORK_DFRN,NETWORK_MAIL,NETWORK_DIASPORA);
  69. else
  70. $networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL,NETWORK_DIASPORA,NETWORK_OSTATUS);
  71. break;
  72. default:
  73. break;
  74. }
  75. }
  76. }
  77. $x = array('options' => $options, 'size' => $size, 'single' => $single, 'mutual' => $mutual, 'exclude' => $exclude, 'networks' => $networks);
  78. call_hooks('contact_select_options', $x);
  79. $o = '';
  80. $sql_extra = '';
  81. if($x['mutual']) {
  82. $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
  83. }
  84. if(intval($x['exclude']))
  85. $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));
  86. if(is_array($x['networks']) && count($x['networks'])) {
  87. for($y = 0; $y < count($x['networks']) ; $y ++)
  88. $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
  89. $str_nets = implode(',',$x['networks']);
  90. $sql_extra .= " AND `network` IN ( $str_nets ) ";
  91. }
  92. $tabindex = (x($options, 'tabindex') ? "tabindex=\"" . $options["tabindex"] . "\"" : "");
  93. if($x['single'])
  94. $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" $tabindex >\r\n";
  95. else
  96. $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n";
  97. $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
  98. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
  99. $sql_extra
  100. ORDER BY `name` ASC ",
  101. intval(local_user())
  102. );
  103. $arr = array('contact' => $r, 'entry' => $o);
  104. // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
  105. call_hooks($a->module . '_pre_' . $selname, $arr);
  106. if(count($r)) {
  107. foreach($r as $rr) {
  108. if((is_array($preselected)) && in_array($rr['id'], $preselected))
  109. $selected = " selected=\"selected\" ";
  110. else
  111. $selected = '';
  112. $trimmed = mb_substr($rr['name'],0,20);
  113. $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
  114. }
  115. }
  116. $o .= "</select>\r\n";
  117. call_hooks($a->module . '_post_' . $selname, $o);
  118. return $o;
  119. }
  120. function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
  121. require_once("include/bbcode.php");
  122. $a = get_app();
  123. $o = '';
  124. // When used for private messages, we limit correspondence to mutual DFRN/Friendica friends and the selector
  125. // to one recipient. By default our selector allows multiple selects amongst all contacts.
  126. $sql_extra = '';
  127. if($privmail || $celeb) {
  128. $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
  129. }
  130. if($privmail)
  131. $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ",
  132. NETWORK_DFRN, NETWORK_DIASPORA);
  133. elseif($privatenet)
  134. $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ",
  135. NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK, NETWORK_DIASPORA);
  136. $tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
  137. if ($privmail AND $preselected) {
  138. $sql_extra .= " AND `id` IN (".implode(",", $preselected).")";
  139. $hidepreselected = ' style="display: none;"';
  140. } else
  141. $hidepreselected = "";
  142. if($privmail)
  143. $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" $tabindex $hidepreselected>\r\n";
  144. else
  145. $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" $tabindex >\r\n";
  146. $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
  147. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
  148. $sql_extra
  149. ORDER BY `name` ASC ",
  150. intval(local_user())
  151. );
  152. $arr = array('contact' => $r, 'entry' => $o);
  153. // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
  154. call_hooks($a->module . '_pre_' . $selname, $arr);
  155. $receiverlist = array();
  156. if(count($r)) {
  157. foreach($r as $rr) {
  158. if((is_array($preselected)) && in_array($rr['id'], $preselected))
  159. $selected = " selected=\"selected\" ";
  160. else
  161. $selected = '';
  162. if($privmail)
  163. $trimmed = GetProfileUsername($rr['url'], $rr['name'], false);
  164. else
  165. $trimmed = mb_substr($rr['name'],0,20);
  166. $receiverlist[] = $trimmed;
  167. $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
  168. }
  169. }
  170. $o .= "</select>\r\n";
  171. if ($privmail AND $preselected)
  172. $o .= implode(", ", $receiverlist);
  173. call_hooks($a->module . '_post_' . $selname, $o);
  174. return $o;
  175. }
  176. function fixacl(&$item) {
  177. $item = intval(str_replace(array('<','>'),array('',''),$item));
  178. }
  179. function prune_deadguys($arr) {
  180. if(! $arr)
  181. return $arr;
  182. $str = dbesc(implode(',',$arr));
  183. $r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
  184. if($r) {
  185. $ret = array();
  186. foreach($r as $rr)
  187. $ret[] = intval($rr['id']);
  188. return $ret;
  189. }
  190. return array();
  191. }
  192. function get_acl_permissions($user = null) {
  193. $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
  194. if(is_array($user)) {
  195. $allow_cid = ((strlen($user['allow_cid']))
  196. ? explode('><', $user['allow_cid']) : array() );
  197. $allow_gid = ((strlen($user['allow_gid']))
  198. ? explode('><', $user['allow_gid']) : array() );
  199. $deny_cid = ((strlen($user['deny_cid']))
  200. ? explode('><', $user['deny_cid']) : array() );
  201. $deny_gid = ((strlen($user['deny_gid']))
  202. ? explode('><', $user['deny_gid']) : array() );
  203. array_walk($allow_cid,'fixacl');
  204. array_walk($allow_gid,'fixacl');
  205. array_walk($deny_cid,'fixacl');
  206. array_walk($deny_gid,'fixacl');
  207. }
  208. $allow_cid = prune_deadguys($allow_cid);
  209. return array(
  210. 'allow_cid' => $allow_cid,
  211. 'allow_gid' => $allow_gid,
  212. 'deny_cid' => $deny_cid,
  213. 'deny_gid' => $deny_gid,
  214. );
  215. }
  216. function populate_acl($user = null, $show_jotnets = false) {
  217. $perms = get_acl_permissions($user);
  218. $jotnets = '';
  219. if($show_jotnets) {
  220. $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
  221. $mail_enabled = false;
  222. $pubmail_enabled = false;
  223. if(! $mail_disabled) {
  224. $r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
  225. intval(local_user())
  226. );
  227. if(count($r)) {
  228. $mail_enabled = true;
  229. if(intval($r[0]['pubmail']))
  230. $pubmail_enabled = true;
  231. }
  232. }
  233. if (!$user['hidewall']) {
  234. if($mail_enabled) {
  235. $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
  236. $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
  237. }
  238. call_hooks('jot_networks', $jotnets);
  239. } else
  240. $jotnets .= sprintf(t('Connectors disabled, since "%s" is enabled.'),
  241. t('Hide your profile details from unknown viewers?'));
  242. }
  243. $tpl = get_markup_template("acl_selector.tpl");
  244. $o = replace_macros($tpl, array(
  245. '$showall'=> t("Visible to everybody"),
  246. '$show' => t("show"),
  247. '$hide' => t("don't show"),
  248. '$allowcid' => json_encode($perms['allow_cid']),
  249. '$allowgid' => json_encode($perms['allow_gid']),
  250. '$denycid' => json_encode($perms['deny_cid']),
  251. '$denygid' => json_encode($perms['deny_gid']),
  252. '$networks' => $show_jotnets,
  253. '$emailcc' => t('CC: email addresses'),
  254. '$emtitle' => t('Example: bob@example.com, mary@example.com'),
  255. '$jotnets' => $jotnets,
  256. '$aclModalTitle' => t('Permissions'),
  257. '$aclModalDismiss' => t('Close'),
  258. '$features' => array(
  259. "aclautomention"=>(feature_enabled($user['uid'],"aclautomention")?"true":"false")
  260. ),
  261. ));
  262. return $o;
  263. }
  264. function construct_acl_data(&$a, $user) {
  265. // Get group and contact information for html ACL selector
  266. $acl_data = acl_lookup($a, 'html');
  267. $user_defaults = get_acl_permissions($user);
  268. if($acl_data['groups']) {
  269. foreach($acl_data['groups'] as $key=>$group) {
  270. // Add a "selected" flag to groups that are posted to by default
  271. if($user_defaults['allow_gid'] &&
  272. in_array($group['id'], $user_defaults['allow_gid']) && !in_array($group['id'], $user_defaults['deny_gid']) )
  273. $acl_data['groups'][$key]['selected'] = 1;
  274. else
  275. $acl_data['groups'][$key]['selected'] = 0;
  276. }
  277. }
  278. if($acl_data['contacts']) {
  279. foreach($acl_data['contacts'] as $key=>$contact) {
  280. // Add a "selected" flag to groups that are posted to by default
  281. if($user_defaults['allow_cid'] &&
  282. in_array($contact['id'], $user_defaults['allow_cid']) && !in_array($contact['id'], $user_defaults['deny_cid']) )
  283. $acl_data['contacts'][$key]['selected'] = 1;
  284. else
  285. $acl_data['contacts'][$key]['selected'] = 0;
  286. }
  287. }
  288. return $acl_data;
  289. }
  290. function acl_lookup(&$a, $out_type = 'json') {
  291. if(!local_user())
  292. return "";
  293. $start = (x($_REQUEST,'start') ? $_REQUEST['start'] : 0);
  294. $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 100);
  295. $search = (x($_REQUEST,'search') ? $_REQUEST['search'] : "");
  296. $type = (x($_REQUEST,'type') ? $_REQUEST['type'] : "");
  297. $mode = (x($_REQUEST,'smode') ? $_REQUEST['smode'] : "");
  298. $conv_id = (x($_REQUEST,'conversation') ? $_REQUEST['conversation'] : null);
  299. // For use with jquery.textcomplete for private mail completion
  300. if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
  301. if(! $type)
  302. $type = 'm';
  303. $search = $_REQUEST['query'];
  304. }
  305. logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG);
  306. if ($search!=""){
  307. $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
  308. $sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
  309. } else {
  310. $sql_extra = $sql_extra2 = "";
  311. }
  312. // count groups and contacts
  313. if ($type=='' || $type=='g'){
  314. $r = q("SELECT COUNT(*) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
  315. intval(local_user())
  316. );
  317. $group_count = (int)$r[0]['g'];
  318. } else {
  319. $group_count = 0;
  320. }
  321. $sql_extra2 .= " ".unavailable_networks();
  322. // autocomplete for editor mentions
  323. if ($type=='' || $type=='c'){
  324. $r = q("SELECT COUNT(*) AS c FROM `contact`
  325. WHERE `uid` = %d AND `self` = 0
  326. AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
  327. AND `notify` != '' $sql_extra2" ,
  328. intval(local_user())
  329. );
  330. $contact_count = (int)$r[0]['c'];
  331. }
  332. elseif ($type == 'm') {
  333. // autocomplete for Private Messages
  334. $r = q("SELECT COUNT(*) AS c FROM `contact`
  335. WHERE `uid` = %d AND `self` = 0
  336. AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
  337. AND `network` IN ('%s','%s','%s') $sql_extra2" ,
  338. intval(local_user()),
  339. dbesc(NETWORK_DFRN),
  340. dbesc(NETWORK_ZOT),
  341. dbesc(NETWORK_DIASPORA)
  342. );
  343. $contact_count = (int)$r[0]['c'];
  344. }
  345. elseif ($type == 'a') {
  346. // autocomplete for Contacts
  347. $r = q("SELECT COUNT(*) AS c FROM `contact`
  348. WHERE `uid` = %d AND `self` = 0
  349. AND `pending` = 0 $sql_extra2" ,
  350. intval(local_user())
  351. );
  352. $contact_count = (int)$r[0]['c'];
  353. } else {
  354. $contact_count = 0;
  355. }
  356. $tot = $group_count+$contact_count;
  357. $groups = array();
  358. $contacts = array();
  359. if ($type=='' || $type=='g'){
  360. $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') AS uids
  361. FROM `group`
  362. INNER JOIN `group_member` ON `group_member`.`gid`=`group`.`id` AND `group_member`.`uid` = `group`.`uid`
  363. WHERE NOT `group`.`deleted` AND `group`.`uid` = %d
  364. $sql_extra
  365. GROUP BY `group`.`name`
  366. ORDER BY `group`.`name`
  367. LIMIT %d,%d",
  368. intval(local_user()),
  369. intval($start),
  370. intval($count)
  371. );
  372. foreach($r as $g){
  373. // logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
  374. $groups[] = array(
  375. "type" => "g",
  376. "photo" => "images/twopeople.png",
  377. "name" => htmlentities($g['name']),
  378. "id" => intval($g['id']),
  379. "uids" => array_map("intval", explode(",",$g['uids'])),
  380. "link" => '',
  381. "forum" => '0'
  382. );
  383. }
  384. }
  385. if ($type==''){
  386. $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
  387. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
  388. AND NOT (`network` IN ('%s', '%s'))
  389. $sql_extra2
  390. ORDER BY `name` ASC ",
  391. intval(local_user()),
  392. dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET)
  393. );
  394. }
  395. elseif ($type=='c'){
  396. $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
  397. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
  398. AND NOT (`network` IN ('%s'))
  399. $sql_extra2
  400. ORDER BY `name` ASC ",
  401. intval(local_user()),
  402. dbesc(NETWORK_STATUSNET)
  403. );
  404. }
  405. elseif($type == 'm') {
  406. $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
  407. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
  408. AND `network` IN ('%s','%s','%s')
  409. $sql_extra2
  410. ORDER BY `name` ASC ",
  411. intval(local_user()),
  412. dbesc(NETWORK_DFRN),
  413. dbesc(NETWORK_ZOT),
  414. dbesc(NETWORK_DIASPORA)
  415. );
  416. }
  417. elseif($type == 'a') {
  418. $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
  419. WHERE `uid` = %d AND `pending` = 0
  420. $sql_extra2
  421. ORDER BY `name` ASC ",
  422. intval(local_user())
  423. );
  424. }
  425. elseif($type == 'x') {
  426. // autocomplete for global contact search (e.g. navbar search)
  427. $r = navbar_complete($a);
  428. $contacts = array();
  429. if($r) {
  430. foreach($r as $g) {
  431. $contacts[] = array(
  432. "photo" => proxy_url($g['photo'], false, PROXY_SIZE_MICRO),
  433. "name" => $g['name'],
  434. "nick" => (x($g['addr']) ? $g['addr'] : $g['url']),
  435. "network" => $g['network'],
  436. "link" => $g['url'],
  437. "forum" => (x($g['community']) ? 1 : 0),
  438. );
  439. }
  440. }
  441. $o = array(
  442. 'start' => $start,
  443. 'count' => $count,
  444. 'items' => $contacts,
  445. );
  446. echo json_encode($o);
  447. killme();
  448. }
  449. else
  450. $r = array();
  451. if(count($r)) {
  452. foreach($r as $g){
  453. $contacts[] = array(
  454. "type" => "c",
  455. "photo" => proxy_url($g['micro'], false, PROXY_SIZE_MICRO),
  456. "name" => htmlentities($g['name']),
  457. "id" => intval($g['id']),
  458. "network" => $g['network'],
  459. "link" => $g['url'],
  460. "nick" => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
  461. "forum" => ((x($g['forum']) || x($g['prv'])) ? 1 : 0),
  462. );
  463. }
  464. }
  465. $items = array_merge($groups, $contacts);
  466. if ($conv_id) {
  467. /* if $conv_id is set, get unknow contacts in thread */
  468. /* but first get know contacts url to filter them out */
  469. function _contact_link($i){ return dbesc($i['link']); }
  470. $known_contacts = array_map(_contact_link, $contacts);
  471. $unknow_contacts=array();
  472. $r = q("SELECT `author-avatar`,`author-name`,`author-link`
  473. FROM `item` WHERE `parent` = %d
  474. AND (`author-name` LIKE '%%%s%%' OR `author-link` LIKE '%%%s%%')
  475. AND `author-link` NOT IN ('%s')
  476. GROUP BY `author-link`
  477. ORDER BY `author-name` ASC
  478. ",
  479. intval($conv_id),
  480. dbesc($search),
  481. dbesc($search),
  482. implode("','", $known_contacts)
  483. );
  484. if (is_array($r) && count($r)){
  485. foreach($r as $row) {
  486. // nickname..
  487. $up = parse_url($row['author-link']);
  488. $nick = explode("/",$up['path']);
  489. $nick = $nick[count($nick)-1];
  490. $nick .= "@".$up['host'];
  491. // /nickname
  492. $unknow_contacts[] = array(
  493. "type" => "c",
  494. "photo" => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO),
  495. "name" => htmlentities($row['author-name']),
  496. "id" => '',
  497. "network" => "unknown",
  498. "link" => $row['author-link'],
  499. "nick" => htmlentities($nick),
  500. "forum" => false
  501. );
  502. }
  503. }
  504. $items = array_merge($items, $unknow_contacts);
  505. $tot += count($unknow_contacts);
  506. }
  507. $results = array(
  508. "tot" => $tot,
  509. "start" => $start,
  510. "count" => $count,
  511. "groups" => $groups,
  512. "contacts" => $contacts,
  513. "items" => $items,
  514. "type" => $type,
  515. "search" => $search,
  516. );
  517. call_hooks('acl_lookup_end', $results);
  518. if($out_type === 'html') {
  519. $o = array(
  520. 'tot' => $results["tot"],
  521. 'start' => $results["start"],
  522. 'count' => $results["count"],
  523. 'groups' => $results["groups"],
  524. 'contacts' => $results["contacts"],
  525. );
  526. return $o;
  527. }
  528. $o = array(
  529. 'tot' => $results["tot"],
  530. 'start' => $results["start"],
  531. 'count' => $results["count"],
  532. 'items' => $results["items"],
  533. );
  534. echo json_encode($o);
  535. killme();
  536. }
  537. /**
  538. * @brief Searching for global contacts for autocompletion
  539. *
  540. * @param App $a
  541. * @return array with the search results
  542. */
  543. function navbar_complete(&$a) {
  544. // logger('navbar_complete');
  545. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  546. return;
  547. }
  548. // check if searching in the local global contact table is enabled
  549. $localsearch = get_config('system','poco_local_search');
  550. $search = $prefix.notags(trim($_REQUEST['search']));
  551. $mode = $_REQUEST['smode'];
  552. // don't search if search term has less than 2 characters
  553. if(! $search || mb_strlen($search) < 2)
  554. return array();
  555. if(substr($search,0,1) === '@')
  556. $search = substr($search,1);
  557. if($localsearch) {
  558. $x = DirSearch::global_search_by_name($search, $mode);
  559. return $x;
  560. }
  561. if(! $localsearch) {
  562. $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
  563. $x = z_fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
  564. if($x['success']) {
  565. $t = 0;
  566. $j = json_decode($x['body'],true);
  567. if($j && $j['results']) {
  568. return $j['results'];
  569. }
  570. }
  571. }
  572. return;
  573. }