Vergleich inc/class_parser.php - 1.2.3 - 1.2.12

  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 2800 2007-02-14 05:57:01Z chris $

 * $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 119Zeile 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);

 
		
// 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")
{


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

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

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

		}

// Replace MyCode if requested.

		}

// Replace MyCode if requested.

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

				}
}
}

				}
}
}

Zeile 192Zeile 199
		$message = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $message); // fix & but allow unicode
$message = str_replace("<","&lt;",$message);
$message = str_replace(">","&gt;",$message);

		$message = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $message); // fix & but allow unicode
$message = str_replace("<","&lt;",$message);
$message = str_replace(">","&gt;",$message);

		return $message;

		return $message;

	}

/**

	}

/**

Zeile 213Zeile 220

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


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





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


Zeile 225Zeile 232

$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']['replacement'] = "\$this->mycode_parse_url(\"$1$2\")";


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


Zeile 234Zeile 241

$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']['regex'] = "#\[url=([a-z]+?://)([^\r\n\"\[<]+?)\](.+?)\[/url\]#esi";
$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']['replacement'] = "\$this->mycode_parse_url(\"$1\", \"$2\")";


		$standard_mycode['url_complex2']['regex'] = "#\[url=([^\r\n\"\[<&\(\)]+?)\](.+?)\[/url\]#esi";
$standard_mycode['url_complex2']['replacement'] = "\$this->mycode_parse_url(\"$1\", \"$2\")";


Zeile 246Zeile 253

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


Zeile 258Zeile 265

$standard_mycode['align']['regex'] = "#\[align=(left|center|right|justify)\](.*?)\[/align\]#si";
$standard_mycode['align']['replacement'] = "<p style=\"text-align: $1;\">$2</p>";


$standard_mycode['align']['regex'] = "#\[align=(left|center|right|justify)\](.*?)\[/align\]#si";
$standard_mycode['align']['replacement'] = "<p style=\"text-align: $1;\">$2</p>";





		$standard_mycode['hr']['regex'] = "#\[hr\]#si";
$standard_mycode['hr']['replacement'] = "<hr />";

$custom_mycode = $cache->read("mycode");

		$standard_mycode['hr']['regex'] = "#\[hr\]#si";
$standard_mycode['hr']['replacement'] = "<hr />";

$custom_mycode = $cache->read("mycode");





		// If there is custom MyCode, load it.
if(is_array($custom_mycode))

		// If there is custom MyCode, load it.
if(is_array($custom_mycode))

		{

		{

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

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

		}

		}

		else
{
$mycode = $standard_mycode;
}


		else
{
$mycode = $standard_mycode;
}


		if(strtolower($lang->settings['charset']) == 'utf-8')
{
$extra_modifier = 'u';
}
else
{
$extra_modifier = '';
}


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

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

			$this->mycode_cache['find'][] = $code['regex'] . $extra_modifier;

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

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

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

		}
}

/**

		}
}

/**

	 * Parses MyCode tags in a specific message with the specified options.
*
* @param string The message to be parsed.

	 * Parses MyCode tags in a specific message with the specified options.
*
* @param string The message to be parsed.

Zeile 316Zeile 314
		$message = $this->mycode_parse_quotes($message);

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

		$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 340Zeile 338
			$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 align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$3', array(), '$1');", $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);
$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('$4', array('$1', '$2', '$3'));", $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=([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;
}





	/**
* Generates a cache of smilies
*

	/**
* Generates a cache of smilies
*

Zeile 362Zeile 353
	{
global $cache;
$this->smilies_cache = array();

	{
global $cache;
$this->smilies_cache = array();





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

		$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']}\" />";
}
}

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

				}

				}

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

 
			}
}

			}
}

		return $message;












// 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 trim($message);

	}

/**

	}

/**

Zeile 531Zeile 545
			return;
}


			return;
}


		$code = str_replace('&amp;', '&', $code);

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

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

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

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

if($added_open_tag)

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

if($added_open_tag)