From c42922f25f34f7d34fa50bc743680169542ac4a5 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Wed, 20 Jan 2016 03:34:22 +0100 Subject: [PATCH] rework autocomplete: make remote and local search work --- include/acl_selectors.php | 75 +++++++++++++++++++++++++++++++++++++++ include/dir_fns.php | 36 +++++++++++++++++++ include/nav.php | 8 +++++ 3 files changed, 119 insertions(+) create mode 100644 include/dir_fns.php diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 69181b7359..19197981e0 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -545,6 +545,26 @@ function acl_lookup(&$a, $out_type = 'json') { intval(local_user()) ); } + elseif($type == 'x') { + $r = navbar_complete($a); + $contacts = array(); + if($r) { + foreach($r as $g) { + $contacts[] = array( + "photo" => $g['photo'], + "name" => $g['name'], + "nick" => (x($g['addr']) ? $g['addr'] : $g['url']), + ); + } + } + $o = array( + 'start' => $start, + 'count' => $count, + 'items' => $contacts, + ); + echo json_encode($o); + killme(); + } else $r = array(); @@ -655,3 +675,58 @@ function acl_lookup(&$a, $out_type = 'json') { killme(); } +function navbar_complete(&$a) { + +// logger('navbar_complete'); + + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + return; + } + + $local = get_config('system','poco_local_search'); + $local = true; + + $search = $prefix.notags(trim($_REQUEST['search'])); + if(! $search || mb_strlen($search) < 2) + return array(); + + $star = false; + $address = false; + + if(substr($search,0,1) === '@') + $search = substr($search,1); + + if(substr($search,0,1) === '*') { + $star = true; + $search = substr($search,1); + } + + if(strpos($search,'@') !== false) { + $address = true; + } + + if($local) { + require_once("include/dir_fns.php"); + $x = dirsearch_autocomplete($search); + return $x; + } + + if(! $local) { + require_once("include/dir_fns.php"); + $url = $directory['url'] . '/dirsearch'; + + + $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); + + + $x = z_fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + if($x['success']) { + $t = 0; + $j = json_decode($x['body'],true); + if($j && $j['results']) { + return $j['results']; + } + } + } + return; +} \ No newline at end of file diff --git a/include/dir_fns.php b/include/dir_fns.php new file mode 100644 index 0000000000..a362732b7b --- /dev/null +++ b/include/dir_fns.php @@ -0,0 +1,36 @@ + 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND + ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND + (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s' + ) + GROUP BY `gcontact`.`nurl` + ORDER BY `gcontact`.`updated` DESC ", + intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND), + dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), + dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search))); + return $results; + } + +} \ No newline at end of file diff --git a/include/nav.php b/include/nav.php index 6512d35609..0261ab7d66 100644 --- a/include/nav.php +++ b/include/nav.php @@ -11,10 +11,18 @@ function nav(&$a) { if(!(x($a->page,'nav'))) $a->page['nav'] = ''; + $base = z_root(); /** * Placeholder div for popup panel */ + $a->page['htmlhead'] .= <<< EOT + + +EOT; $a->page['nav'] .= '' ; $nav_info = nav_info($a);