Vergleich inc/class_parser.php - 1.4.3 - 1.4.16

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/about/license
*

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/about/license
*

 * $Id: class_parser.php 4052 2008-07-29 15:45:49Z Tikitiki $

 * $Id: class_parser.php 5379 2011-02-21 11:06:42Z Tomm $

 */

/*

 */

/*

Zeile 18Zeile 18
	filter_badwords
me_username
shorten_urls

	filter_badwords
me_username
shorten_urls

 
	highlight

)
*/


)
*/


Zeile 50Zeile 51
	 * @var string
*/
var $base_url;

	 * @var string
*/
var $base_url;

 
	
/**
* Parsed Highlights cache
*
* @access private
* @var array
*/
var $highlight_cache = array();

	
/**
* Options for this parsed message (Private - set by parse_message argument)

	
/**
* Options for this parsed message (Private - set by parse_message argument)

Zeile 58Zeile 67
	 * @var array
*/
var $options;

	 * @var array
*/
var $options;



	 

	/**
* Parses a message with the specified options.
*

	/**
* Parses a message with the specified options.
*

Zeile 78Zeile 87
			if(my_substr($this->base_url, my_strlen($this->base_url) -1) != "/")
{
$this->base_url = $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;


		
// Set the options
$this->options = $options;


		$message = $plugins->run_hooks("parse_message_start", $message);


		$message = $plugins->run_hooks("parse_message_start", $message);


		// Get rid of cartridge returns for they are the workings of the devil
$message = str_replace("\r", "", $message);


		// Get rid of cartridge returns for they are the workings of the devil
$message = str_replace("\r", "", $message);


Zeile 93Zeile 102
		if($options['filter_badwords'])
{
$message = $this->parse_badwords($message);

		if($options['filter_badwords'])
{
$message = $this->parse_badwords($message);

		}

		}


if($options['allow_html'] != 1)
{


if($options['allow_html'] != 1)
{

Zeile 105Zeile 114
			{
$message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "&lt;script$1&gt;$2&lt;/script$3&gt;", $message);
}

			{
$message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "&lt;script$1&gt;$2&lt;/script$3&gt;", $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('&lt;?php', '&lt;!--', '--&gt;', '?&gt;', "\n", "\n"), $message);

			$message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('&lt;?php', '&lt;!--', '--&gt;', '?&gt;', "\n", "\n"), $message);

		}

		}

		
// If MyCode needs to be replaced, first filter out [code] and [php] tags.
if($options['allow_mycode'])
{

		
// If MyCode needs to be replaced, first filter out [code] and [php] tags.
if($options['allow_mycode'])
{

			// 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);
}

			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);
}

Zeile 124Zeile 130
		
// Replace "me" code and slaps if we have a username
if($options['me_username'])

		
// Replace "me" code and slaps if we have a username
if($options['me_username'])

		{

		{

			global $lang;

$message = preg_replace('#(>|^|\r|\n)/me ([^\r\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} \\2</span>", $message);

			global $lang;

$message = preg_replace('#(>|^|\r|\n)/me ([^\r\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} \\2</span>", $message);

Zeile 138Zeile 144
		}

// Replace MyCode if requested.

		}

// Replace MyCode if requested.

		if($options['allow_mycode'])
{

		if($options['allow_mycode'])
{

			$message = $this->parse_mycode($message, $options);

			$message = $this->parse_mycode($message, $options);

 
		}

// Parse Highlights
if($options['highlight'])
{
$message = $this->highlight_message($message, $options['highlight']);

		}

// Run plugin hooks

		}

// Run plugin hooks

Zeile 153Zeile 165
			{
foreach($code_matches as $text)
{

			{
foreach($code_matches as $text)
{

					// Fix up HTML inside the code tags so it is clean
if($options['allow_html'] != 0)
{
$text[2] = $this->parse_html($text[2]);
}

if(my_strtolower($text[1]) == "code")

					if(my_strtolower($text[1]) == "code")







					{
$code = $this->mycode_parse_code($text[2]);

					{
$code = $this->mycode_parse_code($text[2]);

					}

					}

					elseif(my_strtolower($text[1]) == "php")
{
$code = $this->mycode_parse_php($text[2]);
}
$message = preg_replace("#\<mybb-code>\n?#", $code, $message, 1);

					elseif(my_strtolower($text[1]) == "php")
{
$code = $this->mycode_parse_php($text[2]);
}
$message = preg_replace("#\<mybb-code>\n?#", $code, $message, 1);

				}

				}

			}

			}

 
		}

// Replace meta and base tags in our post - these are > dangerous <
if($this->options['allow_html'])
{
$message = preg_replace_callback("#<((m[^a])|(b[^diloru>])|(s[^aemptu>]))(\s*[^>]*)>#si", create_function(
'$matches',
'return htmlspecialchars($matches[0]);'
), $message);

		}

if($options['nl2br'] !== 0)

		}

if($options['nl2br'] !== 0)

Zeile 232Zeile 247
		$standard_mycode['reg']['regex'] = "#\(r\)#i";
$standard_mycode['reg']['replacement'] = "&reg;";


		$standard_mycode['reg']['regex'] = "#\(r\)#i";
$standard_mycode['reg']['replacement'] = "&reg;";


		$standard_mycode['url_simple']['regex'] = "#\[url\]([a-z]+?://)([^\r\n\"\[<]+?)\[/url\]#sei";

		$standard_mycode['url_simple']['regex'] = "#\[url\]([a-z]+?://)([^\r\n\"<]+?)\[/url\]#sei";

		$standard_mycode['url_simple']['replacement'] = "\$this->mycode_parse_url(\"$1$2\")";


		$standard_mycode['url_simple']['replacement'] = "\$this->mycode_parse_url(\"$1$2\")";


		$standard_mycode['url_simple2']['regex'] = "#\[url\]([^\r\n\"\[<]+?)\[/url\]#ei";

		$standard_mycode['url_simple2']['regex'] = "#\[url\]([^\r\n\"<]+?)\[/url\]#ei";

		$standard_mycode['url_simple2']['replacement'] = "\$this->mycode_parse_url(\"$1\")";


		$standard_mycode['url_simple2']['replacement'] = "\$this->mycode_parse_url(\"$1\")";


		$standard_mycode['url_complex']['regex'] = "#\[url=([a-z]+?://)([^\r\n\"\[<]+?)\](.+?)\[/url\]#esi";

		$standard_mycode['url_complex']['regex'] = "#\[url=([a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#esi";

		$standard_mycode['url_complex']['replacement'] = "\$this->mycode_parse_url(\"$1$2\", \"$3\")";


		$standard_mycode['url_complex']['replacement'] = "\$this->mycode_parse_url(\"$1$2\", \"$3\")";


		$standard_mycode['url_complex2']['regex'] = "#\[url=([^\r\n\"\[<&\(\)]+?)\](.+?)\[/url\]#esi";

		$standard_mycode['url_complex2']['regex'] = "#\[url=([^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#esi";

		$standard_mycode['url_complex2']['replacement'] = "\$this->mycode_parse_url(\"$1\", \"$2\")";

$standard_mycode['email_simple']['regex'] = "#\[email\](.*?)\[/email\]#ei";

		$standard_mycode['url_complex2']['replacement'] = "\$this->mycode_parse_url(\"$1\", \"$2\")";

$standard_mycode['email_simple']['regex'] = "#\[email\](.*?)\[/email\]#ei";

Zeile 392Zeile 407
		{
foreach($this->smilies_cache as $find => $replace)
{

		{
foreach($this->smilies_cache as $find => $replace)
{

				$find = $this->parse_html($find);



				$find = $this->parse_html($find);				
$find = preg_quote($find, "#");


				if(version_compare(PHP_VERSION, "5.1.0", ">="))
{

				if(version_compare(PHP_VERSION, "5.1.0", ">="))
{

					$message = preg_replace("#(?<=[^&;\"])".preg_quote($find,"#")."(?=.\W|\"|\W.|\W$)#si", $replace, $message, $remaining, $replacements);















					$orig_message = $message;
$orig_find = $find;
// Fix issues for smileys starting with a ";"
if($find{0} == ";")
{
$find = "(?<!&gt|&lt|&amp)".$find;
}

$message = @preg_replace("#(?<=[^\"])".$find."(?=.\W|\"|\W.|\W$)#si", $replace, $message, $remaining, $replacements);

if($message == null)
{
$message = preg_replace("#(?<=[^&;\"])".$orig_find."(?=.\W|\"|\W.|\W$)#si", $replace, $orig_message, $remaining);
}


					$remaining -= $replacements;
if($remaining <= 0)
{

					$remaining -= $replacements;
if($remaining <= 0)
{

Zeile 404Zeile 435
				}
else
{

				}
else
{

					$message = preg_replace("#(?<=[^&;\"])".preg_quote($find,"#")."(?=.\W|\"|\W.|\W$)#si", $replace, $message, $remaining);

					$message = preg_replace("#(?<=[^&;\"])".$find."(?=.\W|\"|\W.|\W$)#si", $replace, $message, $remaining);

				}
}

				}
}

 
			unset($orig_message, $orig_find);

		}

// If we matched any tags previously, swap them back in

		}

// If we matched any tags previously, swap them back in

Zeile 455Zeile 487
				{
$badword['replacement'] = "*****";
}

				{
$badword['replacement'] = "*****";
}

				$badword['badword'] = preg_quote($badword['badword']);

				$badword['badword'] = preg_quote($badword['badword'], "#");

				$message = preg_replace("#(\b|^)".$badword['badword']."(\b|$)#i", "\\1".$badword['replacement']."\\2", $message);
}
}

				$message = preg_replace("#(\b|^)".$badword['badword']."(\b|$)#i", "\\1".$badword['replacement']."\\2", $message);
}
}

Zeile 463Zeile 495
		{
$message = strip_tags($message);
}

		{
$message = strip_tags($message);
}

		return $message;
}

/**

		return $message;
}

/**

	 * Attempts to move any javascript references in the specified message.
*
* @param string The message to be parsed.

	 * Attempts to move any javascript references in the specified message.
*
* @param string The message to be parsed.

Zeile 492Zeile 524
			"#(o)(nunload\s?=)#i",
"#(o)(nkeypress\s?=)#i"
);

			"#(o)(nunload\s?=)#i",
"#(o)(nkeypress\s?=)#i"
);

		$message = preg_replace($js_array, "$1<strong></strong>$2", $message);


		
$message = preg_replace($js_array, "$1<strong></strong>$2$4", $message);


return $message;
}


return $message;
}

Zeile 507Zeile 540
	function mycode_handle_size($size, $text)
{
$size = intval($size)+10;

	function mycode_handle_size($size, $text)
{
$size = intval($size)+10;





		if($size > 50)
{
$size = 50;

		if($size > 50)
{
$size = 50;

Zeile 520Zeile 553

/**
* Parses quote MyCode.


/**
* Parses quote MyCode.

	*
* @param string The message to be parsed

	*
* @param string The message to be parsed

	* @param boolean Are we formatting as text?
* @return string The parsed message.
*/
function mycode_parse_quotes($message, $text_only=false)
{
global $lang, $templates, $theme, $mybb;

	* @param boolean Are we formatting as text?
* @return string The parsed message.
*/
function mycode_parse_quotes($message, $text_only=false)
{
global $lang, $templates, $theme, $mybb;





		// Assign pattern and replace values.
$pattern = array(
"#\[quote=(?:&quot;|\"|')?(.*?)[\"']?(?:&quot;|\"|')?\](.*?)\[\/quote\](\r\n?|\n?)#esi",
"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"

		// Assign pattern and replace values.
$pattern = array(
"#\[quote=(?:&quot;|\"|')?(.*?)[\"']?(?:&quot;|\"|')?\](.*?)\[\/quote\](\r\n?|\n?)#esi",
"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"

		);

if($text_only == false)
{
$replace = array(

		);

if($text_only == false)
{
$replace = array(

				"\$this->mycode_parse_post_quotes('$2','$1')",
"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
);

				"\$this->mycode_parse_post_quotes('$2','$1')",
"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
);

Zeile 547Zeile 580
			$replace = array(
"\$this->mycode_parse_post_quotes('$2', '$1', true)",
"\n{$lang->quote}\n--\n$1\n--\n"

			$replace = array(
"\$this->mycode_parse_post_quotes('$2', '$1', true)",
"\n{$lang->quote}\n--\n$1\n--\n"

			);
}


			);
}


		while(preg_match($pattern[0], $message) || preg_match($pattern[1], $message))
{
$message = preg_replace($pattern, $replace, $message);

		while(preg_match($pattern[0], $message) || preg_match($pattern[1], $message))
{
$message = preg_replace($pattern, $replace, $message);

Zeile 617Zeile 650
		if(intval($match[1]))
{
if($match[1] < TIME_NOW)

		if(intval($match[1]))
{
if($match[1] < TIME_NOW)

			{

			{

				$postdate = my_date($mybb->settings['dateformat'], intval($match[1]));
$posttime = my_date($mybb->settings['timeformat'], intval($match[1]));
$date = " ({$postdate} {$posttime})";

				$postdate = my_date($mybb->settings['dateformat'], intval($match[1]));
$posttime = my_date($mybb->settings['timeformat'], intval($match[1]));
$date = " ({$postdate} {$posttime})";

Zeile 644Zeile 677
			}

return "<blockquote><cite>{$span}".htmlspecialchars_uni($username)." $lang->wrote{$linkback}</cite>{$message}</blockquote>\n";

			}

return "<blockquote><cite>{$span}".htmlspecialchars_uni($username)." $lang->wrote{$linkback}</cite>{$message}</blockquote>\n";

		}
}


		}
}


	/**
* Parses code MyCode.
*

	/**
* Parses code MyCode.
*

Zeile 655Zeile 688
	* @return string The parsed message.
*/
function mycode_parse_code($code, $text_only=false)

	* @return string The parsed message.
*/
function mycode_parse_code($code, $text_only=false)

	{
global $lang;

if($text_only == true)
{

	{
global $lang;

if($text_only == true)
{

			return "\n{$lang->code}\n--\n{$code}\n--\n";

			return "\n{$lang->code}\n--\n{$code}\n--\n";

		}

		}


// Clean the string before parsing.
$code = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $code);
$code = rtrim($code);


// Clean the string before parsing.
$code = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $code);
$code = rtrim($code);

		$original = preg_replace('#^\t*#', '', $code);

if(empty($original))
{
return;
}


		$original = preg_replace('#^\t*#', '', $code);

if(empty($original))
{
return;
}


		$code = str_replace('$', '&#36;', $code);
$code = preg_replace('#\$([0-9])#', '\\\$\\1', $code);
$code = str_replace('\\', '&#92;', $code);

		$code = str_replace('$', '&#36;', $code);
$code = preg_replace('#\$([0-9])#', '\\\$\\1', $code);
$code = str_replace('\\', '&#92;', $code);

Zeile 727Zeile 760
		{
$added_end_tag = true;
$str = $str." \n?>";

		{
$added_end_tag = true;
$str = $str." \n?>";

		}

		}


// If the PHP version < 4.2, catch highlight_string() output.
if(version_compare(PHP_VERSION, "4.2.0", "<"))


// If the PHP version < 4.2, catch highlight_string() output.
if(version_compare(PHP_VERSION, "4.2.0", "<"))

		{

		{

			ob_start();
@highlight_string($str);
$code = ob_get_contents();

			ob_start();
@highlight_string($str);
$code = ob_get_contents();

Zeile 740Zeile 773
		else
{
$code = @highlight_string($str, true);

		else
{
$code = @highlight_string($str, true);

		}

		}


// If < PHP 5, make XHTML compatible.
if(version_compare(PHP_VERSION, "5", "<"))


// If < PHP 5, make XHTML compatible.
if(version_compare(PHP_VERSION, "5", "<"))

Zeile 766Zeile 799
		$code = str_replace("\\", '&#092;', $code);
$code = str_replace('$', '&#36;', $code);
$code = preg_replace("#&amp;\#([0-9]+);#si", "&#$1;", $code);

		$code = str_replace("\\", '&#092;', $code);
$code = str_replace('$', '&#36;', $code);
$code = preg_replace("#&amp;\#([0-9]+);#si", "&#$1;", $code);





		if($added_open_tag)

		if($added_open_tag)

		{

		{

			$code = preg_replace("#<code><span style=\"color: \#([A-Z0-9]{6})\">&lt;\?php( |&nbsp;)(<br />?)#", "<code><span style=\"color: #$1\">", $code);

			$code = preg_replace("#<code><span style=\"color: \#([A-Z0-9]{6})\">&lt;\?php( |&nbsp;)(<br />?)#", "<code><span style=\"color: #$1\">", $code);

		}


		}


		if($added_end_tag)
{
$code = str_replace("?&gt;</span></code>", "</span></code>", $code);
// Wait a minute. It fails highlighting? Stupid highlighter.
$code = str_replace("?&gt;</code>", "</code>", $code);

		if($added_end_tag)
{
$code = str_replace("?&gt;</span></code>", "</span></code>", $code);
// Wait a minute. It fails highlighting? Stupid highlighter.
$code = str_replace("?&gt;</code>", "</code>", $code);

		}


		}


		$code = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "", $code);
$code = str_replace("<code>", "<div dir=\"ltr\"><code>", $code);
$code = str_replace("</code>", "</code></div>", $code);

		$code = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "", $code);
$code = str_replace("<code>", "<div dir=\"ltr\"><code>", $code);
$code = str_replace("</code>", "</code></div>", $code);

Zeile 810Zeile 843

$url = str_replace('&amp;', '&', $url);
$name = str_replace('&amp;', '&', $name);


$url = str_replace('&amp;', '&', $url);
$name = str_replace('&amp;', '&', $name);


if(!preg_match("#[a-z0-9]+://#i", $fullurl))
{
$fullurl = "http://".$fullurl;
}

		





		if(!$name)
{
$name = $url;

		if(!$name)
{
$name = $url;

		}


		}


		$name = str_replace("\'", "'", $name);
$url = str_replace("\'", "'", $url);
$fullurl = str_replace("\'", "'", $fullurl);

		$name = str_replace("\'", "'", $name);
$url = str_replace("\'", "'", $url);
$fullurl = str_replace("\'", "'", $fullurl);

Zeile 831Zeile 860
				$name = my_substr($url, 0, 40)."...".my_substr($url, -10);
}
}

				$name = my_substr($url, 0, 40)."...".my_substr($url, -10);
}
}







		
// Fix some entities in URLs
$entities = array('$' => '%24', '&#36;' => '%24', '^' => '%5E', '`' => '%60', '[' => '%5B', ']' => '%5D', '{' => '%7B', '}' => '%7D', '"' => '%22', '<' => '%3C', '>' => '%3E', ' ' => '%20');
$fullurl = str_replace(array_keys($entities), array_values($entities), $fullurl);


		$name = preg_replace("#&amp;\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode
$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
return $link;

		$name = preg_replace("#&amp;\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode
$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
return $link;

Zeile 882Zeile 915
	*/
function mycode_parse_email($email, $name="")
{

	*/
function mycode_parse_email($email, $name="")
{

 
		$name = str_replace("\\'", "'", $name);
$email = str_replace("\\'", "'", $email);

		if(!$name)
{
$name = $email;

		if(!$name)
{
$name = $email;

Zeile 904Zeile 939
	*/
function mycode_auto_url($message)
{

	*/
function mycode_auto_url($message)
{

		$message = " ".$message;
$message = preg_replace("#([\>\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2://$3[/url]", $message);
$message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2.$3[/url]", $message);
















		static $utf8_pcre_supported;
if(!isset($utf8_pcre_supported))
{
$utf8_pcre_supported = @preg_match('#^.#u', 'a');
}

if($utf8_pcre_supported)
{
$utf8_regex_chr = "u";
}
else
{
$utf8_regex_chr = "";
}

$message = " ".$message;
$message = preg_replace("#([\>\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i".$utf8_regex_chr, "$1[url]$2://$3[/url]", $message);
$message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i".$utf8_regex_chr, "$1[url]$2.$3[/url]", $message);

		$message = my_substr($message, 1);
return $message;
}

		$message = my_substr($message, 1);
return $message;
}

Zeile 953Zeile 1003
		{
$message = str_replace($this->smilies_cache, array_keys($this->smilies_cache), $message);
}

		{
$message = str_replace($this->smilies_cache, array_keys($this->smilies_cache), $message);
}

 
		return $message;
}

/**
* Highlights a string
*
* @param string The message to be highligted
* @param string The highlight keywords
* @return string The message with highlight bbcodes
*/
function highlight_message($message, $highlight)
{
if(empty($this->highlight_cache))
{
$this->highlight_cache = build_highlight_array($highlight);
}

if(is_array($this->highlight_cache) && !empty($this->highlight_cache))
{
$message = preg_replace(array_keys($this->highlight_cache), $this->highlight_cache, $message);
}


		return $message;
}


		return $message;
}