function parse_message($message, $options=array())
{
//global $plugins, $mybb;
// Set base URL for parsing smilies
$this->base_url = "/myBB";
//if($this->base_url != "")
//{
// if(my_substr($this->base_url, my_strlen($this->base_url) -1) != "/")
// {
// $this->base_url = $this->base_url."/";
// }
//}
// Set the options
$this->options = $options;
// Get rid of cartridge returns for they are the workings of the devil
$message = str_replace("\r", "", $message);
// Filter bad words if requested.
if($options['filter_badwords'] != "no")
{
$message = $this->parse_badwords($message);
}
if($options['allow_html'] != "yes")
{
$message = $this->parse_html($message);
}
else
{
// Strip out any script tags if HTML is enabled
if($options['allow_html'] == "yes")
{
while(preg_match("#<script(.*)>(.*)</script(.*)>#is", $message))
{
$message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "<script$1>$2</script$3>", $message);
}
// Remove these completely
$message = preg_replace("#\s*<base[^>]*>\s*#is", "", $message);
$message = preg_replace("#\s*<meta[^>]*>\s*#is", "", $message);
$message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('<?php', '<!--', '-->', '?>', "\n", "\n"), $message);
}
}
// If MyCode needs to be replaced, first filter out [code] and [php] tags.
if($options['allow_mycode'] != "no")
{
// First we split up the contents of code and php tags to ensure they're not parsed.
preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);
$message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "{{mybb-code}}\n", $message);
}
// Always fix bad Javascript in the message.
$message = $this->fix_javascript($message);
// Replace "me" code and slaps if we have a username
if($options['me_username'])
{
$message = preg_replace('#(>|^|\r|\n)/me ([^\r\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} \\2</span>", $message);
$message = preg_replace('#(>|^|\r|\n)/slap ([^\r\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} {$lang->slaps} \\2 {$lang->with_trout}</span>", $message);
}
// If we can, parse smilies
if($options['allow_smilies'] != "no")
{
$message = $this->parse_smilies($message, $options['allow_html']);
}
// Replace MyCode if requested.
if($options['allow_mycode'] != "no")
{
$message = $this->parse_mycode($message, $options);
}
// Run plugin hooks
//$message = $plugins->run_hooks("parse_message", $message);
if($options['allow_mycode'] != "no")
{
// Now that we're done, if we split up any code tags, parse them and glue it all back together
if(count($code_matches) > 0)
{
foreach($code_matches as $text)
{
// Fix up HTML inside the code tags so it is clean
if($options['allow_html'] != "no")
{
$text[2] = $this->parse_html($text[2]);
}
if(strtolower($text[1]) == "code")
{
$code = $this->mycode_parse_code($text[2]);
}
elseif(strtolower($text[1]) == "php")
{
$code = $this->mycode_parse_php($text[2]);
}
$message = preg_replace("#\{\{mybb-code\}\}\n?#", $code, $message, 1);
}
}
}
if($options['nl2br'] != "no")
{
$message = nl2br($message);
// Fix up new lines and block level elements
$message = preg_replace("#(</?(?:html|head|body|form|div|p|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p)[^>]*>)\s*<br />#i", "$1", $message);
$message = preg_replace("#( )+(</?(?:html|head|body|form|div|p|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p)[^>]*>)#i", "$2", $message);
}
$message = my_wordwrap($message);
//$message = $plugins->run_hooks("parse_message_end", $message);
return $message;
}