rework autocomplete: add NavBar forum search
This commit is contained in:
parent
3b305ad8ef
commit
ac912eaadf
|
@ -395,11 +395,12 @@ function acl_lookup(&$a, $out_type = 'json') {
|
||||||
if(!local_user())
|
if(!local_user())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
$start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
|
$start = (x($_REQUEST,'start') ? $_REQUEST['start'] : 0);
|
||||||
$count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
|
$count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 100);
|
||||||
$search = (x($_REQUEST,'search')?$_REQUEST['search']:"");
|
$search = (x($_REQUEST,'search') ? $_REQUEST['search'] : "");
|
||||||
$type = (x($_REQUEST,'type')?$_REQUEST['type']:"");
|
$type = (x($_REQUEST,'type') ? $_REQUEST['type'] : "");
|
||||||
$conv_id = (x($_REQUEST,'conversation')?$_REQUEST['conversation']:null);
|
$mode = (x($_REQUEST,'mode') ? $_REQUEST['mode'] : "");
|
||||||
|
$conv_id = (x($_REQUEST,'conversation') ? $_REQUEST['conversation'] : null);
|
||||||
|
|
||||||
// For use with jquery.textcomplete for private mail completion
|
// For use with jquery.textcomplete for private mail completion
|
||||||
|
|
||||||
|
@ -673,6 +674,7 @@ function navbar_complete(&$a) {
|
||||||
$localsearch = get_config('system','poco_local_search');
|
$localsearch = get_config('system','poco_local_search');
|
||||||
|
|
||||||
$search = $prefix.notags(trim($_REQUEST['search']));
|
$search = $prefix.notags(trim($_REQUEST['search']));
|
||||||
|
$mode = $_REQUEST['mode'];
|
||||||
|
|
||||||
// don't search if search term has less than 2 characters
|
// don't search if search term has less than 2 characters
|
||||||
if(! $search || mb_strlen($search) < 2)
|
if(! $search || mb_strlen($search) < 2)
|
||||||
|
@ -682,7 +684,7 @@ function navbar_complete(&$a) {
|
||||||
$search = substr($search,1);
|
$search = substr($search,1);
|
||||||
|
|
||||||
if($localsearch) {
|
if($localsearch) {
|
||||||
$x = dir::global_search_by_name($search);
|
$x = dir::global_search_by_name($search, $mode);
|
||||||
return $x;
|
return $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,10 @@ class dir {
|
||||||
* @brief Search global contact table by nick or name
|
* @brief Search global contact table by nick or name
|
||||||
* *
|
* *
|
||||||
* @param string $search Name or nick
|
* @param string $search Name or nick
|
||||||
|
* @param string $mode Search mode
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function global_search_by_name($search) {
|
public static function global_search_by_name($search, $mode = '') {
|
||||||
|
|
||||||
if($search) {
|
if($search) {
|
||||||
// check supported networks
|
// check supported networks
|
||||||
|
@ -30,6 +31,12 @@ class dir {
|
||||||
else
|
else
|
||||||
$ostatus = NETWORK_DFRN;
|
$ostatus = NETWORK_DFRN;
|
||||||
|
|
||||||
|
// check if fo
|
||||||
|
if($mode === "community")
|
||||||
|
$extra_sql = " AND `community`";
|
||||||
|
else
|
||||||
|
$extra_sql = "";
|
||||||
|
|
||||||
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`,
|
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`,
|
||||||
`gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
|
`gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
|
||||||
FROM `gcontact`
|
FROM `gcontact`
|
||||||
|
@ -38,13 +45,12 @@ class dir {
|
||||||
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
|
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
|
||||||
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
|
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
|
||||||
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
|
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
|
||||||
(`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s'
|
(`gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s') $extra_sql
|
||||||
)
|
|
||||||
GROUP BY `gcontact`.`nurl`
|
GROUP BY `gcontact`.`nurl`
|
||||||
ORDER BY `gcontact`.`updated` DESC ",
|
ORDER BY `gcontact`.`updated` DESC ",
|
||||||
intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
|
intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
|
||||||
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
|
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
|
||||||
dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)));
|
dbesc(escape_tags($search)), dbesc(escape_tags($search)));
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function contact_search(term, callback, backend_url, type) {
|
function contact_search(term, callback, backend_url, type, mode) {
|
||||||
|
|
||||||
// Check if there is a conversation id to include the unkonwn contacts of the conversation
|
// Check if there is a conversation id to include the unkonwn contacts of the conversation
|
||||||
var conv_id = document.activeElement.id.match(/\d+$/);
|
var conv_id = document.activeElement.id.match(/\d+$/);
|
||||||
|
|
||||||
|
|
||||||
// Check if there is a cached result that contains the same information we would get with a full server-side search
|
// Check if there is a cached result that contains the same information we would get with a full server-side search
|
||||||
var bt = backend_url+type;
|
var bt = backend_url+type;
|
||||||
if(!(bt in contact_search.cache)) contact_search.cache[bt] = {};
|
if(!(bt in contact_search.cache)) contact_search.cache[bt] = {};
|
||||||
|
@ -41,6 +40,9 @@ function contact_search(term, callback, backend_url, type) {
|
||||||
if(conv_id !== null)
|
if(conv_id !== null)
|
||||||
postdata['conversation'] = conv_id[0];
|
postdata['conversation'] = conv_id[0];
|
||||||
|
|
||||||
|
if(mode !== null)
|
||||||
|
postdata['mode'] = mode;
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:'POST',
|
type:'POST',
|
||||||
|
@ -126,6 +128,7 @@ function submit_form(e) {
|
||||||
template: contact_format,
|
template: contact_format,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Autocomplete smilies e.g. ":like"
|
||||||
smilies = {
|
smilies = {
|
||||||
match: /(^|\s)(:[a-z]{2,})$/,
|
match: /(^|\s)(:[a-z]{2,})$/,
|
||||||
index: 2,
|
index: 2,
|
||||||
|
@ -134,6 +137,7 @@ function submit_form(e) {
|
||||||
replace: function(item) { return "$1" + item.text + ' '; },
|
replace: function(item) { return "$1" + item.text + ' '; },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Autocomplete BBTags
|
||||||
bbtags = {
|
bbtags = {
|
||||||
match: /\[(\w*)$/,
|
match: /\[(\w*)$/,
|
||||||
index: 1,
|
index: 1,
|
||||||
|
@ -154,12 +158,21 @@ function submit_form(e) {
|
||||||
contacts = {
|
contacts = {
|
||||||
match: /(^@)([^\n]{2,})$/,
|
match: /(^@)([^\n]{2,})$/,
|
||||||
index: 2,
|
index: 2,
|
||||||
search: function(term, callback) { contact_search(term, callback, backend_url, 'x'); },
|
search: function(term, callback) { contact_search(term, callback, backend_url, 'x', 'contact'); },
|
||||||
|
replace: basic_replace,
|
||||||
|
template: contact_format,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Autocomplete forum accounts
|
||||||
|
community = {
|
||||||
|
match: /(^!)([^\n]{2,})$/,
|
||||||
|
index: 2,
|
||||||
|
search: function(term, callback) { contact_search(term, callback, backend_url, 'x', 'community'); },
|
||||||
replace: basic_replace,
|
replace: basic_replace,
|
||||||
template: contact_format,
|
template: contact_format,
|
||||||
};
|
};
|
||||||
this.attr('autocomplete', 'off');
|
this.attr('autocomplete', 'off');
|
||||||
var a = this.textcomplete([contacts], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'nav'});
|
var a = this.textcomplete([contacts, community], {className:'acpopup', maxCount:100, zIndex: 1020, appendTo:'#nav-search-box'});
|
||||||
a.on('textComplete:select', function(e, value, strategy) { submit_form(this); });
|
a.on('textComplete:select', function(e, value, strategy) { submit_form(this); });
|
||||||
};
|
};
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
|
Loading…
Reference in a new issue