aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Search_ac.php
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-04-20 21:05:01 -0400
committerAndrew Manning <tamanning@zoho.com>2016-04-20 21:05:01 -0400
commitb96eb1c8230ae2f5986d6f22934c606bbca9728e (patch)
treefecd2279927b61da28801094dc7d6b1cfa8d98fe /Zotlabs/Module/Search_ac.php
parent7594796ee11c0b245d02d145868a13ac3d84ebfc (diff)
parent635580091a227529cb491e6441a5acbfff3177be (diff)
downloadvolse-hubzilla-b96eb1c8230ae2f5986d6f22934c606bbca9728e.tar.gz
volse-hubzilla-b96eb1c8230ae2f5986d6f22934c606bbca9728e.tar.bz2
volse-hubzilla-b96eb1c8230ae2f5986d6f22934c606bbca9728e.zip
Merge branch 'dev' into toggle-context-help
Diffstat (limited to 'Zotlabs/Module/Search_ac.php')
-rw-r--r--Zotlabs/Module/Search_ac.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/Zotlabs/Module/Search_ac.php b/Zotlabs/Module/Search_ac.php
new file mode 100644
index 000000000..78bcf374d
--- /dev/null
+++ b/Zotlabs/Module/Search_ac.php
@@ -0,0 +1,82 @@
+<?php
+namespace Zotlabs\Module;
+
+// Autocomplete for saved searches. Should probably be put in the same place as the other autocompletes
+
+class Search_ac extends \Zotlabs\Web\Controller {
+
+ function init(){
+ if(!local_channel())
+ killme();
+
+
+ $start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
+ $count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
+ $search = (x($_REQUEST,'search')?$_REQUEST['search']:"");
+
+ if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
+ $search = $_REQUEST['query'];
+ }
+
+ // Priority to people searches
+
+ if ($search) {
+ $people_sql_extra = protect_sprintf(" AND `xchan_name` LIKE '%". dbesc($search) . "%' ");
+ $tag_sql_extra = protect_sprintf(" AND term LIKE '%". dbesc($search) . "%' ");
+ }
+
+
+ $r = q("SELECT `abook_id`, `xchan_name`, `xchan_photo_s`, `xchan_url`, `xchan_addr` FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d
+ $people_sql_extra
+ ORDER BY `xchan_name` ASC ",
+ intval(local_channel())
+ );
+
+ $results = array();
+ if($r) {
+ foreach($r as $g) {
+ $results[] = array(
+ "photo" => $g['xchan_photo_s'],
+ "name" => '@'.$g['xchan_name'],
+ "id" => $g['abook_id'],
+ "link" => $g['xchan_url'],
+ "label" => '',
+ "nick" => '',
+ );
+ }
+ }
+
+ $r = q("select distinct term, tid, url from term where type in ( %d, %d ) $tag_sql_extra group by term order by term asc",
+ intval(TERM_HASHTAG),
+ intval(TERM_COMMUNITYTAG)
+ );
+
+ if(count($r)) {
+ foreach($r as $g) {
+ $results[] = array(
+ "photo" => z_root() . '/images/hashtag.png',
+ "name" => '#'.$g['term'],
+ "id" => $g['tid'],
+ "link" => $g['url'],
+ "label" => '',
+ "nick" => '',
+ );
+ }
+ }
+
+ header("content-type: application/json");
+ $o = array(
+ 'start' => $start,
+ 'count' => $count,
+ 'items' => $results,
+ );
+ echo json_encode($o);
+
+ logger('search_ac: ' . print_r($x,true));
+
+ killme();
+ }
+
+
+
+}