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.

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