]> git.mxchange.org Git - friendica.git/commitdiff
auto-complete contact/group endpoint
authorFriendika <info@friendika.com>
Fri, 25 Feb 2011 23:28:07 +0000 (15:28 -0800)
committerFriendika <info@friendika.com>
Fri, 25 Feb 2011 23:28:07 +0000 (15:28 -0800)
mod/qsearch.php [new file with mode: 0644]

diff --git a/mod/qsearch.php b/mod/qsearch.php
new file mode 100644 (file)
index 0000000..e61915c
--- /dev/null
@@ -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