Vergleich inc/class_parser.php - 1.4.6 - 1.4.15

  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 4322 2009-02-21 23:00: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 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]);
}
elseif(my_strtolower($text[1]) == "php")

						$code = $this->mycode_parse_code($text[2]);
}
elseif(my_strtolower($text[1]) == "php")

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

					$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 290Zeile 305
		{
$this->mycode_cache['find'][] = $code['regex'];
$this->mycode_cache['replacement'][] = $code['replacement'];

		{
$this->mycode_cache['find'][] = $code['regex'];
$this->mycode_cache['replacement'][] = $code['replacement'];

		}

		}

	}

/**

	}

/**

Zeile 472Zeile 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 523Zeile 538
	* @return string The parsed text.
*/
function mycode_handle_size($size, $text)

	* @return string The parsed text.
*/
function mycode_handle_size($size, $text)

	{

	{

		$size = intval($size)+10;

		$size = intval($size)+10;





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

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

Zeile 538Zeile 553

/**
* Parses quote MyCode.


/**
* Parses quote MyCode.

	*

	*

	* @param string The message to be parsed
* @param boolean Are we formatting as text?
* @return string The parsed message.

	* @param string The message to be parsed
* @param boolean Are we formatting as text?
* @return string The parsed message.

Zeile 546Zeile 561
	function mycode_parse_quotes($message, $text_only=false)
{
global $lang, $templates, $theme, $mybb;

	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)

		if($text_only == false)

		{

		{

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

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

			);
}

			);
}

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

		else
{
$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 639Zeile 654
				$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})";

			}

			}

			$username = preg_replace("#(?:&quot;|\"|')? dateline=(?:&quot;|\"|')?[0-9]+(?:&quot;|\"|')?#i", '', $username);
$delete_quote = false;

			$username = preg_replace("#(?:&quot;|\"|')? dateline=(?:&quot;|\"|')?[0-9]+(?:&quot;|\"|')?#i", '', $username);
$delete_quote = false;

		}

		}


if($delete_quote)


if($delete_quote)

		{

		{

			$username = my_substr($username, 0, my_strlen($username)-1);

			$username = my_substr($username, 0, my_strlen($username)-1);

		}

		}


if($text_only)
{
return "\n".htmlspecialchars_uni($username)." $lang->wrote{$date}\n--\n{$message}\n--\n";


if($text_only)
{
return "\n".htmlspecialchars_uni($username)." $lang->wrote{$date}\n--\n{$message}\n--\n";

		}
else

		}
else

		{
$span = "";
if(!$delete_quote)

		{
$span = "";
if(!$delete_quote)

Zeile 667Zeile 682

/**
* Parses code MyCode.


/**
* Parses code MyCode.

	*

	*

	* @param string The message to be parsed
* @param boolean Are we formatting as text?
* @return string The parsed message.

	* @param string The message to be parsed
* @param boolean Are we formatting as text?
* @return string The parsed message.

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

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





		return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n";
}


		return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n";
}


Zeile 738Zeile 753
		{
$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 754Zeile 769
			@highlight_string($str);
$code = ob_get_contents();
ob_end_clean();

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

		}
else

		}
else

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

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

Zeile 788Zeile 803
		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);

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

		}

		}


if($added_end_tag)
{


if($added_end_tag)
{

Zeile 823Zeile 838
		if(!preg_match("#^[a-z0-9]+://#i", $url))
{
$url = "http://".$url;

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

		}

		}

		$fullurl = $url;

		$fullurl = $url;





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

Zeile 851Zeile 861
			}
}


			}
}


		// fix some entities in URLs
$fullurl = strtr($fullurl, array('$' => '%24', '^' => '%5E', '`' => '%60', '[' => '%5B', ']' => '%5D', '{' => '%7B', '}' => '%7D', '"' => '%22', '<' => '%3C', '>' => '%3E', ' ' => '%20'));



		// 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 992Zeile 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;
}