Пример #1
0
 /**
  * Replaces any instances of words censored in self::$censorship['words'] with self::$censorship['char']
  *
  * @param	string	Text to be censored
  *
  * @return	string
  */
 public function fetchCensoredText($text)
 {
     if (!$text) {
         // return $text rather than nothing, since this could be '' or 0
         return $text;
     }
     if (!empty(self::$censorship['words'])) {
         foreach (self::$censorship['words'] as $censorword) {
             if (substr($censorword, 0, 2) == '\\{') {
                 if (substr($censorword, -2, 2) == '\\}') {
                     // prevents errors from the replace if the { and } are mismatched
                     $censorword = substr($censorword, 2, -2);
                 }
                 // ASCII character search 0-47, 58-64, 91-96, 123-127
                 $nonword_chars = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f';
                 // words are delimited by ASCII characters outside of A-Z, a-z and 0-9
                 $text = preg_replace('#(?<=[' . $nonword_chars . ']|^)' . $censorword . '(?=[' . $nonword_chars . ']|$)#si', str_repeat(self::$censorship['char'], vB_String::vbStrlen($censorword)), $text);
             } else {
                 $text = preg_replace("#{$censorword}#si", str_repeat(self::$censorship['char'], vB_String::vbStrlen($censorword)), $text);
             }
         }
     }
     // strip any admin-specified blank ascii chars
     $text = vB_String::stripBlankAscii($text, self::$censorship['char'], self::$blankAsciiStrip);
     return $text;
 }