Example #1
0
 protected function do_filter($var)
 {
     if (is_string($this->strings)) {
         $this->strings = array($this->strings);
     }
     foreach ($this->strings as $word) {
         // Check for custom replacement
         $customReplacement = '';
         if (JString::stristr($word, '=')) {
             $tmp = explode('=', $word);
             $customReplacement = JString::trim($tmp[1]);
             $word = JString::trim($tmp[0]);
         }
         // $word = preg_replace('#[^A-Za-z0-9\*\$\^]#', '', JString::trim($word));
         $replacement = '';
         if (JString::stristr($word, '*') === false && JString::stristr($word, '$') === false && JString::stristr($word, '^') === false) {
             $str = JString::strlen($word);
             $first = $this->keep_first_last ? $word[0] : '';
             $str = $this->keep_first_last ? $str - 2 : $str;
             $last = $this->keep_first_last ? $word[JString::strlen($word) - 1] : '';
             if ($customReplacement == '') {
                 $replacement = str_repeat('*', $str);
             } else {
                 $replacement = $customReplacement;
             }
             if ($this->replace_matches_inside_words) {
                 $var = JString::str_replace($word, $first . $replacement . $last, $var);
             } else {
                 $var = preg_replace('/\\b' . $word . '\\b/ui', $first . $replacement . $last, $var);
             }
         } else {
             // Rebuiling the regex
             $keySearch = array('/\\*/ms', '/\\$/ms');
             $keyReplace = array('%', '#');
             $word = preg_replace($keySearch, $keyReplace, $word);
             $keySearch = array('/\\%/ms', '/\\#/ms');
             $keyReplace = array('.?', '.*?');
             $word = preg_replace($keySearch, $keyReplace, $word);
             if ($customReplacement != '') {
                 $replacement = str_repeat('*', JString::strlen($word));
             } else {
                 $replacement = $customReplacement;
             }
             $var = preg_replace('/\\b' . $word . '\\b/uims', $replacement, $var);
         }
     }
     return $var;
 }