2011-02-26 00:28:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function qsearch_init(&$a) {
|
|
|
|
|
|
|
|
if(! local_user())
|
|
|
|
killme();
|
|
|
|
|
2011-03-01 08:39:59 +01:00
|
|
|
$limit = (get_config('system','qsearch_limit') ? intval(get_config('system','qsearch_limit')) : 100);
|
2011-02-26 00:28:07 +01:00
|
|
|
|
|
|
|
$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)
|
2011-02-26 04:56:38 +01:00
|
|
|
$results[] = array( 0, (int) $rr['id'], $rr['name'], '', '');
|
2011-02-26 00:28:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$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)
|
2011-02-26 04:56:38 +01:00
|
|
|
$results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']);
|
2011-02-26 00:28:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo str_replace('\\/','/',json_encode((object) $results));
|
|
|
|
killme();
|
2011-02-26 04:57:44 +01:00
|
|
|
}
|
|
|
|
|