Vergleich inc/class_parser.php - 1.6.0 - 1.6.4

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * $Id: class_parser.php 5141 2010-07-29 23:32:11Z RyanGordon $

 * $Id: class_parser.php 5520 2011-07-28 08:56:12Z Tomm $

 */

/*

 */

/*

Zeile 27Zeile 27
	/**
* Internal cache of MyCode.
*

	/**
* Internal cache of MyCode.
*

 
	 * @access public

	 * @var mixed
*/
public $mycode_cache = 0;

	 * @var mixed
*/
public $mycode_cache = 0;

Zeile 34Zeile 35
	/**
* Internal cache of smilies
*

	/**
* Internal cache of smilies
*

 
	 * @access public

	 * @var mixed
*/
public $smilies_cache = 0;

	 * @var mixed
*/
public $smilies_cache = 0;

Zeile 41Zeile 43
	/**
* Internal cache of badwords filters
*

	/**
* Internal cache of badwords filters
*

 
	 * @access public

	 * @var mixed
*/
public $badwords_cache = 0;

	 * @var mixed
*/
public $badwords_cache = 0;

Zeile 48Zeile 51
	/**
* Base URL for smilies
*

	/**
* Base URL for smilies
*

 
	 * @access public

	 * @var string
*/
public $base_url;

	 * @var string
*/
public $base_url;

Zeile 55Zeile 59
	/**
* Parsed Highlights cache
*

	/**
* Parsed Highlights cache
*

	 * @access private

	 * @access public

	 * @var array
*/

	 * @var array
*/

	var $highlight_cache = array();

	public $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)
*

	 * @access private

	 * @access public

	 * @var array
*/

	 * @var array
*/

	private $options;

	public $options;


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


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

Zeile 114Zeile 118
			{
$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($this->options['allow_mycode'])
{

		// If MyCode needs to be replaced, first filter out [code] and [php] tags.
if($this->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 150Zeile 151
		if($this->options['allow_mycode'])
{
$message = $this->parse_mycode($message, $this->options);

		if($this->options['allow_mycode'])
{
$message = $this->parse_mycode($message, $this->options);

		}

		}

		
// Parse Highlights
if($this->options['highlight'])

		
// Parse Highlights
if($this->options['highlight'])

Zeile 168Zeile 169
			{
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 185Zeile 180
					$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 329Zeile 333
		if($this->mycode_cache == 0)
{
$this->cache_mycode();

		if($this->mycode_cache == 0)
{
$this->cache_mycode();

		}

		}

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

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

Zeile 378Zeile 382
		}

return $message;

		}

return $message;

	}


	}


	/**
* Generates a cache of smilies
*

	/**
* Generates a cache of smilies
*

Zeile 387Zeile 391
	 */
private function cache_smilies()
{

	 */
private function cache_smilies()
{

		global $cache;

		global $cache, $mybb;

		$this->smilies_cache = array();

$smilies = $cache->read("smilies");
if(is_array($smilies))
{
foreach($smilies as $sid => $smilie)

		$this->smilies_cache = array();

$smilies = $cache->read("smilies");
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']}\" />";
}







			{
if(defined("IN_ARCHIVE") && substr($smilie['image'], 0, 4) != "http")
{
// We're in the archive and not using an outside image, add in our address
$smilie['image'] = $mybb->settings['bburl']."/".$smilie['image'];
}

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

		}
}


		}
}


Zeile 413Zeile 423
		if($this->smilies_cache == 0)
{
$this->cache_smilies();

		if($this->smilies_cache == 0)
{
$this->cache_smilies();

		}

		}

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

// First we take out any of the tags we don't want parsed between (url= etc)

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

// First we take out any of the tags we don't want parsed between (url= etc)

		preg_match_all("#\[(url(=[^\]]*])?\](.*?)\[\/url\]|quote=([^\]]*)?\])#i", $message, $bad_matches, PREG_PATTERN_ORDER);
$message = preg_replace("#\[(url(=[^\]]*])?\](.*?)\[\/url\]|quote=([^\]]*)?\])#si", "<mybb-bad-sm>", $message);

		preg_match_all("#\[(url(=[^\]]*)?\](.*?)\[\/url\]|quote=([^\]]*)?\])#i", $message, $bad_matches, PREG_PATTERN_ORDER);
$message = preg_replace("#\[(url(=[^\]]*)?\](.*?)\[\/url\]|quote=([^\]]*)?\])#si", "<mybb-bad-sm>", $message);

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

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

Zeile 431Zeile 441
				$orig_message = $message;
$find = $this->parse_html($find);
$find = preg_quote($find, "#");

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

				




$replace = strip_tags($replace, "<img>");


				// Fix issues for smileys starting with a ";"
$orig_find = $find;
if(substr($find, 0, 1) == ";")

				// Fix issues for smileys starting with a ";"
$orig_find = $find;
if(substr($find, 0, 1) == ";")

Zeile 462Zeile 474
			{
$match = str_replace('$', '\$', $match);
$message = preg_replace("#<mybb-bad-sm>#", $match, $message, 1);

			{
$match = str_replace('$', '\$', $match);
$message = preg_replace("#<mybb-bad-sm>#", $match, $message, 1);

			}
}


			}
}


		return trim($message);

		return trim($message);

	}

	}


/**
* Generates a cache of badwords filters.


/**
* Generates a cache of badwords filters.

Zeile 478Zeile 490
		global $cache;
$this->badwords_cache = array();
$this->badwords_cache = $cache->read("badwords");

		global $cache;
$this->badwords_cache = array();
$this->badwords_cache = $cache->read("badwords");

	}

	}


/**
* Parses a list of filtered/badwords in the specified message.


/**
* Parses a list of filtered/badwords in the specified message.

Zeile 494Zeile 506
			$this->cache_badwords();
}
if(is_array($this->badwords_cache))

			$this->cache_badwords();
}
if(is_array($this->badwords_cache))

		{

		{

			reset($this->badwords_cache);
foreach($this->badwords_cache as $bid => $badword)
{

			reset($this->badwords_cache);
foreach($this->badwords_cache as $bid => $badword)
{

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

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

				$badword['badword'] = str_replace('\*', '(.*)',preg_quote($badword['badword'], "#"));
$message = preg_replace("#(^|\s|\W)".$badword['badword']."(\W|\s|$)#i", "\\1".$badword['replacement']."\\2", $message);










				
// Take into account the position offset for our last replacement.
$index = substr_count($badword['badword'], '*')+2;
$badword['badword'] = str_replace('\*', '([a-zA-Z0-9_]{1})', preg_quote($badword['badword'], "#"));

// Ensure we run the replacement enough times but not recursively (i.e. not while(preg_match..))
$count = preg_match_all("#(^|\W)".$badword['badword']."(\W|$)#i", $message, $matches);
for($i=0; $i < $count; ++$i)
{
$message = preg_replace("#(^|\W)".$badword['badword']."(\W|$)#i", "\\1".$badword['replacement'].'\\'.$index, $message);
}

			}

			}

		}

		}

		if($options['strip_tags'] == 1)
{
$message = strip_tags($message);

		if($options['strip_tags'] == 1)
{
$message = strip_tags($message);

		}

		}

		return $message;
}


		return $message;
}


Zeile 522Zeile 543
	function fix_javascript($message)
{
$js_array = array(

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

			"#(&\#(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",

			"#(&\#(0*)106;?|&\#(0*)74;?|&\#x(0*)4a;?|&\#x(0*)6a;?|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 559Zeile 580
		if($size > 50)
{
$size = 50;

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

		}

		}


$text = "<span style=\"font-size: {$size}pt;\">".str_replace("\'", "'", $text)."</span>";



$text = "<span style=\"font-size: {$size}pt;\">".str_replace("\'", "'", $text)."</span>";


Zeile 579Zeile 600

// Assign pattern and replace values.
$pattern = array(


// Assign pattern and replace values.
$pattern = array(

			"#\[quote=(?:&quot;|\"|')?(.*?)[\"']?(?:&quot;|\"|')?\](.*?)\[\/quote\](\r\n?|\n?)#esi",

			"#\[quote=([\"']|&quot;|)(.*?)(?:\\1)(.*?)(?:[\"']|&quot;)?\](.*?)\[/quote\](\r\n?|\n?)#esi",

			"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"
);

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

			"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"
);

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

				"\$this->mycode_parse_post_quotes('$2','$1')",

				"\$this->mycode_parse_post_quotes('$4','$2$3')",

				"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
);
}
else
{
$replace = array(

				"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
);
}
else
{
$replace = array(

				"\$this->mycode_parse_post_quotes('$2', '$1', true)",

				"\$this->mycode_parse_post_quotes('$4','$2$3', true)",

				"\n{$lang->quote}\n--\n$1\n--\n"

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

if($text_only == false)
{

			);
}

do
{
$message = preg_replace($pattern, $replace, $message, -1, $count);
} while($count);

if($text_only == false)
{

			$find = array(
"#(\r\n*|\n*)<\/cite>(\r\n*|\n*)#",
"#(\r\n*|\n*)<\/blockquote>#"

			$find = array(
"#(\r\n*|\n*)<\/cite>(\r\n*|\n*)#",
"#(\r\n*|\n*)<\/blockquote>#"

Zeile 621Zeile 642
	
/**
* Parses quotes with post id and/or dateline.

	
/**
* Parses quotes with post id and/or dateline.

	*

	*

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

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

Zeile 654Zeile 675
			else
{
eval("\$linkback = \" ".$templates->get("postbit_gotopost", 1, 0)."\";");

			else
{
eval("\$linkback = \" ".$templates->get("postbit_gotopost", 1, 0)."\";");

			}

			}

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

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

Zeile 735Zeile 756
	*
* @param string The message to be parsed
* @param boolean Whether or not it should return it as pre-wrapped in a div or not.

	*
* @param string The message to be parsed
* @param boolean Whether or not it should return it as pre-wrapped in a div or not.

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

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

	function mycode_parse_php($str, $bare_return = false, $text_only = false)
{
global $lang;

	function mycode_parse_php($str, $bare_return = false, $text_only = false)
{
global $lang;

Zeile 977Zeile 998
				if($fragments[0])
{
$id = str_replace('!v=', '', $fragments[0]); // http://www.youtube.com/watch#!v=fds123

				if($fragments[0])
{
$id = str_replace('!v=', '', $fragments[0]); // http://www.youtube.com/watch#!v=fds123

 
				}
elseif($input['v'])
{
$id = $input['v']; // http://www.youtube.com/watch?v=fds123

				}
else
{

				}
else
{

					$id = $input['v']; // http://www.youtube.com/watch?v=fds123

					$id = $path[1]; // http://www.youtu.be/fds123

				}
break;
default:
return "[video={$video}]{$url}[/video]";

				}
break;
default:
return "[video={$video}]{$url}[/video]";

		}


		}


		if(empty($id) || ($video == "yahoo" && empty($vid)))
{
return "[video={$video}]{$url}[/video]";

		if(empty($id) || ($video == "yahoo" && empty($vid)))
{
return "[video={$video}]{$url}[/video]";

Zeile 1001Zeile 1026

/**
* Parses URLs automatically.


/**
* Parses URLs automatically.

	*

	*

	* @param string The message to be parsed
* @return string The parsed message.
*/
function mycode_auto_url($message)
{
$message = " ".$message;

	* @param string The message to be parsed
* @return string The parsed message.
*/
function mycode_auto_url($message)
{
$message = " ".$message;

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

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

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


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


Zeile 1052Zeile 1077
		if($this->smilies_cache == 0)
{
$this->cache_smilies();

		if($this->smilies_cache == 0)
{
$this->cache_smilies();

		}

		}

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

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

Zeile 1068Zeile 1093
	 * @return string The message with highlight bbcodes
*/
function highlight_message($message, $highlight)

	 * @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(empty($this->highlight_cache))
{
$this->highlight_cache = build_highlight_array($highlight);

Zeile 1083Zeile 1108
	}

/**

	}

/**

	 * Parses message to plain text equivilents of MyCode.

	 * Parses message to plain text equivalents of MyCode.

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

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

Zeile 1103Zeile 1128

$find = array(
"#\[(b|u|i|s|url|email|color|img)\](.*?)\[/\\1\]#is",


$find = array(
"#\[(b|u|i|s|url|email|color|img)\](.*?)\[/\\1\]#is",

			"#\[code\](.*?)\[/code\](\r\n?|\n?)#ise",

 
			"#\[php\](.*?)\[/php\](\r\n?|\n?)#ise",

			"#\[php\](.*?)\[/php\](\r\n?|\n?)#ise",

 
			"#\[code\](.*?)\[/code\](\r\n?|\n?)#ise",

			"#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is",
"#\[url=([a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#si",
"#\[url=([^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#si",

			"#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is",
"#\[url=([a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#si",
"#\[url=([^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#si",

Zeile 1130Zeile 1155
		}

// Special code requiring special attention

		}

// Special code requiring special attention

		while(preg_match("#\[list\](.*?)\[/list\]#si", $message))
{
$message = preg_replace("#\[list\](.*?)\[/list\](\r\n?|\n?)#esi", "\$this->mycode_parse_list('$1', '', true)\n", $message);

		while(preg_match("#\[list\](.*?)\[/list\]#esi", $message))
{
$message = preg_replace("#\s?\[list\](.*?)\[/list\](\r\n?|\n?)#esi", "\$this->mycode_parse_list('$1')\n", $message);

		}

// Replace lists.
while(preg_match("#\[list=(a|A|i|I|1)\](.*?)\[/list\](\r\n?|\n?)#esi", $message))
{

		}

// Replace lists.
while(preg_match("#\[list=(a|A|i|I|1)\](.*?)\[/list\](\r\n?|\n?)#esi", $message))
{

			$message = preg_replace("#\[list=(a|A|i|I|1)\](.*?)\[/list\]#esi", "\$this->mycode_parse_list('$2', '$1', true)\n", $message);

			$message = preg_replace("#\s?\[list=(a|A|i|I|1)\](.*?)\[/list\]#esi", "\$this->mycode_parse_list('$2', '$1')\n", $message);

		}

// Run plugin hooks

		}

// Run plugin hooks