mirror of
https://github.com/e107inc/e107.git
synced 2025-04-20 04:32:01 +02:00
UTF-8 aware search rendering
Search view supports glyph (former bullet) Some old paths corrected
This commit is contained in:
parent
db385a00d1
commit
5bae035cf6
@ -416,6 +416,28 @@ class e_parse extends e_parser
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unicode (UTF-8) analogue of standard @link http://php.net/stristr stristr PHP function.
|
||||
* Returns all of haystack starting from and including the first occurrence of needle to the end.
|
||||
*
|
||||
* @param string $haystack The UTF-8 encoded string to search in.
|
||||
* @param mixed $needle If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.
|
||||
* @param integer $length [optional] (PHP 5.3+) If TRUE, returns the part of the haystack before the first occurrence of the needle (excluding needle).
|
||||
* @return string Returns the matched substring. If needle is not found, returns FALSE.
|
||||
*/
|
||||
public function ustristr($haystack, $needle, $before_needle = false)
|
||||
{
|
||||
switch($this->utfAction)
|
||||
{
|
||||
case 0:
|
||||
return stristr($haystack, $needle, $before_needle);
|
||||
case 1:
|
||||
return mb_substr($haystack, $needle, $before_needle);
|
||||
}
|
||||
// No utf8 pack backup
|
||||
return stristr($str, $start, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unicode (UTF-8) analogue of standard @link http://php.net/substr substr PHP function.
|
||||
* Returns the portion of string specified by the start and length parameters.
|
||||
|
@ -28,24 +28,30 @@ class e_search {
|
||||
|
||||
function e_search()
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
$this->query = $query;
|
||||
$this->bullet = '';
|
||||
if(defined('BULLET'))
|
||||
|
||||
if(defined('GLYPH'))
|
||||
{
|
||||
$this->bullet = '<img src="'.THEME.'images/'.BULLET.'" alt="" class="icon" />';
|
||||
$this->bullet = '<i class="'.GLYPH.'"></i>';
|
||||
}
|
||||
elseif(defined('BULLET'))
|
||||
{
|
||||
$this->bullet = '<img src="'.THEME_ABS.'images/'.BULLET.'" alt="" class="icon" />';
|
||||
}
|
||||
elseif(file_exists(THEME.'images/bullet2.gif'))
|
||||
{
|
||||
$this->bullet = '<img src="'.THEME.'images/bullet2.gif" alt="bullet" class="icon" />';
|
||||
$this->bullet = '<img src="'.THEME_ABS.'images/bullet2.gif" alt="bullet" class="icon" />';
|
||||
}
|
||||
|
||||
preg_match_all('/(\W?".*?")|(.*?)(\s|$)/', $this -> query, $boolean_keys);
|
||||
sort($this -> keywords['split'] = array_unique(array_filter(str_replace('"', '', array_merge($boolean_keys[1], $boolean_keys[2])))));
|
||||
foreach ($this -> keywords['split'] as $k_key => $key) {
|
||||
if (!$this -> stopword($key)) {
|
||||
if ($key{(strlen($key) - 1)} == '*') {
|
||||
if ($key{($tp->ustrlen($key) - 1)} == '*') {
|
||||
$this -> keywords['wildcard'][$k_key] = TRUE;
|
||||
$key = substr($key, 0, -1);
|
||||
$key = $tp->usubstr($key, 0, -1);
|
||||
} else {
|
||||
$this -> keywords['wildcard'][$k_key] = FALSE;
|
||||
}
|
||||
@ -59,7 +65,7 @@ class e_search {
|
||||
$this -> keywords['boolean'][$k_key] = FALSE;
|
||||
$this -> keywords['match'][$k_key] = $key;
|
||||
}
|
||||
$this -> keywords['exact'][$k_key] = (strpos($key, ' ') !== FALSE) ? TRUE : FALSE;
|
||||
$this -> keywords['exact'][$k_key] = ($tp->ustrpos($key, ' ') !== FALSE) ? TRUE : FALSE;
|
||||
$this -> keywords['match'][$k_key] = $tp -> toDB($this -> keywords['match'][$k_key]);
|
||||
} else {
|
||||
unset ($this -> keywords['split'][$k_key]);
|
||||
@ -69,6 +75,7 @@ class e_search {
|
||||
|
||||
function parsesearch($table, $return_fields, $search_fields, $weights, $handler, $no_results, $where, $order) {
|
||||
global $sql, $query, $tp, $search_prefs, $pre_title, $search_chars, $search_res, $result_flag;
|
||||
$tp = e107::getParser();
|
||||
$this -> query = $tp -> toDB($query);
|
||||
if (!$search_prefs['mysql_sort']) {
|
||||
$field_operator = 'AND ';
|
||||
@ -219,13 +226,13 @@ class e_search {
|
||||
} else {
|
||||
$regex_append = $boundary.")";
|
||||
}
|
||||
if (($match_start = stristr($this -> text, $this -> query)) !== FALSE) {
|
||||
$this -> pos = strlen($this -> text) - strlen($match_start);
|
||||
if (($match_start = $tp->ustristr($this -> text, $this -> query)) !== FALSE) {
|
||||
$this -> pos = $tp->ustrlen($this -> text) - $tp->ustrlen($match_start);
|
||||
if (!$endcrop && !$title) {
|
||||
$this -> parsesearch_crop();
|
||||
$endcrop = TRUE;
|
||||
}
|
||||
$key = substr($this -> text, $this -> pos, strlen($this -> query));
|
||||
$key = $tp->usubstr($this -> text, $this->pos, $tp->ustrlen($this -> query));
|
||||
$this -> text = preg_replace("#(".$boundary.$this -> query.$regex_append."#i", "<span class='searchhighlight'>\\1</span>", $this -> text);
|
||||
}
|
||||
}
|
||||
@ -268,32 +275,34 @@ class e_search {
|
||||
|
||||
function parsesearch_crop() {
|
||||
global $search_chars;
|
||||
$tp = e107::getParser();
|
||||
if (strlen($this -> text) > $search_chars) {
|
||||
if ($this -> pos < ($search_chars - strlen($this -> query))) {
|
||||
$this -> text = substr($this -> text, 0, $search_chars)."...";
|
||||
} else if ($this -> pos > (strlen($this -> text) - ($search_chars - strlen($this -> query)))) {
|
||||
$this -> text = "...".substr($this -> text, (strlen($this -> text) - ($search_chars - strlen($this -> query))));
|
||||
if ($this -> pos < ($search_chars - $tp->ustrlen($this -> query))) {
|
||||
$this -> text = $tp->usubstr($this -> text, 0, $search_chars)."...";
|
||||
} else if ($this -> pos > ($tp->ustrlen($this -> text) - ($search_chars - $tp->ustrlen($this -> query)))) {
|
||||
$this -> text = "...".$tp->usubstr($this -> text, ($tp->ustrlen($this -> text) - ($search_chars - $tp->ustrlen($this -> query))));
|
||||
} else {
|
||||
$this -> text = "...".substr($this -> text, ($this -> pos - round(($search_chars / 3))), $search_chars)."...";
|
||||
$this -> text = "...".$tp->usubstr($this -> text, ($this -> pos - round(($search_chars / 3))), $search_chars)."...";
|
||||
}
|
||||
$match_start = stristr($this -> text, $this -> query);
|
||||
$this -> pos = strlen($this -> text) - strlen($match_start);
|
||||
$match_start = $tp->ustristr($this -> text, $this -> query);
|
||||
$this -> pos = $tp->ustrlen($this -> text) - $tp->ustrlen($match_start);
|
||||
}
|
||||
}
|
||||
|
||||
function stopword($key) {
|
||||
global $search_prefs;
|
||||
$tp = e107::getParser();
|
||||
if ($search_prefs['mysql_sort'] && ($key{0} == '+')) {
|
||||
$key = substr($key, 1);
|
||||
$key = $tp->usubstr($key, 1);
|
||||
}
|
||||
if (($key{(strlen($key) - 1)} != '*') && ($key{0} != '+')) {
|
||||
if (strlen($key) > 2) {
|
||||
if (($key{($tp->ustrlen($key) - 1)} != '*') && ($key{0} != '+')) {
|
||||
if ($tp->ustrlen($key) > 2) {
|
||||
if ($search_prefs['mysql_sort']) {
|
||||
$stopword_list = $this -> stopwords_mysql;
|
||||
} else {
|
||||
$stopword_list = $this -> stopwords_php;
|
||||
}
|
||||
if (strpos($stopword_list, '|'.$key.'|') !== FALSE) {
|
||||
if ($tp->ustrpos($stopword_list, '|'.$key.'|') !== FALSE) {
|
||||
$this -> stop_keys[] = $key;
|
||||
return TRUE;
|
||||
} else {
|
||||
@ -308,5 +317,3 @@ class e_search {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
16
search.php
16
search.php
@ -539,7 +539,7 @@ if ($perform_search)
|
||||
$text .= '<div class="search-block">';
|
||||
@require_once($search_info[$key]['sfile']);
|
||||
$text .= '</div>';
|
||||
$parms = $results.",".$search_res.",".$_GET['r'].",".e_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]";
|
||||
$parms = $results.",".$search_res.",".$_GET['r'].",".e_REQUEST_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]";
|
||||
$core_parms = array('r' => '', 'q' => '', 't' => '', 's' => '');
|
||||
foreach ($_GET as $pparm_key => $pparm_value)
|
||||
{
|
||||
@ -572,15 +572,17 @@ if ($perform_search)
|
||||
}
|
||||
|
||||
// old 6xx search parser for reverse compatability
|
||||
function parsesearch($text, $match) {
|
||||
function parsesearch($text, $match)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
$text = strip_tags($text);
|
||||
$temp = stristr($text, $match);
|
||||
$pos = strlen($text) - strlen($temp);
|
||||
$matchedText = substr($text,$pos,strlen($match));
|
||||
$temp = $tp->ustristr($text, $match);
|
||||
$pos = $tp->ustrlen($text) - $tp->ustrlen($temp);
|
||||
$matchedText = $tp->usubstr($text,$pos,$tp->ustrlen($match));
|
||||
if ($pos < 70) {
|
||||
$text = "...".substr($text, 0, 100)."...";
|
||||
$text = "...".$tp->usubstr($text, 0, 100)."...";
|
||||
} else {
|
||||
$text = "...".substr($text, ($pos-50), $pos+30)."...";
|
||||
$text = "...".$tp->usubstr($text, ($pos-50), $pos+30)."...";
|
||||
}
|
||||
$text = preg_replace("/".$match."/i", "<span class='searchhighlight'>".$matchedText."</span>", $text);
|
||||
return($text);
|
||||
|
Loading…
x
Reference in New Issue
Block a user