2011-02-25 18:28:07 -05:00
|
|
|
<?php
|
|
|
|
|
2017-04-30 00:07:00 -04:00
|
|
|
use Friendica\App;
|
|
|
|
|
2017-01-09 07:14:55 -05:00
|
|
|
function qsearch_init(App $a) {
|
2011-02-25 18:28:07 -05:00
|
|
|
|
2016-12-20 05:56:34 -05:00
|
|
|
if (! local_user()) {
|
2011-02-25 18:28:07 -05:00
|
|
|
killme();
|
2016-12-20 05:56:34 -05:00
|
|
|
}
|
2011-02-25 18:28:07 -05:00
|
|
|
|
2011-03-01 02:39:59 -05:00
|
|
|
$limit = (get_config('system','qsearch_limit') ? intval(get_config('system','qsearch_limit')) : 100);
|
2011-02-25 18:28:07 -05:00
|
|
|
|
|
|
|
$search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : '');
|
|
|
|
|
2017-03-21 12:02:59 -04:00
|
|
|
if(! strlen($search))
|
2011-02-25 18:28:07 -05:00
|
|
|
killme();
|
|
|
|
|
|
|
|
|
2017-03-21 12:02:59 -04:00
|
|
|
if($search)
|
2011-02-25 18:28:07 -05:00
|
|
|
$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)
|
|
|
|
);
|
|
|
|
|
2016-12-14 03:41:33 -05:00
|
|
|
if (dbm::is_result($r)) {
|
2017-03-21 12:02:59 -04:00
|
|
|
|
|
|
|
foreach($r as $rr)
|
2011-02-25 22:56:38 -05:00
|
|
|
$results[] = array( 0, (int) $rr['id'], $rr['name'], '', '');
|
2011-02-25 18:28:07 -05: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)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-12-14 03:41:33 -05:00
|
|
|
if (dbm::is_result($r)) {
|
2017-03-21 12:02:59 -04:00
|
|
|
|
|
|
|
foreach($r as $rr)
|
2011-02-25 22:56:38 -05:00
|
|
|
$results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']);
|
2011-02-25 18:28:07 -05:00
|
|
|
}
|
|
|
|
|
2011-06-02 23:42:09 -04:00
|
|
|
echo json_encode((object) $results);
|
2011-02-25 18:28:07 -05:00
|
|
|
killme();
|
2011-02-25 22:57:44 -05:00
|
|
|
}
|