Commit fd0aba76 authored by generalredneck's avatar generalredneck

[#1832526] Words asked to be removed need to be removed reguardless where they are.

Didn't work if the word was at the beginning of the string. Order matters too apparently.
parent 37ba1670
......@@ -129,26 +129,38 @@ function _views_natural_sort_store_node($node) {
*/
function views_natural_sort_encode($string) {
$beginning_words = variable_get('views_natural_sort_beginning_words_remove', array());
$words = variable_get('views_natural_sort_words_remove', array());
$beginning_words = variable_get('views_natural_sort_beginning_words_remove', array());
$symbols = variable_get('views_natural_sort_symbols_remove', '');
// Get the words ready for being put in a regex.
array_walk($beginning_words, 'preg_quote');
array_walk($words, 'preg_quote');
$beginning_words_regex = '/^(' . implode('|', $beginning_words) . ')\s+/i';
$words_regex = '/\s(' . implode('|', $words) . ')\s+/i';
$symbols_regex = '/[' . preg_quote($symbols) . ']/';
$regex = array();
$replace = array();
// Remove words from the beginning only!
if (!empty($beginning_words)) {
$string = preg_replace($beginning_words_regex, '', $string);
$regex[] = '/^(' . implode('|', $beginning_words) . ')\s+/i';
}
// Remove words reguardless where they are as long as they are a word.
if (!empty($words)) {
$regex[] = '/\s(' . implode('|', $words) . ')\s+/i';
$replace[] = ' ';
$regex[] = '/^(' . implode('|', $words) . ')\s+/i';
$replace[] = '';
}
// Remove symbols.
if (strlen($symbols) != 0) {
$string = preg_replace($symbols_regex, '', $string);
$regex[] = '/[' . preg_quote($symbols) . ']/';
$replace[] = '';
}
if (!empty($words)) {
$string = preg_replace($words_regex, ' ', $string);
if (!empty($regex) && !empty($replace)) {
$string = preg_replace($regex, $replace, $string);
}
// Find an optional leading dash (either preceded by whitespace or the first character) followed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment