/** * Censors the given string. * * @param string $string * @param array|null $words Words to censor. Null to use option value. * @param string|null $censorString String to censor each character with. Null to use option value. * * @return string */ public static function censorString($string, array $words = null, $censorString = null) { $allowCache = $words === null && $censorString === null; // ok to use cache for default $censorCache = $allowCache ? self::$_censorCache : null; if ($censorCache === null) { if ($words === null) { $words = XenForo_Application::get('options')->censorWords; } if (!$words) { if ($allowCache) { self::$_censorCache = array(); } return $string; } if ($censorString === null) { $censorString = XenForo_Application::get('options')->censorCharacter; } $censorCache = self::buildCensorArray($words, $censorString); if ($allowCache) { self::$_censorCache = $censorCache; } } if (!empty($censorCache['exact'])) { $string = preg_replace(array_keys($censorCache['exact']), $censorCache['exact'], $string); } if (!empty($censorCache['any'])) { $string = str_ireplace(array_keys($censorCache['any']), $censorCache['any'], $string); } return $string; }