aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-01-19 00:43:05 -0800
committerfriendica <info@friendica.com>2013-01-19 00:43:05 -0800
commit9725dcf41dce7b03828a29b7f6def11ef120a88f (patch)
tree34a697e6dc276bde2fbc18540f7d64af26bc00c6
parent33b6d916611f6b9ec214fff38f60df128fbc940a (diff)
downloadvolse-hubzilla-9725dcf41dce7b03828a29b7f6def11ef120a88f.tar.gz
volse-hubzilla-9725dcf41dce7b03828a29b7f6def11ef120a88f.tar.bz2
volse-hubzilla-9725dcf41dce7b03828a29b7f6def11ef120a88f.zip
distributed directory search from the navbar
-rw-r--r--include/text.php29
-rw-r--r--library/jquery_ac/friendica.complete.js2
-rw-r--r--mod/acl.php100
-rw-r--r--mod/directory.php2
-rw-r--r--mod/dirsearch.php42
-rw-r--r--view/theme/redbasic/css/style.css7
-rw-r--r--view/tpl/nav.tpl1
-rw-r--r--view/tpl/smarty3/nav.tpl1
8 files changed, 142 insertions, 42 deletions
diff --git a/include/text.php b/include/text.php
index 9db22d9ed..1cfc89cae 100644
--- a/include/text.php
+++ b/include/text.php
@@ -302,26 +302,33 @@ function paginate(&$a) {
}}
if(! function_exists('alt_pager')) {
-function alt_pager(&$a, $i) {
- $o = '';
+function alt_pager(&$a, $i, $more = '', $less = '') {
+
+ $o = '';
+
+ if(! $more)
+ $more = t('older');
+ if(! $less)
+ $less = t('newer');
+
$stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
$stripped = str_replace('q=','',$stripped);
$stripped = trim($stripped,'/');
$pagenum = $a->pager['page'];
- $url = $a->get_baseurl() . '/' . $stripped;
+ $url = $a->get_baseurl() . '/' . $stripped;
- $o .= '<div class="pager">';
+ $o .= '<div class="pager">';
- if($a->pager['page']>1)
- $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'">' . t('newer') . '</a>';
- if($i>0) {
- if($a->pager['page']>1)
- $o .= "&nbsp;-&nbsp;";
- $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('older') . '</a>';
+ if($a->pager['page'] > 1)
+ $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'">' . $less . '</a>';
+ if($i > 0 && $i == $a->pager['itemspage']) {
+ if($a->pager['page']>1)
+ $o .= " | ";
+ $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . $more . '</a>';
}
- $o .= '</div>'."\r\n";
+ $o .= '</div>'."\r\n";
return $o;
}}
diff --git a/library/jquery_ac/friendica.complete.js b/library/jquery_ac/friendica.complete.js
index 4599c7bc1..c8a28c0a7 100644
--- a/library/jquery_ac/friendica.complete.js
+++ b/library/jquery_ac/friendica.complete.js
@@ -242,6 +242,7 @@
} else if (!this.isBadQuery(q)) {
me = this;
me.options.params.query = q;
+ $('#nav-search-spinner').show();
$.get(this.serviceUrl, me.options.params, function(txt) { me.processResponse(txt); }, 'text');
}
},
@@ -304,6 +305,7 @@
this.data = response.data;
this.suggest();
}
+ $('#nav-search-spinner').hide();
},
activate: function(index) {
diff --git a/mod/acl.php b/mod/acl.php
index 76be01ee6..16945d1a9 100644
--- a/mod/acl.php
+++ b/mod/acl.php
@@ -5,6 +5,7 @@ require_once("include/acl_selectors.php");
function acl_init(&$a){
+ logger('mod_acl: ' . print_r($_REQUEST,true));
$start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
$count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
@@ -21,12 +22,13 @@ function acl_init(&$a){
}
- if(! (local_user() || $type == 'x'))
- return "";
+ if(!(local_user()))
+ if($type != 'x')
+ killme();
+ logger('continue');
-
- if ($search!=""){
+ if ($search != "") {
$sql_extra = " AND `name` LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " ";
$sql_extra2 = "AND ( xchan_name LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " OR xchan_addr LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . ") ";
@@ -150,18 +152,40 @@ function acl_init(&$a){
);
}
elseif($type == 'x') {
- $r = q("SELECT xchan_name as id, xchan_name as name, xchan_photo_s as micro, xchan_url as url from xchan
- where 1
- $sql_extra3
- ORDER BY `xchan_name` ASC ",
- intval(local_user())
- );
+
+ $r = navbar_complete($a);
+ $x = array();
+ $x['query'] = $search;
+ $x['photos'] = array();
+ $x['links'] = array();
+ $x['suggestions'] = array();
+ $x['data'] = array();
+ if($r) {
+ foreach($r as $g) {
+ $x['photos'][] = $g['photo'];
+ $x['links'][] = $g['url'];
+ $x['suggestions'][] = '@' . $g['name'];
+ $x['data'][] = $g['name'];
+ }
+ }
+ echo json_encode($x);
+ killme();
+
+
+
+
+// $r = q("SELECT xchan_name as id, xchan_name as name, xchan_photo_s as micro, xchan_url as url from xchan
+// where 1
+// $sql_extra3
+// ORDER BY `xchan_name` ASC ",
+// intval(local_user())
+// );
}
else
$r = array();
- if($type == 'm' || $type == 'a' || $type == 'x') {
+ if($type == 'm' || $type == 'a') {
$x = array();
$x['query'] = $search;
$x['photos'] = array();
@@ -209,3 +233,57 @@ function acl_init(&$a){
}
+function navbar_complete(&$a) {
+
+ logger('navbar_complete');
+
+ $dirmode = intval(get_config('system','directory_mode'));
+ $search = ((x($_REQUEST,'query')) ? htmlentities($_REQUEST['query'],ENT_COMPAT,'UTF-8',false) : '');
+ if(! $search || mb_strlen($search) < 2)
+ return array();
+
+ $star = false;
+ $address = false;
+
+ if(substr($search,0,1) === '@')
+ $search = substr($search,1);
+
+ if(substr($search,0,1) === '*') {
+ $star = true;
+ $search = substr($search,1);
+ }
+
+ if(strpos($search,'@') !== false) {
+ $address = true;
+ }
+
+ if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
+ $url = z_root() . '/dirsearch';
+ }
+
+ if(! $url) {
+ $directory = find_upstream_directory($dirmode);
+
+ if($directory) {
+ $url = $directory['url'];
+ }
+ else {
+ $url = DIRECTORY_FALLBACK_MASTER . '/dirsearch';
+ }
+ }
+
+ if($url) {
+ $query = $url . '?f=' ;
+ $query .= '&name=' . urlencode($search) . '&limit=50' . (($address) ? '&address=' . urlencode($search) : '');
+
+ $x = z_fetch_url($query);
+ if($x['success']) {
+ $t = 0;
+ $j = json_decode($x['body'],true);
+ if($j && $j['results']) {
+ return $j['results'];
+ }
+ }
+ }
+ return array();
+} \ No newline at end of file
diff --git a/mod/directory.php b/mod/directory.php
index cd0ab4a48..99687a373 100644
--- a/mod/directory.php
+++ b/mod/directory.php
@@ -163,7 +163,7 @@ function directory_content(&$a) {
));
- $o .= alt_pager($a,$j['records']);
+ $o .= alt_pager($a,$j['records'], t('more'), t('back'));
}
diff --git a/mod/dirsearch.php b/mod/dirsearch.php
index 50348bc4a..b3b824b24 100644
--- a/mod/dirsearch.php
+++ b/mod/dirsearch.php
@@ -39,46 +39,50 @@ function dirsearch_content(&$a) {
$sql_extra = '';
if($name)
- $sql_extra .= " AND xchan_name like '" . protect_sprintf( '%' . dbesc($name) . '%' ) . "' ";
- if($addr)
- $sql_extra .= " AND xchan_addr like '" . protect_sprintf( '%' . dbesc($addr) . '%' ) . "' ";
+ $sql_extra .= " OR xchan_name like '" . protect_sprintf( '%' . dbesc($name) . '%' ) . "' ";
+ if($address)
+ $sql_extra .= " OR xchan_addr like '" . protect_sprintf( '%' . dbesc($address) . '%' ) . "' ";
if($city)
- $sql_extra .= " AND xprof_locale like '" . protect_sprintf( '%' . dbesc($city) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_locale like '" . protect_sprintf( '%' . dbesc($city) . '%' ) . "' ";
if($region)
- $sql_extra .= " AND xprof_region like '" . protect_sprintf( '%' . dbesc($region) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_region like '" . protect_sprintf( '%' . dbesc($region) . '%' ) . "' ";
if($post)
- $sql_extra .= " AND xprof_postcode like '" . protect_sprintf( '%' . dbesc($post) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_postcode like '" . protect_sprintf( '%' . dbesc($post) . '%' ) . "' ";
if($country)
- $sql_extra .= " AND xprof_country like '" . protect_sprintf( '%' . dbesc($country) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_country like '" . protect_sprintf( '%' . dbesc($country) . '%' ) . "' ";
if($gender)
- $sql_extra .= " AND xprof_gender like '" . protect_sprintf( '%' . dbesc($gender) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_gender like '" . protect_sprintf( '%' . dbesc($gender) . '%' ) . "' ";
if($marital)
- $sql_extra .= " AND xprof_marital like '" . protect_sprintf( '%' . dbesc($marital) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_marital like '" . protect_sprintf( '%' . dbesc($marital) . '%' ) . "' ";
if($keywords)
- $sql_extra .= " AND xprof_keywords like '" . protect_sprintf( '%' . dbesc($keywords) . '%' ) . "' ";
+ $sql_extra .= " OR xprof_keywords like '" . protect_sprintf( '%' . dbesc($keywords) . '%' ) . "' ";
$perpage = (($_REQUEST['n']) ? $_REQUEST['n'] : 80);
$page = (($_REQUEST['p']) ? intval($_REQUEST['p'] - 1) : 0);
$startrec = (($page+1) * $perpage) - $perpage;
+ $limit = (($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 0);
// ok a separate tag table won't work.
// merge them into xprof
$ret['success'] = true;
- $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where 1 $sql_extra");
- if($r) {
- $ret['total_items'] = $r[0]['total'];
+
+ if($limit)
+ $qlimit = " LIMIT $limit ";
+ else {
+ $qlimit = " LIMIT " . intval($startrec) . " , " . intval($perpage);
+ $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where 1 $sql_extra");
+ if($r) {
+ $ret['total_items'] = $r[0]['total'];
+ }
}
- $order = " ORDER BY `xchan_name` ASC ";
+ $order = " ORDER BY `xchan_name` ASC ";
+ $logic = ((strlen($sql_extra)) ? 0 : 1);
dbg(1);
- $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where 1 $sql_extra $order LIMIT %d , %d ",
- intval($startrec),
- intval($perpage)
- );
+ $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra $order $qlimit ");
dbg(0);
-
$ret['page'] = $page + 1;
$ret['records'] = count($r);
diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css
index 21704e21c..fd989554b 100644
--- a/view/theme/redbasic/css/style.css
+++ b/view/theme/redbasic/css/style.css
@@ -2569,6 +2569,13 @@ aside input[type='text'] {
margin-top: 4px;
}
+#nav-search-spinner {
+ float: right;
+ margin-top: 8px;
+ margin-left: 5px;
+ margin-right: 5px;
+}
+
#nav-search-text:hover {
background-color: #FFF;
color: #000;
diff --git a/view/tpl/nav.tpl b/view/tpl/nav.tpl
index b0eb098aa..b0c2393cd 100644
--- a/view/tpl/nav.tpl
+++ b/view/tpl/nav.tpl
@@ -133,6 +133,7 @@
<input id="nav-search-text" type="text" value="" placeholder="$nav.search.1" name="search" title="$nav.search.3" onclick="this.submit();" />
</form>
</li>
+ <img src="images/rotator.gif" id="nav-search-spinner" style="display: none;" alt="$pleasewait" />
</ul>
</nav>
diff --git a/view/tpl/smarty3/nav.tpl b/view/tpl/smarty3/nav.tpl
index da50bc7bb..0b8344b07 100644
--- a/view/tpl/smarty3/nav.tpl
+++ b/view/tpl/smarty3/nav.tpl
@@ -133,6 +133,7 @@
<input id="nav-search-text" type="text" value="" placeholder="{{$nav.search.1}}" name="search" title="{{$nav.search.3}}" onclick="this.submit();" />
</form>
</li>
+ <img src="images/rotator.gif" id="nav-search-spinner" style="display: none;" alt="{{$pleasewait}}" />
</ul>
</nav>