phpBB

Code Changes

File: phpbb/textformatter/s9e/bbcode_merger.php

  Unmodified   Added   Modified   Removed
Line 50Line 50
		$with    = $this->create_bbcode($with);

// Select the appropriate strategy for merging this BBCode

		$with    = $this->create_bbcode($with);

// Select the appropriate strategy for merging this BBCode

		if ($this->is_content_bbcode($without, $with))

		if (!$this->is_optional_bbcode($without, $with) && $this->is_content_bbcode($without, $with))

		{
$merged = $this->merge_content_bbcode($without, $with);
}

		{
$merged = $this->merge_content_bbcode($without, $with);
}

Line 107Line 107
	/**
* Test whether the two definitions form a "content"-style BBCode
*

	/**
* Test whether the two definitions form a "content"-style BBCode
*

	* Such BBCodes include the [URL] BBCode, which uses its text content as

	* Such BBCodes include the [url] BBCode, which uses its text content as

	* attribute if none is provided
*
* @param array $without BBCode definition without an attribute
* @param array $with BBCode definition with an attribute

	* attribute if none is provided
*
* @param array $without BBCode definition without an attribute
* @param array $with BBCode definition with an attribute

	* @return array          Merged definition

	* @return bool

	*/
protected function is_content_bbcode(array $without, array $with)
{

	*/
protected function is_content_bbcode(array $without, array $with)
{

Line 120Line 120
		// as between ">" and "<" in the template
return (preg_match('(\\]\\s*(\\{(?!TEXT)[^}]+\\})\\s*\\[)', $without['usage'], $m)
&& preg_match('(>[^<]*?' . preg_quote($m[1]) . '[^>]*?<)s', $without['template']));

		// as between ">" and "<" in the template
return (preg_match('(\\]\\s*(\\{(?!TEXT)[^}]+\\})\\s*\\[)', $without['usage'], $m)
&& preg_match('(>[^<]*?' . preg_quote($m[1]) . '[^>]*?<)s', $without['template']));

 
	}

/**
* Test whether the two definitions form BBCode with an optional attribute
*
* @param array $without BBCode definition without an attribute
* @param array $with BBCode definition with an attribute
* @return bool
*/
protected function is_optional_bbcode(array $without, array $with)
{
// Remove the default attribute from the definition
$with['usage'] = preg_replace('(=[^\\]]++)', '', $with['usage']);

// Test whether both definitions are the same, regardless of case
return strcasecmp($without['usage'], $with['usage']) === 0;

	}

/**

	}

/**

Line 131Line 147
	*/
protected function merge_content_bbcode(array $without, array $with)
{

	*/
protected function merge_content_bbcode(array $without, array $with)
{

		// Convert [X={X}] into [X={X;useContent}]

		// Convert [x={X}] into [x={X;useContent}]

		$usage = preg_replace('(\\})', ';useContent}', $with['usage'], 1);

// Use the template from the definition that uses an attribute

		$usage = preg_replace('(\\})', ';useContent}', $with['usage'], 1);

// Use the template from the definition that uses an attribute

Line 143Line 159
	/**
* Merge the two BBCode definitions of a BBCode with an optional argument
*

	/**
* Merge the two BBCode definitions of a BBCode with an optional argument
*

	* Such BBCodes include the [QUOTE] BBCode, which takes an optional argument

	* Such BBCodes include the [quote] BBCode, which takes an optional argument

	* but otherwise does not behave differently
*
* @param array $without BBCode definition without an attribute

	* but otherwise does not behave differently
*
* @param array $without BBCode definition without an attribute