It looks like you're new here. If you want to get involved, click one of these buttons!
function Execute($String)
{
$AllowedProtocols = array('http', 'ftp', 'https', 'irc', 'gopher');
$Patterns = array(
"/o(?i)(n)/", //block all js events, but keep it as exact as possible in case
"/O(?i)(n)/", //we're mistaking it for a url or something
"/<a(.+?)href\s*=(\W*)([\w\d\x0a\x0d#&;]+?):([^>]+?)>/esi",
//on some browsers the js protocol will still work even if it
//contains html entities or a newline seperating 'java' and 'script'
"/s(?i)(cript)/", //now we can go through and cancel out any script tags
"/S(?i)(cript)/"
);
$Replacements = array(
"&#111;\\1",
"&#79;\\1",
'$this->CheckProtocol("\\3", $AllowedProtocols, "href="."\\2", "<a"."\\1", "\\4".">")',
"&#115;\\1",
"&#83;\\1"
);
return preg_replace($Patterns, $Replacements, $String);
}
Then you'd want to add in this function in the same class as well:
function CheckProtocol($Check, $Allow, $Extra, $Prefix, $Suffix)
{
$sReturn = stripslashes($Prefix);
if(!in_array($Check, $Allow)) $sReturn .= ($Extra.'http://');
else $sReturn .= ($Extra.$Check.':');
$sReturn .= stripslashes($Suffix);
return $sReturn;
}
Comments