friendica-github/mod/qsearch.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2011-02-25 23:28:07 +00:00
<?php
use Friendica\App;
function qsearch_init(App $a) {
2011-02-25 23:28:07 +00:00
if (! local_user()) {
2011-02-25 23:28:07 +00:00
killme();
}
2011-02-25 23:28:07 +00:00
2011-03-01 07:39:59 +00:00
$limit = (get_config('system','qsearch_limit') ? intval(get_config('system','qsearch_limit')) : 100);
2011-02-25 23:28:07 +00:00
$search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : '');
if(! strlen($search))
2011-02-25 23:28:07 +00:00
killme();
if($search)
2011-02-25 23:28:07 +00: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)
);
if (dbm::is_result($r)) {
foreach($r as $rr)
$results[] = array( 0, (int) $rr['id'], $rr['name'], '', '');
2011-02-25 23:28:07 +00: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 (dbm::is_result($r)) {
foreach($r as $rr)
$results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']);
2011-02-25 23:28:07 +00:00
}
echo json_encode((object) $results);
2011-02-25 23:28:07 +00:00
killme();
2011-02-26 03:57:44 +00:00
}