rework autocomplete: make remote and local search work
This commit is contained in:
parent
16e4e94b29
commit
c42922f25f
3 changed files with 119 additions and 0 deletions
|
@ -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;
|
||||
}
|
36
include/dir_fns.php
Normal file
36
include/dir_fns.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
function dirsearch_autocomplete($search) {
|
||||
|
||||
if($search) {
|
||||
|
||||
if (get_config('system','diaspora_enabled'))
|
||||
$diaspora = NETWORK_DIASPORA;
|
||||
else
|
||||
$diaspora = NETWORK_DFRN;
|
||||
|
||||
if (!get_config('system','ostatus_disabled'))
|
||||
$ostatus = NETWORK_OSTATUS;
|
||||
else
|
||||
$ostatus = NETWORK_DFRN;
|
||||
|
||||
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
|
||||
FROM `gcontact`
|
||||
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
|
||||
AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
|
||||
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
|
||||
WHERE (`contact`.`id` > 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
||||
<script>$(document).ready(function() {
|
||||
$("#search-text").search_autocomplete('$base/acl');
|
||||
});
|
||||
</script>
|
||||
EOT;
|
||||
$a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
|
||||
|
||||
$nav_info = nav_info($a);
|
||||
|
|
Loading…
Reference in a new issue