]> git.mxchange.org Git - friendica.git/blob - mod/qsearch.php
Cleanup /format pre-move
[friendica.git] / mod / qsearch.php
1 <?php
2
3 function qsearch_init(App $a) {
4
5         if (! local_user()) {
6                 killme();
7         }
8
9         $limit = (get_config('system','qsearch_limit') ? intval(get_config('system','qsearch_limit')) : 100);
10
11         $search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : '');
12
13         if(! strlen($search))
14                 killme();
15
16
17         if($search)
18                 $search = dbesc($search);
19
20         $results = array();
21
22         $r = q("SELECT * FROM `group` WHERE `name` REGEXP '$search' AND `deleted` = 0 AND `uid` = %d LIMIT 0, %d ",
23                 intval(local_user()),
24                 intval($limit)
25         );
26
27         if (dbm::is_result($r)) {
28
29                 foreach($r as $rr)
30                         $results[] = array( 0, (int) $rr['id'], $rr['name'], '', '');
31         }
32
33         $sql_extra = ((strlen($search)) ? " AND (`name` REGEXP '$search' OR `nick` REGEXP '$search') " : "");
34
35
36         $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra ORDER BY `name` ASC LIMIT 0, %d ",
37                 intval(local_user()),
38                 intval($limit)
39         );
40
41
42         if (dbm::is_result($r)) {
43
44                 foreach($r as $rr)
45                         $results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']);
46         }
47
48         echo json_encode((object) $results);
49         killme();
50 }