Vergleich inc/class_parser.php - 1.2.2 - 1.2.14

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 3Zeile 3
 * MyBB 1.2
* Copyright � 2006 MyBB Group, All Rights Reserved
*

 * MyBB 1.2
* Copyright � 2006 MyBB Group, All Rights Reserved
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/eula.html

 *

 *

 * $Id: class_parser.php 2447 2006-11-27 04:18:13Z CraKteR $

 * $Id: class_parser.php 3531 2007-12-02 01:21:43Z chris $

 */

/*

 */

/*

Zeile 68Zeile 68
	 */
function parse_message($message, $options=array())
{

	 */
function parse_message($message, $options=array())
{

		global $plugins, $mybb;

		global $plugins, $mybb, $lang;


// Set base URL for parsing smilies
$this->base_url = $mybb->settings['bburl'];


// Set base URL for parsing smilies
$this->base_url = $mybb->settings['bburl'];

Zeile 106Zeile 106
				{
$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);
}

				$message = preg_replace("#<base(.*)>#is", "&lt;base$1&gt;", $message);
$message = preg_replace("#<meta(.*)>#is", "&lt;meta$1&gt;", $message);
$message = str_replace(array('<?php', '<!--', '-->', '?>'), array('&lt;?php', '&lt;!--', '--&gt;', '?&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);

			}
}


			}
}


Zeile 117Zeile 119
		{
// 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);

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


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

		// Always fix bad Javascript in the message.
$message = $this->fix_javascript($message);


// If we can, parse smiliesa
if($options['allow_smilies'] != "no")

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

		{

		{

			$message = $this->parse_smilies($message, $options['allowhtml']);








			$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.

		}

// Replace MyCode if requested.

Zeile 137Zeile 146

// Run plugin hooks
$message = $plugins->run_hooks("parse_message", $message);


// 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($options['allow_mycode'] != "no")
{
// Now that we're done, if we split up any code tags, parse them and glue it all back together

Zeile 159Zeile 168
					{
$code = $this->mycode_parse_php($text[2]);
}

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

					$message = preg_replace("#\{\{mybb-code\}\}\n?#", $code, $message, 1);

					$message = preg_replace("#\<mybb-code>\n?#", $code, $message, 1);

				}
}

				}
}

		}


		}


		if($options['nl2br'] != "no")
{
$message = nl2br($message);

		if($options['nl2br'] != "no")
{
$message = nl2br($message);

			$message = str_replace("</div><br />", "</div>", $message);
$message = preg_replace("#<(/?)p>\s*(<br />?)#", "<$1p>", $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("#(&nbsp;)+(</?(?: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 = my_wordwrap($message);

		
$message = str_replace(" ", "&nbsp;&nbsp;", $message);

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


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


Zeile 182Zeile 190

/**
* Converts HTML in a message to their specific entities whilst allowing unicode characters.


/**
* Converts HTML in a message to their specific entities whilst allowing unicode characters.

	 *

	 *

	 * @param string The message to be parsed.
* @return string The formatted message.
*/

	 * @param string The message to be parsed.
* @return string The formatted message.
*/

Zeile 201Zeile 209
	 */
function cache_mycode()
{

	 */
function cache_mycode()
{

		global $cache;

		global $cache, $lang;

		$this->mycode_cache = array();

$standard_mycode['b']['regex'] = "#\[b\](.*?)\[/b\]#si";

		$this->mycode_cache = array();

$standard_mycode['b']['regex'] = "#\[b\](.*?)\[/b\]#si";

Zeile 215Zeile 223

$standard_mycode['s']['regex'] = "#\[s\](.*?)\[/s\]#si";
$standard_mycode['s']['replacement'] = "<del>$1</del>";


$standard_mycode['s']['regex'] = "#\[s\](.*?)\[/s\]#si";
$standard_mycode['s']['replacement'] = "<del>$1</del>";





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


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


Zeile 239Zeile 247

$standard_mycode['email_simple']['regex'] = "#\[email\](.*?)\[/email\]#ei";
$standard_mycode['email_simple']['replacement'] = "\$this->mycode_parse_email(\"$1\")";


$standard_mycode['email_simple']['regex'] = "#\[email\](.*?)\[/email\]#ei";
$standard_mycode['email_simple']['replacement'] = "\$this->mycode_parse_email(\"$1\")";





		$standard_mycode['email_complex']['regex'] = "#\[email=(.*?)\](.*?)\[/email\]#ei";
$standard_mycode['email_complex']['replacement'] = "\$this->mycode_parse_email(\"$1\", \"$2\")";

		$standard_mycode['email_complex']['regex'] = "#\[email=(.*?)\](.*?)\[/email\]#ei";
$standard_mycode['email_complex']['replacement'] = "\$this->mycode_parse_email(\"$1\", \"$2\")";





		$standard_mycode['color']['regex'] = "#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#si";
$standard_mycode['color']['replacement'] = "<span style=\"color: $1;\">$2</span>";

		$standard_mycode['color']['regex'] = "#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#si";
$standard_mycode['color']['replacement'] = "<span style=\"color: $1;\">$2</span>";





		$standard_mycode['size']['regex'] = "#\[size=(xx-small|x-small|small|medium|large|x-large|xx-large)\](.*?)\[/size\]#si";
$standard_mycode['size']['replacement'] = "<span style=\"font-size: $1;\">$2</span>";

		$standard_mycode['size']['regex'] = "#\[size=(xx-small|x-small|small|medium|large|x-large|xx-large)\](.*?)\[/size\]#si";
$standard_mycode['size']['replacement'] = "<span style=\"font-size: $1;\">$2</span>";





		$standard_mycode['size_int']['regex'] = "#\[size=([0-9\+\-]+?)\](.*?)\[/size\]#si";
$standard_mycode['size_int']['replacement'] = "<span style=\"font-size: $1em;\">$2</span>";


		$standard_mycode['size_int']['regex'] = "#\[size=([0-9\+\-]+?)\](.*?)\[/size\]#si";
$standard_mycode['size_int']['replacement'] = "<span style=\"font-size: $1em;\">$2</span>";


Zeile 271Zeile 279
				$custom_mycode[$key]['regex'] = "#".$mycode['regex']."#si";
}
$mycode = array_merge($standard_mycode, $custom_mycode);

				$custom_mycode[$key]['regex'] = "#".$mycode['regex']."#si";
}
$mycode = array_merge($standard_mycode, $custom_mycode);

		}

		}

		else
{
$mycode = $standard_mycode;
}

		else
{
$mycode = $standard_mycode;
}



		

		// Assign the MyCode to the cache.
foreach($mycode as $code)
{

		// Assign the MyCode to the cache.
foreach($mycode as $code)
{

Zeile 301Zeile 309
		{
$this->cache_mycode();
}

		{
$this->cache_mycode();
}





		// Parse quotes first
$message = $this->mycode_parse_quotes($message);

$message = $this->mycode_auto_url($message);

		// Parse quotes first
$message = $this->mycode_parse_quotes($message);

$message = $this->mycode_auto_url($message);





		$message = str_replace('$', '&#36;', $message);

		$message = str_replace('$', '&#36;', $message);

		



		// Replace the rest
$message = preg_replace($this->mycode_cache['find'], $this->mycode_cache['replacement'], $message);


		// Replace the rest
$message = preg_replace($this->mycode_cache['find'], $this->mycode_cache['replacement'], $message);


Zeile 329Zeile 337
		{
$message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$2')\n", $message);
$message = preg_replace("#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$4', array('$1', '$2'));", $message);

		{
$message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$2')\n", $message);
$message = preg_replace("#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$4', array('$1', '$2'));", $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);

			$message = preg_replace("#\[img align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$3', array(), '$1');", $message);
$message = preg_replace("#\[img=([0-9]{1,3})x([0-9]{1,3}) align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$5', array('$1', '$2'), '$3');", $message);






		}

return $message;

		}

return $message;

Zeile 343Zeile 346

/**
* Generates a cache of smilies


/**
* Generates a cache of smilies

	 *

	 *

	 * @access private
*/
function cache_smilies()

	 * @access private
*/
function cache_smilies()

Zeile 355Zeile 358
		if(is_array($smilies))
{
foreach($smilies as $sid => $smilie)

		if(is_array($smilies))
{
foreach($smilies as $sid => $smilie)

			{

			{

				$this->smilies_cache[$smilie['find']] = "<img src=\"{$this->base_url}{$smilie['image']}\" style=\"vertical-align: middle;\" border=\"0\" alt=\"{$smilie['name']}\" title=\"{$smilie['name']}\" />";
}
}

				$this->smilies_cache[$smilie['find']] = "<img src=\"{$this->base_url}{$smilie['image']}\" style=\"vertical-align: middle;\" border=\"0\" alt=\"{$smilie['name']}\" title=\"{$smilie['name']}\" />";
}
}

Zeile 375Zeile 378
		{
$this->cache_smilies();
}

		{
$this->cache_smilies();
}

 
		
$message = ' ' . $message . ' ';

// First we take out any of the tags we don't want parsed between (url= etc)
preg_match_all("#\[(url=([^\]]*])|url\].*\[\/url\])#i", $message, $bad_matches, PREG_PATTERN_ORDER);
$message = preg_replace("#\[(url=([^\]]*])|url\].*\[\/url\])#si", "<mybb-bad-sm>", $message);

// Impose a hard limit of 500 smilies per message as to not overload the parser
$remaining = 500;

		if(is_array($this->smilies_cache))
{

		if(is_array($this->smilies_cache))
{

			reset($this->smilies_cache);

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

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

				if($allow_html != "yes")

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

				{

				{

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



					$message = preg_replace('#([^<])(?<!"|&amp|&quot|&lt|&gt|&\#[0-9]{1}|&\#[0-9]{2}|&\#[0-9]{3}|&\#[0-9]{4})'.preg_quote($find, "#")."#is", "$1".$replace, $message,	$remaining, $replacements);
$remaining -= $replacements;
if($remaining <= 0) break; // Reached the limit

				}

				}

				$message = str_replace($find, $replace, $message);
}













				else
{
$message = preg_replace('#([^<])(?<!"|&amp|&quot|&lt|&gt|&\#[0-9]{1}|&\#[0-9]{2}|&\#[0-9]{3}|&\#[0-9]{4})'.preg_quote($find, "#")."#is", "$1".$replace, $message, $remaining);
}
}
}

// If we matched any tags previously, swap them back in
if(count($bad_matches[0]) > 0)
{
foreach($bad_matches[0] as $match)
{
$message = preg_replace("#<mybb-bad-sm>#", $match, $message, 1);
}

		}

		}

		return $message;



return trim($message);

	}

/**

	}

/**

Zeile 441Zeile 467
	function fix_javascript($message)
{
$js_array = array(

	function fix_javascript($message)
{
$js_array = array(

			"#(j)(avascript\:)#i",

			"#(&\#(0*)106;|&\#(0*)74;|j)((&\#(0*)97;|&\#(0*)65;|a)(&\#(0*)118;|&\#(0*)86;|v)(&\#(0*)97;|&\#(0*)65;|a)(\s)?(&\#(0*)115;|&\#(0*)83;|s)(&\#(0*)99;|&\#(0*)67;|c)(&\#(0*)114;|&\#(0*)82;|r)(&\#(0*)105;|&\#(0*)73;|i)(&\#112;|&\#(0*)80;|p)(&\#(0*)116;|&\#(0*)84;|t)(&\#(0*)58;|\:))#i",

			"#(o)(nmouseover\s?=)#i",
"#(o)(nmouseout\s?=)#i",
"#(o)(nmousedown\s?=)#i",

			"#(o)(nmouseover\s?=)#i",
"#(o)(nmouseout\s?=)#i",
"#(o)(nmousedown\s?=)#i",

Zeile 508Zeile 534
	function mycode_parse_code($code)
{
global $lang;

	function mycode_parse_code($code)
{
global $lang;

		$code = trim($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;
}

$code = str_replace('$', '&#36;', $code);

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

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

 
		$code = str_replace('\\', '&#92;', $code);
$code = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $code);
$code = str_replace(" ", '&nbsp;&nbsp;', $code);

		return "</p>\n<div class=\"code_header\">".$lang->code."\n</div><div class=\"code_body\"><div dir=\"ltr\"><code>".$code."</code></div></div>\n<p>\n";
}


		return "</p>\n<div class=\"code_header\">".$lang->code."\n</div><div class=\"code_body\"><div dir=\"ltr\"><code>".$code."</code></div></div>\n<p>\n";
}


Zeile 520Zeile 560
	* @return string The parsed message.
*/
function mycode_parse_php($str)

	* @return string The parsed message.
*/
function mycode_parse_php($str)

	{

	{

		global $lang;

		global $lang;





		// Clean the string before parsing.

		// Clean the string before parsing.

		$str = trim($str);
if(!$str)





		$str = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $str);
$str = rtrim($str);

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

if(empty($original))

		{
return;
}

		{
return;
}

 


		$str = str_replace('&amp;', '&', $str);
$str = str_replace('&lt;', '<', $str);
$str = str_replace('&gt;', '>', $str);

		$str = str_replace('&amp;', '&', $str);
$str = str_replace('&lt;', '<', $str);
$str = str_replace('&gt;', '>', $str);

		$original = $str;

 

// See if open and close tags are provided.
$added_open_tag = false;


// See if open and close tags are provided.
$added_open_tag = false;

Zeile 541Zeile 585
			$added_open_tag = true;
$str = "<?php \n".$str;
}

			$added_open_tag = true;
$str = "<?php \n".$str;
}

		



		$added_end_tag = false;
if(!preg_match("#\?>\s*$#si", $str))
{
$added_end_tag = true;
$str = $str." \n?>";
}

		$added_end_tag = false;
if(!preg_match("#\?>\s*$#si", $str))
{
$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", "<"))
{

Zeile 560Zeile 605
		{
$code = @highlight_string($str, true);
}

		{
$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 567Zeile 613
				"<font",
"color=\"",
"</font>"

				"<font",
"color=\"",
"</font>"

			);


			);


			$replace = array(
"<span",
"style=\"color: ",

			$replace = array(
"<span",
"style=\"color: ",

Zeile 582Zeile 627
		$code = preg_replace("#</span>\s*</code>#", "</code>", $code);
$code = preg_replace("#</span>(\r\n?|\n?)</code>#", "</span></code>", $code);
$code = str_replace("\\", '&#092;', $code);

		$code = preg_replace("#</span>\s*</code>#", "</code>", $code);
$code = preg_replace("#</span>(\r\n?|\n?)</code>#", "</span></code>", $code);
$code = str_replace("\\", '&#092;', $code);

 
		$code = str_replace('$', '&#36;', $code);

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

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



 

if($added_open_tag)
{


if($added_open_tag)
{

Zeile 593Zeile 638
		if($added_end_tag)
{
$code = str_replace("?&gt;</span></code>", "</span></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 = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "", $code);

Zeile 653Zeile 700
	 * @param string The URL to the image
* @param array Optional array of dimensions
*/

	 * @param string The URL to the image
* @param array Optional array of dimensions
*/

	function mycode_parse_img($url, $dimensions=array())

	function mycode_parse_img($url, $dimensions=array(), $align='')

	{
$url = trim($url);
$url = str_replace("\n", "", $url);
$url = str_replace("\r", "", $url);

	{
$url = trim($url);
$url = str_replace("\n", "", $url);
$url = str_replace("\r", "", $url);

 
		if($align == "right")
{
$css_align = " style=\"float: right;\"";
}
else if($align == "left")
{
$css_align = " style=\"float: left;\"";
}

		if($dimensions[0] > 0 && $dimensions[1] > 0)
{

		if($dimensions[0] > 0 && $dimensions[1] > 0)
{

			return "<img src=\"{$url}\" width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" alt=\"\" />";

			return "<img src=\"{$url}\" width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" alt=\"\"{$css_align} />";

		}
else
{

		}
else
{

			return "<img src=\"{$url}\" border=\"0\" alt=\"\" />";			

			return "<img src=\"{$url}\" border=\"0\" alt=\"\"{$css_align} />";			

		}
}


		}
}


Zeile 715Zeile 770
	function mycode_parse_list($message, $type="")
{
$message = str_replace('\"', '"', $message);

	function mycode_parse_list($message, $type="")
{
$message = str_replace('\"', '"', $message);

		$message = preg_replace("#\[\*\]\s?#", "</li><li>", $message);

		$message = preg_replace("#\s*\[\*\]\s*#", "</li>\n<li>", $message);

		$message .= "</li>";

if($type)
{

		$message .= "</li>";

if($type)
{

			$list = "</p>\n<ol type=\"$type\">$message</ol>\n<p>";

			$list = "\n<ol type=\"$type\">$message</ol>\n";

		}
else
{

		}
else
{

			$list = "</p>\n<ul>$message</ul>\n</p>";

			$list = "<ul>$message</ul>\n";

		}
$list = preg_replace("#<(ol type=\"$type\"|ul)>\s*</li>#", "<$1>", $list);
return $list;

		}
$list = preg_replace("#<(ol type=\"$type\"|ul)>\s*</li>#", "<$1>", $list);
return $list;