Blame Identity/Webenv/App/phpBB/3.0.4/includes/bbcode.php

f2e824
f2e824
/**
f2e824
*
f2e824
* @package phpBB3
f2e824
* @version $Id: bbcode.php 8953 2008-09-28 17:08:09Z acydburn $
f2e824
* @copyright (c) 2005 phpBB Group
f2e824
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
f2e824
*
f2e824
*/
f2e824
f2e824
/**
f2e824
* @ignore
f2e824
*/
f2e824
if (!defined('IN_PHPBB'))
f2e824
{
f2e824
	exit;
f2e824
}
f2e824
f2e824
/**
f2e824
* BBCode class
f2e824
* @package phpBB3
f2e824
*/
f2e824
class bbcode
f2e824
{
f2e824
	var $bbcode_uid = '';
f2e824
	var $bbcode_bitfield = '';
f2e824
	var $bbcode_cache = array();
f2e824
	var $bbcode_template = array();
f2e824
f2e824
	var $bbcodes = array();
f2e824
f2e824
	var $template_bitfield;
f2e824
	var $template_filename = '';
f2e824
f2e824
	/**
f2e824
	* Constructor
f2e824
	* Init bbcode cache entries if bitfield is specified
f2e824
	*/
f2e824
	function bbcode($bitfield = '')
f2e824
	{
f2e824
		if ($bitfield)
f2e824
		{
f2e824
			$this->bbcode_bitfield = $bitfield;
f2e824
			$this->bbcode_cache_init();
f2e824
		}
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Second pass bbcodes
f2e824
	*/
f2e824
	function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
f2e824
	{
f2e824
		if ($bbcode_uid)
f2e824
		{
f2e824
			$this->bbcode_uid = $bbcode_uid;
f2e824
		}
f2e824
f2e824
		if ($bbcode_bitfield !== false)
f2e824
		{
f2e824
			$this->bbcode_bitfield = $bbcode_bitfield;
f2e824
f2e824
			// Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
f2e824
			$this->bbcode_cache_init();
f2e824
		}
f2e824
f2e824
		if (!$this->bbcode_bitfield)
f2e824
		{
f2e824
			// Remove the uid from tags that have not been transformed into HTML
f2e824
			if ($this->bbcode_uid)
f2e824
			{
f2e824
				$message = str_replace(':' . $this->bbcode_uid, '', $message);
f2e824
			}
f2e824
f2e824
			return;
f2e824
		}
f2e824
f2e824
		$str = array('search' => array(), 'replace' => array());
f2e824
		$preg = array('search' => array(), 'replace' => array());
f2e824
f2e824
		$bitfield = new bitfield($this->bbcode_bitfield);
f2e824
		$bbcodes_set = $bitfield->get_all_set();
f2e824
f2e824
		$undid_bbcode_specialchars = false;
f2e824
		foreach ($bbcodes_set as $bbcode_id)
f2e824
		{
f2e824
			if (!empty($this->bbcode_cache[$bbcode_id]))
f2e824
			{
f2e824
				foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
f2e824
				{
f2e824
					foreach ($array as $search => $replace)
f2e824
					{
f2e824
						${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
f2e824
						${$type}['replace'][] = $replace;
f2e824
					}
f2e824
f2e824
					if (sizeof($str['search']))
f2e824
					{
f2e824
						$message = str_replace($str['search'], $str['replace'], $message);
f2e824
						$str = array('search' => array(), 'replace' => array());
f2e824
					}
f2e824
f2e824
					if (sizeof($preg['search']))
f2e824
					{
f2e824
						// we need to turn the entities back into their original form to allow the
f2e824
						// search patterns to work properly
f2e824
						if (!$undid_bbcode_specialchars)
f2e824
						{
f2e824
							$message = str_replace(array(':', '.'), array(':', '.'), $message);
f2e824
							$undid_bbcode_specialchars = true;
f2e824
						}
f2e824
f2e824
						$message = preg_replace($preg['search'], $preg['replace'], $message);
f2e824
						$preg = array('search' => array(), 'replace' => array());
f2e824
					}
f2e824
				}
f2e824
			}
f2e824
		}
f2e824
f2e824
		// Remove the uid from tags that have not been transformed into HTML
f2e824
		$message = str_replace(':' . $this->bbcode_uid, '', $message);
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Init bbcode cache
f2e824
	*
f2e824
	* requires: $this->bbcode_bitfield
f2e824
	* sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
f2e824
	*/
f2e824
	function bbcode_cache_init()
f2e824
	{
f2e824
		global $user, $phpbb_root_path;
f2e824
f2e824
		if (empty($this->template_filename))
f2e824
		{
f2e824
			$this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
f2e824
			$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';
f2e824
			
f2e824
			if (!@file_exists($this->template_filename))
f2e824
			{
f2e824
				if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
f2e824
				{
f2e824
					$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/bbcode.html';
f2e824
					if (!@file_exists($this->template_filename))
f2e824
					{
f2e824
						trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
f2e824
					}
f2e824
				}
f2e824
				else
f2e824
				{
f2e824
					trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
f2e824
				}
f2e824
			}
f2e824
		}
f2e824
f2e824
		$bbcode_ids = $rowset = $sql = array();
f2e824
f2e824
		$bitfield = new bitfield($this->bbcode_bitfield);
f2e824
		$bbcodes_set = $bitfield->get_all_set();
f2e824
f2e824
		foreach ($bbcodes_set as $bbcode_id)
f2e824
		{
f2e824
			if (isset($this->bbcode_cache[$bbcode_id]))
f2e824
			{
f2e824
				// do not try to re-cache it if it's already in
f2e824
				continue;
f2e824
			}
f2e824
			$bbcode_ids[] = $bbcode_id;
f2e824
f2e824
			if ($bbcode_id > NUM_CORE_BBCODES)
f2e824
			{
f2e824
				$sql[] = $bbcode_id;
f2e824
			}
f2e824
		}
f2e824
f2e824
		if (sizeof($sql))
f2e824
		{
f2e824
			global $db;
f2e824
f2e824
			$sql = 'SELECT *
f2e824
				FROM ' . BBCODES_TABLE . '
f2e824
				WHERE ' . $db->sql_in_set('bbcode_id', $sql);
f2e824
			$result = $db->sql_query($sql, 3600);
f2e824
f2e824
			while ($row = $db->sql_fetchrow($result))
f2e824
			{
f2e824
				// To circumvent replacing newlines with 
for the generated html,
f2e824
				// we use carriage returns here. They are later changed back to newlines
f2e824
				$row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
f2e824
				$row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
f2e824
f2e824
				$rowset[$row['bbcode_id']] = $row;
f2e824
			}
f2e824
			$db->sql_freeresult($result);
f2e824
		}
f2e824
f2e824
		foreach ($bbcode_ids as $bbcode_id)
f2e824
		{
f2e824
			switch ($bbcode_id)
f2e824
			{
f2e824
				case 0:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'str' => array(
f2e824
							'[/quote:$uid]'	=> $this->bbcode_tpl('quote_close', $bbcode_id)
f2e824
						),
f2e824
						'preg' => array(
f2e824
							'#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise'	=> "\$this->bbcode_second_pass_quote('\$1', '\$2')"
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 1:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'str' => array(
f2e824
							'[b:$uid]'	=> $this->bbcode_tpl('b_open', $bbcode_id),
f2e824
							'[/b:$uid]'	=> $this->bbcode_tpl('b_close', $bbcode_id),
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 2:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'str' => array(
f2e824
							'[i:$uid]'	=> $this->bbcode_tpl('i_open', $bbcode_id),
f2e824
							'[/i:$uid]'	=> $this->bbcode_tpl('i_close', $bbcode_id),
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 3:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'preg' => array(
f2e824
							'#\[url:$uid\]((.*?))\[/url:$uid\]#s'			=> $this->bbcode_tpl('url', $bbcode_id),
f2e824
							'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s'	=> $this->bbcode_tpl('url', $bbcode_id),
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 4:
f2e824
					if ($user->optionget('viewimg'))
f2e824
					{
f2e824
						$this->bbcode_cache[$bbcode_id] = array(
f2e824
							'preg' => array(
f2e824
								'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> $this->bbcode_tpl('img', $bbcode_id),
f2e824
							)
f2e824
						);
f2e824
					}
f2e824
					else
f2e824
					{
f2e824
						$this->bbcode_cache[$bbcode_id] = array(
f2e824
							'preg' => array(
f2e824
								'#\[img:$uid\](.*?)\[/img:$uid\]#s'		=> str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
f2e824
							)
f2e824
						);
f2e824
					}
f2e824
				break;
f2e824
f2e824
				case 5:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'preg' => array(
f2e824
							'#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s'	=> $this->bbcode_tpl('size', $bbcode_id),
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 6:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'preg' => array(
f2e824
							'!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'	=> $this->bbcode_tpl('color', $bbcode_id),
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 7:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'str' => array(
f2e824
							'[u:$uid]'	=> $this->bbcode_tpl('u_open', $bbcode_id),
f2e824
							'[/u:$uid]'	=> $this->bbcode_tpl('u_close', $bbcode_id),
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 8:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'preg' => array(
f2e824
							'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'	=> "\$this->bbcode_second_pass_code('\$1', '\$2')",
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 9:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'preg' => array(
f2e824
							'#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#'	=> "\$1",
f2e824
							'#(\[list=([^\[]+):$uid\])[\n]{1}#'			=> "\$1",
f2e824
							'#\[list=([^\[]+):$uid\]#e'					=> "\$this->bbcode_list('\$1')",
f2e824
						),
f2e824
						'str' => array(
f2e824
							'[list:$uid]'		=> $this->bbcode_tpl('ulist_open_default', $bbcode_id),
f2e824
							'[/list:u:$uid]'	=> $this->bbcode_tpl('ulist_close', $bbcode_id),
f2e824
							'[/list:o:$uid]'	=> $this->bbcode_tpl('olist_close', $bbcode_id),
f2e824
							'[*:$uid]'			=> $this->bbcode_tpl('listitem', $bbcode_id),
f2e824
							'[/*:$uid]'			=> $this->bbcode_tpl('listitem_close', $bbcode_id),
f2e824
							'[/*:m:$uid]'		=> $this->bbcode_tpl('listitem_close', $bbcode_id)
f2e824
						),
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 10:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'preg' => array(
f2e824
							'#\[email:$uid\]((.*?))\[/email:$uid\]#is'			=> $this->bbcode_tpl('email', $bbcode_id),
f2e824
							'#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is'	=> $this->bbcode_tpl('email', $bbcode_id)
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				case 11:
f2e824
					if ($user->optionget('viewflash'))
f2e824
					{
f2e824
						$this->bbcode_cache[$bbcode_id] = array(
f2e824
							'preg' => array(
f2e824
								'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'	=> $this->bbcode_tpl('flash', $bbcode_id),
f2e824
							)
f2e824
						);
f2e824
					}
f2e824
					else
f2e824
					{
f2e824
						$this->bbcode_cache[$bbcode_id] = array(
f2e824
							'preg' => array(
f2e824
								'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#'	=> str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
f2e824
							)
f2e824
						);
f2e824
					}
f2e824
				break;
f2e824
f2e824
				case 12:
f2e824
					$this->bbcode_cache[$bbcode_id] = array(
f2e824
						'str'	=> array(
f2e824
							'[/attachment:$uid]'	=> $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
f2e824
						),
f2e824
						'preg'	=> array(
f2e824
							'#\[attachment=([0-9]+):$uid\]#'	=> $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
f2e824
						)
f2e824
					);
f2e824
				break;
f2e824
f2e824
				default:
f2e824
					if (isset($rowset[$bbcode_id]))
f2e824
					{
f2e824
						if ($this->template_bitfield->get($bbcode_id))
f2e824
						{
f2e824
							// The bbcode requires a custom template to be loaded
f2e824
							if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
f2e824
							{
f2e824
								// For some reason, the required template seems not to be available, use the default template
f2e824
								$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
f2e824
							}
f2e824
							else
f2e824
							{
f2e824
								// In order to use templates with custom bbcodes we need
f2e824
								// to replace all {VARS} to corresponding backreferences
f2e824
								// Note that backreferences are numbered from bbcode_match
f2e824
								if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
f2e824
								{
f2e824
									foreach ($m[0] as $i => $tok)
f2e824
									{
f2e824
										$bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
f2e824
									}
f2e824
								}
f2e824
							}
f2e824
						}
f2e824
						else
f2e824
						{
f2e824
							// Default template
f2e824
							$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
f2e824
						}
f2e824
f2e824
						// Replace {L_*} lang strings
f2e824
						$bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
f2e824
f2e824
						if (!empty($rowset[$bbcode_id]['second_pass_replace']))
f2e824
						{
f2e824
							// The custom BBCode requires second-pass pattern replacements
f2e824
							$this->bbcode_cache[$bbcode_id] = array(
f2e824
								'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
f2e824
							);
f2e824
						}
f2e824
						else
f2e824
						{
f2e824
							$this->bbcode_cache[$bbcode_id] = array(
f2e824
								'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
f2e824
							);
f2e824
						}
f2e824
					}
f2e824
					else
f2e824
					{
f2e824
						$this->bbcode_cache[$bbcode_id] = false;
f2e824
					}
f2e824
				break;
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Return bbcode template
f2e824
	*/
f2e824
	function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
f2e824
	{
f2e824
		static $bbcode_hardtpl = array();
f2e824
		if (empty($bbcode_hardtpl))
f2e824
		{
f2e824
			global $user;
f2e824
			
f2e824
			$bbcode_hardtpl = array(
f2e824
				'b_open'	=> '',
f2e824
				'b_close'	=> '',
f2e824
				'i_open'	=> '',
f2e824
				'i_close'	=> '',
f2e824
				'u_open'	=> '',
f2e824
				'u_close'	=> '',
f2e824
				'img'		=> '' . $user->lang['IMAGE'] . '',
f2e824
				'size'		=> '$2',
f2e824
				'color'		=> '$2',
f2e824
				'email'		=> '$2'
f2e824
			);
f2e824
		}
f2e824
f2e824
		if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
f2e824
		{
f2e824
			return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
f2e824
		}
f2e824
f2e824
		if (empty($this->bbcode_template))
f2e824
		{
f2e824
			if (($tpl = file_get_contents($this->template_filename)) === false)
f2e824
			{
f2e824
				trigger_error('Could not load bbcode template', E_USER_ERROR);
f2e824
			}
f2e824
f2e824
			// replace \ with \\ and then ' with \'.
f2e824
			$tpl = str_replace('\\', '\\\\', $tpl);
f2e824
			$tpl = str_replace("'", "\'", $tpl);
f2e824
f2e824
			// strip newlines and indent
f2e824
			$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
f2e824
f2e824
			// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
f2e824
			$this->bbcode_template = array();
f2e824
f2e824
			$matches = preg_match_all('#(.*?)#', $tpl, $match);
f2e824
f2e824
			for ($i = 0; $i < $matches; $i++)
f2e824
			{
f2e824
				if (empty($match[1][$i]))
f2e824
				{
f2e824
					continue;
f2e824
				}
f2e824
f2e824
				$this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
f2e824
			}
f2e824
		}
f2e824
f2e824
		return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Return bbcode template replacement
f2e824
	*/
f2e824
	function bbcode_tpl_replace($tpl_name, $tpl)
f2e824
	{
f2e824
		global $user;
f2e824
f2e824
		static $replacements = array(
f2e824
			'quote_username_open'	=> array('{USERNAME}'	=> '$1'),
f2e824
			'color'					=> array('{COLOR}'		=> '$1', '{TEXT}'			=> '$2'),
f2e824
			'size'					=> array('{SIZE}'		=> '$1', '{TEXT}'			=> '$2'),
f2e824
			'img'					=> array('{URL}'		=> '$1'),
f2e824
			'flash'					=> array('{WIDTH}'		=> '$1', '{HEIGHT}'			=> '$2', '{URL}'	=> '$3'),
f2e824
			'url'					=> array('{URL}'		=> '$1', '{DESCRIPTION}'	=> '$2'),
f2e824
			'email'					=> array('{EMAIL}'		=> '$1', '{DESCRIPTION}'	=> '$2')
f2e824
		);
f2e824
f2e824
		$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);
f2e824
f2e824
		if (!empty($replacements[$tpl_name]))
f2e824
		{
f2e824
			$tpl = strtr($tpl, $replacements[$tpl_name]);
f2e824
		}
f2e824
f2e824
		return trim($tpl);
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Second parse list bbcode
f2e824
	*/
f2e824
	function bbcode_list($type)
f2e824
	{
f2e824
		if ($type == '')
f2e824
		{
f2e824
			$tpl = 'ulist_open_default';
f2e824
			$type = 'default';
f2e824
		}
f2e824
		else if ($type == 'i')
f2e824
		{
f2e824
			$tpl = 'olist_open';
f2e824
			$type = 'lower-roman';
f2e824
		}
f2e824
		else if ($type == 'I')
f2e824
		{
f2e824
			$tpl = 'olist_open';
f2e824
			$type = 'upper-roman';
f2e824
		}
f2e824
		else if (preg_match('#^(disc|circle|square)$#i', $type))
f2e824
		{
f2e824
			$tpl = 'ulist_open';
f2e824
			$type = strtolower($type);
f2e824
		}
f2e824
		else if (preg_match('#^[a-z]$#', $type))
f2e824
		{
f2e824
			$tpl = 'olist_open';
f2e824
			$type = 'lower-alpha';
f2e824
		}
f2e824
		else if (preg_match('#[A-Z]#', $type))
f2e824
		{
f2e824
			$tpl = 'olist_open';
f2e824
			$type = 'upper-alpha';
f2e824
		}
f2e824
		else if (is_numeric($type))
f2e824
		{
f2e824
			$tpl = 'olist_open';
f2e824
			$type = 'arabic-numbers';
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$tpl = 'olist_open';
f2e824
			$type = 'arabic-numbers';
f2e824
		}
f2e824
f2e824
		return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Second parse quote tag
f2e824
	*/
f2e824
	function bbcode_second_pass_quote($username, $quote)
f2e824
	{
f2e824
		// when using the /e modifier, preg_replace slashes double-quotes but does not
f2e824
		// seem to slash anything else
f2e824
		$quote = str_replace('\"', '"', $quote);
f2e824
		$username = str_replace('\"', '"', $username);
f2e824
f2e824
		// remove newline at the beginning
f2e824
		if ($quote == "\n")
f2e824
		{
f2e824
			$quote = '';
f2e824
		}
f2e824
f2e824
		$quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
f2e824
f2e824
		return $quote;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Second parse code tag
f2e824
	*/
f2e824
	function bbcode_second_pass_code($type, $code)
f2e824
	{
f2e824
		// when using the /e modifier, preg_replace slashes double-quotes but does not
f2e824
		// seem to slash anything else
f2e824
		$code = str_replace('\"', '"', $code);
f2e824
f2e824
		switch ($type)
f2e824
		{
f2e824
			case 'php':
f2e824
				// Not the english way, but valid because of hardcoded syntax highlighting
f2e824
				if (strpos($code, '
') === 0)
f2e824
				{
f2e824
					$code = substr($code, 41);
f2e824
				}
f2e824
f2e824
			// no break;
f2e824
f2e824
			default:
f2e824
				$code = str_replace("\t", '   ', $code);
f2e824
				$code = str_replace('  ', '  ', $code);
f2e824
				$code = str_replace('  ', '  ', $code);
f2e824
f2e824
				// remove newline at the beginning
f2e824
				if (!empty($code) && $code[0] == "\n")
f2e824
				{
f2e824
					$code = substr($code, 1);
f2e824
				}
f2e824
			break;
f2e824
		}
f2e824
f2e824
		$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
f2e824
f2e824
		return $code;
f2e824
	}
f2e824
}
f2e824
f2e824
?>