protected function cleanupText($text, $method)
{
switch ($method) {
case 'url_cleanup':
$sep = $this->getWordSeparator();
$sepQ = preg_quote($sep);
$text = preg_replace(array('#[^a-zA-Z0-9_!.-]+#', '#^[.]+|[!.]+$#', "#\\.\\.+#", "#[{$sepQ}]+#", "#^[{$sepQ}]+|[{$sepQ}]+\$#"), array($sep, $sep, $sep, $sep, ''), $text);
break;
case 'url_cleanup_iri':
// With IRI support we keep all characters except some reserved ones,
// they are space, ampersand, semi-colon, forward slash, colon, equal sign, question mark,
// square brackets, parenthesis, plus.
//
// Note: Space is turned into a dash to make it easier for people to
// paste urls from the system and have the whole url recognized
// instead of being broken off
$sep = $this->getWordSeparator();
$sepQ = preg_quote($sep);
$prepost = ' .' . $sepQ;
if ($sep != '-') {
$prepost .= '-';
}
$text = preg_replace(array("#[ \\\\%\\#&;/:=?\\[\\]()+]+#", '#^[.]+|[!.]+$#', "#\\.\\.+#", "#[{$sepQ}]+#", "#^[{$prepost}]+|[{$prepost}]+\$#"), array($sep, $sep, $sep, $sep, ''), $text);
break;
case 'url_cleanup_compat':
// Old style of url alias with lowercase only and underscores for separators
$text = strtolower($text);
$text = preg_replace(array('#[^a-z0-9]+#', '#^_+|_+$#'), array('_', ''), $text);
break;
default:
// Nothing
}
return $text;
}