phpBB

Code Changes

File: phpbb/textformatter/s9e/factory.php

  Unmodified   Added   Modified   Removed
Line 78Line 78
		'b'     => '[B]{TEXT}[/B]',
'code' => '[CODE lang={IDENTIFIER;optional}]{TEXT}[/CODE]',
'color' => '[COLOR={COLOR}]{TEXT}[/COLOR]',

		'b'     => '[B]{TEXT}[/B]',
'code' => '[CODE lang={IDENTIFIER;optional}]{TEXT}[/CODE]',
'color' => '[COLOR={COLOR}]{TEXT}[/COLOR]',

		'email' => '[EMAIL={EMAIL;useContent} subject={TEXT;optional;postFilter=rawurlencode} body={TEXT;optional;postFilter=rawurlencode}]{TEXT}[/EMAIL]',

		'email' => '[EMAIL={EMAIL;useContent} subject={TEXT1;optional;postFilter=rawurlencode} body={TEXT2;optional;postFilter=rawurlencode}]{TEXT}[/EMAIL]',

		'flash' => '[FLASH={NUMBER1},{NUMBER2} width={NUMBER1;postFilter=#flashwidth} height={NUMBER2;postFilter=#flashheight} url={URL;useContent} /]',
'i' => '[I]{TEXT}[/I]',
'img' => '[IMG src={IMAGEURL;useContent}]',

		'flash' => '[FLASH={NUMBER1},{NUMBER2} width={NUMBER1;postFilter=#flashwidth} height={NUMBER2;postFilter=#flashheight} url={URL;useContent} /]',
'i' => '[I]{TEXT}[/I]',
'img' => '[IMG src={IMAGEURL;useContent}]',

Line 89Line 89
				author={TEXT1;optional}
post_id={UINT;optional}
post_url={URL;optional;postFilter=#false}

				author={TEXT1;optional}
post_id={UINT;optional}
post_url={URL;optional;postFilter=#false}

 
				msg_id={UINT;optional}
msg_url={URL;optional;postFilter=#false}

				profile_url={URL;optional;postFilter=#false}
time={UINT;optional}
url={URL;optional}

				profile_url={URL;optional;postFilter=#false}
time={UINT;optional}
url={URL;optional}

Line 110Line 112
		'i'     => '<span style="font-style: italic"><xsl:apply-templates/></span>',
'u' => '<span style="text-decoration: underline"><xsl:apply-templates/></span>',
'img' => '<img src="{IMAGEURL}" class="postimage" alt="{L_IMAGE}"/>',

		'i'     => '<span style="font-style: italic"><xsl:apply-templates/></span>',
'u' => '<span style="text-decoration: underline"><xsl:apply-templates/></span>',
'img' => '<img src="{IMAGEURL}" class="postimage" alt="{L_IMAGE}"/>',

		'size'  => '<span style="font-size: {FONTSIZE}%; line-height: normal"><xsl:apply-templates/></span>',

		'size'	=> '<span><xsl:attribute name="style"><xsl:text>font-size: </xsl:text><xsl:value-of select="substring(@size, 1, 4)"/><xsl:text>%; line-height: normal</xsl:text></xsl:attribute><xsl:apply-templates/></span>',

		'color' => '<span style="color: {COLOR}"><xsl:apply-templates/></span>',
'email' => '<a>
<xsl:attribute name="href">

		'color' => '<span style="color: {COLOR}"><xsl:apply-templates/></span>',
'email' => '<a>
<xsl:attribute name="href">

Line 130Line 132
	* @var \phpbb\event\dispatcher_interface
*/
protected $dispatcher;

	* @var \phpbb\event\dispatcher_interface
*/
protected $dispatcher;

 

/**
* @var \phpbb\log\log_interface
*/
protected $log;


/**
* Constructor


/**
* Constructor

Line 139Line 146
	* @param \phpbb\event\dispatcher_interface $dispatcher
* @param \phpbb\config\config $config
* @param \phpbb\textformatter\s9e\link_helper $link_helper

	* @param \phpbb\event\dispatcher_interface $dispatcher
* @param \phpbb\config\config $config
* @param \phpbb\textformatter\s9e\link_helper $link_helper

 
	* @param \phpbb\log\log_interface $log

	* @param string $cache_dir          Path to the cache dir
* @param string $cache_key_parser Cache key used for the parser
* @param string $cache_key_renderer Cache key used for the renderer
*/

	* @param string $cache_dir          Path to the cache dir
* @param string $cache_key_parser Cache key used for the parser
* @param string $cache_key_renderer Cache key used for the renderer
*/

	public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\config $config, \phpbb\textformatter\s9e\link_helper $link_helper, $cache_dir, $cache_key_parser, $cache_key_renderer)

	public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\config\config $config, \phpbb\textformatter\s9e\link_helper $link_helper, \phpbb\log\log_interface $log, $cache_dir, $cache_key_parser, $cache_key_renderer)

	{
$this->link_helper = $link_helper;
$this->cache = $cache;

	{
$this->link_helper = $link_helper;
$this->cache = $cache;

Line 153Line 161
		$this->config = $config;
$this->data_access = $data_access;
$this->dispatcher = $dispatcher;

		$this->config = $config;
$this->data_access = $data_access;
$this->dispatcher = $dispatcher;

 
		$this->log = $log;

	}

/**

	}

/**

Line 266Line 275
			->addParameterByName('logger')
->addParameterByName('max_img_height')
->addParameterByName('max_img_width')

			->addParameterByName('logger')
->addParameterByName('max_img_height')
->addParameterByName('max_img_width')

			->markAsSafeAsURL();


			->markAsSafeAsURL()
->setJS('UrlFilter.filter');


// Add default BBCodes
foreach ($this->get_default_bbcodes($configurator) as $bbcode)
{


// Add default BBCodes
foreach ($this->get_default_bbcodes($configurator) as $bbcode)
{

			$configurator->BBCodes->addCustom($bbcode['usage'], $bbcode['template']);






			$this->add_bbcode($configurator, $bbcode['usage'], $bbcode['template']);
}
if (isset($configurator->tags['QUOTE']))
{
// Remove the nesting limit and let other services remove quotes at parsing time
$configurator->tags['QUOTE']->nestingLimit = PHP_INT_MAX;

		}

// Modify the template to disable images/flash depending on user's settings

		}

// Modify the template to disable images/flash depending on user's settings

Line 293Line 308
				},
$row['bbcode_tpl']
);

				},
$row['bbcode_tpl']
);


try
{
$configurator->BBCodes->addCustom($row['bbcode_match'], new UnsafeTemplate($tpl));
}
catch (\Exception $e)
{
/**
* @todo log an error?
*/
}

			$this->add_bbcode($configurator, $row['bbcode_match'], $tpl);











		}

// Load smilies

		}

// Load smilies

Line 311Line 316
		{
$configurator->Emoticons->set(
$row['code'],

		{
$configurator->Emoticons->set(
$row['code'],

				'<img class="smilies" src="{$T_SMILIES_PATH}/' . htmlspecialchars($row['smiley_url']) . '" width="' . $row['smiley_width'] . '" height="' . $row['smiley_height'] . '" alt="{.}" title="' . htmlspecialchars($row['emotion']) . '"/>'

				'<img class="smilies" src="{$T_SMILIES_PATH}/' . $this->escape_html_attribute($row['smiley_url']) . '" width="' . $row['smiley_width'] . '" height="' . $row['smiley_height'] . '" alt="{.}" title="' . $this->escape_html_attribute($row['emotion']) . '"/>'

			);
}


			);
}


Line 323Line 328
			// Only parse emoticons at the beginning of the text or if they're preceded by any
// one of: a new line, a space, a dot, or a right square bracket
$configurator->Emoticons->notAfter = '[^\\n .\\]]';

			// Only parse emoticons at the beginning of the text or if they're preceded by any
// one of: a new line, a space, a dot, or a right square bracket
$configurator->Emoticons->notAfter = '[^\\n .\\]]';

 

// Ignore emoticons that are immediately followed by a "word" character
$configurator->Emoticons->notBefore = '\\w';

		}

// Load the censored words

		}

// Load the censored words

Line 333Line 341
			$configurator->plugins->load('Censor', array('tagName' => 'censor:tag'));
foreach ($censor as $row)
{

			$configurator->plugins->load('Censor', array('tagName' => 'censor:tag'));
foreach ($censor as $row)
{

				// NOTE: words are stored as HTML, we need to decode them to plain text
$configurator->Censor->add(htmlspecialchars_decode($row['word']), htmlspecialchars_decode($row['replacement']));

				$configurator->Censor->add($row['word'], $row['replacement']);


			}
}


			}
}


Line 348Line 355
		$configurator->registeredVars['max_img_width'] = 0;

// Load the Emoji plugin and modify its tag's template to obey viewsmilies

		$configurator->registeredVars['max_img_width'] = 0;

// Load the Emoji plugin and modify its tag's template to obey viewsmilies

		$configurator->Emoji->omitImageSize();
$configurator->Emoji->useSVG();

 
		$tag = $configurator->Emoji->getTag();

		$tag = $configurator->Emoji->getTag();

 
		$tag->template = '<xsl:choose>
<xsl:when test="@tseq">
<img alt="{.}" class="emoji" draggable="false" src="//twemoji.maxcdn.com/2/svg/{@tseq}.svg"/>
</xsl:when>
<xsl:otherwise>
<img alt="{.}" class="emoji" draggable="false" src="https://cdn.jsdelivr.net/gh/s9e/emoji-assets-twemoji@11.2/dist/svgz/{@seq}.svgz"/>
</xsl:otherwise>
</xsl:choose>';

		$tag->template = '<xsl:choose><xsl:when test="$S_VIEWSMILIES">' . str_replace('class="emoji"', 'class="emoji smilies"', $tag->template) . '</xsl:when><xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose>';

/**

		$tag->template = '<xsl:choose><xsl:when test="$S_VIEWSMILIES">' . str_replace('class="emoji"', 'class="emoji smilies"', $tag->template) . '</xsl:when><xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose>';

/**

Line 383Line 396
			unset($configurator->tags['censor:tag']);
}


			unset($configurator->tags['censor:tag']);
}


		$objects  = $configurator->finalize();












		$objects = $configurator->finalize();

/**
* Access the objects returned by finalize() before they are saved to cache
*
* @event core.text_formatter_s9e_configure_finalize
* @var array objects Array containing a "parser" object, a "renderer" object and optionally a "js" string
* @since 3.2.2-RC1
*/
$vars = array('objects');
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_finalize', compact($vars)));


		$parser   = $objects['parser'];
$renderer = $objects['renderer'];


		$parser   = $objects['parser'];
$renderer = $objects['renderer'];


Line 399Line 423
		$this->cache->put($this->cache_key_renderer, $renderer_data);

return array('parser' => $parser, 'renderer' => $renderer);

		$this->cache->put($this->cache_key_renderer, $renderer_data);

return array('parser' => $parser, 'renderer' => $renderer);

 
	}

/**
* Add a BBCode to given configurator
*
* @param Configurator $configurator
* @param string $usage
* @param string $template
* @return void
*/
protected function add_bbcode(Configurator $configurator, $usage, $template)
{
try
{
$configurator->BBCodes->addCustom($usage, new UnsafeTemplate($template));
}
catch (\Exception $e)
{
$this->log->add('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]);
}

	}

/**

	}

/**

Line 440Line 484
			->resetParameters()
->addParameterByName('tag')
->addParameterByName('parser');

			->resetParameters()
->addParameterByName('tag')
->addParameterByName('parser');

 
	}

/**
* Escape a literal to be used in an HTML attribute in an XSL template
*
* Escapes "HTML special chars" for obvious reasons and curly braces to avoid them
* being interpreted as an attribute value template
*
* @param string $value Original string
* @return string Escaped string
*/
protected function escape_html_attribute($value)
{
return htmlspecialchars(strtr($value, ['{' => '{{', '}' => '}}']), ENT_COMPAT | ENT_XML1, 'UTF-8');

	}

/**

	}

/**

Line 505Line 563
	protected function extract_templates($template)
{
// Capture the template fragments

	protected function extract_templates($template)
{
// Capture the template fragments

		preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END .*? -->#s', $template, $matches, PREG_SET_ORDER);



		// Allow either phpBB template or the Twig syntax
preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END .*? -->#s', $template, $matches, PREG_SET_ORDER) ?:
preg_match_all('#{% for (.*?) in .*? %}(.*?){% endfor %}#s', $template, $matches, PREG_SET_ORDER);


$fragments = array();
foreach ($matches as $match)


$fragments = array();
foreach ($matches as $match)