diff options
author | Friendika <info@friendika.com> | 2011-02-25 15:28:07 -0800 |
---|---|---|
committer | Friendika <info@friendika.com> | 2011-02-25 15:28:07 -0800 |
commit | ee4800a4d3eb3c1f11e1dc33a8d6902cf97c2c1f (patch) | |
tree | b9c0ff47f128a2b22f8428dd9008fd360989c718 /mod/qsearch.php | |
parent | c3cb3d75e593faa06e4050a016ef1893bd5a4a3a (diff) | |
download | volse-hubzilla-ee4800a4d3eb3c1f11e1dc33a8d6902cf97c2c1f.tar.gz volse-hubzilla-ee4800a4d3eb3c1f11e1dc33a8d6902cf97c2c1f.tar.bz2 volse-hubzilla-ee4800a4d3eb3c1f11e1dc33a8d6902cf97c2c1f.zip |
auto-complete contact/group endpoint
Diffstat (limited to 'mod/qsearch.php')
-rw-r--r-- | mod/qsearch.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/mod/qsearch.php b/mod/qsearch.php new file mode 100644 index 000000000..e61915c75 --- /dev/null +++ b/mod/qsearch.php @@ -0,0 +1,49 @@ +<?php + +function qsearch_init(&$a) { + + if(! local_user()) + killme(); + + $limit = (get_config('system','lsearch_limit') ? intval(get_config('system','lsearch_limit')) : 100); + + $search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : ''); + + if(! strlen($search)) + killme(); + + + if($search) + $search = dbesc($search); + + $results = array(); + + $r = q("SELECT * FROM `group` WHERE `name` REGEXP '$search' AND `deleted` = 0 AND `uid` = %d LIMIT 0, %d ", + intval(local_user()), + intval($limit) + ); + + if(count($r)) { + + foreach($r as $rr) + $results[] = array( t('Group: ') . $rr['name'],'[group]<' . $rr['id'] . '>',''); + } + + $sql_extra = ((strlen($search)) ? " AND (`name` REGEXP '$search' OR `nick` REGEXP '$search') " : ""); + + + $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra ORDER BY `name` ASC LIMIT 0, %d ", + intval(local_user()), + intval($limit) + ); + + + if(count($r)) { + + foreach($r as $rr) + $results[] = array($rr['name'],$rr['url'],$rr['photo']); + } + + echo str_replace('\\/','/',json_encode((object) $results)); + killme(); +}
\ No newline at end of file |