aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-07-16 18:14:45 -0700
committerfriendica <info@friendica.com>2012-07-16 18:14:45 -0700
commit07c31d547fce54dfdcad34a77f1dfcc6269ef62c (patch)
tree24bfdbc7c91f390a401dfa75a0d127eb0c42db82 /mod
parentd3d60c8ae555a784427178235093de4d9cb13dad (diff)
downloadvolse-hubzilla-07c31d547fce54dfdcad34a77f1dfcc6269ef62c.tar.gz
volse-hubzilla-07c31d547fce54dfdcad34a77f1dfcc6269ef62c.tar.bz2
volse-hubzilla-07c31d547fce54dfdcad34a77f1dfcc6269ef62c.zip
unified search autocomplete backend, browser performance seems to be a bit sucky
Diffstat (limited to 'mod')
-rw-r--r--mod/network.php19
-rw-r--r--mod/search_ac.php85
2 files changed, 104 insertions, 0 deletions
diff --git a/mod/network.php b/mod/network.php
index 07b91b1be..f9f9b4a02 100644
--- a/mod/network.php
+++ b/mod/network.php
@@ -114,6 +114,25 @@ function network_init(&$a) {
$a->page['aside'] .= saved_searches($search);
$a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
+ $base = $a->get_baseurl();
+
+ $a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
+
+ $a->page['htmlhead'] .= <<< EOT
+
+<script>$(document).ready(function() {
+ var a;
+ a = $("#search-text").autocomplete({
+ serviceUrl: '$base/search_ac',
+ minChars: 2,
+ width: 350,
+ });
+});
+</script>
+EOT;
+
+
+
}
function saved_searches($search) {
diff --git a/mod/search_ac.php b/mod/search_ac.php
new file mode 100644
index 000000000..fb3b872da
--- /dev/null
+++ b/mod/search_ac.php
@@ -0,0 +1,85 @@
+<?php
+
+function search_ac_init(&$a){
+ if(!local_user())
+ return "";
+
+
+ $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'];
+ }
+
+
+ $sql_extra = '';
+
+ $x = array();
+ $x['query'] = $search;
+ $x['photos'] = array();
+ $x['links'] = array();
+ $x['suggestions'] = array();
+ $x['data'] = array();
+
+
+ // Priority to people searches
+
+ if ($search) {
+ $people_sql_extra = protect_sprintf(" AND `name` LIKE '%". dbesc($search) . "%' ");
+ $tag_sql_extra = protect_sprintf(" AND term LIKE '%". dbesc($search) . "%' ");
+ }
+
+ $r = q("SELECT `id`, `name`, `micro`, `url` FROM `contact`
+ WHERE `uid` = %d AND `pending` = 0
+ $people_sql_extra
+ ORDER BY `name` ASC ",
+ intval(local_user())
+ );
+
+ if(count($r)) {
+ foreach($r as $g) {
+ $x['photos'][] = $g['micro'];
+ $x['links'][] = $g['url'];
+ $x['suggestions'][] = '@' . $g['name'];
+ $x['data'][] = intval($g['id']);
+ }
+ }
+
+ $r = q("SELECT `id`, `name`, `photo`, `url` FROM `gcontact` where 1
+ $people_sql_extra
+ ORDER BY `name` ASC "
+ );
+
+ if(count($r)) {
+ foreach($r as $g) {
+ $x['photos'][] = $g['photo'];
+ $x['links'][] = $g['url'];
+ $x['suggestions'][] = '@' . $g['name'];
+ $x['data'][] = intval($g['id']);
+ }
+ }
+
+ $r = q("select tid, term, url from term where type = %d $tag_sql_extra order by term asc",
+ intval(TERM_HASHTAG)
+ );
+
+ if(count($r)) {
+ foreach($r as $g) {
+ $x['photos'][] = $a->get_baseurl() . '/images/hashtag.png';
+ $x['links'][] = $g['url'];
+ $x['suggestions'][] = '#' . $g['term'];
+ $x['data'][] = intval($g['tid']);
+ }
+ }
+
+ header("content-type: application/json");
+ echo json_encode($x);
+
+ logger('search_ac: ' . print_r($x,true));
+
+ killme();
+}
+
+