mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
PHP7.2 compatibility
each() and create_function() are deprecated in PHP7.2 , -> I copied the code from the 4 branch - seems to work in my local environment
This commit is contained in:
parent
3097bccadc
commit
af99004549
@ -131,12 +131,12 @@ class SearchForm extends Form {
|
||||
|
||||
$keywords = $data['Search'];
|
||||
|
||||
$andProcessor = create_function('$matches','
|
||||
return " +" . $matches[2] . " +" . $matches[4] . " ";
|
||||
');
|
||||
$notProcessor = create_function('$matches', '
|
||||
return " -" . $matches[3];
|
||||
');
|
||||
$andProcessor = function ($matches) {
|
||||
return ' +' . $matches[2] . ' +' . $matches[4] . ' ';
|
||||
};
|
||||
$notProcessor = function ($matches) {
|
||||
return ' -' . $matches[3];
|
||||
};
|
||||
|
||||
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
|
||||
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
|
||||
@ -173,23 +173,31 @@ class SearchForm extends Form {
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function addStarsToKeywords($keywords) {
|
||||
if(!trim($keywords)) return "";
|
||||
// Add * to each keyword
|
||||
$splitWords = preg_split("/ +/" , trim($keywords));
|
||||
while(list($i,$word) = each($splitWords)) {
|
||||
if($word[0] == '"') {
|
||||
while(list($i,$subword) = each($splitWords)) {
|
||||
$word .= ' ' . $subword;
|
||||
if(substr($subword,-1) == '"') break;
|
||||
}
|
||||
} else {
|
||||
$word .= '*';
|
||||
}
|
||||
$newWords[] = $word;
|
||||
}
|
||||
return implode(" ", $newWords);
|
||||
}
|
||||
protected function addStarsToKeywords($keywords)
|
||||
{
|
||||
if (!trim($keywords)) {
|
||||
return "";
|
||||
}
|
||||
// Add * to each keyword
|
||||
$splitWords = preg_split("/ +/", trim($keywords));
|
||||
$newWords = [];
|
||||
for ($i = 0; $i < count($splitWords); $i++) {
|
||||
$word = $splitWords[$i];
|
||||
if ($word[0] == '"') {
|
||||
while (++$i < count($splitWords)) {
|
||||
$subword = $splitWords[$i];
|
||||
$word .= ' ' . $subword;
|
||||
if (substr($subword, -1) == '"') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$word .= '*';
|
||||
}
|
||||
$newWords[] = $word;
|
||||
}
|
||||
return implode(" ", $newWords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the search query for display in a "You searched for ..." sentence.
|
||||
|
Loading…
Reference in New Issue
Block a user