phpBB

Code Changes

File: includes/message_parser.php

  Unmodified   Added   Modified   Removed
Line 128Line 128
		// [quote] in second position.
// To parse multiline URL we enable dotall option setting only for URL text
// but not for link itself, thus [url][/url] is not affected.

		// [quote] in second position.
// To parse multiline URL we enable dotall option setting only for URL text
// but not for link itself, thus [url][/url] is not affected.

 
		//
// To perform custom validation in extension, use $this->validate_bbcode_by_extension()
// method which accepts variable number of parameters

		$this->bbcodes = array(
'code' => array('bbcode_id' => 8, 'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")),
'quote' => array('bbcode_id' => 0, 'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#uise' => "\$this->bbcode_quote('\$0')")),

		$this->bbcodes = array(
'code' => array('bbcode_id' => 8, 'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")),
'quote' => array('bbcode_id' => 0, 'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#uise' => "\$this->bbcode_quote('\$0')")),

Line 788Line 791
				else if (preg_match('#^quote(?:="(.*?)")?$#is', $buffer, $m) && substr($out, -1, 1) == '[')
{
$this->parsed_items['quote']++;

				else if (preg_match('#^quote(?:="(.*?)")?$#is', $buffer, $m) && substr($out, -1, 1) == '[')
{
$this->parsed_items['quote']++;


// the buffer holds a valid opening tag
if ($config['max_quote_depth'] && sizeof($close_tags) >= $config['max_quote_depth'])
{
if ($config['max_quote_depth'] == 1)
{
// Depth 1 - no nesting is allowed
$error_ary['quote_depth'] = $user->lang('QUOTE_NO_NESTING');
}
else
{
// There are too many nested quotes
$error_ary['quote_depth'] = $user->lang('QUOTE_DEPTH_EXCEEDED', (int) $config['max_quote_depth']);
}

$out .= $buffer . $tok;
$tok = '[]';
$buffer = '';

continue;
}


 
					array_push($close_tags, '/quote:' . $this->bbcode_uid);

if (isset($m[1]) && $m[1])

					array_push($close_tags, '/quote:' . $this->bbcode_uid);

if (isset($m[1]) && $m[1])

Line 1190Line 1171
		* @var bool		return					Do we return after the event is triggered if $warn_msg is not empty
* @var array warn_msg Array of the warning messages
* @since 3.1.2-RC1

		* @var bool		return					Do we return after the event is triggered if $warn_msg is not empty
* @var array warn_msg Array of the warning messages
* @since 3.1.2-RC1

		* @change 3.1.3-RC1 Added vars $bbcode_bitfield and $bbcode_uid

		* @changed 3.1.3-RC1 Added vars $bbcode_bitfield and $bbcode_uid

		*/
$message = $this->message;
$warn_msg = $this->warn_msg;

		*/
$message = $this->message;
$warn_msg = $this->warn_msg;

Line 1272Line 1253
			$character_list = implode('<br />', $matches[0]);
$this->warn_msg[] = $user->lang('UNSUPPORTED_CHARACTERS_MESSAGE', $character_list);
return $update_this_message ? $this->warn_msg : $return_message;

			$character_list = implode('<br />', $matches[0]);
$this->warn_msg[] = $user->lang('UNSUPPORTED_CHARACTERS_MESSAGE', $character_list);
return $update_this_message ? $this->warn_msg : $return_message;

 
		}

// Remove quotes that are nested too deep
if ($config['max_quote_depth'] > 0)
{
$this->remove_nested_quotes($config['max_quote_depth']);

		}

// Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length.

		}

// Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length.

Line 1313Line 1300
			$tmp_message = $this->message;
$return_message = &$this->message;
}

			$tmp_message = $this->message;
$return_message = &$this->message;
}

 

$text = $this->message;
$uid = $this->bbcode_uid;

/**
* Event to modify the text before it is parsed
*
* @event core.modify_format_display_text_before
* @var string text The message text to parse
* @var string uid The bbcode uid
* @var bool allow_bbcode Do we allow bbcodes
* @var bool allow_magic_url Do we allow magic urls
* @var bool allow_smilies Do we allow smilies
* @var bool update_this_message Do we update the internal message
* with the parsed result
* @since 3.1.6-RC1
*/
$vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message');
extract($phpbb_dispatcher->trigger_event('core.modify_format_display_text_before', compact($vars)));

$this->message = $text;
$this->bbcode_uid = $uid;
unset($text, $uid);


if ($this->message_status == 'plain')
{


if ($this->message_status == 'plain')
{

Line 1812Line 1822
		$this->message = $poll['poll_title'];
$this->bbcode_bitfield = $bbcode_bitfield;


		$this->message = $poll['poll_title'];
$this->bbcode_bitfield = $bbcode_bitfield;


		$poll['poll_options'] = explode("\n", trim($poll['poll_option_text']));

		$poll['poll_options'] = preg_split('/\s*?\n\s*/', trim($poll['poll_option_text']));

		$poll['poll_options_size'] = sizeof($poll['poll_options']);

if (!$poll['poll_title'] && $poll['poll_options_size'])

		$poll['poll_options_size'] = sizeof($poll['poll_options']);

if (!$poll['poll_title'] && $poll['poll_options_size'])

Line 1850Line 1860
		}

$poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']);

		}

$poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']);

 
	}

/**
* Remove nested quotes at given depth in current parsed message
*
* @param integer $max_depth Depth limit
* @return null
*/
public function remove_nested_quotes($max_depth)
{
// Capture all [quote] and [/quote] tags
preg_match_all('(\\[/?quote(?:=&quot;(.*?)&quot;)?:' . $this->bbcode_uid . '\\])', $this->message, $matches, PREG_OFFSET_CAPTURE);

// Iterate over the quote tags to mark the ranges that must be removed
$depth = 0;
$ranges = array();
$start_pos = 0;
foreach ($matches[0] as $match)
{
if ($match[0][1] === '/')
{
--$depth;
if ($depth == $max_depth)
{
$end_pos = $match[1] + strlen($match[0]);
$length = $end_pos - $start_pos;
$ranges[] = array($start_pos, $length);
}
}
else
{
++$depth;
if ($depth == $max_depth + 1)
{
$start_pos = $match[1];
}
}
}

foreach (array_reverse($ranges) as $range)
{
list($start_pos, $length) = $range;
$this->message = substr_replace($this->message, '', $start_pos, $length);
}

	}

/**

	}

/**

Line 1874Line 1928
	public function set_mimetype_guesser(\phpbb\mimetype\guesser $mimetype_guesser)
{
$this->mimetype_guesser = $mimetype_guesser;

	public function set_mimetype_guesser(\phpbb\mimetype\guesser $mimetype_guesser)
{
$this->mimetype_guesser = $mimetype_guesser;

 
	}

/**
* Function to perform custom bbcode validation by extensions
* can be used in bbcode_init() to assign regexp replacement
* Example: 'regexp' => array('#\[b\](.*?)\[/b\]#uise' => "\$this->validate_bbcode_by_extension('\$1')")
*
* Accepts variable number of parameters
*
* @return mixed Validation result
*/
public function validate_bbcode_by_extension()
{
global $phpbb_dispatcher;

$return = false;
$params_array = func_get_args();

/**
* Event to validate bbcode with the custom validating methods
* provided by extensions
*
* @event core.validate_bbcode_by_extension
* @var array params_array Array with the function parameters
* @var mixed return Validation result to return
*
* @since 3.1.5-RC1
*/
$vars = array('params_array', 'return');
extract($phpbb_dispatcher->trigger_event('core.validate_bbcode_by_extension', compact($vars)));

return $return;

	}
}


	}
}