aboutsummaryrefslogtreecommitdiffstats
path: root/mod/qsearch.php
blob: e61915c758f928e50a650ce8ac55ed04cc0e2cab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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();
}