phpBB

Code Changes

File: phpbb/textformatter/s9e/parser.php

  Unmodified   Added   Modified   Removed
Line 15Line 15

use s9e\TextFormatter\Parser\AttributeFilters\UrlFilter;
use s9e\TextFormatter\Parser\Logger;


use s9e\TextFormatter\Parser\AttributeFilters\UrlFilter;
use s9e\TextFormatter\Parser\Logger;

 
use s9e\TextFormatter\Parser\Tag;


/**
* s9e\TextFormatter\Parser adapter


/**
* s9e\TextFormatter\Parser adapter

Line 34Line 35
	/**
* Constructor
*

	/**
* Constructor
*

	* @param \phpbb\cache\driver_interface $cache

	* @param \phpbb\cache\driver\driver_interface $cache

	* @param string $key Cache key
* @param factory $factory
* @param \phpbb\event\dispatcher_interface $dispatcher

	* @param string $key Cache key
* @param factory $factory
* @param \phpbb\event\dispatcher_interface $dispatcher

Line 196Line 197
	public function get_errors()
{
$errors = array();

	public function get_errors()
{
$errors = array();

		foreach ($this->parser->getLogger()->getLogs() as $entry)



		$entries = $this->parser->getLogger()->getLogs();

foreach ($entries as $entry)

		{
list(, $msg, $context) = $entry;


		{
list(, $msg, $context) = $entry;


Line 219Line 222
			{
$errors[] = array($msg, $context['max_' . strtolower($m[1])]);
}

			{
$errors[] = array($msg, $context['max_' . strtolower($m[1])]);
}

			else if ($msg === 'Tag is disabled')

			else if ($msg === 'Tag is disabled' && $this->is_a_bbcode($context['tag']))

			{
$name = strtolower($context['tag']->getName());
$errors[] = array('UNAUTHORISED_BBCODE', '[' . $name . ']');

			{
$name = strtolower($context['tag']->getName());
$errors[] = array('UNAUTHORISED_BBCODE', '[' . $name . ']');

Line 235Line 238
		{
$errors = array_map('unserialize', array_unique(array_map('serialize', $errors)));
}

		{
$errors = array_map('unserialize', array_unique(array_map('serialize', $errors)));
}

 

$parser = $this;

/**
* Modify error messages generated by the s9e\TextFormatter's logger
*
* @event core.text_formatter_s9e_get_errors
* @var parser parser This parser service
* @var array entries s9e\TextFormatter's logger entries
* @var array errors Error arrays with language key and optional arguments
* @since 3.2.10-RC1
* @since 3.3.1-RC1
*/
$vars = [
'parser',
'entries',
'errors',
];
extract($this->dispatcher->trigger_event('core.text_formatter_s9e_get_errors', compact($vars)));


return $errors;
}


return $errors;
}

Line 358Line 380
	* @param  string  $url        Original URL
* @param array $url_config Config used by the URL filter
* @param Logger $logger

	* @param  string  $url        Original URL
* @param array $url_config Config used by the URL filter
* @param Logger $logger

	* @param  integer $max_height Maximum height allowed
* @param integer $max_width Maximum width allowed

	*


	* @return string|bool         Original value if valid, FALSE otherwise
*/

	* @return string|bool         Original value if valid, FALSE otherwise
*/

	static public function filter_img_url($url, array $url_config, Logger $logger, $max_height, $max_width)

	static public function filter_img_url($url, array $url_config, Logger $logger)

	{
// Validate the URL
$url = UrlFilter::filter($url, $url_config, $logger);

	{
// Validate the URL
$url = UrlFilter::filter($url, $url_config, $logger);

Line 371Line 392
			return false;
}


			return false;
}


		if ($max_height || $max_width)
{
$imagesize = new \FastImageSize\FastImageSize();
$size_info = $imagesize->getImageSize($url);
if ($size_info === false)
{
$logger->err('UNABLE_GET_IMAGE_SIZE');
return false;

		return $url;








			}


			}


			if ($max_height && $max_height < $size_info['height'])







	/**
* Test whether given tag consumes text that looks like BBCode-styled markup
*
* @param Tag $tag Original tag
* @return bool
*/
protected function is_a_bbcode(Tag $tag)

			{

			{

				$logger->err('MAX_IMG_HEIGHT_EXCEEDED', array('max_height' => $max_height));
return false;
}

if ($max_width && $max_width < $size_info['width'])

		if ($tag->getLen() < 3)





			{

			{

				$logger->err('MAX_IMG_WIDTH_EXCEEDED', array('max_width' => $max_width));

 
				return false;
}

				return false;
}

		}

		$markup = substr($this->parser->getText(), $tag->getPos(), $tag->getLen());





		return $url;

		return (bool) preg_match('(^\\[\\w++.*?\\]$)s', $markup);

	}
}


	}
}