From 147a713cc066d493b50b82a9d475aa9af940e2b4 Mon Sep 17 00:00:00 2001 From: s9e Date: Sat, 22 Nov 2014 20:00:58 +0100 Subject: [ticket/11768] This commit integrates s9e\TextFormatter This commit integrates s9e\TextFormatter as outlined in http://area51.phpbb.com/phpBB/viewtopic.php?f=108&t=44467 PHPBB3-11768 --- phpBB/phpbb/textformatter/cache.php | 37 +++ phpBB/phpbb/textformatter/data_access.php | 233 ++++++++++++++ phpBB/phpbb/textformatter/parser.php | 121 +++++++ phpBB/phpbb/textformatter/renderer.php | 136 ++++++++ phpBB/phpbb/textformatter/s9e/factory.php | 493 +++++++++++++++++++++++++++++ phpBB/phpbb/textformatter/s9e/parser.php | 335 ++++++++++++++++++++ phpBB/phpbb/textformatter/s9e/renderer.php | 228 +++++++++++++ phpBB/phpbb/textformatter/s9e/utils.php | 67 ++++ phpBB/phpbb/textformatter/utils.php | 62 ++++ 9 files changed, 1712 insertions(+) create mode 100644 phpBB/phpbb/textformatter/cache.php create mode 100644 phpBB/phpbb/textformatter/data_access.php create mode 100644 phpBB/phpbb/textformatter/parser.php create mode 100644 phpBB/phpbb/textformatter/renderer.php create mode 100644 phpBB/phpbb/textformatter/s9e/factory.php create mode 100644 phpBB/phpbb/textformatter/s9e/parser.php create mode 100644 phpBB/phpbb/textformatter/s9e/renderer.php create mode 100644 phpBB/phpbb/textformatter/s9e/utils.php create mode 100644 phpBB/phpbb/textformatter/utils.php (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/cache.php b/phpBB/phpbb/textformatter/cache.php new file mode 100644 index 0000000000..c92683217e --- /dev/null +++ b/phpBB/phpbb/textformatter/cache.php @@ -0,0 +1,37 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* text_formatter.cache service +* +* Currently only used to signal that something that could effect the rendering has changed. +* BBCodes, smilies, censored words, templates, etc... +* +* @todo functionality should be moved to data_access +* +* @package phpBB3 +*/ +interface cache +{ + /** + * Invalidate and/or regenerate this text formatter's cache(s) + */ + public function invalidate(); + + /** + * Tidy/prune this text formatter's cache(s) + */ + public function tidy(); +} diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php new file mode 100644 index 0000000000..ec6bf9f88e --- /dev/null +++ b/phpBB/phpbb/textformatter/data_access.php @@ -0,0 +1,233 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* text_formatter.data_access service +* +* Data access layer that fetchs BBCodes, smilies and censored words from the database. +* To be extended to include insert/update/delete operations. +* +* Also used to get templates. +* +* @package phpBB3 +*/ +class data_access +{ + /** + * @var string Name of the BBCodes table + */ + protected $bbcodes_table; + + /** + * @var phpbb_db_driver + */ + protected $db; + + /** + * @var string Name of the smilies table + */ + protected $smilies_table; + + /** + * @var string Name of the styles table + */ + protected $styles_table; + + /** + * @var string Path to the styles dir + */ + protected $styles_path; + + /** + * @var string Name of the words table + */ + protected $words_table; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param string $bbcodes_table Name of the BBCodes table + * @param string $smilies_table Name of the smilies table + * @param string $styles_table Name of the styles table + * @param string $words_table Name of the words table + * @param string $styles_path Path to the styles dir + * @return null + */ + public function __construct(\phpbb\db\driver\driver_interface $db, $bbcodes_table, $smilies_table, $styles_table, $words_table, $styles_path) + { + $this->db = $db; + + $this->bbcodes_table = $bbcodes_table; + $this->smilies_table = $smilies_table; + $this->styles_table = $styles_table; + $this->words_table = $words_table; + + $this->styles_path = $styles_path; + } + + /** + * Return the list of custom BBCodes + * + * @return array + */ + public function get_bbcodes() + { + $sql = 'SELECT bbcode_match, bbcode_tpl FROM ' . $this->bbcodes_table; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $rows; + } + + /** + * Return the list of smilies + * + * @return array + */ + public function get_smilies() + { + // NOTE: smilies that are displayed on the posting page are processed first because they're + // typically the most used smilies and it ends up producing a slightly more efficient + // renderer + $sql = 'SELECT code, emotion, smiley_url, smiley_width, smiley_height + FROM ' . $this->smilies_table . ' + ORDER BY display_on_posting DESC'; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $rows; + } + + /** + * Return the list of installed styles + * + * @return array + */ + protected function get_styles() + { + $sql = 'SELECT style_id, style_path, bbcode_bitfield FROM ' . $this->styles_table; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $rows; + } + + /** + * Return the bbcode.html template for every installed style + * + * @return array 2D array. style_id as keys, each element is an array with a "template" element that contains the style's bbcode.html and a "bbcodes" element that contains the name of each BBCode that is to be stylised + */ + public function get_styles_templates() + { + $templates = array(); + + $bbcode_ids = array( + 'quote' => 0, + 'b' => 1, + 'i' => 2, + 'url' => 3, + 'img' => 4, + 'size' => 5, + 'color' => 6, + 'u' => 7, + 'code' => 8, + 'list' => 9, + '*' => 9, + 'email' => 10, + 'flash' => 11, + 'attachment' => 12, + ); + + $styles = array(); + foreach ($this->get_styles() as $row) + { + $styles[$row['style_id']] = $row; + } + + foreach ($styles as $style_id => $style) + { + $bbcodes = array(); + + // Collect the name of the BBCodes whose bit is set in the style's bbcode_bitfield + $template_bitfield = new \bitfield($style['bbcode_bitfield']); + foreach ($bbcode_ids as $bbcode_name => $bit) + { + if ($template_bitfield->get($bit)) + { + $bbcodes[] = $bbcode_name; + } + } + + $filename = $this->resolve_style_filename($styles, $style); + if ($filename === false) + { + // Ignore this style, it will use the default templates + continue; + } + + $templates[$style_id] = array( + 'bbcodes' => $bbcodes, + 'template' => file_get_contents($filename), + ); + } + + return $templates; + } + + /** + * Resolve inheritance for given style and return the path to their bbcode.html file + * + * @param array $styles Associative array of [style_id => style] containing all styles + * @param array $style Style for which we resolve + * @return string|bool Path to this style's bbcode.html, or FALSE + */ + protected function resolve_style_filename(array $styles, array $style) + { + // Look for a bbcode.html in this style's dir + $filename = $this->styles_path . $style['style_path'] . '/template/bbcode.html'; + if (file_exists($filename)) + { + return $filename; + } + + // Resolve using this style's parent + $parent_id = $style['style_parent_id']; + if ($parent_id && !empty($styles[$parent_id])) + { + return $this->resolve_style_filename($styles, $styles[$parent_id]); + } + + return false; + } + + /** + * Return the list of censored words + * + * @return array + */ + public function get_words() + { + $sql = 'SELECT word, replacement FROM ' . $this->words_table; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $rows; + } +} diff --git a/phpBB/phpbb/textformatter/parser.php b/phpBB/phpbb/textformatter/parser.php new file mode 100644 index 0000000000..c595a459bd --- /dev/null +++ b/phpBB/phpbb/textformatter/parser.php @@ -0,0 +1,121 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* text_formatter.parser service +* @package phpBB3 +*/ +abstract class parser +{ + /** + * Parse given text + * + * @param string $text + * @return string + */ + abstract public function parse($text); + + /** + * Disable a specific BBCode + * + * @param string $name BBCode name + * @return null + */ + abstract public function disable_bbcode($name); + + /** + * Disable BBCodes in general + */ + abstract public function disable_bbcodes(); + + /** + * Disable the censor + */ + abstract public function disable_censor(); + + /** + * Disable magic URLs + */ + abstract public function disable_magic_url(); + + /** + * Disable smilies + */ + abstract public function disable_smilies(); + + /** + * Enable a specific BBCode + * + * @param string $name BBCode name + * @return null + */ + abstract public function enable_bbcode($name); + + /** + * Enable BBCodes in general + */ + abstract public function enable_bbcodes(); + + /** + * Enable the censor + */ + abstract public function enable_censor(); + + /** + * Enable magic URLs + */ + abstract public function enable_magic_url(); + + /** + * Enable smilies + */ + abstract public function enable_smilies(); + + /** + * Get the list of errors that were generated during last parsing + * + * @return array + */ + abstract public function get_errors(); + + /** + * Set a variable to be used by the parser + * + * - max_font_size + * - max_img_height + * - max_img_width + * - max_smilies + * - max_urls + * + * @param string $name + * @param mixed $value + * @return null + */ + abstract public function set_var($name, $value); + + /** + * Set multiple variables to be used by the parser + * + * @param array Associative array of [name => value] + * @return null + */ + public function set_vars(array $vars) + { + foreach ($vars as $name => $value) + { + $this->set_var($name, $value); + } + } +} diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php new file mode 100644 index 0000000000..fb731a5294 --- /dev/null +++ b/phpBB/phpbb/textformatter/renderer.php @@ -0,0 +1,136 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* text_formatter.renderer service +* @package phpBB3 +*/ +abstract class renderer +{ + /** + * Render given text + * + * @param string $text Text, as parsed by the text_formatter.parser service + * @return string + */ + abstract public function render($text); + + /** + * Automatically set the smilies path based on config + * + * Called by the service container + * + * @param phpbb\config\config $config + * @param phpbb\path_helper $path_helper + * @return null + */ + public function configure_smilies_path(\phpbb\config\config $config, \phpbb\path_helper $path_helper) + { + /** + * @see smiley_text() + */ + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $path_helper->get_web_root_path(); + + $this->set_smilies_path($root_path . $config['smilies_path']); + } + + /** + * Configure this renderer as per the user's settings + * + * Should set the locale as well as the viewcensor/viewflash/viewimg/viewsmilies options. + * Called by the service container + * + * @param phpbb\user $user + * @param phpbb\config\config $config + * @param phpbb\auth\auth $auth + * @return null + */ + public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) + { + $censor = $user->optionget('viewcensors') || !$config['allow_nocensors'] || !$auth->acl_get('u_chgcensors'); + + $this->set_viewcensors($censor); + $this->set_viewflash($user->optionget('viewflash')); + $this->set_viewimg($user->optionget('viewimg')); + $this->set_viewsmilies($user->optionget('viewsmilies')); + } + + /** + * Set the smilies' path + * + * @return null + */ + abstract public function set_smilies_path($path); + + /** + * Return the value of the "viewcensors" option + * + * @return bool Option's value + */ + abstract public function get_viewcensors(); + + /** + * Return the value of the "viewflash" option + * + * @return bool Option's value + */ + abstract public function get_viewflash(); + + /** + * Return the value of the "viewimg" option + * + * @return bool Option's value + */ + abstract public function get_viewimg(); + + /** + * Return the value of the "viewsmilies" option + * + * @return bool Option's value + */ + abstract public function get_viewsmilies(); + + /** + * Set the "viewcensors" option + * + * @param bool $value Option's value + * @return null + */ + abstract public function set_viewcensors($value); + + /** + * Set the "viewflash" option + * + * @param bool $value Option's value + * @return null + */ + abstract public function set_viewflash($value); + + /** + * Set the "viewimg" option + * + * @param bool $value Option's value + * @return null + */ + abstract public function set_viewimg($value); + + /** + * Set the "viewsmilies" option + * + * @param bool $value Option's value + * @return null + */ + abstract public function set_viewsmilies($value); +} diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php new file mode 100644 index 0000000000..8d61f2caac --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -0,0 +1,493 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +use s9e\TextFormatter\Configurator; +use s9e\TextFormatter\Configurator\Items\AttributeFilters\Regexp as RegexpFilter; + +/** +* Creates s9e\TextFormatter objects +* @package phpBB3 +*/ +class factory implements \phpbb\textformatter\cache +{ + /** + * @var phpbb_cache_driver_interface $cache + */ + protected $cache; + + /** + * @var string Path to the cache dir + */ + protected $cache_dir; + + /** + * @var string Cache key used for the parser + */ + protected $cache_key_parser; + + /** + * @var string Cache key used for the renderer + */ + protected $cache_key_renderer; + + /** + * @var array Custom tokens used in bbcode.html and their corresponding token from the definition + */ + protected $custom_tokens = array( + 'email' => array('{DESCRIPTION}' => '{TEXT}'), + 'flash' => array('{WIDTH}' => '{NUMBER1}', '{HEIGHT}' => '{NUMBER2}'), + 'img' => array('{URL}' => '{IMAGEURL}'), + 'list' => array('{LIST_TYPE}' => '{HASHMAP}'), + 'quote' => array('{USERNAME}' => '{TEXT1}'), + 'size' => array('{SIZE}' => '{FONTSIZE}'), + 'url' => array('{DESCRIPTION}' => '{TEXT}'), + ); + + /** + * @var \phpbb\textformatter\data_access + */ + protected $dal; + + /** + * @var array Default BBCode definitions + */ + protected $default_definitions = array( + 'attachment' => '[ATTACHMENT index={NUMBER} filename={TEXT;useContent}]', + 'b' => '[B]{TEXT}[/B]', + 'code' => '[CODE]{TEXT}[/CODE]', + 'color' => '[COLOR={COLOR}]{TEXT}[/COLOR]', + 'email' => '[EMAIL={EMAIL;useContent}]{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}]', + 'list' => '[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext}]{TEXT}[/LIST]', + 'li' => '[* $tagName=LI]{TEXT}[/*]', + 'quote' => '[QUOTE author={TEXT1;optional}]{TEXT2}[/QUOTE]', + 'size' => '[SIZE={FONTSIZE}]{TEXT}[/SIZE]', + 'u' => '[U]{TEXT}[/U]', + 'url' => '[URL={URL;useContent}]{TEXT}[/URL]', + ); + + /** + * @var array Default templates, taken from bbcode::bbcode_tpl() + */ + protected $default_templates = array( + 'b' => '', + 'i' => '', + 'u' => '', + 'img' => '{L_IMAGE}', + 'size' => '', + 'color' => '', + 'email' => '', + ); + + /** + * Constructor + * + * @param phpbb\textformatter\data_access $dal + * @param phpbb\cache\driver\driver_interface $cache + * @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 + * @return null + */ + public function __construct(\phpbb\textformatter\data_access $dal, \phpbb\cache\driver\driver_interface $cache, $cache_dir, $cache_key_parser, $cache_key_renderer) + { + $this->cache = $cache; + $this->cache_dir = $cache_dir; + $this->cache_key_parser = $cache_key_parser; + $this->cache_key_renderer = $cache_key_renderer; + + $this->dal = $dal; + } + + /** + * {@inheritdoc} + */ + public function invalidate() + { + $this->regenerate(); + } + + /** + * {@inheritdoc} + * + * Will remove old renderers from the cache dir but won't touch the current renderer + */ + public function tidy() + { + // Get the name of current renderer + $renderer_data = $this->cache->get($this->cache_key_renderer); + $renderer_file = ($renderer_data) ? $renderer_data['class'] . '.php' : null; + + foreach (glob($this->cache_dir . 's9e_*') as $filename) + { + // Only remove the file if it's not the current renderer + if (!$renderer_file || substr($filename, -strlen($renderer_file)) !== $renderer_file) + { + unlink($filename); + } + } + } + + /** + * Generate and return a new configured instance of s9e\TextFormatter\Configurator + * + * @return s9e\TextFormatter\Configurator + */ + public function get_configurator() + { + // Create a new Configurator + $configurator = new Configurator; + + // Convert newlines to br elements by default + $configurator->rootRules->enableAutoLineBreaks(); + + // Set the rendering engine and configure it to save to the cache dir + $configurator->rendering->engine = 'PHP'; + $configurator->rendering->engine->cacheDir = $this->cache_dir; + $configurator->rendering->engine->defaultClassPrefix = 's9e_renderer_'; + $configurator->rendering->engine->enableQuickRenderer = true; + + // Create custom filters for BBCode tokens that are supported in phpBB but not in + // s9e\TextFormatter + $filter = new RegexpFilter('#^' . get_preg_expression('relative_url') . '$#D'); + $configurator->attributeFilters->add('#local_url', $filter); + $configurator->attributeFilters->add('#relative_url', $filter); + + $regexp = (phpbb_pcre_utf8_support()) + ? '!^([\p{L}\p{N}\-+,_. ]+)$!uD' + : '!^([a-zA-Z0-9\-+,_. ]+)$!uD'; + $configurator->attributeFilters->add('#inttext', new RegexpFilter($regexp)); + + // Create custom filters for Flash restrictions, which use the same values as the image + // restrictions but have their own error message + $configurator->attributeFilters + ->add('#flashheight', __NAMESPACE__ . '\\parser::filter_flash_height') + ->addParameterByName('max_img_height') + ->addParameterByName('logger'); + + $configurator->attributeFilters + ->add('#flashwidth', __NAMESPACE__ . '\\parser::filter_flash_width') + ->addParameterByName('max_img_width') + ->addParameterByName('logger'); + + // Create a custom filter for phpBB's per-mode font size limits + $configurator->attributeFilters + ->add('#fontsize', __NAMESPACE__ . '\\parser::filter_font_size') + ->addParameterByName('max_font_size') + ->addParameterByName('logger') + ->markAsSafeInCSS(); + + // Create a custom filter for image URLs + $configurator->attributeFilters + ->add('#imageurl', __NAMESPACE__ . '\\parser::filter_img_url') + ->addParameterByName('urlConfig') + ->addParameterByName('logger') + ->addParameterByName('max_img_height') + ->addParameterByName('max_img_width') + ->markAsSafeAsURL(); + + // Add default BBCodes + foreach ($this->get_default_bbcodes($configurator) as $bbcode) + { + $configurator->BBCodes->addCustom($bbcode['usage'], $bbcode['template']); + } + + // Modify the template to disable images/flash depending on user's settings + foreach (array('FLASH', 'IMG') as $name) + { + $tag = $configurator->tags[$name]; + $tag->template = '' . $tag->template . ''; + } + + // Load custom BBCodes + foreach ($this->dal->get_bbcodes() as $row) + { + // Insert the board's URL before {LOCAL_URL} tokens + $tpl = preg_replace_callback( + '#\\{LOCAL_URL\\d*\\}#', + function ($m) + { + return generate_board_url() . '/' . $m[0]; + }, + $row['bbcode_tpl'] + ); + + try + { + $configurator->BBCodes->addCustom($row['bbcode_match'], $tpl); + } + catch (\Exception $e) + { + /** + * @todo log an error? + */ + } + } + + // Load smilies + foreach ($this->dal->get_smilies() as $row) + { + $configurator->Emoticons->add( + $row['code'], + '{.}' + ); + } + + if (isset($configurator->Emoticons)) + { + // Force emoticons to be rendered as text if $S_VIEWSMILIES is not set + $configurator->Emoticons->notIfCondition = 'not($S_VIEWSMILIES)'; + + // 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 .\\]]'; + } + + // Load the censored words + foreach ($this->dal->get_words() as $row) + { + $configurator->Censor->add($row['word'], $row['replacement']); + } + + if (isset($configurator->Censor)) + { + // Replace the template with a template that applies only when $S_VIEWCENSORS is set + $tag = $configurator->Censor->getTag(); + $tag->template = + ' + + + + + + + **** + '; + } + + // Load the magic links plugins. We do that after BBCodes so that they use the same tags + $configurator->plugins->load('Autoemail'); + $configurator->plugins->load('Autolink'); + + // Register some vars with a default value. Those should be set at runtime by whatever calls + // the parser + $configurator->registeredVars['max_font_size'] = 0; + $configurator->registeredVars['max_img_height'] = 0; + $configurator->registeredVars['max_img_width'] = 0; + + return $configurator; + } + + /** + * Regenerate and cache a new parser and renderer + * + * @return array Array with two elements: an instance of the parser, an instance of the renderer + */ + public function regenerate() + { + $configurator = $this->get_configurator(); + + // Create $parser and $renderer + extract($configurator->finalize()); + + // Cache the parser as-is + $this->cache->put($this->cache_key_parser, $parser); + + // We need to cache the name of the renderer's generated class so that we can load the class + // before the renderer is unserialized. That's why we save them together, with the renderer + // in serialized form + $renderer_data = array( + 'class' => get_class($renderer), + 'renderer' => serialize($renderer) + ); + $this->cache->put($this->cache_key_renderer, $renderer_data); + + return array($parser, $renderer); + } + + /** + * Return the default BBCodes configuration + * + * @return array 2D array. Each element has a 'usage' key, a 'template' key, and an optional 'options' key + */ + protected function get_default_bbcodes($configurator) + { + // For each BBCode, build an associative array matching style_ids to their template + $templates = array(); + foreach ($this->dal->get_styles_templates() as $style_id => $data) + { + foreach ($this->extract_templates($data['template']) as $bbcode_name => $template) + { + $templates[$bbcode_name][$style_id] = $template; + } + + // Add default templates wherever missing, or for BBCodes that were not specified in + // this template's bitfield. For instance, prosilver has a custom template for b but its + // bitfield does not enable it so the default template is used instead + foreach ($this->default_templates as $bbcode_name => $template) + { + if (!isset($templates[$bbcode_name][$style_id]) || !in_array($bbcode_name, $data['bbcodes'], true)) + { + $templates[$bbcode_name][$style_id] = $template; + } + } + } + + // Replace custom tokens and normalize templates + foreach ($templates as $bbcode_name => &$style_templates) + { + foreach ($style_templates as &$template) + { + if (isset($this->custom_tokens[$bbcode_name])) + { + $template = strtr($template, $this->custom_tokens[$bbcode_name]); + } + + $template = $configurator->templateNormalizer->normalizeTemplate($template); + } + unset($template); + } + unset($style_templates); + + $bbcodes = array(); + foreach ($this->default_definitions as $bbcode_name => $usage) + { + $bbcodes[$bbcode_name] = array( + 'usage' => $usage, + 'template' => $this->merge_templates($templates[$bbcode_name]), + ); + } + + return $bbcodes; + } + + /** + * Extract and recompose individual BBCode templates from a style's template file + * + * @param string $template Style template (bbcode.html) + * @return array Associative array matching BBCode names to their template + */ + protected function extract_templates($template) + { + // Capture the template fragments + preg_match_all('#(.*?)#s', $template, $matches, PREG_SET_ORDER); + + $fragments = array(); + foreach ($matches as $match) + { + // Normalize the whitespace + $fragment = preg_replace('#>\\n\\t*<#', '><', trim($match[2])); + + $fragments[$match[1]] = $fragment; + } + + // Automatically recompose templates split between *_open and *_close + foreach ($fragments as $fragment_name => $fragment) + { + if (preg_match('#^(\\w+)_close$#', $fragment_name, $match)) + { + $bbcode_name = $match[1]; + + if (isset($fragments[$bbcode_name . '_open'])) + { + $templates[$bbcode_name] = $fragments[$bbcode_name . '_open'] . '' . $fragment; + } + } + } + + // Manually recompose and overwrite irregular templates + $templates['list'] = + ' + + ' . $fragments['ulist_open_default'] . '' . $fragments['ulist_close'] . ' + + + ' . $fragments['olist_open'] . '' . $fragments['olist_close'] . ' + + + ' . $fragments['ulist_open'] . '' . $fragments['ulist_close'] . ' + + '; + + $templates['li'] = $fragments['listitem'] . '' . $fragments['listitem_close']; + + $templates['quote'] = + ' + + ' . $fragments['quote_username_open'] . '' . $fragments['quote_close'] . ' + + + ' . $fragments['quote_open'] . '' . $fragments['quote_close'] . ' + + '; + + // The [attachment] BBCode uses the inline_attachment template to output a comment that + // is post-processed by parse_attachments() + $templates['attachment'] = $fragments['inline_attachment_open'] . ' ia ia ' . $fragments['inline_attachment_close']; + + // Finally save fragments whose names look like the name of a BBCode, e.g. "flash" + foreach ($fragments as $fragment_name => $fragment) + { + if (preg_match('#^\\w+$#', $fragment_name)) + { + $templates[$fragment_name] = $fragment; + } + } + + return $templates; + } + + /** + * Merge the templates from any number of styles into one BBCode template + * + * @param array $style_templates Associative array matching style_ids to their template + * @return string + */ + protected function merge_templates(array $style_templates) + { + // Group identical templates together + $grouped_templates = array(); + foreach ($style_templates as $style_id => $style_template) + { + $grouped_templates[$style_template][] = $style_id; + } + + if (count($grouped_templates) === 1) + { + return $style_template; + } + + // Sort templates by frequency descending + $templates_cnt = array_map('sizeof', $grouped_templates); + array_multisort($grouped_templates, $templates_cnt); + + // Remove the most frequent template from the list; It becomes the default + reset($grouped_templates); + $default_template = key($grouped_templates); + unset($grouped_templates[$default_template]); + + // Build an xsl:choose switch + $template = ''; + foreach ($grouped_templates as $style_template => $style_ids) + { + $template .= '' . $style_template . ''; + } + $template .= '' . $default_template . ''; + + return $template; + } +} diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php new file mode 100644 index 0000000000..10e33f47e6 --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -0,0 +1,335 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +use Symfony\Component\DependencyInjection\ContainerInterface; +use s9e\TextFormatter\Parser\BuiltInFilters; +use s9e\TextFormatter\Parser\Logger; + +/** +* s9e\TextFormatter\Parser adapter +* @package phpBB3 +*/ +class parser extends \phpbb\textformatter\parser +{ + /** + * @var s9e\TextFormatter\Parser + */ + protected $parser; + + /** + * @var phpbb\user User object, used for translating errors + */ + protected $user; + + /** + * Constructor + * + * @param phpbb\cache\driver_interface $cache + * @param string $key Cache key + * @param phpbb\user $user + * @param Symfony\Component\DependencyInjection\ContainerInterface $container + * @return null + */ + public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, ContainerInterface $container) + { + $this->user = $user; + + $parser = $cache->get($key); + if (!$parser) + { + list($parser) = $container->get('text_formatter.s9e.factory')->regenerate(); + } + + $this->parser = $parser; + } + + /** + * {@inheritdoc} + */ + public function parse($text) + { + return $this->parser->parse($text); + } + + /** + * {@inheritdoc} + */ + public function disable_bbcode($name) + { + $this->parser->disableTag(strtoupper($name)); + } + + /** + * {@inheritdoc} + */ + public function disable_bbcodes() + { + $this->parser->disablePlugin('BBCodes'); + } + + /** + * {@inheritdoc} + */ + public function disable_censor() + { + $this->parser->disablePlugin('Censor'); + } + + /** + * {@inheritdoc} + */ + public function disable_magic_url() + { + $this->parser->disablePlugin('Autoemail'); + $this->parser->disablePlugin('Autolink'); + } + + /** + * {@inheritdoc} + */ + public function disable_smilies() + { + $this->parser->disablePlugin('Emoticons'); + } + + /** + * {@inheritdoc} + */ + public function enable_bbcode($name) + { + $this->parser->enableTag(strtoupper($name)); + } + + /** + * {@inheritdoc} + */ + public function enable_bbcodes() + { + $this->parser->enablePlugin('BBCodes'); + } + + /** + * {@inheritdoc} + */ + public function enable_censor() + { + $this->parser->enablePlugin('Censor'); + } + + /** + * {@inheritdoc} + */ + public function enable_magic_url() + { + $this->parser->enablePlugin('Autoemail'); + $this->parser->enablePlugin('Autolink'); + } + + /** + * {@inheritdoc} + */ + public function enable_smilies() + { + $this->parser->enablePlugin('Emoticons'); + } + + /** + * {@inheritdoc} + * + * This will translate the log entries found in s9e\TextFormatter's logger into phpBB error + * messages + */ + public function get_errors() + { + $errors = array(); + + foreach ($this->parser->getLogger()->get() as $entry) + { + list($type, $msg, $context) = $entry; + + if ($msg === 'Tag limit exceeded') + { + if ($context['tagName'] === 'E') + { + $errors[] = $this->user->lang('TOO_MANY_SMILIES', $context['tagLimit']); + } + else if ($context['tagName'] === 'URL') + { + $errors[] = $this->user->lang('TOO_MANY_URLS', $context['tagLimit']); + } + } + else if ($msg === 'MAX_FONT_SIZE_EXCEEDED') + { + $errors[] = $this->user->lang($msg, $context['max_size']); + } + else if (preg_match('/^MAX_(?:FLASH|IMG)_(HEIGHT|WIDTH)_EXCEEDED$/D', $msg, $m)) + { + $errors[] = $this->user->lang($msg, $context['max_' . strtolower($m[1])]); + } + else if ($msg === 'Tag is disabled') + { + $name = strtolower($context['tag']->getName()); + $errors[] = $this->user->lang('UNAUTHORISED_BBCODE', '[' . $name . ']'); + } + else if ($msg === 'UNABLE_GET_IMAGE_SIZE') + { + $errors[] = $this->user->lang[$msg]; + } + } + + return array_unique($errors); + } + + /** + * {@inheritdoc} + */ + public function set_var($name, $value) + { + if ($name === 'max_smilies') + { + $this->parser->setTagLimit('E', $value ?: PHP_INT_MAX); + } + else if ($name === 'max_urls') + { + $this->parser->setTagLimit('URL', $value ?: PHP_INT_MAX); + } + else + { + $this->parser->registeredVars[$name] = $value; + } + } + + /** + * Filter a flash object's height + * + * @see bbcode_firstpass::bbcode_flash() + * + * @param string $height + * @param integer $max_height + * @param s9e\TextFormatter\Parser\Logger $logger + * @return mixed Original value if valid, FALSE otherwise + */ + static public function filter_flash_height($height, $max_height, Logger $logger) + { + if ($max_height && $height > $max_height) + { + $logger->err('MAX_FLASH_HEIGHT_EXCEEDED', array('max_height' => $max_height)); + + return false; + } + + return $height; + } + + /** + * Filter a flash object's width + * + * @see bbcode_firstpass::bbcode_flash() + * + * @param string $width + * @param integer $max_width + * @param s9e\TextFormatter\Parser\Logger $logger + * @return mixed Original value if valid, FALSE otherwise + */ + static public function filter_flash_width($width, $max_width, Logger $logger) + { + if ($max_width && $width > $max_width) + { + $logger->err('MAX_FLASH_WIDTH_EXCEEDED', array('max_width' => $max_width)); + + return false; + } + + return $width; + } + + /** + * Filter the value used in a [size] BBCode + * + * @see bbcode_firstpass::bbcode_size() + * + * @param string $size Original size + * @param integer $max_size Maximum allowed size + * @param s9e\TextFormatter\Parser\Logger $logger + * @return mixed Original value if valid, FALSE otherwise + */ + static public function filter_font_size($size, $max_size, Logger $logger) + { + if ($max_size && $size > $max_size) + { + $logger->err('MAX_FONT_SIZE_EXCEEDED', array('max_size' => $max_size)); + + return false; + } + + if ($size < 1) + { + return false; + } + + return $size; + } + + /** + * Filter an image's URL to enforce restrictions on its dimensions + * + * @see bbcode_firstpass::bbcode_img() + * + * @param string $url Original URL + * @param array $url_config Config used by the URL filter + * @param s9e\TextFormatter\Parser\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 + */ + static public function filter_img_url($url, array $url_config, Logger $logger, $max_height, $max_width) + { + // Validate the URL + $url = BuiltInFilters::filterUrl($url, $url_config, $logger); + + if ($url === false) + { + return false; + } + + if ($max_height || $max_width) + { + $stats = @getimagesize($url); + + if ($stats === false) + { + $logger->err('UNABLE_GET_IMAGE_SIZE'); + + return false; + } + + if ($max_height && $max_height < $stats[1]) + { + $logger->err('MAX_IMG_HEIGHT_EXCEEDED', array('max_height' => $max_height)); + + return false; + } + + if ($max_width && $max_width < $stats[0]) + { + $logger->err('MAX_IMG_WIDTH_EXCEEDED', array('max_width' => $max_width)); + + return false; + } + } + + return $url; + } +} diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php new file mode 100644 index 0000000000..2c8412f961 --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -0,0 +1,228 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** +* s9e\TextFormatter\Renderer adapter +* @package phpBB3 +*/ +class renderer extends \phpbb\textformatter\renderer +{ + /** + * @var s9e\TextFormatter\Renderer + */ + protected $renderer; + + /** + * @var bool Status of the viewcensors option + */ + protected $viewcensors = false; + + /** + * @var bool Status of the viewflash option + */ + protected $viewflash = false; + + /** + * @var bool Status of the viewimg option + */ + protected $viewimg = false; + + /** + * @var bool Status of the viewsmilies option + */ + protected $viewsmilies = false; + + /** + * Constructor + * + * @param phpbb\cache\driver\driver_interface $cache + * @param string $cache_dir Path to the cache dir + * @param string $key Cache key + * @param Symfony\Component\DependencyInjection\ContainerInterface $container + * @return null + */ + public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, ContainerInterface $container) + { + $renderer_data = $cache->get($key); + + if ($renderer_data) + { + $class = $renderer_data['class']; + + if (!class_exists($class, false)) + { + // Try to load the renderer class from its cache file + $cache_file = $cache_dir . $class . '.php'; + + if (file_exists($cache_file)) + { + include($cache_file); + } + } + + if (class_exists($class, false)) + { + $renderer = unserialize($renderer_data['renderer']); + } + } + + if (!isset($renderer)) + { + list(, $renderer) = $container->get('text_formatter.s9e.factory')->regenerate(); + } + + $this->renderer = $renderer; + } + + /** + * {@inheritdoc} + */ + public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) + { + parent::configure_user($user, $config, $auth); + + // Set the stylesheet parameters + foreach (array_keys($this->renderer->getParameters()) as $param_name) + { + if (substr($param_name, 0, 2) === 'L_') + { + // L_FOO is set to $user->lang('FOO') + $this->renderer->setParameter($param_name, $user->lang(substr($param_name, 2))); + } + } + + // Set the style id + $this->renderer->setParameter('STYLE_ID', $user->style['style_id']); + } + + /** + * {@inheritdoc} + */ + public function get_viewcensors() + { + return $this->viewcensors; + } + + /** + * {@inheritdoc} + */ + public function get_viewflash() + { + return $this->viewflash; + } + + /** + * {@inheritdoc} + */ + public function get_viewimg() + { + return $this->viewimg; + } + + /** + * {@inheritdoc} + */ + public function get_viewsmilies() + { + return $this->viewsmilies; + } + + /** + * {@inheritdoc} + */ + public function render($text) + { + $html = $this->renderer->render($text); + + /** + * @see bbcode::bbcode_second_pass_code() + */ + $html = preg_replace_callback( + '#()(.*?)()#is', + function ($captures) + { + $code = $captures[2]; + + $code = str_replace("\t", '   ', $code); + $code = str_replace(' ', '  ', $code); + $code = str_replace(' ', '  ', $code); + $code = str_replace("\n ", "\n ", $code); + + // keep space at the beginning + if (!empty($code) && $code[0] == ' ') + { + $code = ' ' . substr($code, 1); + } + + // remove newline at the beginning + if (!empty($code) && $code[0] == "\n") + { + $code = substr($code, 1); + } + + return $captures[1] . $code . $captures[3]; + }, + $html + ); + + return $html; + } + + /** + * {@inheritdoc} + */ + public function set_smilies_path($path) + { + $this->renderer->setParameter('T_SMILIES_PATH', $path); + } + + /** + * {@inheritdoc} + */ + public function set_viewcensors($value) + { + $this->viewcensors = $value; + $this->renderer->setParameter('S_VIEWCENSORS', $value); + } + + /** + * {@inheritdoc} + */ + public function set_viewflash($value) + { + $this->viewflash = $value; + $this->renderer->setParameter('S_VIEWFLASH', $value); + } + + /** + * {@inheritdoc} + */ + public function set_viewimg($value) + { + $this->viewimg = $value; + $this->renderer->setParameter('S_VIEWIMG', $value); + } + + /** + * {@inheritdoc} + */ + public function set_viewsmilies($value) + { + $this->viewsmilies = $value; + $this->renderer->setParameter('S_VIEWSMILIES', $value); + } +} diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php new file mode 100644 index 0000000000..19cd3a11c8 --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -0,0 +1,67 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +/** +* Text manipulation utilities +* @package phpBB3 +*/ +class utils extends \phpbb\textformatter\utils +{ + /** + * {@inheritdoc} + */ + public function clean_formatting($text) + { + // Insert a space before and then remove formatting + $text = preg_replace('#<[es]>#', ' $0', $text); + + return \s9e\TextFormatter\Unparser::removeFormatting($text); + } + + /** + * {@inheritdoc} + */ + public function remove_bbcode($text, $bbcode_name, $depth = 0) + { + $dom = new \DOMDocument; + $dom->loadXML($text); + + $xpath = new \DOMXPath($dom); + $nodes = $xpath->query(str_repeat('//' . strtoupper($bbcode_name), 1 + $depth)); + + foreach ($nodes as $node) + { + $node->parentNode->removeChild($node); + } + + return $dom->saveXML($dom->documentElement); + } + + /** + * {@inheritdoc} + */ + public function remove_formatting($text) + { + return \s9e\TextFormatter\Unparser::removeFormatting($text); + } + + /** + * {@inheritdoc} + */ + public function unparse($text) + { + return \s9e\TextFormatter\Unparser::unparse($text); + } +} diff --git a/phpBB/phpbb/textformatter/utils.php b/phpBB/phpbb/textformatter/utils.php new file mode 100644 index 0000000000..c9bed94553 --- /dev/null +++ b/phpBB/phpbb/textformatter/utils.php @@ -0,0 +1,62 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* text_formatter.utils service +* +* Used to manipulate a parsed text +* +* @package phpBB3 +*/ +abstract class utils +{ + /** + * Replace BBCodes and other formatting elements with whitespace + * + * NOTE: preserves smilies as text + * + * @param string $text + * @return string + */ + abstract public function clean_formatting($text); + + /** + * Remove given BBCode at given nesting depth + * + * @param string $text Parsed text + * @param string $bbcode_name BBCode's name + * @param integer $depth Minimum nesting depth (number of parents of the same name) + * @return string + */ + abstract public function remove_bbcode($text, $bbcode_name, $depth = 0); + + /** + * Remove BBCodes and other formatting from a parsed text + * + * NOTE: preserves smilies as text + * + * @param string $text + * @return string + */ + abstract public function remove_formatting($text); + + /** + * Return a parsed text to its original form + * + * @param string $text + * @return string + */ + abstract public function unparse($text); +} -- cgit v1.2.1 From cf39b02891d5ab021e4abc0932e1bb964cbd680c Mon Sep 17 00:00:00 2001 From: s9e Date: Thu, 8 Jan 2015 11:28:23 +0100 Subject: [ticket/11768] Updated annotations to pass sniff PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- phpBB/phpbb/textformatter/s9e/parser.php | 10 +++++----- phpBB/phpbb/textformatter/s9e/renderer.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 8d61f2caac..39697f6d4b 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -145,7 +145,7 @@ class factory implements \phpbb\textformatter\cache /** * Generate and return a new configured instance of s9e\TextFormatter\Configurator * - * @return s9e\TextFormatter\Configurator + * @return Configurator */ public function get_configurator() { diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 10e33f47e6..58cef8fa9e 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -39,7 +39,7 @@ class parser extends \phpbb\textformatter\parser * @param phpbb\cache\driver_interface $cache * @param string $key Cache key * @param phpbb\user $user - * @param Symfony\Component\DependencyInjection\ContainerInterface $container + * @param ContainerInterface $container * @return null */ public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, ContainerInterface $container) @@ -218,7 +218,7 @@ class parser extends \phpbb\textformatter\parser * * @param string $height * @param integer $max_height - * @param s9e\TextFormatter\Parser\Logger $logger + * @param Logger $logger * @return mixed Original value if valid, FALSE otherwise */ static public function filter_flash_height($height, $max_height, Logger $logger) @@ -240,7 +240,7 @@ class parser extends \phpbb\textformatter\parser * * @param string $width * @param integer $max_width - * @param s9e\TextFormatter\Parser\Logger $logger + * @param Logger $logger * @return mixed Original value if valid, FALSE otherwise */ static public function filter_flash_width($width, $max_width, Logger $logger) @@ -262,7 +262,7 @@ class parser extends \phpbb\textformatter\parser * * @param string $size Original size * @param integer $max_size Maximum allowed size - * @param s9e\TextFormatter\Parser\Logger $logger + * @param Logger $logger * @return mixed Original value if valid, FALSE otherwise */ static public function filter_font_size($size, $max_size, Logger $logger) @@ -289,7 +289,7 @@ class parser extends \phpbb\textformatter\parser * * @param string $url Original URL * @param array $url_config Config used by the URL filter - * @param s9e\TextFormatter\Parser\Logger $logger + * @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 diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 2c8412f961..c724be7cfe 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -50,9 +50,9 @@ class renderer extends \phpbb\textformatter\renderer * Constructor * * @param phpbb\cache\driver\driver_interface $cache - * @param string $cache_dir Path to the cache dir - * @param string $key Cache key - * @param Symfony\Component\DependencyInjection\ContainerInterface $container + * @param string $cache_dir Path to the cache dir + * @param string $key Cache key + * @param ContainerInterface $container * @return null */ public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, ContainerInterface $container) -- cgit v1.2.1 From dc303cbc993755ec446fcc3f060659668e5073f8 Mon Sep 17 00:00:00 2001 From: s9e Date: Fri, 16 Jan 2015 02:31:14 +0100 Subject: [ticket/11768] Toggled Unicode modifier in relative URL filter get_preg_expression('relative_url') returns an expression that requires it PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 39697f6d4b..06bee34767 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -163,13 +163,11 @@ class factory implements \phpbb\textformatter\cache // Create custom filters for BBCode tokens that are supported in phpBB but not in // s9e\TextFormatter - $filter = new RegexpFilter('#^' . get_preg_expression('relative_url') . '$#D'); + $filter = new RegexpFilter('#^' . get_preg_expression('relative_url') . '$#Du'); $configurator->attributeFilters->add('#local_url', $filter); $configurator->attributeFilters->add('#relative_url', $filter); - $regexp = (phpbb_pcre_utf8_support()) - ? '!^([\p{L}\p{N}\-+,_. ]+)$!uD' - : '!^([a-zA-Z0-9\-+,_. ]+)$!uD'; + $regexp = '!^([\p{L}\p{N}\-+,_. ]+)$!Du'; $configurator->attributeFilters->add('#inttext', new RegexpFilter($regexp)); // Create custom filters for Flash restrictions, which use the same values as the image -- cgit v1.2.1 From e0bb446c57d692b3e968a7a3ccd9d726f0779391 Mon Sep 17 00:00:00 2001 From: s9e Date: Fri, 16 Jan 2015 03:54:42 +0100 Subject: [ticket/11768] Reorganized code for readability No functional change intended PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 06bee34767..d000262bec 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -167,8 +167,9 @@ class factory implements \phpbb\textformatter\cache $configurator->attributeFilters->add('#local_url', $filter); $configurator->attributeFilters->add('#relative_url', $filter); - $regexp = '!^([\p{L}\p{N}\-+,_. ]+)$!Du'; - $configurator->attributeFilters->add('#inttext', new RegexpFilter($regexp)); + // INTTEXT regexp from acp_bbcodes + $filter = new RegexpFilter('!^([\p{L}\p{N}\-+,_. ]+)$!Du'); + $configurator->attributeFilters->add('#inttext', $filter); // Create custom filters for Flash restrictions, which use the same values as the image // restrictions but have their own error message -- cgit v1.2.1 From 72fb380c9fbb0d6fa51236bdc179ba7ef6126a5a Mon Sep 17 00:00:00 2001 From: s9e Date: Wed, 4 Feb 2015 23:07:58 +0100 Subject: [ticket/11768] Updated constructors with explicit dependencies The trade-off is that an instance of phpbb\textformatter\s9e\factory and phpbb\textformatter\data_access is created on any page that uses the parser or the renderer, even when neither need to be regenerated. It has no measureable impact on performance and costs ~20KB of RAM. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 6 +++--- phpBB/phpbb/textformatter/s9e/renderer.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 58cef8fa9e..d9f693ba18 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -39,17 +39,17 @@ class parser extends \phpbb\textformatter\parser * @param phpbb\cache\driver_interface $cache * @param string $key Cache key * @param phpbb\user $user - * @param ContainerInterface $container + * @param factory $factory * @return null */ - public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, ContainerInterface $container) + public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory) { $this->user = $user; $parser = $cache->get($key); if (!$parser) { - list($parser) = $container->get('text_formatter.s9e.factory')->regenerate(); + list($parser) = $factory->regenerate(); } $this->parser = $parser; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index c724be7cfe..9fe538e35d 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -49,13 +49,13 @@ class renderer extends \phpbb\textformatter\renderer /** * Constructor * - * @param phpbb\cache\driver\driver_interface $cache - * @param string $cache_dir Path to the cache dir - * @param string $key Cache key - * @param ContainerInterface $container + * @param \phpbb\cache\driver\driver_interface $cache + * @param string $cache_dir Path to the cache dir + * @param string $key Cache key + * @param factory $factory * @return null */ - public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, ContainerInterface $container) + public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory) { $renderer_data = $cache->get($key); @@ -82,7 +82,7 @@ class renderer extends \phpbb\textformatter\renderer if (!isset($renderer)) { - list(, $renderer) = $container->get('text_formatter.s9e.factory')->regenerate(); + list(, $renderer) = $factory->regenerate(); } $this->renderer = $renderer; -- cgit v1.2.1 From 3b115a903a5651f05ac388dea774d1b4022e2ed8 Mon Sep 17 00:00:00 2001 From: s9e Date: Thu, 5 Feb 2015 00:59:29 +0100 Subject: [ticket/11768] Removed unused use statements PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 1 - phpBB/phpbb/textformatter/s9e/renderer.php | 2 -- 2 files changed, 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index d9f693ba18..3b490131f2 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -13,7 +13,6 @@ namespace phpbb\textformatter\s9e; -use Symfony\Component\DependencyInjection\ContainerInterface; use s9e\TextFormatter\Parser\BuiltInFilters; use s9e\TextFormatter\Parser\Logger; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 9fe538e35d..eea01f82af 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -13,8 +13,6 @@ namespace phpbb\textformatter\s9e; -use Symfony\Component\DependencyInjection\ContainerInterface; - /** * s9e\TextFormatter\Renderer adapter * @package phpBB3 -- cgit v1.2.1 From f6e3e41717e71fb43ea63785cfe7980e33be3fbf Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 13 Feb 2015 11:28:51 +0100 Subject: [ticket/11768] Added support for magic links that start with "www." PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index d000262bec..77b1a1c916 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -280,7 +280,7 @@ class factory implements \phpbb\textformatter\cache // Load the magic links plugins. We do that after BBCodes so that they use the same tags $configurator->plugins->load('Autoemail'); - $configurator->plugins->load('Autolink'); + $configurator->plugins->load('Autolink', array('matchWww' => true)); // Register some vars with a default value. Those should be set at runtime by whatever calls // the parser -- cgit v1.2.1 From 6bd86a8e8a7c8e2ccf90d02343132c085978cd44 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 15 Feb 2015 03:08:36 +0100 Subject: [ticket/11768] Updated phpbb\textformatter\s9e\factory::regenerate() Returns an associative array rather than a numerically-indexed array. Feels cleaner and more extensible. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 4 ++-- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 77b1a1c916..ed99bba4a1 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -294,7 +294,7 @@ class factory implements \phpbb\textformatter\cache /** * Regenerate and cache a new parser and renderer * - * @return array Array with two elements: an instance of the parser, an instance of the renderer + * @return array Associative array with at least two elements: "parser" and "renderer" */ public function regenerate() { @@ -315,7 +315,7 @@ class factory implements \phpbb\textformatter\cache ); $this->cache->put($this->cache_key_renderer, $renderer_data); - return array($parser, $renderer); + return array('parser' => $parser, 'renderer' => $renderer); } /** diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 3b490131f2..8e78a18d40 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -48,7 +48,7 @@ class parser extends \phpbb\textformatter\parser $parser = $cache->get($key); if (!$parser) { - list($parser) = $factory->regenerate(); + extract($factory->regenerate()); } $this->parser = $parser; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index eea01f82af..943056e6ca 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -80,7 +80,7 @@ class renderer extends \phpbb\textformatter\renderer if (!isset($renderer)) { - list(, $renderer) = $factory->regenerate(); + extract($factory->regenerate()); } $this->renderer = $renderer; -- cgit v1.2.1 From 6578e1c6ec7172016fbfa375dd2fce5cb20f3ce1 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 17 Feb 2015 09:18:31 +0100 Subject: [ticket/11768] Added limited support for [url] in [quote] author PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index ed99bba4a1..47da3e3eb7 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -74,7 +74,14 @@ class factory implements \phpbb\textformatter\cache 'img' => '[IMG src={IMAGEURL;useContent}]', 'list' => '[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext}]{TEXT}[/LIST]', 'li' => '[* $tagName=LI]{TEXT}[/*]', - 'quote' => '[QUOTE author={TEXT1;optional}]{TEXT2}[/QUOTE]', + 'quote' => + "[QUOTE + author={TEXT1;optional} + url={URL;optional} + author={PARSE=/^\\[url=(?'url'.*?)](?'author'.*)\\[\\/url]$/i} + author={PARSE=/^\\[url](?'author'(?'url'.*?))\\[\\/url]$/i} + author={PARSE=/(?'url'https?:\\/\\/[^[\\]]+)/i} + ]{TEXT2}[/QUOTE]", 'size' => '[SIZE={FONTSIZE}]{TEXT}[/SIZE]', 'u' => '[U]{TEXT}[/U]', 'url' => '[URL={URL;useContent}]{TEXT}[/URL]', @@ -424,6 +431,15 @@ class factory implements \phpbb\textformatter\cache $templates['li'] = $fragments['listitem'] . '' . $fragments['listitem_close']; + $fragments['quote_username_open'] = str_replace( + '{USERNAME}', + ' + ' . str_replace('{DESCRIPTION}', '{USERNAME}', $fragments['url']) . ' + {USERNAME} + ', + $fragments['quote_username_open'] + ); + $templates['quote'] = ' @@ -438,7 +454,7 @@ class factory implements \phpbb\textformatter\cache // is post-processed by parse_attachments() $templates['attachment'] = $fragments['inline_attachment_open'] . ' ia ia ' . $fragments['inline_attachment_close']; - // Finally save fragments whose names look like the name of a BBCode, e.g. "flash" + // Add fragments as templates foreach ($fragments as $fragment_name => $fragment) { if (preg_match('#^\\w+$#', $fragment_name)) @@ -447,6 +463,9 @@ class factory implements \phpbb\textformatter\cache } } + // Keep only templates that are named after an existing BBCode + $templates = array_intersect_key($templates, $this->default_definitions); + return $templates; } -- cgit v1.2.1 From f721b85a7835c18459b310e4db74cc0f654b05ec Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 19 Feb 2015 06:05:39 +0100 Subject: [ticket/11768] Replaced the Censor plugin ...with something that is run at rendering time. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 38 ++++++++++++++++-------------- phpBB/phpbb/textformatter/s9e/renderer.php | 21 ++++++++++++++++- 2 files changed, 40 insertions(+), 19 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 47da3e3eb7..557645b0d6 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -264,25 +264,15 @@ class factory implements \phpbb\textformatter\cache } // Load the censored words - foreach ($this->dal->get_words() as $row) + $censor = $this->dal->get_words(); + if (!empty($censor)) { - $configurator->Censor->add($row['word'], $row['replacement']); - } - - if (isset($configurator->Censor)) - { - // Replace the template with a template that applies only when $S_VIEWCENSORS is set - $tag = $configurator->Censor->getTag(); - $tag->template = - ' - - - - - - - **** - '; + // Use a namespaced tag to avoid collisions + $configurator->plugins->load('Censor', array('tagName' => 'censor:tag')); + foreach ($censor as $row) + { + $configurator->Censor->add($row['word'], $row['replacement']); + } } // Load the magic links plugins. We do that after BBCodes so that they use the same tags @@ -307,6 +297,14 @@ class factory implements \phpbb\textformatter\cache { $configurator = $this->get_configurator(); + // Get the censor helper and remove the Censor plugin if applicable + if (isset($configurator->Censor)) + { + $censor = $configurator->Censor->getHelper(); + unset($configurator->Censor); + unset($configurator->tags['censor:tag']); + } + // Create $parser and $renderer extract($configurator->finalize()); @@ -320,6 +318,10 @@ class factory implements \phpbb\textformatter\cache 'class' => get_class($renderer), 'renderer' => serialize($renderer) ); + if (isset($censor)) + { + $renderer_data['censor'] = $censor; + } $this->cache->put($this->cache_key_renderer, $renderer_data); return array('parser' => $parser, 'renderer' => $renderer); diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 943056e6ca..3ec5f38029 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -19,6 +19,11 @@ namespace phpbb\textformatter\s9e; */ class renderer extends \phpbb\textformatter\renderer { + /** + * @var s9e\TextFormatter\Plugins\Censor\Helper + */ + protected $censor; + /** * @var s9e\TextFormatter\Renderer */ @@ -56,7 +61,6 @@ class renderer extends \phpbb\textformatter\renderer public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory) { $renderer_data = $cache->get($key); - if ($renderer_data) { $class = $renderer_data['class']; @@ -76,6 +80,11 @@ class renderer extends \phpbb\textformatter\renderer { $renderer = unserialize($renderer_data['renderer']); } + + if (isset($renderer_data['censor'])) + { + $censor = $renderer_data['censor']; + } } if (!isset($renderer)) @@ -83,6 +92,11 @@ class renderer extends \phpbb\textformatter\renderer extract($factory->regenerate()); } + if (isset($censor)) + { + $this->censor = $censor; + } + $this->renderer = $renderer; } @@ -146,6 +160,11 @@ class renderer extends \phpbb\textformatter\renderer { $html = $this->renderer->render($text); + if (isset($this->censor) && $this->viewcensors) + { + $html = $this->censor->censorHtml($html, true); + } + /** * @see bbcode::bbcode_second_pass_code() */ -- cgit v1.2.1 From 3e5ee87b15c70fbfc246b6d8f6d18a186d11d83a Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 20 Feb 2015 06:03:05 +0100 Subject: [ticket/11768] Allowed text in places where text is not valid HTML PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 557645b0d6..a6639976c4 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -162,6 +162,9 @@ class factory implements \phpbb\textformatter\cache // Convert newlines to br elements by default $configurator->rootRules->enableAutoLineBreaks(); + // Don't automatically ignore text in places where text is not allowed + $configurator->rulesGenerator->remove('IgnoreTextIfDisallowed'); + // Set the rendering engine and configure it to save to the cache dir $configurator->rendering->engine = 'PHP'; $configurator->rendering->engine->cacheDir = $this->cache_dir; -- cgit v1.2.1 From c1ba3a678d5a565b74d893c57eb5133623702350 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Feb 2015 19:03:41 +0100 Subject: [ticket/11768] Added methods to access the library's parser/renderer PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 10 ++++++++++ phpBB/phpbb/textformatter/s9e/renderer.php | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 8e78a18d40..b717dea962 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -191,6 +191,16 @@ class parser extends \phpbb\textformatter\parser return array_unique($errors); } + /** + * Return the instance of s9e\TextFormatter\Parser used by this object + * + * @return s9e\TextFormatter\Parser + */ + public function get_parser() + { + return $this->parser; + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 3ec5f38029..3ccb40cc2d 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -121,6 +121,16 @@ class renderer extends \phpbb\textformatter\renderer $this->renderer->setParameter('STYLE_ID', $user->style['style_id']); } + /** + * Return the instance of s9e\TextFormatter\Renderer used by this object + * + * @return s9e\TextFormatter\Renderer + */ + public function get_renderer() + { + return $this->renderer; + } + /** * {@inheritdoc} */ -- cgit v1.2.1 From 73ce09b73a97e351197005ac89113d3451b41da0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Feb 2015 19:34:10 +0100 Subject: [ticket/11768] Fixed censored words being escaped twice PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index a6639976c4..9af34ab90a 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -274,7 +274,8 @@ class factory implements \phpbb\textformatter\cache $configurator->plugins->load('Censor', array('tagName' => 'censor:tag')); foreach ($censor as $row) { - $configurator->Censor->add($row['word'], $row['replacement']); + // 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'])); } } -- cgit v1.2.1 From 5fe74cd3944387831fb1949198409481a1358ee5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Feb 2015 19:35:49 +0100 Subject: [ticket/11768] Updated censor to apply to XML values PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 3ccb40cc2d..54382d7d1e 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -168,13 +168,14 @@ class renderer extends \phpbb\textformatter\renderer */ public function render($text) { - $html = $this->renderer->render($text); - if (isset($this->censor) && $this->viewcensors) { - $html = $this->censor->censorHtml($html, true); + // NOTE: censorHtml() is XML-safe + $text = $this->censor->censorHtml($text, true); } + $html = $this->renderer->render($text); + /** * @see bbcode::bbcode_second_pass_code() */ -- cgit v1.2.1 From baadc2a6e52437d9d5912c828a337a3c2866c9eb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:38:35 +0100 Subject: [ticket/11768] Removed unused annotations PHPBB3-11768 --- phpBB/phpbb/textformatter/cache.php | 6 ------ phpBB/phpbb/textformatter/data_access.php | 4 ---- phpBB/phpbb/textformatter/parser.php | 4 ---- phpBB/phpbb/textformatter/renderer.php | 4 ---- phpBB/phpbb/textformatter/s9e/factory.php | 1 - phpBB/phpbb/textformatter/s9e/parser.php | 1 - phpBB/phpbb/textformatter/s9e/renderer.php | 1 - phpBB/phpbb/textformatter/s9e/utils.php | 1 - phpBB/phpbb/textformatter/utils.php | 4 ---- 9 files changed, 26 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/cache.php b/phpBB/phpbb/textformatter/cache.php index c92683217e..a2f7ff7d7b 100644 --- a/phpBB/phpbb/textformatter/cache.php +++ b/phpBB/phpbb/textformatter/cache.php @@ -14,14 +14,8 @@ namespace phpbb\textformatter; /** -* text_formatter.cache service -* * Currently only used to signal that something that could effect the rendering has changed. * BBCodes, smilies, censored words, templates, etc... -* -* @todo functionality should be moved to data_access -* -* @package phpBB3 */ interface cache { diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index ec6bf9f88e..2576b734f4 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -14,14 +14,10 @@ namespace phpbb\textformatter; /** -* text_formatter.data_access service -* * Data access layer that fetchs BBCodes, smilies and censored words from the database. * To be extended to include insert/update/delete operations. * * Also used to get templates. -* -* @package phpBB3 */ class data_access { diff --git a/phpBB/phpbb/textformatter/parser.php b/phpBB/phpbb/textformatter/parser.php index c595a459bd..6746ccada5 100644 --- a/phpBB/phpbb/textformatter/parser.php +++ b/phpBB/phpbb/textformatter/parser.php @@ -13,10 +13,6 @@ namespace phpbb\textformatter; -/** -* text_formatter.parser service -* @package phpBB3 -*/ abstract class parser { /** diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php index fb731a5294..808beda0a5 100644 --- a/phpBB/phpbb/textformatter/renderer.php +++ b/phpBB/phpbb/textformatter/renderer.php @@ -13,10 +13,6 @@ namespace phpbb\textformatter; -/** -* text_formatter.renderer service -* @package phpBB3 -*/ abstract class renderer { /** diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 9af34ab90a..20ed692850 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -18,7 +18,6 @@ use s9e\TextFormatter\Configurator\Items\AttributeFilters\Regexp as RegexpFilter /** * Creates s9e\TextFormatter objects -* @package phpBB3 */ class factory implements \phpbb\textformatter\cache { diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index b717dea962..977097462b 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -18,7 +18,6 @@ use s9e\TextFormatter\Parser\Logger; /** * s9e\TextFormatter\Parser adapter -* @package phpBB3 */ class parser extends \phpbb\textformatter\parser { diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 54382d7d1e..ab0b032eb4 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -15,7 +15,6 @@ namespace phpbb\textformatter\s9e; /** * s9e\TextFormatter\Renderer adapter -* @package phpBB3 */ class renderer extends \phpbb\textformatter\renderer { diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 19cd3a11c8..57e836d2d4 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -15,7 +15,6 @@ namespace phpbb\textformatter\s9e; /** * Text manipulation utilities -* @package phpBB3 */ class utils extends \phpbb\textformatter\utils { diff --git a/phpBB/phpbb/textformatter/utils.php b/phpBB/phpbb/textformatter/utils.php index c9bed94553..13942b9248 100644 --- a/phpBB/phpbb/textformatter/utils.php +++ b/phpBB/phpbb/textformatter/utils.php @@ -14,11 +14,7 @@ namespace phpbb\textformatter; /** -* text_formatter.utils service -* * Used to manipulate a parsed text -* -* @package phpBB3 */ abstract class utils { -- cgit v1.2.1 From b12043d4b076b1e214fd85da28358ba829d47a76 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:43:46 +0100 Subject: [ticket/11768] Renamed get_words() to get_censored_words() PHPBB3-11768 --- phpBB/phpbb/textformatter/data_access.php | 2 +- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index 2576b734f4..008e1fd5c0 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -217,7 +217,7 @@ class data_access * * @return array */ - public function get_words() + public function get_censored_words() { $sql = 'SELECT word, replacement FROM ' . $this->words_table; $result = $this->db->sql_query($sql); diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 20ed692850..ce9d34e247 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -266,7 +266,7 @@ class factory implements \phpbb\textformatter\cache } // Load the censored words - $censor = $this->dal->get_words(); + $censor = $this->dal->get_censored_words(); if (!empty($censor)) { // Use a namespaced tag to avoid collisions -- cgit v1.2.1 From 694e515f7c812a470a9a1890aa49ba6ad59385fb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:52:31 +0100 Subject: [ticket/11768] Replaced \phpbb\textformatter\parser with an interface PHPBB3-11768 --- phpBB/phpbb/textformatter/parser.php | 36 +++++++++++++------------------- phpBB/phpbb/textformatter/s9e/parser.php | 13 +++++++++++- 2 files changed, 27 insertions(+), 22 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/parser.php b/phpBB/phpbb/textformatter/parser.php index 6746ccada5..922226cf44 100644 --- a/phpBB/phpbb/textformatter/parser.php +++ b/phpBB/phpbb/textformatter/parser.php @@ -13,7 +13,7 @@ namespace phpbb\textformatter; -abstract class parser +interface parser { /** * Parse given text @@ -21,7 +21,7 @@ abstract class parser * @param string $text * @return string */ - abstract public function parse($text); + public function parse($text); /** * Disable a specific BBCode @@ -29,27 +29,27 @@ abstract class parser * @param string $name BBCode name * @return null */ - abstract public function disable_bbcode($name); + public function disable_bbcode($name); /** * Disable BBCodes in general */ - abstract public function disable_bbcodes(); + public function disable_bbcodes(); /** * Disable the censor */ - abstract public function disable_censor(); + public function disable_censor(); /** * Disable magic URLs */ - abstract public function disable_magic_url(); + public function disable_magic_url(); /** * Disable smilies */ - abstract public function disable_smilies(); + public function disable_smilies(); /** * Enable a specific BBCode @@ -57,34 +57,34 @@ abstract class parser * @param string $name BBCode name * @return null */ - abstract public function enable_bbcode($name); + public function enable_bbcode($name); /** * Enable BBCodes in general */ - abstract public function enable_bbcodes(); + public function enable_bbcodes(); /** * Enable the censor */ - abstract public function enable_censor(); + public function enable_censor(); /** * Enable magic URLs */ - abstract public function enable_magic_url(); + public function enable_magic_url(); /** * Enable smilies */ - abstract public function enable_smilies(); + public function enable_smilies(); /** * Get the list of errors that were generated during last parsing * * @return array */ - abstract public function get_errors(); + public function get_errors(); /** * Set a variable to be used by the parser @@ -99,7 +99,7 @@ abstract class parser * @param mixed $value * @return null */ - abstract public function set_var($name, $value); + public function set_var($name, $value); /** * Set multiple variables to be used by the parser @@ -107,11 +107,5 @@ abstract class parser * @param array Associative array of [name => value] * @return null */ - public function set_vars(array $vars) - { - foreach ($vars as $name => $value) - { - $this->set_var($name, $value); - } - } + public function set_vars(array $vars); } diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 977097462b..de51929994 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -19,7 +19,7 @@ use s9e\TextFormatter\Parser\Logger; /** * s9e\TextFormatter\Parser adapter */ -class parser extends \phpbb\textformatter\parser +class parser implements \phpbb\textformatter\parser { /** * @var s9e\TextFormatter\Parser @@ -219,6 +219,17 @@ class parser extends \phpbb\textformatter\parser } } + /** + * {@inheritdoc} + */ + public function set_vars(array $vars) + { + foreach ($vars as $name => $value) + { + $this->set_var($name, $value); + } + } + /** * Filter a flash object's height * -- cgit v1.2.1 From 3d9596be79cc68bc4caa2263c0bd996606ab3543 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:54:37 +0100 Subject: [ticket/11768] Updated renderer annotation PHPBB3-11768 --- phpBB/phpbb/textformatter/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php index 808beda0a5..1b0a36715f 100644 --- a/phpBB/phpbb/textformatter/renderer.php +++ b/phpBB/phpbb/textformatter/renderer.php @@ -18,7 +18,7 @@ abstract class renderer /** * Render given text * - * @param string $text Text, as parsed by the text_formatter.parser service + * @param string $text Text, as parsed by something that implements \phpbb\textformatter\parser * @return string */ abstract public function render($text); -- cgit v1.2.1 From 825bc45983f961b4d84f5d869dc0cb6111902aa7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:56:14 +0100 Subject: [ticket/11768] Removed comments PHPBB3-11768 --- phpBB/phpbb/textformatter/renderer.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php index 1b0a36715f..a2375d206b 100644 --- a/phpBB/phpbb/textformatter/renderer.php +++ b/phpBB/phpbb/textformatter/renderer.php @@ -26,8 +26,6 @@ abstract class renderer /** * Automatically set the smilies path based on config * - * Called by the service container - * * @param phpbb\config\config $config * @param phpbb\path_helper $path_helper * @return null @@ -46,7 +44,6 @@ abstract class renderer * Configure this renderer as per the user's settings * * Should set the locale as well as the viewcensor/viewflash/viewimg/viewsmilies options. - * Called by the service container * * @param phpbb\user $user * @param phpbb\config\config $config -- cgit v1.2.1 From 458cf95b1e0614b8dbecaca36c57f21e8a3a7bb7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:58:38 +0100 Subject: [ticket/11768] Replaced class names in annotations with their FQN PHPBB3-11768 --- phpBB/phpbb/textformatter/renderer.php | 10 +++++----- phpBB/phpbb/textformatter/s9e/factory.php | 6 +++--- phpBB/phpbb/textformatter/s9e/parser.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php index a2375d206b..d3594bb4ae 100644 --- a/phpBB/phpbb/textformatter/renderer.php +++ b/phpBB/phpbb/textformatter/renderer.php @@ -26,8 +26,8 @@ abstract class renderer /** * Automatically set the smilies path based on config * - * @param phpbb\config\config $config - * @param phpbb\path_helper $path_helper + * @param \phpbb\config\config $config + * @param \phpbb\path_helper $path_helper * @return null */ public function configure_smilies_path(\phpbb\config\config $config, \phpbb\path_helper $path_helper) @@ -45,9 +45,9 @@ abstract class renderer * * Should set the locale as well as the viewcensor/viewflash/viewimg/viewsmilies options. * - * @param phpbb\user $user - * @param phpbb\config\config $config - * @param phpbb\auth\auth $auth + * @param \phpbb\user $user + * @param \phpbb\config\config $config + * @param \phpbb\auth\auth $auth * @return null */ public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index ce9d34e247..ebed2521b2 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -22,7 +22,7 @@ use s9e\TextFormatter\Configurator\Items\AttributeFilters\Regexp as RegexpFilter class factory implements \phpbb\textformatter\cache { /** - * @var phpbb_cache_driver_interface $cache + * @var \phpbb\cache\driver_interface $cache */ protected $cache; @@ -102,8 +102,8 @@ class factory implements \phpbb\textformatter\cache /** * Constructor * - * @param phpbb\textformatter\data_access $dal - * @param phpbb\cache\driver\driver_interface $cache + * @param \phpbb\textformatter\data_access $dal + * @param \phpbb\cache\driver\driver_interface $cache * @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 diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index de51929994..4362a7870e 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -34,9 +34,9 @@ class parser implements \phpbb\textformatter\parser /** * Constructor * - * @param phpbb\cache\driver_interface $cache + * @param \phpbb\cache\driver_interface $cache * @param string $key Cache key - * @param phpbb\user $user + * @param \phpbb\user $user * @param factory $factory * @return null */ -- cgit v1.2.1 From 70b7e57497e8822dc237268c54d859125cdea4d0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:59:44 +0100 Subject: [ticket/11768] Renamed property PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index ebed2521b2..a0817a9a4f 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -57,7 +57,7 @@ class factory implements \phpbb\textformatter\cache /** * @var \phpbb\textformatter\data_access */ - protected $dal; + protected $data_access; /** * @var array Default BBCode definitions @@ -102,21 +102,21 @@ class factory implements \phpbb\textformatter\cache /** * Constructor * - * @param \phpbb\textformatter\data_access $dal + * @param \phpbb\textformatter\data_access $data_access * @param \phpbb\cache\driver\driver_interface $cache * @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 * @return null */ - public function __construct(\phpbb\textformatter\data_access $dal, \phpbb\cache\driver\driver_interface $cache, $cache_dir, $cache_key_parser, $cache_key_renderer) + public function __construct(\phpbb\textformatter\data_access $data_access, \phpbb\cache\driver\driver_interface $cache, $cache_dir, $cache_key_parser, $cache_key_renderer) { $this->cache = $cache; $this->cache_dir = $cache_dir; $this->cache_key_parser = $cache_key_parser; $this->cache_key_renderer = $cache_key_renderer; - $this->dal = $dal; + $this->data_access = $data_access; } /** @@ -222,7 +222,7 @@ class factory implements \phpbb\textformatter\cache } // Load custom BBCodes - foreach ($this->dal->get_bbcodes() as $row) + foreach ($this->data_access->get_bbcodes() as $row) { // Insert the board's URL before {LOCAL_URL} tokens $tpl = preg_replace_callback( @@ -247,7 +247,7 @@ class factory implements \phpbb\textformatter\cache } // Load smilies - foreach ($this->dal->get_smilies() as $row) + foreach ($this->data_access->get_smilies() as $row) { $configurator->Emoticons->add( $row['code'], @@ -266,7 +266,7 @@ class factory implements \phpbb\textformatter\cache } // Load the censored words - $censor = $this->dal->get_censored_words(); + $censor = $this->data_access->get_censored_words(); if (!empty($censor)) { // Use a namespaced tag to avoid collisions @@ -339,7 +339,7 @@ class factory implements \phpbb\textformatter\cache { // For each BBCode, build an associative array matching style_ids to their template $templates = array(); - foreach ($this->dal->get_styles_templates() as $style_id => $data) + foreach ($this->data_access->get_styles_templates() as $style_id => $data) { foreach ($this->extract_templates($data['template']) as $bbcode_name => $template) { -- cgit v1.2.1 From 6cb3fb614022fe4e56a6651ffad4f476056ae520 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 01:44:48 +0100 Subject: [ticket/11768] Replaced FQNs in annotations PHPBB3-11768 --- phpBB/phpbb/textformatter/data_access.php | 2 +- phpBB/phpbb/textformatter/s9e/parser.php | 4 ++-- phpBB/phpbb/textformatter/s9e/renderer.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index 008e1fd5c0..bc33791e15 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -27,7 +27,7 @@ class data_access protected $bbcodes_table; /** - * @var phpbb_db_driver + * @var \phpbb_db_driver */ protected $db; diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 4362a7870e..bf0e715ada 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -22,12 +22,12 @@ use s9e\TextFormatter\Parser\Logger; class parser implements \phpbb\textformatter\parser { /** - * @var s9e\TextFormatter\Parser + * @var \s9e\TextFormatter\Parser */ protected $parser; /** - * @var phpbb\user User object, used for translating errors + * @var \phpbb\user User object, used for translating errors */ protected $user; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index ab0b032eb4..7b2fef5f4b 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -19,12 +19,12 @@ namespace phpbb\textformatter\s9e; class renderer extends \phpbb\textformatter\renderer { /** - * @var s9e\TextFormatter\Plugins\Censor\Helper + * @var \s9e\TextFormatter\Plugins\Censor\Helper */ protected $censor; /** - * @var s9e\TextFormatter\Renderer + * @var \s9e\TextFormatter\Renderer */ protected $renderer; -- cgit v1.2.1 From d37f2d10f02b6a7a2b12e4b21284df310f39d3e6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 02:14:09 +0100 Subject: [ticket/11768] Removed the cached renderer We don't need to cache an instance of the renderer, we can just instantiate it every time we need one. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 9 ++------- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index a0817a9a4f..a7cf2d89b8 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -314,13 +314,8 @@ class factory implements \phpbb\textformatter\cache // Cache the parser as-is $this->cache->put($this->cache_key_parser, $parser); - // We need to cache the name of the renderer's generated class so that we can load the class - // before the renderer is unserialized. That's why we save them together, with the renderer - // in serialized form - $renderer_data = array( - 'class' => get_class($renderer), - 'renderer' => serialize($renderer) - ); + // We need to cache the name of the renderer's generated class + $renderer_data = array('class' => get_class($renderer)); if (isset($censor)) { $renderer_data['censor'] = $censor; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 7b2fef5f4b..71c207e6fc 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -77,7 +77,7 @@ class renderer extends \phpbb\textformatter\renderer if (class_exists($class, false)) { - $renderer = unserialize($renderer_data['renderer']); + $renderer = new $class; } if (isset($renderer_data['censor'])) -- cgit v1.2.1 From 40340004aac7ac1752c90a1dbca1faa486e668b9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 02:52:40 +0100 Subject: [ticket/11768] Replaced some references PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index a7cf2d89b8..66dba14ac0 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -354,20 +354,18 @@ class factory implements \phpbb\textformatter\cache } // Replace custom tokens and normalize templates - foreach ($templates as $bbcode_name => &$style_templates) + foreach ($templates as $bbcode_name => $style_templates) { - foreach ($style_templates as &$template) + foreach ($style_templates as $i => $template) { if (isset($this->custom_tokens[$bbcode_name])) { $template = strtr($template, $this->custom_tokens[$bbcode_name]); } - $template = $configurator->templateNormalizer->normalizeTemplate($template); + $templates[$bbcode_name][$i] = $configurator->templateNormalizer->normalizeTemplate($template); } - unset($template); } - unset($style_templates); $bbcodes = array(); foreach ($this->default_definitions as $bbcode_name => $usage) -- cgit v1.2.1 From dc9a28d346370b38c10def92358170a5cef23b36 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 03:07:23 +0100 Subject: [ticket/11768] Replaced extract() calls PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 5 +++-- phpBB/phpbb/textformatter/s9e/parser.php | 3 ++- phpBB/phpbb/textformatter/s9e/renderer.php | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 66dba14ac0..a5b3527822 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -308,8 +308,9 @@ class factory implements \phpbb\textformatter\cache unset($configurator->tags['censor:tag']); } - // Create $parser and $renderer - extract($configurator->finalize()); + $objects = $configurator->finalize(); + $parser = $objects['parser']; + $renderer = $objects['renderer']; // Cache the parser as-is $this->cache->put($this->cache_key_parser, $parser); diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index bf0e715ada..be717bb1c9 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -47,7 +47,8 @@ class parser implements \phpbb\textformatter\parser $parser = $cache->get($key); if (!$parser) { - extract($factory->regenerate()); + $objects = $factory->regenerate(); + $parser = $objects['parser']; } $this->parser = $parser; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 71c207e6fc..5468af450f 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -88,7 +88,8 @@ class renderer extends \phpbb\textformatter\renderer if (!isset($renderer)) { - extract($factory->regenerate()); + $objects = $factory->regenerate(); + $renderer = $objects['renderer']; } if (isset($censor)) -- cgit v1.2.1 From 78b544920c0d3984dd814cfe59f43c46feac6f12 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 04:18:17 +0100 Subject: [ticket/11768] Added support for creating unsafe BBCodes PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index a5b3527822..9327da4b4f 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -15,6 +15,7 @@ namespace phpbb\textformatter\s9e; use s9e\TextFormatter\Configurator; use s9e\TextFormatter\Configurator\Items\AttributeFilters\Regexp as RegexpFilter; +use s9e\TextFormatter\Configurator\Items\UnsafeTemplate; /** * Creates s9e\TextFormatter objects @@ -236,7 +237,7 @@ class factory implements \phpbb\textformatter\cache try { - $configurator->BBCodes->addCustom($row['bbcode_match'], $tpl); + $configurator->BBCodes->addCustom($row['bbcode_match'], new UnsafeTemplate($tpl)); } catch (\Exception $e) { -- cgit v1.2.1 From 8411db62576a73beb921d58953bb5b767d4ee079 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:21:15 +0100 Subject: [ticket/11768] Renamed interfaces PHPBB3-11768 --- phpBB/phpbb/textformatter/cache.php | 31 ------ phpBB/phpbb/textformatter/cache_interface.php | 31 ++++++ phpBB/phpbb/textformatter/data_access.php | 2 +- phpBB/phpbb/textformatter/parser.php | 111 ------------------- phpBB/phpbb/textformatter/parser_interface.php | 111 +++++++++++++++++++ phpBB/phpbb/textformatter/renderer.php | 129 ----------------------- phpBB/phpbb/textformatter/renderer_interface.php | 92 ++++++++++++++++ phpBB/phpbb/textformatter/s9e/factory.php | 2 +- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- phpBB/phpbb/textformatter/s9e/renderer.php | 35 +++++- 10 files changed, 269 insertions(+), 277 deletions(-) delete mode 100644 phpBB/phpbb/textformatter/cache.php create mode 100644 phpBB/phpbb/textformatter/cache_interface.php delete mode 100644 phpBB/phpbb/textformatter/parser.php create mode 100644 phpBB/phpbb/textformatter/parser_interface.php delete mode 100644 phpBB/phpbb/textformatter/renderer.php create mode 100644 phpBB/phpbb/textformatter/renderer_interface.php (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/cache.php b/phpBB/phpbb/textformatter/cache.php deleted file mode 100644 index a2f7ff7d7b..0000000000 --- a/phpBB/phpbb/textformatter/cache.php +++ /dev/null @@ -1,31 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textformatter; - -/** -* Currently only used to signal that something that could effect the rendering has changed. -* BBCodes, smilies, censored words, templates, etc... -*/ -interface cache -{ - /** - * Invalidate and/or regenerate this text formatter's cache(s) - */ - public function invalidate(); - - /** - * Tidy/prune this text formatter's cache(s) - */ - public function tidy(); -} diff --git a/phpBB/phpbb/textformatter/cache_interface.php b/phpBB/phpbb/textformatter/cache_interface.php new file mode 100644 index 0000000000..f6b5f195c7 --- /dev/null +++ b/phpBB/phpbb/textformatter/cache_interface.php @@ -0,0 +1,31 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* Currently only used to signal that something that could effect the rendering has changed. +* BBCodes, smilies, censored words, templates, etc... +*/ +interface cache_interface +{ + /** + * Invalidate and/or regenerate this text formatter's cache(s) + */ + public function invalidate(); + + /** + * Tidy/prune this text formatter's cache(s) + */ + public function tidy(); +} diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index bc33791e15..2dfba27960 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -27,7 +27,7 @@ class data_access protected $bbcodes_table; /** - * @var \phpbb_db_driver + * @var \phpbb_db_driver_interface */ protected $db; diff --git a/phpBB/phpbb/textformatter/parser.php b/phpBB/phpbb/textformatter/parser.php deleted file mode 100644 index 922226cf44..0000000000 --- a/phpBB/phpbb/textformatter/parser.php +++ /dev/null @@ -1,111 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textformatter; - -interface parser -{ - /** - * Parse given text - * - * @param string $text - * @return string - */ - public function parse($text); - - /** - * Disable a specific BBCode - * - * @param string $name BBCode name - * @return null - */ - public function disable_bbcode($name); - - /** - * Disable BBCodes in general - */ - public function disable_bbcodes(); - - /** - * Disable the censor - */ - public function disable_censor(); - - /** - * Disable magic URLs - */ - public function disable_magic_url(); - - /** - * Disable smilies - */ - public function disable_smilies(); - - /** - * Enable a specific BBCode - * - * @param string $name BBCode name - * @return null - */ - public function enable_bbcode($name); - - /** - * Enable BBCodes in general - */ - public function enable_bbcodes(); - - /** - * Enable the censor - */ - public function enable_censor(); - - /** - * Enable magic URLs - */ - public function enable_magic_url(); - - /** - * Enable smilies - */ - public function enable_smilies(); - - /** - * Get the list of errors that were generated during last parsing - * - * @return array - */ - public function get_errors(); - - /** - * Set a variable to be used by the parser - * - * - max_font_size - * - max_img_height - * - max_img_width - * - max_smilies - * - max_urls - * - * @param string $name - * @param mixed $value - * @return null - */ - public function set_var($name, $value); - - /** - * Set multiple variables to be used by the parser - * - * @param array Associative array of [name => value] - * @return null - */ - public function set_vars(array $vars); -} diff --git a/phpBB/phpbb/textformatter/parser_interface.php b/phpBB/phpbb/textformatter/parser_interface.php new file mode 100644 index 0000000000..37d538470d --- /dev/null +++ b/phpBB/phpbb/textformatter/parser_interface.php @@ -0,0 +1,111 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +interface parser_interface +{ + /** + * Parse given text + * + * @param string $text + * @return string + */ + public function parse($text); + + /** + * Disable a specific BBCode + * + * @param string $name BBCode name + * @return null + */ + public function disable_bbcode($name); + + /** + * Disable BBCodes in general + */ + public function disable_bbcodes(); + + /** + * Disable the censor + */ + public function disable_censor(); + + /** + * Disable magic URLs + */ + public function disable_magic_url(); + + /** + * Disable smilies + */ + public function disable_smilies(); + + /** + * Enable a specific BBCode + * + * @param string $name BBCode name + * @return null + */ + public function enable_bbcode($name); + + /** + * Enable BBCodes in general + */ + public function enable_bbcodes(); + + /** + * Enable the censor + */ + public function enable_censor(); + + /** + * Enable magic URLs + */ + public function enable_magic_url(); + + /** + * Enable smilies + */ + public function enable_smilies(); + + /** + * Get the list of errors that were generated during last parsing + * + * @return array + */ + public function get_errors(); + + /** + * Set a variable to be used by the parser + * + * - max_font_size + * - max_img_height + * - max_img_width + * - max_smilies + * - max_urls + * + * @param string $name + * @param mixed $value + * @return null + */ + public function set_var($name, $value); + + /** + * Set multiple variables to be used by the parser + * + * @param array Associative array of [name => value] + * @return null + */ + public function set_vars(array $vars); +} diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php deleted file mode 100644 index d3594bb4ae..0000000000 --- a/phpBB/phpbb/textformatter/renderer.php +++ /dev/null @@ -1,129 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textformatter; - -abstract class renderer -{ - /** - * Render given text - * - * @param string $text Text, as parsed by something that implements \phpbb\textformatter\parser - * @return string - */ - abstract public function render($text); - - /** - * Automatically set the smilies path based on config - * - * @param \phpbb\config\config $config - * @param \phpbb\path_helper $path_helper - * @return null - */ - public function configure_smilies_path(\phpbb\config\config $config, \phpbb\path_helper $path_helper) - { - /** - * @see smiley_text() - */ - $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $path_helper->get_web_root_path(); - - $this->set_smilies_path($root_path . $config['smilies_path']); - } - - /** - * Configure this renderer as per the user's settings - * - * Should set the locale as well as the viewcensor/viewflash/viewimg/viewsmilies options. - * - * @param \phpbb\user $user - * @param \phpbb\config\config $config - * @param \phpbb\auth\auth $auth - * @return null - */ - public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) - { - $censor = $user->optionget('viewcensors') || !$config['allow_nocensors'] || !$auth->acl_get('u_chgcensors'); - - $this->set_viewcensors($censor); - $this->set_viewflash($user->optionget('viewflash')); - $this->set_viewimg($user->optionget('viewimg')); - $this->set_viewsmilies($user->optionget('viewsmilies')); - } - - /** - * Set the smilies' path - * - * @return null - */ - abstract public function set_smilies_path($path); - - /** - * Return the value of the "viewcensors" option - * - * @return bool Option's value - */ - abstract public function get_viewcensors(); - - /** - * Return the value of the "viewflash" option - * - * @return bool Option's value - */ - abstract public function get_viewflash(); - - /** - * Return the value of the "viewimg" option - * - * @return bool Option's value - */ - abstract public function get_viewimg(); - - /** - * Return the value of the "viewsmilies" option - * - * @return bool Option's value - */ - abstract public function get_viewsmilies(); - - /** - * Set the "viewcensors" option - * - * @param bool $value Option's value - * @return null - */ - abstract public function set_viewcensors($value); - - /** - * Set the "viewflash" option - * - * @param bool $value Option's value - * @return null - */ - abstract public function set_viewflash($value); - - /** - * Set the "viewimg" option - * - * @param bool $value Option's value - * @return null - */ - abstract public function set_viewimg($value); - - /** - * Set the "viewsmilies" option - * - * @param bool $value Option's value - * @return null - */ - abstract public function set_viewsmilies($value); -} diff --git a/phpBB/phpbb/textformatter/renderer_interface.php b/phpBB/phpbb/textformatter/renderer_interface.php new file mode 100644 index 0000000000..609b0bb642 --- /dev/null +++ b/phpBB/phpbb/textformatter/renderer_interface.php @@ -0,0 +1,92 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +interface renderer_interface +{ + /** + * Render given text + * + * @param string $text Text, as parsed by something that implements \phpbb\textformatter\parser + * @return string + */ + public function render($text); + + /** + * Set the smilies' path + * + * @return null + */ + public function set_smilies_path($path); + + /** + * Return the value of the "viewcensors" option + * + * @return bool Option's value + */ + public function get_viewcensors(); + + /** + * Return the value of the "viewflash" option + * + * @return bool Option's value + */ + public function get_viewflash(); + + /** + * Return the value of the "viewimg" option + * + * @return bool Option's value + */ + public function get_viewimg(); + + /** + * Return the value of the "viewsmilies" option + * + * @return bool Option's value + */ + public function get_viewsmilies(); + + /** + * Set the "viewcensors" option + * + * @param bool $value Option's value + * @return null + */ + public function set_viewcensors($value); + + /** + * Set the "viewflash" option + * + * @param bool $value Option's value + * @return null + */ + public function set_viewflash($value); + + /** + * Set the "viewimg" option + * + * @param bool $value Option's value + * @return null + */ + public function set_viewimg($value); + + /** + * Set the "viewsmilies" option + * + * @param bool $value Option's value + * @return null + */ + public function set_viewsmilies($value); +} diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 9327da4b4f..aa37beeef6 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -20,7 +20,7 @@ use s9e\TextFormatter\Configurator\Items\UnsafeTemplate; /** * Creates s9e\TextFormatter objects */ -class factory implements \phpbb\textformatter\cache +class factory implements \phpbb\textformatter\cache_interface { /** * @var \phpbb\cache\driver_interface $cache diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index be717bb1c9..4775175f73 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -19,7 +19,7 @@ use s9e\TextFormatter\Parser\Logger; /** * s9e\TextFormatter\Parser adapter */ -class parser implements \phpbb\textformatter\parser +class parser implements \phpbb\textformatter\parser_interface { /** * @var \s9e\TextFormatter\Parser diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 5468af450f..0b3c63fb91 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -16,7 +16,7 @@ namespace phpbb\textformatter\s9e; /** * s9e\TextFormatter\Renderer adapter */ -class renderer extends \phpbb\textformatter\renderer +class renderer implements \phpbb\textformatter\renderer_interface { /** * @var \s9e\TextFormatter\Plugins\Censor\Helper @@ -101,11 +101,40 @@ class renderer extends \phpbb\textformatter\renderer } /** - * {@inheritdoc} + * Automatically set the smilies path based on config + * + * @param \phpbb\config\config $config + * @param \phpbb\path_helper $path_helper + * @return null + */ + public function configure_smilies_path(\phpbb\config\config $config, \phpbb\path_helper $path_helper) + { + /** + * @see smiley_text() + */ + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $path_helper->get_web_root_path(); + + $this->set_smilies_path($root_path . $config['smilies_path']); + } + + /** + * Configure this renderer as per the user's settings + * + * Should set the locale as well as the viewcensor/viewflash/viewimg/viewsmilies options. + * + * @param \phpbb\user $user + * @param \phpbb\config\config $config + * @param \phpbb\auth\auth $auth + * @return null */ public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) { - parent::configure_user($user, $config, $auth); + $censor = $user->optionget('viewcensors') || !$config['allow_nocensors'] || !$auth->acl_get('u_chgcensors'); + + $this->set_viewcensors($censor); + $this->set_viewflash($user->optionget('viewflash')); + $this->set_viewimg($user->optionget('viewimg')); + $this->set_viewsmilies($user->optionget('viewsmilies')); // Set the stylesheet parameters foreach (array_keys($this->renderer->getParameters()) as $param_name) -- cgit v1.2.1 From a611366bd398c02b47aa71b0fdaa9c16765d0f6b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:24:03 +0100 Subject: [ticket/11768] Whitespace [ci skip] PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 0b3c63fb91..42567098d9 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -129,7 +129,7 @@ class renderer implements \phpbb\textformatter\renderer_interface */ public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) { - $censor = $user->optionget('viewcensors') || !$config['allow_nocensors'] || !$auth->acl_get('u_chgcensors'); + $censor = $user->optionget('viewcensors') || !$config['allow_nocensors'] || !$auth->acl_get('u_chgcensors'); $this->set_viewcensors($censor); $this->set_viewflash($user->optionget('viewflash')); -- cgit v1.2.1 From 44fc3d64dafdadd1959ab53dd7e0d1be67c75c1b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:46:59 +0100 Subject: [ticket/11768] Made capturing code blocks a bit more flexible PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 42567098d9..c896c9f1c7 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -209,7 +209,7 @@ class renderer implements \phpbb\textformatter\renderer_interface * @see bbcode::bbcode_second_pass_code() */ $html = preg_replace_callback( - '#()(.*?)()#is', + '#(]*>)(.*?)()#is', function ($captures) { $code = $captures[2]; -- cgit v1.2.1 From 20a1646fc6336635cee89426e3a60bb22cb138de Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:50:05 +0100 Subject: [ticket/11768] Renamed utils PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/utils.php | 2 +- phpBB/phpbb/textformatter/utils.php | 58 --------------------------- phpBB/phpbb/textformatter/utils_interface.php | 58 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 phpBB/phpbb/textformatter/utils.php create mode 100644 phpBB/phpbb/textformatter/utils_interface.php (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 57e836d2d4..df4ae4b9ec 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -16,7 +16,7 @@ namespace phpbb\textformatter\s9e; /** * Text manipulation utilities */ -class utils extends \phpbb\textformatter\utils +class utils implements \phpbb\textformatter\utils_interface { /** * {@inheritdoc} diff --git a/phpBB/phpbb/textformatter/utils.php b/phpBB/phpbb/textformatter/utils.php deleted file mode 100644 index 13942b9248..0000000000 --- a/phpBB/phpbb/textformatter/utils.php +++ /dev/null @@ -1,58 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textformatter; - -/** -* Used to manipulate a parsed text -*/ -abstract class utils -{ - /** - * Replace BBCodes and other formatting elements with whitespace - * - * NOTE: preserves smilies as text - * - * @param string $text - * @return string - */ - abstract public function clean_formatting($text); - - /** - * Remove given BBCode at given nesting depth - * - * @param string $text Parsed text - * @param string $bbcode_name BBCode's name - * @param integer $depth Minimum nesting depth (number of parents of the same name) - * @return string - */ - abstract public function remove_bbcode($text, $bbcode_name, $depth = 0); - - /** - * Remove BBCodes and other formatting from a parsed text - * - * NOTE: preserves smilies as text - * - * @param string $text - * @return string - */ - abstract public function remove_formatting($text); - - /** - * Return a parsed text to its original form - * - * @param string $text - * @return string - */ - abstract public function unparse($text); -} diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php new file mode 100644 index 0000000000..45610f7ecb --- /dev/null +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -0,0 +1,58 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter; + +/** +* Used to manipulate a parsed text +*/ +interface utils_interface +{ + /** + * Replace BBCodes and other formatting elements with whitespace + * + * NOTE: preserves smilies as text + * + * @param string $text + * @return string + */ + public function clean_formatting($text); + + /** + * Remove given BBCode at given nesting depth + * + * @param string $text Parsed text + * @param string $bbcode_name BBCode's name + * @param integer $depth Minimum nesting depth (number of parents of the same name) + * @return string + */ + public function remove_bbcode($text, $bbcode_name, $depth = 0); + + /** + * Remove BBCodes and other formatting from a parsed text + * + * NOTE: preserves smilies as text + * + * @param string $text + * @return string + */ + public function remove_formatting($text); + + /** + * Return a parsed text to its original form + * + * @param string $text + * @return string + */ + public function unparse($text); +} -- cgit v1.2.1 From 89d87a99db403d7045406b869a92258e61122f67 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 11:11:07 +0100 Subject: [ticket/11768] Replaced array access with call to $user->lang() PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 4775175f73..f3e437b163 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -184,7 +184,7 @@ class parser implements \phpbb\textformatter\parser_interface } else if ($msg === 'UNABLE_GET_IMAGE_SIZE') { - $errors[] = $this->user->lang[$msg]; + $errors[] = $this->user->lang($msg); } } -- cgit v1.2.1 From 40c54898ccd80744ba159784d631328e0338bad2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 13:08:18 +0100 Subject: [ticket/11768] Updated various annotations PHPBB3-11768 --- phpBB/phpbb/textformatter/data_access.php | 15 +++++++-------- phpBB/phpbb/textformatter/parser_interface.php | 2 +- phpBB/phpbb/textformatter/s9e/factory.php | 13 ++++++------- phpBB/phpbb/textformatter/s9e/parser.php | 11 +++++------ phpBB/phpbb/textformatter/s9e/renderer.php | 11 +++++------ 5 files changed, 24 insertions(+), 28 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index 2dfba27960..8938d66935 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -27,7 +27,7 @@ class data_access protected $bbcodes_table; /** - * @var \phpbb_db_driver_interface + * @var \phpbb\db\driver\driver_interface */ protected $db; @@ -54,13 +54,12 @@ class data_access /** * Constructor * - * @param \phpbb\db\driver\driver_interface $db Database connection - * @param string $bbcodes_table Name of the BBCodes table - * @param string $smilies_table Name of the smilies table - * @param string $styles_table Name of the styles table - * @param string $words_table Name of the words table - * @param string $styles_path Path to the styles dir - * @return null + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param string $bbcodes_table Name of the BBCodes table + * @param string $smilies_table Name of the smilies table + * @param string $styles_table Name of the styles table + * @param string $words_table Name of the words table + * @param string $styles_path Path to the styles dir */ public function __construct(\phpbb\db\driver\driver_interface $db, $bbcodes_table, $smilies_table, $styles_table, $words_table, $styles_path) { diff --git a/phpBB/phpbb/textformatter/parser_interface.php b/phpBB/phpbb/textformatter/parser_interface.php index 37d538470d..3cb9f8e977 100644 --- a/phpBB/phpbb/textformatter/parser_interface.php +++ b/phpBB/phpbb/textformatter/parser_interface.php @@ -104,7 +104,7 @@ interface parser_interface /** * Set multiple variables to be used by the parser * - * @param array Associative array of [name => value] + * @param array $vars Associative array of [name => value] * @return null */ public function set_vars(array $vars); diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index aa37beeef6..f3df2ad7a5 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -23,7 +23,7 @@ use s9e\TextFormatter\Configurator\Items\UnsafeTemplate; class factory implements \phpbb\textformatter\cache_interface { /** - * @var \phpbb\cache\driver_interface $cache + * @var \phpbb\cache\driver\driver_interface */ protected $cache; @@ -103,12 +103,11 @@ class factory implements \phpbb\textformatter\cache_interface /** * Constructor * - * @param \phpbb\textformatter\data_access $data_access - * @param \phpbb\cache\driver\driver_interface $cache - * @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 - * @return null + * @param \phpbb\textformatter\data_access $data_access + * @param \phpbb\cache\driver\driver_interface $cache + * @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, $cache_dir, $cache_key_parser, $cache_key_renderer) { diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index f3e437b163..2f4a03d4c2 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -34,11 +34,10 @@ class parser implements \phpbb\textformatter\parser_interface /** * Constructor * - * @param \phpbb\cache\driver_interface $cache - * @param string $key Cache key - * @param \phpbb\user $user - * @param factory $factory - * @return null + * @param \phpbb\cache\driver_interface $cache + * @param string $key Cache key + * @param \phpbb\user $user + * @param factory $factory */ public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory) { @@ -194,7 +193,7 @@ class parser implements \phpbb\textformatter\parser_interface /** * Return the instance of s9e\TextFormatter\Parser used by this object * - * @return s9e\TextFormatter\Parser + * @return \s9e\TextFormatter\Parser */ public function get_parser() { diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index c896c9f1c7..882a19b4ac 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -51,11 +51,10 @@ class renderer implements \phpbb\textformatter\renderer_interface /** * Constructor * - * @param \phpbb\cache\driver\driver_interface $cache - * @param string $cache_dir Path to the cache dir - * @param string $key Cache key - * @param factory $factory - * @return null + * @param \phpbb\cache\driver\driver_interface $cache + * @param string $cache_dir Path to the cache dir + * @param string $key Cache key + * @param factory $factory */ public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory) { @@ -153,7 +152,7 @@ class renderer implements \phpbb\textformatter\renderer_interface /** * Return the instance of s9e\TextFormatter\Renderer used by this object * - * @return s9e\TextFormatter\Renderer + * @return \s9e\TextFormatter\Renderer */ public function get_renderer() { -- cgit v1.2.1 From b46bf9f02f8d1810bdb95d64603632b6fab06960 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 9 Mar 2015 12:07:10 +0100 Subject: [ticket/11768] Updated merge_templates(). No functional change intended PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index f3df2ad7a5..b053fd6468 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -480,7 +480,7 @@ class factory implements \phpbb\textformatter\cache_interface $grouped_templates = array(); foreach ($style_templates as $style_id => $style_template) { - $grouped_templates[$style_template][] = $style_id; + $grouped_templates[$style_template][] = '$STYLE_ID=' . $style_id; } if (count($grouped_templates) === 1) @@ -499,9 +499,9 @@ class factory implements \phpbb\textformatter\cache_interface // Build an xsl:choose switch $template = ''; - foreach ($grouped_templates as $style_template => $style_ids) + foreach ($grouped_templates as $style_template => $exprs) { - $template .= '' . $style_template . ''; + $template .= '' . $style_template . ''; } $template .= '' . $default_template . ''; -- cgit v1.2.1 From 4398da234ec75cb95ddab82a0fb8f3567790a60b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 16 Mar 2015 03:03:02 +0100 Subject: [ticket/11768] Updated merge_templates(). No functional change intended PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index b053fd6468..01209d352a 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -471,11 +471,21 @@ class factory implements \phpbb\textformatter\cache_interface /** * Merge the templates from any number of styles into one BBCode template * + * When multiple templates are available for the same BBCode (because of multiple styles) we + * merge them into a single template that uses an xsl:choose construct that determines which + * style to use at rendering time. + * * @param array $style_templates Associative array matching style_ids to their template * @return string */ protected function merge_templates(array $style_templates) { + // Return the template as-is if there's only one style or all styles share the same template + if (count(array_unique($style_templates)) === 1) + { + return end($style_templates); + } + // Group identical templates together $grouped_templates = array(); foreach ($style_templates as $style_id => $style_template) @@ -483,11 +493,6 @@ class factory implements \phpbb\textformatter\cache_interface $grouped_templates[$style_template][] = '$STYLE_ID=' . $style_id; } - if (count($grouped_templates) === 1) - { - return $style_template; - } - // Sort templates by frequency descending $templates_cnt = array_map('sizeof', $grouped_templates); array_multisort($grouped_templates, $templates_cnt); -- cgit v1.2.1 From 49b9e8e4eafff93f25a99bf263982fe79b7f0549 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 19 Mar 2015 12:45:12 +0100 Subject: [ticket/11768] Added configurator events PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 01209d352a..4504a329af 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -100,23 +100,29 @@ class factory implements \phpbb\textformatter\cache_interface 'email' => '', ); + /** + * @var \phpbb\event\dispatcher_interface + */ + protected $dispatcher; + /** * Constructor * * @param \phpbb\textformatter\data_access $data_access * @param \phpbb\cache\driver\driver_interface $cache + * @param \phpbb\event\dispatcher_interface $dispatcher * @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, $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, $cache_dir, $cache_key_parser, $cache_key_renderer) { $this->cache = $cache; $this->cache_dir = $cache_dir; $this->cache_key_parser = $cache_key_parser; $this->cache_key_renderer = $cache_key_renderer; - $this->data_access = $data_access; + $this->dispatcher = $dispatcher; } /** @@ -158,6 +164,16 @@ class factory implements \phpbb\textformatter\cache_interface // Create a new Configurator $configurator = new Configurator; + /** + * Modify the s9e\TextFormatter configurator before the default settings are set + * + * @event core.text_formatter_s9e_configure_before + * @var \s9e\TextFormatter\Configurator configurator Configurator instance + * @since 3.2.0-a1 + */ + $vars = array('configurator'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_before', compact($vars))); + // Convert newlines to br elements by default $configurator->rootRules->enableAutoLineBreaks(); @@ -288,6 +304,16 @@ class factory implements \phpbb\textformatter\cache_interface $configurator->registeredVars['max_img_height'] = 0; $configurator->registeredVars['max_img_width'] = 0; + /** + * Modify the s9e\TextFormatter configurator after the default settings are set + * + * @event core.text_formatter_s9e_configure_after + * @var \s9e\TextFormatter\Configurator configurator Configurator instance + * @since 3.2.0-a1 + */ + $vars = array('configurator'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_after', compact($vars))); + return $configurator; } -- cgit v1.2.1 From 69dae16ba79a82714b3fa24955c5cbc6e372a388 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 21 Mar 2015 12:32:17 +0100 Subject: [ticket/11768] Preserve comments in custom BBCodes PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 4504a329af..bad9190973 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -180,6 +180,10 @@ class factory implements \phpbb\textformatter\cache_interface // Don't automatically ignore text in places where text is not allowed $configurator->rulesGenerator->remove('IgnoreTextIfDisallowed'); + // Don't remove comments and instead convert them to xsl:comment elements + $configurator->templateNormalizer->remove('RemoveComments'); + $configurator->templateNormalizer->add('TransposeComments'); + // Set the rendering engine and configure it to save to the cache dir $configurator->rendering->engine = 'PHP'; $configurator->rendering->engine->cacheDir = $this->cache_dir; -- cgit v1.2.1 From c165eaa37ccfa817c3ba1373255efc131f7be509 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Mar 2015 12:34:22 +0100 Subject: [ticket/11768] Removed superfluous whitespace [ci skip] PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 882a19b4ac..75de54d942 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -62,7 +62,6 @@ class renderer implements \phpbb\textformatter\renderer_interface if ($renderer_data) { $class = $renderer_data['class']; - if (!class_exists($class, false)) { // Try to load the renderer class from its cache file @@ -73,12 +72,10 @@ class renderer implements \phpbb\textformatter\renderer_interface include($cache_file); } } - if (class_exists($class, false)) { $renderer = new $class; } - if (isset($renderer_data['censor'])) { $censor = $renderer_data['censor']; -- cgit v1.2.1 From 37fedc656fbdeb36b098375201042eed4c7e7229 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Mar 2015 21:34:49 +0100 Subject: [ticket/11768] Updated the text_formatter.s9e.utils service Made it use s9e\TextFormatter\Utils. Refactored some tests to make them more readable. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/utils.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index df4ae4b9ec..29dcfcdf58 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -26,7 +26,7 @@ class utils implements \phpbb\textformatter\utils_interface // Insert a space before and then remove formatting $text = preg_replace('#<[es]>#', ' $0', $text); - return \s9e\TextFormatter\Unparser::removeFormatting($text); + return \s9e\TextFormatter\Utils::removeFormatting($text); } /** @@ -34,18 +34,7 @@ class utils implements \phpbb\textformatter\utils_interface */ public function remove_bbcode($text, $bbcode_name, $depth = 0) { - $dom = new \DOMDocument; - $dom->loadXML($text); - - $xpath = new \DOMXPath($dom); - $nodes = $xpath->query(str_repeat('//' . strtoupper($bbcode_name), 1 + $depth)); - - foreach ($nodes as $node) - { - $node->parentNode->removeChild($node); - } - - return $dom->saveXML($dom->documentElement); + return \s9e\TextFormatter\Utils::removeTag($text, strtoupper($bbcode_name), $depth); } /** @@ -53,7 +42,7 @@ class utils implements \phpbb\textformatter\utils_interface */ public function remove_formatting($text) { - return \s9e\TextFormatter\Unparser::removeFormatting($text); + return \s9e\TextFormatter\Utils::removeFormatting($text); } /** -- cgit v1.2.1 From 2a462bb7e43b848d0277bd27e14ca4d645230eeb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 25 Mar 2015 01:13:31 +0100 Subject: [ticket/11768] Removed get_parser() / get_renderer() accessors There's no need to access the s9e\TextFormatter objects outside of events. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 10 ---------- phpBB/phpbb/textformatter/s9e/renderer.php | 10 ---------- 2 files changed, 20 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 2f4a03d4c2..6fda94d7ba 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -190,16 +190,6 @@ class parser implements \phpbb\textformatter\parser_interface return array_unique($errors); } - /** - * Return the instance of s9e\TextFormatter\Parser used by this object - * - * @return \s9e\TextFormatter\Parser - */ - public function get_parser() - { - return $this->parser; - } - /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 75de54d942..b68c9dd9be 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -146,16 +146,6 @@ class renderer implements \phpbb\textformatter\renderer_interface $this->renderer->setParameter('STYLE_ID', $user->style['style_id']); } - /** - * Return the instance of s9e\TextFormatter\Renderer used by this object - * - * @return \s9e\TextFormatter\Renderer - */ - public function get_renderer() - { - return $this->renderer; - } - /** * {@inheritdoc} */ -- cgit v1.2.1 From a7a53d5a30d4736f8114721c0d7019d64d24cda2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 25 Mar 2015 01:39:19 +0100 Subject: [ticket/11768] Added core.text_formatter_s9e_parser_setup event PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 33 ++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 6fda94d7ba..37900d3d7c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -21,6 +21,11 @@ use s9e\TextFormatter\Parser\Logger; */ class parser implements \phpbb\textformatter\parser_interface { + /** + * @var \phpbb\event\dispatcher_interface + */ + protected $dispatcher; + /** * @var \s9e\TextFormatter\Parser */ @@ -38,19 +43,39 @@ class parser implements \phpbb\textformatter\parser_interface * @param string $key Cache key * @param \phpbb\user $user * @param factory $factory + * @param \phpbb\event\dispatcher_interface $dispatcher */ - public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory) + public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory, \phpbb\event\dispatcher_interface $dispatcher) { - $this->user = $user; - $parser = $cache->get($key); if (!$parser) { $objects = $factory->regenerate(); $parser = $objects['parser']; } - + $self = $this; + + /** + * Configure the parser service + * + * Can be used to: + * - toggle features according to the user's preferences, + * - toggle BBCodes according to the user's permissions, + * - register variables or custom parsers in the s9e\TextFormatter + * - configure the s9e\TextFormatter parser + * + * @event core.text_formatter_s9e_parser_setup + * @var \s9e\TextFormatter\Parser parser s9e\TextFormatter parser instance + * @var \phpbb\textformatter\s9e\parser self This parser service + * @var \phpbb\user user Current user + * @since 3.2.0-a1 + */ + $vars = array('parser', 'self', 'user'); + extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars))); + + $this->dispatcher = $dispatcher; $this->parser = $parser; + $this->user = $user; } /** -- cgit v1.2.1 From af4f9b860f50a562a03f55efad1da7e0854bdfda Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 04:39:36 +0100 Subject: [ticket/11768] Added core.text_formatter_s9e_renderer_setup event PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index b68c9dd9be..7b8b382074 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -23,6 +23,11 @@ class renderer implements \phpbb\textformatter\renderer_interface */ protected $censor; + /** + * @var \phpbb\event\dispatcher_interface + */ + protected $dispatcher; + /** * @var \s9e\TextFormatter\Renderer */ @@ -55,8 +60,9 @@ class renderer implements \phpbb\textformatter\renderer_interface * @param string $cache_dir Path to the cache dir * @param string $key Cache key * @param factory $factory + * @param \phpbb\event\dispatcher_interface $dispatcher */ - public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory) + public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory, \phpbb\event\dispatcher_interface $dispatcher) { $renderer_data = $cache->get($key); if ($renderer_data) @@ -81,18 +87,29 @@ class renderer implements \phpbb\textformatter\renderer_interface $censor = $renderer_data['censor']; } } - if (!isset($renderer)) { $objects = $factory->regenerate(); $renderer = $objects['renderer']; } + $self = $this; + + /** + * Configure the renderer service + * + * @event core.text_formatter_s9e_renderer_setup + * @var \s9e\TextFormatter\Renderer renderer s9e\TextFormatter renderer instance + * @var \phpbb\textformatter\s9e\renderer self This renderer service + * @since 3.2.0-a1 + */ + $vars = array('renderer', 'self'); + extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars))); if (isset($censor)) { $this->censor = $censor; } - + $this->dispatcher = $dispatcher; $this->renderer = $renderer; } -- cgit v1.2.1 From a04fca86ee4fec3cb615f358f3dc914564d9a9b1 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 05:10:25 +0100 Subject: [ticket/11768] Added renderer events Added core.text_formatter_s9e_render_before and core.text_formatter_s9e_render_after PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 7b8b382074..484b067d47 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -198,15 +198,28 @@ class renderer implements \phpbb\textformatter\renderer_interface /** * {@inheritdoc} */ - public function render($text) + public function render($xml) { + $self = $this; + + /** + * Modify a parsed text before it is rendered + * + * @event core.text_formatter_s9e_render_before + * @var \phpbb\textformatter\s9e\renderer self This renderer service + * @var string xml The parsed text, in its XML form + * @since 3.2.0-a1 + */ + $vars = array('self', 'xml'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_before', compact($vars))); + if (isset($this->censor) && $this->viewcensors) { // NOTE: censorHtml() is XML-safe - $text = $this->censor->censorHtml($text, true); + $xml = $this->censor->censorHtml($xml, true); } - $html = $this->renderer->render($text); + $html = $this->renderer->render($xml); /** * @see bbcode::bbcode_second_pass_code() @@ -239,6 +252,17 @@ class renderer implements \phpbb\textformatter\renderer_interface $html ); + /** + * Modify a rendered text + * + * @event core.text_formatter_s9e_render_after + * @var string html The renderer text's HTML + * @var \phpbb\textformatter\s9e\renderer self This renderer service + * @since 3.2.0-a1 + */ + $vars = array('html', 'self'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_after', compact($vars))); + return $html; } -- cgit v1.2.1 From f75f63b264b2005faedb699dd867bd1d9c429a09 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 05:20:23 +0100 Subject: [ticket/11768] Added parser events Added core.text_formatter_s9e_parse_before and core.text_formatter_s9e_parse_after PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 28 +++++++++++++++++++++++++++- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 37900d3d7c..f220dd3e64 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -83,7 +83,33 @@ class parser implements \phpbb\textformatter\parser_interface */ public function parse($text) { - return $this->parser->parse($text); + $self = $this; + + /** + * Modify a text before it is parsed + * + * @event core.text_formatter_s9e_parse_before + * @var \phpbb\textformatter\s9e\parser self This parser service + * @var string text The original text + * @since 3.2.0-a1 + */ + $vars = array('self', 'text'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_parse_before', compact($vars))); + + $xml = $this->parser->parse($text); + + /** + * Modify a parsed text in its XML form + * + * @event core.text_formatter_s9e_parse_after + * @var \phpbb\textformatter\s9e\parser self This parser service + * @var string xml The parsed text, in XML + * @since 3.2.0-a1 + */ + $vars = array('self', 'xml'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_parse_after', compact($vars))); + + return $xml; } /** diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 484b067d47..272cc5e6f3 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -256,7 +256,7 @@ class renderer implements \phpbb\textformatter\renderer_interface * Modify a rendered text * * @event core.text_formatter_s9e_render_after - * @var string html The renderer text's HTML + * @var string html The rendered text's HTML * @var \phpbb\textformatter\s9e\renderer self This renderer service * @since 3.2.0-a1 */ -- cgit v1.2.1 From 55c3fc02cfe1ce151bfb65c31ec72fc75f9d7872 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 15:28:04 +0100 Subject: [ticket/11768] Updated utils service Updated docblocks. Removed remove_formatting() because it overlaps with clean_formatting() PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/utils.php | 41 +++++++++++++++------------ phpBB/phpbb/textformatter/utils_interface.php | 22 ++++---------- 2 files changed, 29 insertions(+), 34 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 29dcfcdf58..2018bbf519 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -19,37 +19,42 @@ namespace phpbb\textformatter\s9e; class utils implements \phpbb\textformatter\utils_interface { /** - * {@inheritdoc} + * Replace BBCodes and other formatting elements with whitespace + * + * NOTE: preserves smilies as text + * + * @param string $xml Parsed text + * @return string Plain text */ - public function clean_formatting($text) + public function clean_formatting($xml) { // Insert a space before and then remove formatting - $text = preg_replace('#<[es]>#', ' $0', $text); + $xml = preg_replace('#<[es]>#', ' $0', $xml); - return \s9e\TextFormatter\Utils::removeFormatting($text); + return \s9e\TextFormatter\Utils::removeFormatting($xml); } /** - * {@inheritdoc} + * Remove given BBCode and its content, at given nesting depth + * + * @param string $xml Parsed text + * @param string $bbcode_name BBCode's name + * @param integer $depth Minimum nesting depth (number of parents of the same name) + * @return string Parsed text */ - public function remove_bbcode($text, $bbcode_name, $depth = 0) + public function remove_bbcode($xml, $bbcode_name, $depth = 0) { - return \s9e\TextFormatter\Utils::removeTag($text, strtoupper($bbcode_name), $depth); + return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth); } /** - * {@inheritdoc} + * Return a parsed text to its original form + * + * @param string $xml Parsed text + * @return string Original plain text */ - public function remove_formatting($text) + public function unparse($xml) { - return \s9e\TextFormatter\Utils::removeFormatting($text); - } - - /** - * {@inheritdoc} - */ - public function unparse($text) - { - return \s9e\TextFormatter\Unparser::unparse($text); + return \s9e\TextFormatter\Unparser::unparse($xml); } } diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 45610f7ecb..132dc8ece4 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -23,36 +23,26 @@ interface utils_interface * * NOTE: preserves smilies as text * - * @param string $text - * @return string + * @param string $text Parsed text + * @return string Plain text */ public function clean_formatting($text); /** - * Remove given BBCode at given nesting depth + * Remove given BBCode and its content, at given nesting depth * * @param string $text Parsed text * @param string $bbcode_name BBCode's name * @param integer $depth Minimum nesting depth (number of parents of the same name) - * @return string + * @return string Parsed text */ public function remove_bbcode($text, $bbcode_name, $depth = 0); - /** - * Remove BBCodes and other formatting from a parsed text - * - * NOTE: preserves smilies as text - * - * @param string $text - * @return string - */ - public function remove_formatting($text); - /** * Return a parsed text to its original form * - * @param string $text - * @return string + * @param string $text Parsed text + * @return string Original plain text */ public function unparse($text); } -- cgit v1.2.1 From c1bc05a8605ef34c12f42d0ac14e45cca6fbace3 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 17:07:58 +0100 Subject: [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index bad9190973..9576abe1f0 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -14,7 +14,7 @@ namespace phpbb\textformatter\s9e; use s9e\TextFormatter\Configurator; -use s9e\TextFormatter\Configurator\Items\AttributeFilters\Regexp as RegexpFilter; +use s9e\TextFormatter\Configurator\Items\AttributeFilters\RegexpFilter; use s9e\TextFormatter\Configurator\Items\UnsafeTemplate; /** -- cgit v1.2.1 From 0f30301a0cf01c609cdcd5e4d777a47872a4dcba Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 18:32:13 +0100 Subject: [ticket/11768] Moved parser/renderer setup events Moved down the setup events to make them happen after the service is configured and ready to be used PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 8 ++++---- phpBB/phpbb/textformatter/s9e/renderer.php | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index f220dd3e64..ab81a0ab4f 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -53,6 +53,10 @@ class parser implements \phpbb\textformatter\parser_interface $objects = $factory->regenerate(); $parser = $objects['parser']; } + + $this->dispatcher = $dispatcher; + $this->parser = $parser; + $this->user = $user; $self = $this; /** @@ -72,10 +76,6 @@ class parser implements \phpbb\textformatter\parser_interface */ $vars = array('parser', 'self', 'user'); extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars))); - - $this->dispatcher = $dispatcher; - $this->parser = $parser; - $this->user = $user; } /** diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 272cc5e6f3..28498150b3 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -92,6 +92,13 @@ class renderer implements \phpbb\textformatter\renderer_interface $objects = $factory->regenerate(); $renderer = $objects['renderer']; } + + if (isset($censor)) + { + $this->censor = $censor; + } + $this->dispatcher = $dispatcher; + $this->renderer = $renderer; $self = $this; /** @@ -104,13 +111,6 @@ class renderer implements \phpbb\textformatter\renderer_interface */ $vars = array('renderer', 'self'); extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars))); - - if (isset($censor)) - { - $this->censor = $censor; - } - $this->dispatcher = $dispatcher; - $this->renderer = $renderer; } /** -- cgit v1.2.1 From 3e04e643df4ca5463450df5d94f3caca3e5596c0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 01:12:57 +0100 Subject: [ticket/11768] Restored get_parser() / get_renderer() PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 10 ++++++++++ phpBB/phpbb/textformatter/s9e/renderer.php | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index ab81a0ab4f..fb6ef03c1c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -241,6 +241,16 @@ class parser implements \phpbb\textformatter\parser_interface return array_unique($errors); } + /** + * Return the instance of s9e\TextFormatter\Parser used by this object + * + * @return \s9e\TextFormatter\Parser + */ + public function get_parser() + { + return $this->parser; + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 28498150b3..02461b3849 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -163,6 +163,16 @@ class renderer implements \phpbb\textformatter\renderer_interface $this->renderer->setParameter('STYLE_ID', $user->style['style_id']); } + /** + * Return the instance of s9e\TextFormatter\Renderer used by this object + * + * @return \s9e\TextFormatter\Renderer + */ + public function get_renderer() + { + return $this->renderer; + } + /** * {@inheritdoc} */ -- cgit v1.2.1 From d8e7e11ee3a5c49e80a4ec3e0bdf2011ba5e9ce7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 01:29:09 +0100 Subject: [ticket/11768] Renamed service vars The name of the variable that holds the service instance is now consistent across events. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 17 ++++++++--------- phpBB/phpbb/textformatter/s9e/renderer.php | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index fb6ef03c1c..77328ee4d9 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -57,7 +57,7 @@ class parser implements \phpbb\textformatter\parser_interface $this->dispatcher = $dispatcher; $this->parser = $parser; $this->user = $user; - $self = $this; + $parser = $this; /** * Configure the parser service @@ -69,12 +69,11 @@ class parser implements \phpbb\textformatter\parser_interface * - configure the s9e\TextFormatter parser * * @event core.text_formatter_s9e_parser_setup - * @var \s9e\TextFormatter\Parser parser s9e\TextFormatter parser instance - * @var \phpbb\textformatter\s9e\parser self This parser service + * @var \phpbb\textformatter\s9e\parser parser This parser service * @var \phpbb\user user Current user * @since 3.2.0-a1 */ - $vars = array('parser', 'self', 'user'); + $vars = array('parser', 'user'); extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars))); } @@ -83,17 +82,17 @@ class parser implements \phpbb\textformatter\parser_interface */ public function parse($text) { - $self = $this; + $parser = $this; /** * Modify a text before it is parsed * * @event core.text_formatter_s9e_parse_before - * @var \phpbb\textformatter\s9e\parser self This parser service + * @var \phpbb\textformatter\s9e\parser parser This parser service * @var string text The original text * @since 3.2.0-a1 */ - $vars = array('self', 'text'); + $vars = array('parser', 'text'); extract($this->dispatcher->trigger_event('core.text_formatter_s9e_parse_before', compact($vars))); $xml = $this->parser->parse($text); @@ -102,11 +101,11 @@ class parser implements \phpbb\textformatter\parser_interface * Modify a parsed text in its XML form * * @event core.text_formatter_s9e_parse_after - * @var \phpbb\textformatter\s9e\parser self This parser service + * @var \phpbb\textformatter\s9e\parser parser This parser service * @var string xml The parsed text, in XML * @since 3.2.0-a1 */ - $vars = array('self', 'xml'); + $vars = array('parser', 'xml'); extract($this->dispatcher->trigger_event('core.text_formatter_s9e_parse_after', compact($vars))); return $xml; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 02461b3849..168b13e692 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -99,17 +99,16 @@ class renderer implements \phpbb\textformatter\renderer_interface } $this->dispatcher = $dispatcher; $this->renderer = $renderer; - $self = $this; + $renderer = $this; /** * Configure the renderer service * * @event core.text_formatter_s9e_renderer_setup - * @var \s9e\TextFormatter\Renderer renderer s9e\TextFormatter renderer instance - * @var \phpbb\textformatter\s9e\renderer self This renderer service + * @var \phpbb\textformatter\s9e\renderer renderer This renderer service * @since 3.2.0-a1 */ - $vars = array('renderer', 'self'); + $vars = array('renderer'); extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars))); } @@ -210,17 +209,17 @@ class renderer implements \phpbb\textformatter\renderer_interface */ public function render($xml) { - $self = $this; + $renderer = $this; /** * Modify a parsed text before it is rendered * * @event core.text_formatter_s9e_render_before - * @var \phpbb\textformatter\s9e\renderer self This renderer service + * @var \phpbb\textformatter\s9e\renderer renderer This renderer service * @var string xml The parsed text, in its XML form * @since 3.2.0-a1 */ - $vars = array('self', 'xml'); + $vars = array('renderer', 'xml'); extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_before', compact($vars))); if (isset($this->censor) && $this->viewcensors) @@ -267,10 +266,10 @@ class renderer implements \phpbb\textformatter\renderer_interface * * @event core.text_formatter_s9e_render_after * @var string html The rendered text's HTML - * @var \phpbb\textformatter\s9e\renderer self This renderer service + * @var \phpbb\textformatter\s9e\renderer renderer This renderer service * @since 3.2.0-a1 */ - $vars = array('html', 'self'); + $vars = array('html', 'renderer'); extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_after', compact($vars))); return $html; -- cgit v1.2.1 From 76088d64a69ac8fdd10b8a633e72eefc1e36321b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 01:52:26 +0100 Subject: [ticket/11768] Moved the routine that replaces tabs with spaces ...to its own method. Also added a quick stripos() check for performance. PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 44 +++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 168b13e692..7c58cd3d03 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -229,12 +229,37 @@ class renderer implements \phpbb\textformatter\renderer_interface } $html = $this->renderer->render($xml); + if (stripos($html, 'replace_tabs_in_code($html); + } /** - * @see bbcode::bbcode_second_pass_code() + * Modify a rendered text + * + * @event core.text_formatter_s9e_render_after + * @var string html The rendered text's HTML + * @var \phpbb\textformatter\s9e\renderer renderer This renderer service + * @since 3.2.0-a1 */ - $html = preg_replace_callback( - '#(]*>)(.*?)()#is', + $vars = array('html', 'renderer'); + extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_after', compact($vars))); + + return $html; + } + + /** + * Replace tabs in code elements + * + * @see bbcode::bbcode_second_pass_code() + * + * @param string $html Original HTML + * @return string Modified HTML + */ + protected function replace_tabs_in_code($html) + { + return preg_replace_callback( + '((]*>)(.*?)())is', function ($captures) { $code = $captures[2]; @@ -260,19 +285,6 @@ class renderer implements \phpbb\textformatter\renderer_interface }, $html ); - - /** - * Modify a rendered text - * - * @event core.text_formatter_s9e_render_after - * @var string html The rendered text's HTML - * @var \phpbb\textformatter\s9e\renderer renderer This renderer service - * @since 3.2.0-a1 - */ - $vars = array('html', 'renderer'); - extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_after', compact($vars))); - - return $html; } /** -- cgit v1.2.1 From 1d90daf96963de3349cecc54d36ae421a24e0612 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 29 Mar 2015 23:00:29 +0200 Subject: [ticket/11768] Added some default template parameters PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 7c58cd3d03..7c69f37371 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -158,8 +158,13 @@ class renderer implements \phpbb\textformatter\renderer_interface } } - // Set the style id - $this->renderer->setParameter('STYLE_ID', $user->style['style_id']); + // Set this user's style id and other parameters + $this->renderer->setParameters(array( + 'S_IS_BOT' => $user->data['is_bot'], + 'S_REGISTERED_USER' => $user->data['is_registered'], + 'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS), + 'STYLE_ID' => $user->style['style_id'], + )); } /** -- cgit v1.2.1 From b24e0f4f69b6436b3a654502d44d15333b0dfdc3 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 30 Mar 2015 03:31:38 +0200 Subject: [ticket/11768] Stylistic change. No functional change intended PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 7c69f37371..8999f1d25f 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -151,7 +151,7 @@ class renderer implements \phpbb\textformatter\renderer_interface // Set the stylesheet parameters foreach (array_keys($this->renderer->getParameters()) as $param_name) { - if (substr($param_name, 0, 2) === 'L_') + if (strpos($param_name, 'L_') === 0) { // L_FOO is set to $user->lang('FOO') $this->renderer->setParameter($param_name, $user->lang(substr($param_name, 2))); -- cgit v1.2.1 From f23fe9e69d5a49d983af1a06297c162bb2b97f05 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 16 Apr 2015 23:28:52 +0200 Subject: [ticket/13766] Add style_parent_id in textformater's data_access::get_styles() PHPBB3-13766 --- phpBB/phpbb/textformatter/data_access.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index 8938d66935..2103bf8e60 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -115,7 +115,7 @@ class data_access */ protected function get_styles() { - $sql = 'SELECT style_id, style_path, bbcode_bitfield FROM ' . $this->styles_table; + $sql = 'SELECT style_id, style_path, style_parent_id, bbcode_bitfield FROM ' . $this->styles_table; $result = $this->db->sql_query($sql); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); -- cgit v1.2.1 From 245d042e43374e6467f447507783a68fae186ef1 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Apr 2015 21:32:22 +0200 Subject: [ticket/8672] Updated the text_formatter.s9e service PHPBB3-8672 --- phpBB/phpbb/textformatter/s9e/parser.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 77328ee4d9..0582f235e0 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -367,7 +367,6 @@ class parser implements \phpbb\textformatter\parser_interface { // Validate the URL $url = BuiltInFilters::filterUrl($url, $url_config, $logger); - if ($url === false) { return false; @@ -375,26 +374,23 @@ class parser implements \phpbb\textformatter\parser_interface if ($max_height || $max_width) { - $stats = @getimagesize($url); - - if ($stats === false) + $imagesize = new \phpbb\upload\imagesize(); + $size_info = $imagesize->get_imagesize($url); + if ($size_info === false) { $logger->err('UNABLE_GET_IMAGE_SIZE'); - return false; } - if ($max_height && $max_height < $stats[1]) + if ($max_height && $max_height < $size_info['height']) { $logger->err('MAX_IMG_HEIGHT_EXCEEDED', array('max_height' => $max_height)); - return false; } - if ($max_width && $max_width < $stats[0]) + if ($max_width && $max_width < $size_info['width']) { $logger->err('MAX_IMG_WIDTH_EXCEEDED', array('max_width' => $max_width)); - return false; } } -- cgit v1.2.1 From 39d6180c6814996dde84cfcd8c0150bba37354ac Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 7 Apr 2015 16:19:36 +0200 Subject: [ticket/8672] Use fastImageSize in classes PHPBB3-8672 --- phpBB/phpbb/textformatter/s9e/parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 0582f235e0..e46a0578d2 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -374,8 +374,8 @@ class parser implements \phpbb\textformatter\parser_interface if ($max_height || $max_width) { - $imagesize = new \phpbb\upload\imagesize(); - $size_info = $imagesize->get_imagesize($url); + $imagesize = new \fastImageSize\fastImageSize(); + $size_info = $imagesize->getImageSize($url); if ($size_info === false) { $logger->err('UNABLE_GET_IMAGE_SIZE'); -- cgit v1.2.1 From 102b6c2df377759de8b17f3fe6fa7366fb7385dd Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 28 Apr 2015 02:40:33 +0200 Subject: [ticket/10922] Added support for body and subject in email BBCode PHPBB3-10922 --- phpBB/phpbb/textformatter/s9e/factory.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 9576abe1f0..a1bd43e40e 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -68,7 +68,7 @@ class factory implements \phpbb\textformatter\cache_interface 'b' => '[B]{TEXT}[/B]', 'code' => '[CODE]{TEXT}[/CODE]', 'color' => '[COLOR={COLOR}]{TEXT}[/COLOR]', - 'email' => '[EMAIL={EMAIL;useContent}]{TEXT}[/EMAIL]', + 'email' => '[EMAIL={EMAIL;useContent} subject={TEXT;optional;postFilter=urlencode} body={TEXT;optional;postFilter=urlencode}]{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}]', @@ -97,7 +97,18 @@ class factory implements \phpbb\textformatter\cache_interface 'img' => '{L_IMAGE}', 'size' => '', 'color' => '', - 'email' => '', + 'email' => ' + + mailto: + + + ? + subject= + &body= + + + + ', ); /** -- cgit v1.2.1 From 3f54fd49b5bf421852ceb2a54395d5ed353d2f29 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 28 Apr 2015 02:53:40 +0200 Subject: [ticket/10922] Replaced urlencode() with rawurlencode() RFC-6068 asks for percent-encoding so that seems more correct. Not sure about that one. PHPBB3-10922 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index a1bd43e40e..e07a1b52ca 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -68,7 +68,7 @@ class factory implements \phpbb\textformatter\cache_interface 'b' => '[B]{TEXT}[/B]', 'code' => '[CODE]{TEXT}[/CODE]', 'color' => '[COLOR={COLOR}]{TEXT}[/COLOR]', - 'email' => '[EMAIL={EMAIL;useContent} subject={TEXT;optional;postFilter=urlencode} body={TEXT;optional;postFilter=urlencode}]{TEXT}[/EMAIL]', + 'email' => '[EMAIL={EMAIL;useContent} subject={TEXT;optional;postFilter=rawurlencode} body={TEXT;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}]', -- cgit v1.2.1 From f5ce9f273829ba470a1348b4314cddb58f552da0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 3 May 2015 16:06:42 +0200 Subject: [ticket/13680] Updated quote notifications Added get_quote_authors() to text_formatter.utils service to retrieve the names used in first-level quotes PHPBB3-13680 --- phpBB/phpbb/textformatter/s9e/utils.php | 25 +++++++++++++++++++++++++ phpBB/phpbb/textformatter/utils_interface.php | 8 ++++++++ 2 files changed, 33 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 2018bbf519..576ab9481c 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -34,6 +34,31 @@ class utils implements \phpbb\textformatter\utils_interface return \s9e\TextFormatter\Utils::removeFormatting($xml); } + /** + * Get a list of quote authors, limited to the first level of quotes + * + * @param string $xml Parsed text + * @return string[] List of authors + */ + public function get_quote_authors($xml) + { + $authors = array(); + if (strpos($xml, 'loadXML($xml); + $xpath = new \DOMXPath($dom); + foreach ($xpath->query('//QUOTE[not(ancestor::QUOTE)]/@author') as $author) + { + $authors[] = $author->textContent; + } + + return $authors; + } + /** * Remove given BBCode and its content, at given nesting depth * diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 132dc8ece4..183c426161 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -28,6 +28,14 @@ interface utils_interface */ public function clean_formatting($text); + /** + * Get a list of quote authors, limited to the first level of quotes + * + * @param string $text Parsed text + * @return string[] List of authors + */ + public function get_quote_authors($text); + /** * Remove given BBCode and its content, at given nesting depth * -- cgit v1.2.1 From f7ad2c2b32b309edba006a8d4b58727b50642ea2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 15 May 2015 02:12:52 +0200 Subject: [ticket/13680] Renamed get_quote_authors to get_outermost_quote_authors PHPBB3-13680 --- phpBB/phpbb/textformatter/s9e/utils.php | 4 ++-- phpBB/phpbb/textformatter/utils_interface.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 576ab9481c..e21dedecc4 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -35,12 +35,12 @@ class utils implements \phpbb\textformatter\utils_interface } /** - * Get a list of quote authors, limited to the first level of quotes + * Get a list of quote authors, limited to the outermost quotes * * @param string $xml Parsed text * @return string[] List of authors */ - public function get_quote_authors($xml) + public function get_outermost_quote_authors($xml) { $authors = array(); if (strpos($xml, ' Date: Thu, 30 Apr 2015 23:01:28 +0200 Subject: [ticket/13801] Removed user dependency from text_formatter.s9e.parser PHPBB3-13801 --- phpBB/phpbb/textformatter/s9e/parser.php | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index e46a0578d2..178669d84f 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -31,21 +31,15 @@ class parser implements \phpbb\textformatter\parser_interface */ protected $parser; - /** - * @var \phpbb\user User object, used for translating errors - */ - protected $user; - /** * Constructor * * @param \phpbb\cache\driver_interface $cache * @param string $key Cache key - * @param \phpbb\user $user * @param factory $factory * @param \phpbb\event\dispatcher_interface $dispatcher */ - public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory, \phpbb\event\dispatcher_interface $dispatcher) + public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, factory $factory, \phpbb\event\dispatcher_interface $dispatcher) { $parser = $cache->get($key); if (!$parser) @@ -56,24 +50,20 @@ class parser implements \phpbb\textformatter\parser_interface $this->dispatcher = $dispatcher; $this->parser = $parser; - $this->user = $user; $parser = $this; /** * Configure the parser service * * Can be used to: - * - toggle features according to the user's preferences, - * - toggle BBCodes according to the user's permissions, * - register variables or custom parsers in the s9e\TextFormatter * - configure the s9e\TextFormatter parser * * @event core.text_formatter_s9e_parser_setup * @var \phpbb\textformatter\s9e\parser parser This parser service - * @var \phpbb\user user Current user * @since 3.2.0-a1 */ - $vars = array('parser', 'user'); + $vars = array('parser'); extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars))); } @@ -202,7 +192,6 @@ class parser implements \phpbb\textformatter\parser_interface public function get_errors() { $errors = array(); - foreach ($this->parser->getLogger()->get() as $entry) { list($type, $msg, $context) = $entry; @@ -211,29 +200,29 @@ class parser implements \phpbb\textformatter\parser_interface { if ($context['tagName'] === 'E') { - $errors[] = $this->user->lang('TOO_MANY_SMILIES', $context['tagLimit']); + $errors[] = array('TOO_MANY_SMILIES', $context['tagLimit']); } else if ($context['tagName'] === 'URL') { - $errors[] = $this->user->lang('TOO_MANY_URLS', $context['tagLimit']); + $errors[] = array('TOO_MANY_URLS', $context['tagLimit']); } } else if ($msg === 'MAX_FONT_SIZE_EXCEEDED') { - $errors[] = $this->user->lang($msg, $context['max_size']); + $errors[] = array($msg, $context['max_size']); } else if (preg_match('/^MAX_(?:FLASH|IMG)_(HEIGHT|WIDTH)_EXCEEDED$/D', $msg, $m)) { - $errors[] = $this->user->lang($msg, $context['max_' . strtolower($m[1])]); + $errors[] = array($msg, $context['max_' . strtolower($m[1])]); } else if ($msg === 'Tag is disabled') { $name = strtolower($context['tag']->getName()); - $errors[] = $this->user->lang('UNAUTHORISED_BBCODE', '[' . $name . ']'); + $errors[] = array('UNAUTHORISED_BBCODE', '[' . $name . ']'); } else if ($msg === 'UNABLE_GET_IMAGE_SIZE') { - $errors[] = $this->user->lang($msg); + $errors[] = array($msg); } } -- cgit v1.2.1 From 7b552152b416d9f0c2e873f6f70c4d3cec575ea6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 8 May 2015 14:51:46 +0200 Subject: [ticket/13801] Updated comments for clarity PHPBB3-13801 --- phpBB/phpbb/textformatter/parser_interface.php | 3 ++- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/parser_interface.php b/phpBB/phpbb/textformatter/parser_interface.php index 3cb9f8e977..ad611fb5b4 100644 --- a/phpBB/phpbb/textformatter/parser_interface.php +++ b/phpBB/phpbb/textformatter/parser_interface.php @@ -82,7 +82,8 @@ interface parser_interface /** * Get the list of errors that were generated during last parsing * - * @return array + * @return array[] Array of arrays. Each array contains a lang string at index 0 plus any number + * of optional parameters */ public function get_errors(); diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 178669d84f..ee033f6d21 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -186,7 +186,7 @@ class parser implements \phpbb\textformatter\parser_interface /** * {@inheritdoc} * - * This will translate the log entries found in s9e\TextFormatter's logger into phpBB error + * This will convert the log entries found in s9e\TextFormatter's logger into phpBB error * messages */ public function get_errors() -- cgit v1.2.1 From 5772e06b1aace1d5fbef263217e71ad10347364d Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 17 May 2015 14:09:02 +0200 Subject: [ticket/13801] Updated event description [ci skip] PHPBB3-13801 --- phpBB/phpbb/textformatter/s9e/parser.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index ee033f6d21..b7d0b2b90b 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -56,8 +56,9 @@ class parser implements \phpbb\textformatter\parser_interface * Configure the parser service * * Can be used to: - * - register variables or custom parsers in the s9e\TextFormatter - * - configure the s9e\TextFormatter parser + * - toggle features or BBCodes + * - register variables or custom parsers in the s9e\TextFormatter parser + * - configure the s9e\TextFormatter parser's runtime settings * * @event core.text_formatter_s9e_parser_setup * @var \phpbb\textformatter\s9e\parser parser This parser service -- cgit v1.2.1 From 92078dce3393ea705361e1c3c0a332db778ccb0a Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 29 Apr 2015 23:22:30 +0200 Subject: [ticket/11742] Removed tabs-to-space conversion in [code] PHPBB3-11742 --- phpBB/phpbb/textformatter/s9e/renderer.php | 43 ------------------------------ 1 file changed, 43 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 8999f1d25f..51bc44f339 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -234,10 +234,6 @@ class renderer implements \phpbb\textformatter\renderer_interface } $html = $this->renderer->render($xml); - if (stripos($html, 'replace_tabs_in_code($html); - } /** * Modify a rendered text @@ -253,45 +249,6 @@ class renderer implements \phpbb\textformatter\renderer_interface return $html; } - /** - * Replace tabs in code elements - * - * @see bbcode::bbcode_second_pass_code() - * - * @param string $html Original HTML - * @return string Modified HTML - */ - protected function replace_tabs_in_code($html) - { - return preg_replace_callback( - '((]*>)(.*?)())is', - function ($captures) - { - $code = $captures[2]; - - $code = str_replace("\t", '   ', $code); - $code = str_replace(' ', '  ', $code); - $code = str_replace(' ', '  ', $code); - $code = str_replace("\n ", "\n ", $code); - - // keep space at the beginning - if (!empty($code) && $code[0] == ' ') - { - $code = ' ' . substr($code, 1); - } - - // remove newline at the beginning - if (!empty($code) && $code[0] == "\n") - { - $code = substr($code, 1); - } - - return $captures[1] . $code . $captures[3]; - }, - $html - ); - } - /** * {@inheritdoc} */ -- cgit v1.2.1 From 8a077e0e943d87ee1d26b0501f0b9bcc472ab904 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 17 May 2015 20:15:06 +0200 Subject: [ticket/13847] Move quote generation to text_formatter.utils PHPBB3-13847 --- phpBB/phpbb/textformatter/s9e/utils.php | 37 +++++++++++++++++++++++++++ phpBB/phpbb/textformatter/utils_interface.php | 12 +++++++++ 2 files changed, 49 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index e21dedecc4..fe33c04da3 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -34,6 +34,43 @@ class utils implements \phpbb\textformatter\utils_interface return \s9e\TextFormatter\Utils::removeFormatting($xml); } + /** + * Return given string between quotes + * + * Will use either single- or double- quotes depending on whichever requires to be escaped. + * Quotes and backslashes are escaped with backslashes where necessary + * + * @param string $str Original string + * @return string Escaped string within quotes + */ + protected function enquote($str) + { + $quote = (strpos($str, '"') === false || strpos($str, "'") !== false) ? '"' : "'"; + + return $quote . addcslashes($str, '\\' . $quote) . $quote; + } + + /** + * {@inheritdoc} + */ + public function generate_quote($text, array $attributes = array()) + { + $quote = '[quote'; + if (isset($attributes['author'])) + { + // Add the author as the BBCode's default attribute + $quote .= '=' . $this->enquote($attributes['author']); + unset($attributes['author']); + } + foreach ($attributes as $name => $value) + { + $quote .= ' ' . $name . '=' . $this->enquote($value); + } + $quote .= ']' . $text . '[/quote]'; + + return $quote; + } + /** * Get a list of quote authors, limited to the outermost quotes * diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 6d3fd13021..41a6ba2345 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -28,6 +28,18 @@ interface utils_interface */ public function clean_formatting($text); + /** + * Create a quote block for given text + * + * Possible attributes: + * - author + * + * @param string $text Quote's text + * @param array $attributes Quote's attributes + * @return string Quote block to be used in a new post/text + */ + public function generate_quote($text, array $attributes = array()); + /** * Get a list of quote authors, limited to the outermost quotes * -- cgit v1.2.1 From e50d9186ce15367e8f6e2aab5c04481ca0046ec6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 19 May 2015 23:10:35 +0200 Subject: [ticket/13847] Changed enquote() logic to use whichever is the shortest Will enclose attribute values in single- or double- quotes depending on whichever requires the least escaping. Characters that need to be escaped are always escaped regardless. PHPBB3-13847 --- phpBB/phpbb/textformatter/s9e/utils.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index fe33c04da3..04df589930 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -37,7 +37,7 @@ class utils implements \phpbb\textformatter\utils_interface /** * Return given string between quotes * - * Will use either single- or double- quotes depending on whichever requires to be escaped. + * Will use either single- or double- quotes depending on whichever requires less escaping. * Quotes and backslashes are escaped with backslashes where necessary * * @param string $str Original string @@ -45,9 +45,10 @@ class utils implements \phpbb\textformatter\utils_interface */ protected function enquote($str) { - $quote = (strpos($str, '"') === false || strpos($str, "'") !== false) ? '"' : "'"; + $singleQuoted = "'" . addcslashes($str, "\\'") . "'"; + $doubleQuoted = '"' . addcslashes($str, '\\"') . '"'; - return $quote . addcslashes($str, '\\' . $quote) . $quote; + return (strlen($singleQuoted) < strlen($doubleQuoted)) ? $singleQuoted : $doubleQuoted; } /** -- cgit v1.2.1 From e0f7c225bc8f6cf8e62dcfc146bdd630e15b6e22 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 28 May 2015 12:23:45 +0200 Subject: [ticket/13860] Fixed array-to-string conversion PHPBB3-13860 --- phpBB/phpbb/textformatter/s9e/parser.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index b7d0b2b90b..838c211e56 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -227,7 +227,13 @@ class parser implements \phpbb\textformatter\parser_interface } } - return array_unique($errors); + // Deduplicate error messages. array_unique() only works on strings so we have to serialize + if (!empty($errors)) + { + $errors = array_map('unserialize', array_unique(array_map('serialize', $errors))); + } + + return $errors; } /** -- cgit v1.2.1 From 2f0d11ba3c28f27e535988de2a8d08f7b17aef92 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 30 May 2015 22:17:14 +0200 Subject: [ticket/13901] Add more whitespace to long quotes for readability PHPBB3-13901 --- phpBB/phpbb/textformatter/s9e/utils.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 04df589930..64fdb628ca 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -56,6 +56,7 @@ class utils implements \phpbb\textformatter\utils_interface */ public function generate_quote($text, array $attributes = array()) { + $text = trim($text); $quote = '[quote'; if (isset($attributes['author'])) { @@ -67,7 +68,9 @@ class utils implements \phpbb\textformatter\utils_interface { $quote .= ' ' . $name . '=' . $this->enquote($value); } - $quote .= ']' . $text . '[/quote]'; + $quote .= ']'; + $newline = (strlen($quote . $text . '[/quote]') > 80) ? "\n" : ''; + $quote .= $newline . $text . $newline . '[/quote]'; return $quote; } -- cgit v1.2.1 From b69e33c2b0dfaaf9274e783cd189a8d1d49bce07 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 30 May 2015 22:20:52 +0200 Subject: [ticket/13901] Add whitespace to short, multiline quotes for readability PHPBB3-13901 --- phpBB/phpbb/textformatter/s9e/utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 64fdb628ca..803c71a5a2 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -69,7 +69,7 @@ class utils implements \phpbb\textformatter\utils_interface $quote .= ' ' . $name . '=' . $this->enquote($value); } $quote .= ']'; - $newline = (strlen($quote . $text . '[/quote]') > 80) ? "\n" : ''; + $newline = (strlen($quote . $text . '[/quote]') > 80 || strpos($text, "\n") !== false) ? "\n" : ''; $quote .= $newline . $text . $newline . '[/quote]'; return $quote; -- cgit v1.2.1 From f02cc27014c27acaf44b27066959426db27b3493 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 16 Jun 2015 08:16:56 +0200 Subject: [ticket/10620] Implemented quote improvements PHPBB3-10620 --- phpBB/phpbb/textformatter/s9e/factory.php | 28 ++++----- phpBB/phpbb/textformatter/s9e/quote_helper.php | 81 ++++++++++++++++++++++++++ phpBB/phpbb/textformatter/s9e/renderer.php | 19 ++++++ phpBB/phpbb/textformatter/s9e/utils.php | 1 + 4 files changed, 111 insertions(+), 18 deletions(-) create mode 100644 phpBB/phpbb/textformatter/s9e/quote_helper.php (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index e07a1b52ca..cd4e593fb1 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -77,7 +77,12 @@ class factory implements \phpbb\textformatter\cache_interface 'quote' => "[QUOTE author={TEXT1;optional} + post_id={UINT;optional} + post_url={URL;optional;postFilter=#false} + profile_url={URL;optional;postFilter=#false} + time={UINT;optional} url={URL;optional} + user_id={UINT;optional} author={PARSE=/^\\[url=(?'url'.*?)](?'author'.*)\\[\\/url]$/i} author={PARSE=/^\\[url](?'author'(?'url'.*?))\\[\\/url]$/i} author={PARSE=/(?'url'https?:\\/\\/[^[\\]]+)/i} @@ -471,24 +476,11 @@ class factory implements \phpbb\textformatter\cache_interface $templates['li'] = $fragments['listitem'] . '' . $fragments['listitem_close']; - $fragments['quote_username_open'] = str_replace( - '{USERNAME}', - ' - ' . str_replace('{DESCRIPTION}', '{USERNAME}', $fragments['url']) . ' - {USERNAME} - ', - $fragments['quote_username_open'] - ); - - $templates['quote'] = - ' - - ' . $fragments['quote_username_open'] . '' . $fragments['quote_close'] . ' - - - ' . $fragments['quote_open'] . '' . $fragments['quote_close'] . ' - - '; + // Replace the regular quote template with the extended quote template if available + if (isset($fragments['quote_extended'])) + { + $templates['quote'] = $fragments['quote_extended']; + } // The [attachment] BBCode uses the inline_attachment template to output a comment that // is post-processed by parse_attachments() diff --git a/phpBB/phpbb/textformatter/s9e/quote_helper.php b/phpBB/phpbb/textformatter/s9e/quote_helper.php new file mode 100644 index 0000000000..24109ac8cc --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/quote_helper.php @@ -0,0 +1,81 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +class quote_helper +{ + /** + * @var string Base URL for a post link, uses {POST_ID} as placeholder + */ + protected $post_url; + + /** + * @var string Base URL for a profile link, uses {USER_ID} as placeholder + */ + protected $profile_url; + + /** + * @var \phpbb\user + */ + protected $user; + + /** + * Constructor + * + * @param \phpbb\user $user + * @param string $root_path + * @param string $php_ext + */ + public function __construct(\phpbb\user $user, $root_path, $php_ext) + { + $this->post_url = append_sid($root_path . 'viewtopic.' . $php_ext, 'p={POST_ID}#p{POST_ID}'); + $this->profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=viewprofile&u={USER_ID}'); + $this->user = $user; + } + + /** + * Inject dynamic metadata into QUOTE tags in given XML + * + * @param string $xml Original XML + * @return string Modified XML + */ + public function inject_metadata($xml) + { + $post_url = $this->post_url; + $profile_url = $this->profile_url; + $user = $this->user; + + return \s9e\TextFormatter\Utils::replaceAttributes( + $xml, + 'QUOTE', + function ($attributes) use ($post_url, $profile_url, $user) + { + if (isset($attributes['post_id'])) + { + $attributes['post_url'] = str_replace('{POST_ID}', $attributes['post_id'], $post_url); + } + if (isset($attributes['time'])) + { + $attributes['date'] = $user->format_date($attributes['time']); + } + if (isset($attributes['user_id'])) + { + $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $profile_url); + } + + return $attributes; + } + ); + } +} diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 51bc44f339..2206605ba2 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -28,6 +28,11 @@ class renderer implements \phpbb\textformatter\renderer_interface */ protected $dispatcher; + /** + * @var quote_helper + */ + protected $quote_helper; + /** * @var \s9e\TextFormatter\Renderer */ @@ -112,6 +117,16 @@ class renderer implements \phpbb\textformatter\renderer_interface extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars))); } + /** + * Configure the quote_helper object used to display extended information in quotes + * + * @param quote_helper $quote_helper + */ + public function configure_quote_helper(quote_helper $quote_helper) + { + $this->quote_helper = $quote_helper; + } + /** * Automatically set the smilies path based on config * @@ -214,6 +229,10 @@ class renderer implements \phpbb\textformatter\renderer_interface */ public function render($xml) { + if (isset($this->quote_helper)) + { + $xml = $this->quote_helper->inject_metadata($xml); + } $renderer = $this; /** diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 803c71a5a2..df1966fa32 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -64,6 +64,7 @@ class utils implements \phpbb\textformatter\utils_interface $quote .= '=' . $this->enquote($attributes['author']); unset($attributes['author']); } + ksort($attributes); foreach ($attributes as $name => $value) { $quote .= ' ' . $name . '=' . $this->enquote($value); -- cgit v1.2.1 From c934b8f150c81115062687e59988ca0f78b35c37 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 20 Jun 2015 17:18:46 +0200 Subject: [ticket/10620] Updated docblock PHPBB3-10620 --- phpBB/phpbb/textformatter/utils_interface.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 41a6ba2345..4810453cd1 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -32,7 +32,10 @@ interface utils_interface * Create a quote block for given text * * Possible attributes: - * - author + * - author: author's name (usually a username) + * - post_id: post_id of the post being quoted + * - user_id: user_id of the user being quoted + * - time: timestamp of the original message * * @param string $text Quote's text * @param array $attributes Quote's attributes -- cgit v1.2.1 From 4f1b25706f6a1ae6eb1c6c60ef27b42bb7ac4b40 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 24 Jun 2015 22:20:39 +0200 Subject: [ticket/10620] Removed extraneous quotes from attribute values PHPBB3-10620 --- phpBB/phpbb/textformatter/s9e/utils.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index df1966fa32..40479b3423 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -35,16 +35,22 @@ class utils implements \phpbb\textformatter\utils_interface } /** - * Return given string between quotes + * Format given string to be used as an attribute value * - * Will use either single- or double- quotes depending on whichever requires less escaping. + * Will return the string as-is if it can be used in a BBCode without quotes. Otherwise, + * it will use either single- or double- quotes depending on whichever requires less escaping. * Quotes and backslashes are escaped with backslashes where necessary * * @param string $str Original string - * @return string Escaped string within quotes + * @return string Same string if possible, escaped string within quotes otherwise */ - protected function enquote($str) + protected function format_attribute_value($str) { + if (!preg_match('/[ "\'\\\\\\]]/', $str)) + { + // Return as-is if it contains none of: space, ' " \ or ] + return $str; + } $singleQuoted = "'" . addcslashes($str, "\\'") . "'"; $doubleQuoted = '"' . addcslashes($str, '\\"') . '"'; @@ -61,13 +67,13 @@ class utils implements \phpbb\textformatter\utils_interface if (isset($attributes['author'])) { // Add the author as the BBCode's default attribute - $quote .= '=' . $this->enquote($attributes['author']); + $quote .= '=' . $this->format_attribute_value($attributes['author']); unset($attributes['author']); } ksort($attributes); foreach ($attributes as $name => $value) { - $quote .= ' ' . $name . '=' . $this->enquote($value); + $quote .= ' ' . $name . '=' . $this->format_attribute_value($value); } $quote .= ']'; $newline = (strlen($quote . $text . '[/quote]') > 80 || strpos($text, "\n") !== false) ? "\n" : ''; -- cgit v1.2.1 From 353b3b4cfd7133ea0cef4a7fdb34d0451b16a0dd Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 27 Jun 2015 12:33:44 +0200 Subject: [ticket/13970] Save the value of the optional [code] parameter PHPBB3-13970 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index e07a1b52ca..7ad728e6cc 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -66,7 +66,7 @@ class factory implements \phpbb\textformatter\cache_interface protected $default_definitions = array( 'attachment' => '[ATTACHMENT index={NUMBER} filename={TEXT;useContent}]', 'b' => '[B]{TEXT}[/B]', - 'code' => '[CODE]{TEXT}[/CODE]', + '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]', 'flash' => '[FLASH={NUMBER1},{NUMBER2} width={NUMBER1;postFilter=#flashwidth} height={NUMBER2;postFilter=#flashheight} url={URL;useContent} /]', -- cgit v1.2.1 From ca671708cb3ed4fbf218373f5ac310cf955676a4 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 12 Jul 2015 18:55:23 +0200 Subject: [ticket/14000] Added support for emoji PHPBB3-14000 --- phpBB/phpbb/textformatter/s9e/factory.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 2f6498197f..2aab97b667 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -324,6 +324,11 @@ class factory implements \phpbb\textformatter\cache_interface $configurator->registeredVars['max_img_height'] = 0; $configurator->registeredVars['max_img_width'] = 0; + // Load the Emoji plugin and modify its tag's template to obey viewsmilies + $configurator->Emoji->setImageSize(18); + $tag = $configurator->Emoji->getTag(); + $tag->template = '' . str_replace('class="emoji"', 'class="smilies"', $tag->template) . ''; + /** * Modify the s9e\TextFormatter configurator after the default settings are set * -- cgit v1.2.1 From 675cf5e897944318f9666b088a5053f339fe1032 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 13 Jul 2015 16:08:57 +0200 Subject: [ticket/14008] Do not add a user_id value to quotes from guests PHPBB3-14008 --- phpBB/phpbb/textformatter/s9e/utils.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 40479b3423..b317fe4a8d 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -70,6 +70,12 @@ class utils implements \phpbb\textformatter\utils_interface $quote .= '=' . $this->format_attribute_value($attributes['author']); unset($attributes['author']); } + + if (isset($attributes['user_id']) && $attributes['user_id'] == ANONYMOUS) + { + unset($attributes['user_id']); + } + ksort($attributes); foreach ($attributes as $name => $value) { -- cgit v1.2.1 From da7fc9e5daf6e72f9b86dbc5e002febb202f516e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 10 Jun 2015 15:11:27 +0200 Subject: [ticket/13935] Allow more admin-configurable schemes in post links PHPBB3-13935 --- phpBB/phpbb/textformatter/s9e/factory.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 2aab97b667..4a04b34cd8 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -42,6 +42,11 @@ class factory implements \phpbb\textformatter\cache_interface */ protected $cache_key_renderer; + /** + * @var \phpbb\config\config + */ + protected $config; + /** * @var array Custom tokens used in bbcode.html and their corresponding token from the definition */ @@ -127,16 +132,18 @@ class factory implements \phpbb\textformatter\cache_interface * @param \phpbb\textformatter\data_access $data_access * @param \phpbb\cache\driver\driver_interface $cache * @param \phpbb\event\dispatcher_interface $dispatcher + * @param \phpbb\config\config $config * @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, $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, $cache_dir, $cache_key_parser, $cache_key_renderer) { $this->cache = $cache; $this->cache_dir = $cache_dir; $this->cache_key_parser = $cache_key_parser; $this->cache_key_renderer = $cache_key_renderer; + $this->config = $config; $this->data_access = $data_access; $this->dispatcher = $dispatcher; } @@ -190,6 +197,16 @@ class factory implements \phpbb\textformatter\cache_interface $vars = array('configurator'); extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_before', compact($vars))); + // Reset the list of allowed schemes + foreach ($configurator->urlConfig->getAllowedSchemes() as $scheme) + { + $configurator->urlConfig->disallowScheme($scheme); + } + foreach (explode(',', $this->config['allowed_schemes_links']) as $scheme) + { + $configurator->urlConfig->allowScheme(trim($scheme)); + } + // Convert newlines to br elements by default $configurator->rootRules->enableAutoLineBreaks(); -- cgit v1.2.1 From e19d446881ba98d8a1082732585da3f6d4bd262f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 26 Aug 2015 10:05:14 -0700 Subject: [ticket/14128] Fix img bbcode regression, lost postimage class PHPBB3-14128 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 4a04b34cd8..63b23d2fd0 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -104,7 +104,7 @@ class factory implements \phpbb\textformatter\cache_interface 'b' => '', 'i' => '', 'u' => '', - 'img' => '{L_IMAGE}', + 'img' => '{L_IMAGE}', 'size' => '', 'color' => '', 'email' => ' -- cgit v1.2.1 From 58286171f1035495c8c2a6fdffce9f3842601e66 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Sep 2015 12:59:55 +0200 Subject: [ticket/14150] Update fast-image-size to newest version PHPBB3-14150 --- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 838c211e56..ffaffbc63c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -370,7 +370,7 @@ class parser implements \phpbb\textformatter\parser_interface if ($max_height || $max_width) { - $imagesize = new \fastImageSize\fastImageSize(); + $imagesize = new \FastImageSize\FastImageSize(); $size_info = $imagesize->getImageSize($url); if ($size_info === false) { -- cgit v1.2.1 From eb6ceb963ea7b32ef852b53d3da3a7e795291359 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 5 Dec 2015 07:55:52 +0100 Subject: [ticket/14323] Added support for truncating long URLs PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/factory.php | 28 ++++++++++++++++++++-- phpBB/phpbb/textformatter/s9e/parser.php | 40 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 63b23d2fd0..dd3102d4de 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -332,8 +332,7 @@ class factory implements \phpbb\textformatter\cache_interface } // Load the magic links plugins. We do that after BBCodes so that they use the same tags - $configurator->plugins->load('Autoemail'); - $configurator->plugins->load('Autolink', array('matchWww' => true)); + $this->configure_autolink($configurator); // Register some vars with a default value. Those should be set at runtime by whatever calls // the parser @@ -394,6 +393,31 @@ class factory implements \phpbb\textformatter\cache_interface return array('parser' => $parser, 'renderer' => $renderer); } + /** + * Configure the Autolink / Autoemail plugins used to linkify text + * + * @param \s9e\TextFormatter\Configurator $configurator + * @return void + */ + protected function configure_autolink(Configurator $configurator) + { + $configurator->plugins->load('Autoemail'); + $configurator->plugins->load('Autolink', array('matchWww' => true)); + + // Create a tag that will be used to display the truncated text by replacing the original + // content with the content of the @text attribute + $tag = $configurator->tags->add('AUTOLINK_TEXT'); + $tag->attributes->add('text'); + $tag->template = ''; + + // Add a tag filter that replaces the text of links that were created by the Autolink plugin + $configurator->Autolink->getTag()->filterChain + ->add(__NAMESPACE__ . '\\parser::generate_autolink_text') + ->resetParameters() + ->addParameterByName('tag') + ->addParameterByName('parser'); + } + /** * Return the default BBCodes configuration * diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index ffaffbc63c..faddc806cd 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -393,4 +393,44 @@ class parser implements \phpbb\textformatter\parser_interface return $url; } + + /** + * Replace the content displayed inside of a URL tag + * + * Will only apply to URL tags that do not use any markup (e.g. not "[url]") on the assumption + * that those tags were created by the Autolink plugin to linkify URLs found in plain text + * + * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) + * @param \s9e\TextFormatter\Parser $parser Parser + * @return bool Always TRUE to indicate that the tag is valid + */ + public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser) + { + // If the tag consumes any text then we ignore it because it's not a linkified URL. Same if + // it's not paired with an end tag that doesn't consume any text either + if ($url_tag->getLen() > 0 || !$url_tag->getEndTag()) + { + return true; + } + + // Capture the text between the start tag and its end tag + $start = $url_tag->getPos(); + $end = $url_tag->getEndTag()->getPos(); + $length = $end - $start; + $text = substr($parser->getText(), $start, $length); + + if ($length <= 55 || utf8_strlen($text) <= 55) + { + // Do not do anything if the text is not longer than 55 characters + return true; + } + + $tag = $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length); + $url_tag->cascadeInvalidationTo($tag); + + $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + $tag->setAttribute('text', $text); + + return true; + } } -- cgit v1.2.1 From 8fe94a19b46c4e33a117c1a040415f2b1c397e7c Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 5 Dec 2015 19:48:01 +0100 Subject: [ticket/14323] Added support for truncating local URLs PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 ++- phpBB/phpbb/textformatter/s9e/parser.php | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index dd3102d4de..63e49b6dd4 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -415,7 +415,8 @@ class factory implements \phpbb\textformatter\cache_interface ->add(__NAMESPACE__ . '\\parser::generate_autolink_text') ->resetParameters() ->addParameterByName('tag') - ->addParameterByName('parser'); + ->addParameterByName('parser') + ->addParameterByValue(generate_board_url() . '/'); } /** diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index faddc806cd..d8a2b8d62c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -400,11 +400,12 @@ class parser implements \phpbb\textformatter\parser_interface * Will only apply to URL tags that do not use any markup (e.g. not "[url]") on the assumption * that those tags were created by the Autolink plugin to linkify URLs found in plain text * - * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) - * @param \s9e\TextFormatter\Parser $parser Parser - * @return bool Always TRUE to indicate that the tag is valid + * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) + * @param \s9e\TextFormatter\Parser $parser Parser + * @param string $board_url Forum's root URL (with trailing slash) + * @return bool Always TRUE to indicate that the tag is valid */ - public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser) + public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser, $board_url) { // If the tag consumes any text then we ignore it because it's not a linkified URL. Same if // it's not paired with an end tag that doesn't consume any text either @@ -419,16 +420,20 @@ class parser implements \phpbb\textformatter\parser_interface $length = $end - $start; $text = substr($parser->getText(), $start, $length); - if ($length <= 55 || utf8_strlen($text) <= 55) + // Remove the board's root URL from the link if applicable + if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url)) { - // Do not do anything if the text is not longer than 55 characters - return true; + $text = substr($text, strlen($board_url)); } - $tag = $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length); - $url_tag->cascadeInvalidationTo($tag); + // Truncate the text if it's longer than 55 characters + if (utf8_strlen($text) > 55) + { + $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + } - $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + // Create a tag that consumes the link's text + $tag = $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length); $tag->setAttribute('text', $text); return true; -- cgit v1.2.1 From 9a8fb2e1df0d63f46ee0a6e4b64dc8530b8db809 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 6 Dec 2015 15:11:26 +0100 Subject: [ticket/14323] Stylistic change [ci skip] PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/parser.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index d8a2b8d62c..beb737c816 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -397,18 +397,20 @@ class parser implements \phpbb\textformatter\parser_interface /** * Replace the content displayed inside of a URL tag * - * Will only apply to URL tags that do not use any markup (e.g. not "[url]") on the assumption - * that those tags were created by the Autolink plugin to linkify URLs found in plain text + * Will only apply to URL tags that do not use any markup (e.g. not "[url]") + * on the assumption that those tags were created by the Autolink plugin to + * linkify URLs found in plain text * * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) * @param \s9e\TextFormatter\Parser $parser Parser * @param string $board_url Forum's root URL (with trailing slash) - * @return bool Always TRUE to indicate that the tag is valid + * @return bool Always true to indicate that the tag is valid */ public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser, $board_url) { - // If the tag consumes any text then we ignore it because it's not a linkified URL. Same if - // it's not paired with an end tag that doesn't consume any text either + // If the tag consumes any text then we ignore it because it's not a + // linkified URL. Same if it's not paired with an end tag that doesn't + // consume any text either if ($url_tag->getLen() > 0 || !$url_tag->getEndTag()) { return true; -- cgit v1.2.1 From ad2c032d3b748d177403fd495685977f7964f8d4 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 6 Dec 2015 22:08:00 +0100 Subject: [ticket/14323] Moved autolink-related functions to a separate helper PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/autolink_helper.php | 105 ++++++++++++++++++++++ phpBB/phpbb/textformatter/s9e/factory.php | 37 ++++++-- phpBB/phpbb/textformatter/s9e/parser.php | 47 ---------- 3 files changed, 135 insertions(+), 54 deletions(-) create mode 100644 phpBB/phpbb/textformatter/s9e/autolink_helper.php (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/autolink_helper.php b/phpBB/phpbb/textformatter/s9e/autolink_helper.php new file mode 100644 index 0000000000..8fb171f413 --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/autolink_helper.php @@ -0,0 +1,105 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +class autolink_helper +{ + /** + * Clean up and invalidate an AUTOLINK_TEXT tag if applicable + * + * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag + * @param \s9e\TextFormatter\Parser $parser Parser + * @return bool Whether the tag is valid + */ + public function cleanup_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) + { + // Remove the url attribute because it's not needed. + $tag->removeAttribute('url'); + + // Invalidate if the content of the tag matches the text attribute + $text = substr($parser->getText(), $tag->getPos(), $tag->getLen()); + + return ($text !== $tag->getAttribute('text')); + } + + /** + * Create an AUTOLINK_TEXT tag inside of a link created by the Autolink plugin + * + * Will only apply to URL tags that do not use any markup (e.g. not "[url]") + * on the assumption that those tags were created by the Autolink plugin to + * linkify URLs found in plain text + * + * @param \s9e\TextFormatter\Parser\Tag $tag URL tag (start tag) + * @param \s9e\TextFormatter\Parser $parser Parser + * @return bool Always true to indicate that the tag is valid + */ + public function generate_autolink_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) + { + // If the tag consumes any text then we ignore it because it's not a + // linkified URL. Same if it's not paired with an end tag that doesn't + // consume any text either + if ($tag->getLen() > 0 || !$tag->getEndTag()) + { + return true; + } + + // Capture the text between the start tag and its end tag + $start = $tag->getPos(); + $end = $tag->getEndTag()->getPos(); + $length = $end - $start; + $text = substr($parser->getText(), $start, $length); + + // Create a tag that consumes the link's text + $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length)->setAttribute('text', $text); + + return true; + } + + /** + * Remove the board's root URL from a the start of a string + * + * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag + * @param string $board_url Forum's root URL (with trailing slash) + * @return bool Always true to indicate that the tag is valid + */ + public function truncate_local_url(\s9e\TextFormatter\Parser\Tag $tag, $board_url) + { + $text = $tag->getAttribute('text'); + if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url)) + { + $tag->setAttribute('text', substr($text, strlen($board_url))); + } + + return true; + } + + /** + * Truncate the replacement text set in an AUTOLINK_TEXT tag + * + * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag + * @return bool Always true to indicate that the tag is valid + */ + public function truncate_text(\s9e\TextFormatter\Parser\Tag $tag) + { + $text = $tag->getAttribute('text'); + if (utf8_strlen($text) > 55) + { + $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + } + + $tag->setAttribute('text', $text); + + return true; + } +} diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 63e49b6dd4..736f9a9f8a 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -22,6 +22,11 @@ use s9e\TextFormatter\Configurator\Items\UnsafeTemplate; */ class factory implements \phpbb\textformatter\cache_interface { + /** + * @var \phpbb\textformatter\s9e\autolink_helper + */ + protected $autolink_helper; + /** * @var \phpbb\cache\driver\driver_interface */ @@ -133,12 +138,14 @@ class factory implements \phpbb\textformatter\cache_interface * @param \phpbb\cache\driver\driver_interface $cache * @param \phpbb\event\dispatcher_interface $dispatcher * @param \phpbb\config\config $config + * @param \phpbb\textformatter\s9e\autolink_helper $autolink_helper * @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, $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\autolink_helper $autolink_helper, $cache_dir, $cache_key_parser, $cache_key_renderer) { + $this->autolink_helper = $autolink_helper; $this->cache = $cache; $this->cache_dir = $cache_dir; $this->cache_key_parser = $cache_key_parser; @@ -404,19 +411,35 @@ class factory implements \phpbb\textformatter\cache_interface $configurator->plugins->load('Autoemail'); $configurator->plugins->load('Autolink', array('matchWww' => true)); - // Create a tag that will be used to display the truncated text by replacing the original - // content with the content of the @text attribute + // Add a tag filter that creates a tag that stores and replace the + // content of a link created by the Autolink plugin + $configurator->Autolink->getTag()->filterChain + ->add(array($this->autolink_helper, 'generate_autolink_text_tag')) + ->resetParameters() + ->addParameterByName('tag') + ->addParameterByName('parser'); + + // Create a tag that will be used to display the truncated text by + // replacing the original content with the content of the @text attribute $tag = $configurator->tags->add('AUTOLINK_TEXT'); $tag->attributes->add('text'); + $tag->attributes->add('url', array('required' => false))->filterChain->add('#url'); $tag->template = ''; - // Add a tag filter that replaces the text of links that were created by the Autolink plugin - $configurator->Autolink->getTag()->filterChain - ->add(__NAMESPACE__ . '\\parser::generate_autolink_text') + $tag->filterChain + ->add(array($this->autolink_helper, 'truncate_local_url')) ->resetParameters() ->addParameterByName('tag') - ->addParameterByName('parser') ->addParameterByValue(generate_board_url() . '/'); + $tag->filterChain + ->add(array($this->autolink_helper, 'truncate_text')) + ->resetParameters() + ->addParameterByName('tag'); + $tag->filterChain + ->add(array($this->autolink_helper, 'cleanup_tag')) + ->resetParameters() + ->addParameterByName('tag') + ->addParameterByName('parser'); } /** diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index beb737c816..ffaffbc63c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -393,51 +393,4 @@ class parser implements \phpbb\textformatter\parser_interface return $url; } - - /** - * Replace the content displayed inside of a URL tag - * - * Will only apply to URL tags that do not use any markup (e.g. not "[url]") - * on the assumption that those tags were created by the Autolink plugin to - * linkify URLs found in plain text - * - * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) - * @param \s9e\TextFormatter\Parser $parser Parser - * @param string $board_url Forum's root URL (with trailing slash) - * @return bool Always true to indicate that the tag is valid - */ - public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser, $board_url) - { - // If the tag consumes any text then we ignore it because it's not a - // linkified URL. Same if it's not paired with an end tag that doesn't - // consume any text either - if ($url_tag->getLen() > 0 || !$url_tag->getEndTag()) - { - return true; - } - - // Capture the text between the start tag and its end tag - $start = $url_tag->getPos(); - $end = $url_tag->getEndTag()->getPos(); - $length = $end - $start; - $text = substr($parser->getText(), $start, $length); - - // Remove the board's root URL from the link if applicable - if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url)) - { - $text = substr($text, strlen($board_url)); - } - - // Truncate the text if it's longer than 55 characters - if (utf8_strlen($text) > 55) - { - $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); - } - - // Create a tag that consumes the link's text - $tag = $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length); - $tag->setAttribute('text', $text); - - return true; - } } -- cgit v1.2.1 From 5c8373dc20f3cef80b00304ec3b9e27fa86346e5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 26 Dec 2015 17:01:37 +0100 Subject: [ticket/14323] Added comment [ci skip] PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/autolink_helper.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/autolink_helper.php b/phpBB/phpbb/textformatter/s9e/autolink_helper.php index 8fb171f413..81ebc6d029 100644 --- a/phpBB/phpbb/textformatter/s9e/autolink_helper.php +++ b/phpBB/phpbb/textformatter/s9e/autolink_helper.php @@ -18,6 +18,9 @@ class autolink_helper /** * Clean up and invalidate an AUTOLINK_TEXT tag if applicable * + * Will invalidate the tag if its replacement text is the same as the original + * text and would have no visible effect + * * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag * @param \s9e\TextFormatter\Parser $parser Parser * @return bool Whether the tag is valid -- cgit v1.2.1 From 909f8653ec0bf2905ed8d8a9591486f7eefe4d56 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 27 Dec 2015 16:43:45 +0100 Subject: [ticket/14323] Renamed AUTOLINK_TEXT to LINK_TEXT Expanded link text shortening to [url] BBCodes with no parameters PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/autolink_helper.php | 108 ---------------------- phpBB/phpbb/textformatter/s9e/factory.php | 21 ++--- phpBB/phpbb/textformatter/s9e/link_helper.php | 103 +++++++++++++++++++++ 3 files changed, 113 insertions(+), 119 deletions(-) delete mode 100644 phpBB/phpbb/textformatter/s9e/autolink_helper.php create mode 100644 phpBB/phpbb/textformatter/s9e/link_helper.php (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/autolink_helper.php b/phpBB/phpbb/textformatter/s9e/autolink_helper.php deleted file mode 100644 index 81ebc6d029..0000000000 --- a/phpBB/phpbb/textformatter/s9e/autolink_helper.php +++ /dev/null @@ -1,108 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textformatter\s9e; - -class autolink_helper -{ - /** - * Clean up and invalidate an AUTOLINK_TEXT tag if applicable - * - * Will invalidate the tag if its replacement text is the same as the original - * text and would have no visible effect - * - * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag - * @param \s9e\TextFormatter\Parser $parser Parser - * @return bool Whether the tag is valid - */ - public function cleanup_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) - { - // Remove the url attribute because it's not needed. - $tag->removeAttribute('url'); - - // Invalidate if the content of the tag matches the text attribute - $text = substr($parser->getText(), $tag->getPos(), $tag->getLen()); - - return ($text !== $tag->getAttribute('text')); - } - - /** - * Create an AUTOLINK_TEXT tag inside of a link created by the Autolink plugin - * - * Will only apply to URL tags that do not use any markup (e.g. not "[url]") - * on the assumption that those tags were created by the Autolink plugin to - * linkify URLs found in plain text - * - * @param \s9e\TextFormatter\Parser\Tag $tag URL tag (start tag) - * @param \s9e\TextFormatter\Parser $parser Parser - * @return bool Always true to indicate that the tag is valid - */ - public function generate_autolink_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) - { - // If the tag consumes any text then we ignore it because it's not a - // linkified URL. Same if it's not paired with an end tag that doesn't - // consume any text either - if ($tag->getLen() > 0 || !$tag->getEndTag()) - { - return true; - } - - // Capture the text between the start tag and its end tag - $start = $tag->getPos(); - $end = $tag->getEndTag()->getPos(); - $length = $end - $start; - $text = substr($parser->getText(), $start, $length); - - // Create a tag that consumes the link's text - $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length)->setAttribute('text', $text); - - return true; - } - - /** - * Remove the board's root URL from a the start of a string - * - * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag - * @param string $board_url Forum's root URL (with trailing slash) - * @return bool Always true to indicate that the tag is valid - */ - public function truncate_local_url(\s9e\TextFormatter\Parser\Tag $tag, $board_url) - { - $text = $tag->getAttribute('text'); - if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url)) - { - $tag->setAttribute('text', substr($text, strlen($board_url))); - } - - return true; - } - - /** - * Truncate the replacement text set in an AUTOLINK_TEXT tag - * - * @param \s9e\TextFormatter\Parser\Tag $tag AUTOLINK_TEXT tag - * @return bool Always true to indicate that the tag is valid - */ - public function truncate_text(\s9e\TextFormatter\Parser\Tag $tag) - { - $text = $tag->getAttribute('text'); - if (utf8_strlen($text) > 55) - { - $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); - } - - $tag->setAttribute('text', $text); - - return true; - } -} diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 736f9a9f8a..7fdc5afeed 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -23,9 +23,9 @@ use s9e\TextFormatter\Configurator\Items\UnsafeTemplate; class factory implements \phpbb\textformatter\cache_interface { /** - * @var \phpbb\textformatter\s9e\autolink_helper + * @var \phpbb\textformatter\s9e\link_helper */ - protected $autolink_helper; + protected $link_helper; /** * @var \phpbb\cache\driver\driver_interface @@ -138,14 +138,14 @@ class factory implements \phpbb\textformatter\cache_interface * @param \phpbb\cache\driver\driver_interface $cache * @param \phpbb\event\dispatcher_interface $dispatcher * @param \phpbb\config\config $config - * @param \phpbb\textformatter\s9e\autolink_helper $autolink_helper + * @param \phpbb\textformatter\s9e\link_helper $link_helper * @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\autolink_helper $autolink_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, $cache_dir, $cache_key_parser, $cache_key_renderer) { - $this->autolink_helper = $autolink_helper; + $this->link_helper = $link_helper; $this->cache = $cache; $this->cache_dir = $cache_dir; $this->cache_key_parser = $cache_key_parser; @@ -414,29 +414,28 @@ class factory implements \phpbb\textformatter\cache_interface // Add a tag filter that creates a tag that stores and replace the // content of a link created by the Autolink plugin $configurator->Autolink->getTag()->filterChain - ->add(array($this->autolink_helper, 'generate_autolink_text_tag')) + ->add(array($this->link_helper, 'generate_link_text_tag')) ->resetParameters() ->addParameterByName('tag') ->addParameterByName('parser'); // Create a tag that will be used to display the truncated text by // replacing the original content with the content of the @text attribute - $tag = $configurator->tags->add('AUTOLINK_TEXT'); + $tag = $configurator->tags->add('LINK_TEXT'); $tag->attributes->add('text'); - $tag->attributes->add('url', array('required' => false))->filterChain->add('#url'); $tag->template = ''; $tag->filterChain - ->add(array($this->autolink_helper, 'truncate_local_url')) + ->add(array($this->link_helper, 'truncate_local_url')) ->resetParameters() ->addParameterByName('tag') ->addParameterByValue(generate_board_url() . '/'); $tag->filterChain - ->add(array($this->autolink_helper, 'truncate_text')) + ->add(array($this->link_helper, 'truncate_text')) ->resetParameters() ->addParameterByName('tag'); $tag->filterChain - ->add(array($this->autolink_helper, 'cleanup_tag')) + ->add(array($this->link_helper, 'cleanup_tag')) ->resetParameters() ->addParameterByName('tag') ->addParameterByName('parser'); diff --git a/phpBB/phpbb/textformatter/s9e/link_helper.php b/phpBB/phpbb/textformatter/s9e/link_helper.php new file mode 100644 index 0000000000..76948159ba --- /dev/null +++ b/phpBB/phpbb/textformatter/s9e/link_helper.php @@ -0,0 +1,103 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +class link_helper +{ + /** + * Clean up and invalidate a LINK_TEXT tag if applicable + * + * Will invalidate the tag if its replacement text is the same as the original + * text and would have no visible effect + * + * @param \s9e\TextFormatter\Parser\Tag $tag LINK_TEXT tag + * @param \s9e\TextFormatter\Parser $parser Parser + * @return bool Whether the tag is valid + */ + public function cleanup_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) + { + // Invalidate if the content of the tag matches the text attribute + $text = substr($parser->getText(), $tag->getPos(), $tag->getLen()); + + return ($text !== $tag->getAttribute('text')); + } + + /** + * Create a LINK_TEXT tag inside of a link + * + * Meant to only apply to linkified URLs and [url] BBCodes without a parameter + * + * @param \s9e\TextFormatter\Parser\Tag $tag URL tag (start tag) + * @param \s9e\TextFormatter\Parser $parser Parser + * @return bool Always true to indicate that the tag is valid + */ + public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser) + { + // Only create a LINK_TEXT tag if the start tag is paired with an end + // tag, which is the case with tags from the Autolink plugins and with + // the [url] BBCode when its content is used for the URL + if (!$tag->getEndTag()) + { + return true; + } + + // Capture the text between the start tag and its end tag + $start = $tag->getPos() + $tag->getLen(); + $end = $tag->getEndTag()->getPos(); + $length = $end - $start; + $text = substr($parser->getText(), $start, $length); + + // Create a tag that consumes the link's text + $parser->addSelfClosingTag('LINK_TEXT', $start, $length)->setAttribute('text', $text); + + return true; + } + + /** + * Remove the board's root URL from a the start of a string + * + * @param \s9e\TextFormatter\Parser\Tag $tag LINK_TEXT tag + * @param string $board_url Forum's root URL (with trailing slash) + * @return bool Always true to indicate that the tag is valid + */ + public function truncate_local_url(\s9e\TextFormatter\Parser\Tag $tag, $board_url) + { + $text = $tag->getAttribute('text'); + if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url)) + { + $tag->setAttribute('text', substr($text, strlen($board_url))); + } + + return true; + } + + /** + * Truncate the replacement text set in a LINK_TEXT tag + * + * @param \s9e\TextFormatter\Parser\Tag $tag LINK_TEXT tag + * @return bool Always true to indicate that the tag is valid + */ + public function truncate_text(\s9e\TextFormatter\Parser\Tag $tag) + { + $text = $tag->getAttribute('text'); + if (utf8_strlen($text) > 55) + { + $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + } + + $tag->setAttribute('text', $text); + + return true; + } +} -- cgit v1.2.1 From bc5d976786d60d8d33cf77fccf81ce351b59fcdc Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 28 Dec 2015 04:19:21 +0100 Subject: [ticket/14323] Added should_shorten() Explicitly tests a tag's markup to determine whether a link should be shortened PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/link_helper.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/link_helper.php b/phpBB/phpbb/textformatter/s9e/link_helper.php index 76948159ba..0f44603dec 100644 --- a/phpBB/phpbb/textformatter/s9e/link_helper.php +++ b/phpBB/phpbb/textformatter/s9e/link_helper.php @@ -47,7 +47,7 @@ class link_helper // Only create a LINK_TEXT tag if the start tag is paired with an end // tag, which is the case with tags from the Autolink plugins and with // the [url] BBCode when its content is used for the URL - if (!$tag->getEndTag()) + if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText())) { return true; } @@ -64,6 +64,21 @@ class link_helper return true; } + /** + * Test whether we should shorten this tag's text + * + * Will test whether the tag either does not use any markup or uses a single + * [url] BBCode + * + * @param \s9e\TextFormatter\Parser\Tag $tag URL tag + * @param string $text Original text + * @return bool + */ + protected function should_shorten(\s9e\TextFormatter\Parser\Tag $tag, $text) + { + return ($tag->getLen() === 0 || strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[url]'); + } + /** * Remove the board's root URL from a the start of a string * -- cgit v1.2.1 From 73e6e5b77faadbb7676961bf38122d669de111db Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Dec 2015 17:50:29 +0100 Subject: [ticket/13454] Remove unused variables This is the first part of the changes. More to come. PHPBB3-13454 --- phpBB/phpbb/textformatter/s9e/parser.php | 3 --- phpBB/phpbb/textformatter/s9e/renderer.php | 1 - 2 files changed, 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index ffaffbc63c..6470bb8245 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -50,7 +50,6 @@ class parser implements \phpbb\textformatter\parser_interface $this->dispatcher = $dispatcher; $this->parser = $parser; - $parser = $this; /** * Configure the parser service @@ -73,8 +72,6 @@ class parser implements \phpbb\textformatter\parser_interface */ public function parse($text) { - $parser = $this; - /** * Modify a text before it is parsed * diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 2206605ba2..90c39d356d 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -104,7 +104,6 @@ class renderer implements \phpbb\textformatter\renderer_interface } $this->dispatcher = $dispatcher; $this->renderer = $renderer; - $renderer = $this; /** * Configure the renderer service -- cgit v1.2.1 From f50ba9ab4f6e74e4d472c9e2012dfdd29720dfe9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Dec 2015 18:19:02 +0100 Subject: [ticket/13454] Remove unused variables This is part 2 of the pr. PHPBB3-13454 --- phpBB/phpbb/textformatter/s9e/renderer.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 90c39d356d..6ba75d0c04 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -232,7 +232,6 @@ class renderer implements \phpbb\textformatter\renderer_interface { $xml = $this->quote_helper->inject_metadata($xml); } - $renderer = $this; /** * Modify a parsed text before it is rendered -- cgit v1.2.1 From 38f36882177d25e58d5de41060d51f869a20f8d5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Dec 2015 14:03:43 +0100 Subject: [ticket/13454] Fix a few issues introduced by overdeleting stuff PHPBB3-13454 --- phpBB/phpbb/textformatter/s9e/parser.php | 4 ++++ phpBB/phpbb/textformatter/s9e/renderer.php | 3 +++ 2 files changed, 7 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 6470bb8245..39e91f037e 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -51,6 +51,8 @@ class parser implements \phpbb\textformatter\parser_interface $this->dispatcher = $dispatcher; $this->parser = $parser; + $parser = $this; + /** * Configure the parser service * @@ -72,6 +74,8 @@ class parser implements \phpbb\textformatter\parser_interface */ public function parse($text) { + $parser = $this; + /** * Modify a text before it is parsed * diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 6ba75d0c04..9be20b7f53 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -104,6 +104,7 @@ class renderer implements \phpbb\textformatter\renderer_interface } $this->dispatcher = $dispatcher; $this->renderer = $renderer; + $renderer = $this; /** * Configure the renderer service @@ -233,6 +234,8 @@ class renderer implements \phpbb\textformatter\renderer_interface $xml = $this->quote_helper->inject_metadata($xml); } + $renderer = $this; + /** * Modify a parsed text before it is rendered * -- cgit v1.2.1 From 73900d1857a9a59eff82b224537a79110466ce7e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 5 Dec 2015 16:07:14 +0100 Subject: [ticket/13454] Remove more unused variables This should be the last part. Off to checking if the changes were correct. PHPBB3-13454 --- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 39e91f037e..e2653d60f0 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -196,7 +196,7 @@ class parser implements \phpbb\textformatter\parser_interface $errors = array(); foreach ($this->parser->getLogger()->get() as $entry) { - list($type, $msg, $context) = $entry; + list(, $msg, $context) = $entry; if ($msg === 'Tag limit exceeded') { -- cgit v1.2.1 From e4dae8ed4b784d7a70a74a9ba74fb714c9eae750 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 12 Jan 2016 11:54:20 +0100 Subject: [ticket/14405] Force a lookahead check on [URL] BBCodes PHPBB3-14405 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 63b23d2fd0..6ac55e82a8 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -94,7 +94,7 @@ class factory implements \phpbb\textformatter\cache_interface ]{TEXT2}[/QUOTE]", 'size' => '[SIZE={FONTSIZE}]{TEXT}[/SIZE]', 'u' => '[U]{TEXT}[/U]', - 'url' => '[URL={URL;useContent}]{TEXT}[/URL]', + 'url' => '[URL={URL;useContent} $forceLookahead=true]{TEXT}[/URL]', ); /** -- cgit v1.2.1 From 24da2db987c895c474b1d0a59344a7094133f278 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 8 Jul 2016 07:46:53 +0200 Subject: [ticket/14706] Updated [list] BBCode to automatically create a list item Fixes issues with missing list items. Produces valid HTML. PHPBB3-14706 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 8c273c342e..8d1c0fabfe 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -82,7 +82,7 @@ class factory implements \phpbb\textformatter\cache_interface 'flash' => '[FLASH={NUMBER1},{NUMBER2} width={NUMBER1;postFilter=#flashwidth} height={NUMBER2;postFilter=#flashheight} url={URL;useContent} /]', 'i' => '[I]{TEXT}[/I]', 'img' => '[IMG src={IMAGEURL;useContent}]', - 'list' => '[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext}]{TEXT}[/LIST]', + 'list' => '[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext} #createChild=LI]{TEXT}[/LIST]', 'li' => '[* $tagName=LI]{TEXT}[/*]', 'quote' => "[QUOTE -- cgit v1.2.1 From 13a756bfb7f73bdbd89e178617345afa18210b69 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 21 Jul 2016 03:37:44 +0200 Subject: [ticket/14700] Prevent an exception on duplicate smilies in text_formatter PHPBB3-14700 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 8d1c0fabfe..916fdff909 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -309,7 +309,7 @@ class factory implements \phpbb\textformatter\cache_interface // Load smilies foreach ($this->data_access->get_smilies() as $row) { - $configurator->Emoticons->add( + $configurator->Emoticons->set( $row['code'], '{.}' ); -- cgit v1.2.1 From 9225a0fdffdd5830e2f87ec964a90d26576b812b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 5 Aug 2016 16:27:13 +0200 Subject: [ticket/14734] Use SVG emoji PHPBB3-14734 --- phpBB/phpbb/textformatter/s9e/factory.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 916fdff909..f62daefdd9 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -349,6 +349,7 @@ class factory implements \phpbb\textformatter\cache_interface // Load the Emoji plugin and modify its tag's template to obey viewsmilies $configurator->Emoji->setImageSize(18); + $configurator->Emoji->useSVG(); $tag = $configurator->Emoji->getTag(); $tag->template = '' . str_replace('class="emoji"', 'class="smilies"', $tag->template) . ''; -- cgit v1.2.1 From 88c921be23a2cddbfb3ac7272eb14305664b6542 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 27 Nov 2016 13:30:15 +0100 Subject: [ticket/14873] Added width/height attributes to smilies PHPBB3-14873 --- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index f62daefdd9..a310c67359 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -311,7 +311,7 @@ class factory implements \phpbb\textformatter\cache_interface { $configurator->Emoticons->set( $row['code'], - '{.}' + '{.}' ); } -- cgit v1.2.1 From f111e70fc3959d979e61e8134fcaefb670b32603 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 27 Dec 2016 21:48:01 +0100 Subject: [ticket/14914] Made emoji scale in size with text PHPBB3-14914 --- phpBB/phpbb/textformatter/s9e/factory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index a310c67359..55149b8e63 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -348,10 +348,10 @@ class factory implements \phpbb\textformatter\cache_interface $configurator->registeredVars['max_img_width'] = 0; // Load the Emoji plugin and modify its tag's template to obey viewsmilies - $configurator->Emoji->setImageSize(18); + $configurator->Emoji->omitImageSize(); $configurator->Emoji->useSVG(); $tag = $configurator->Emoji->getTag(); - $tag->template = '' . str_replace('class="emoji"', 'class="smilies"', $tag->template) . ''; + $tag->template = '' . str_replace('class="emoji"', 'class="emoji smilies"', $tag->template) . ''; /** * Modify the s9e\TextFormatter configurator after the default settings are set -- cgit v1.2.1 From f82299b8e445cccfc8bad8cbe6505f3fb50d0f8f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 6 Jan 2017 19:52:17 +0100 Subject: [ticket/14962] Introduces a new helper to check emptyness of bbcode texts PHPBB3-14962 --- phpBB/phpbb/textformatter/s9e/utils.php | 13 +++++++++++++ phpBB/phpbb/textformatter/utils_interface.php | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index b317fe4a8d..a9a6d4b892 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -136,4 +136,17 @@ class utils implements \phpbb\textformatter\utils_interface { return \s9e\TextFormatter\Unparser::unparse($xml); } + + /** + * {@inheritdoc} + */ + public function is_empty($text) + { + if ($text === null || $text === '') + { + return true; + } + + return trim($this->unparse($text)) === ''; + } } diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 4810453cd1..4b7392976a 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -62,10 +62,18 @@ interface utils_interface public function remove_bbcode($text, $bbcode_name, $depth = 0); /** - * Return a parsed text to its original form - * - * @param string $text Parsed text - * @return string Original plain text - */ + * Return a parsed text to its original form + * + * @param string $text Parsed text + * @return string Original plain text + */ public function unparse($text); + + /** + * Return whether or not a parsed text represent an empty text. + * + * @param string $text Parsed text + * @return bool Tue if the original text is empty + */ + public function is_empty($text); } -- cgit v1.2.1 From ef215f573e7540bd7f26d936de4108057f9b3225 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 10 Jan 2017 18:04:16 +0100 Subject: [ticket/14985] Decode HTML special chars in plain text columns PHPBB3-14985 --- phpBB/phpbb/textformatter/data_access.php | 50 +++++++++++++++++++++++-------- phpBB/phpbb/textformatter/s9e/factory.php | 3 +- 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php index 2103bf8e60..0d37e62c87 100644 --- a/phpBB/phpbb/textformatter/data_access.php +++ b/phpBB/phpbb/textformatter/data_access.php @@ -81,11 +81,8 @@ class data_access public function get_bbcodes() { $sql = 'SELECT bbcode_match, bbcode_tpl FROM ' . $this->bbcodes_table; - $result = $this->db->sql_query($sql); - $rows = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - return $rows; + return $this->fetch_decoded_rowset($sql, ['bbcode_match']); } /** @@ -101,11 +98,8 @@ class data_access $sql = 'SELECT code, emotion, smiley_url, smiley_width, smiley_height FROM ' . $this->smilies_table . ' ORDER BY display_on_posting DESC'; - $result = $this->db->sql_query($sql); - $rows = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - return $rows; + return $this->fetch_decoded_rowset($sql, ['code', 'emotion', 'smiley_url']); } /** @@ -116,11 +110,8 @@ class data_access protected function get_styles() { $sql = 'SELECT style_id, style_path, style_parent_id, bbcode_bitfield FROM ' . $this->styles_table; - $result = $this->db->sql_query($sql); - $rows = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - return $rows; + return $this->fetch_decoded_rowset($sql); } /** @@ -219,10 +210,43 @@ class data_access public function get_censored_words() { $sql = 'SELECT word, replacement FROM ' . $this->words_table; + + return $this->fetch_decoded_rowset($sql, ['word', 'replacement']); + } + + /** + * Decode HTML special chars in given rowset + * + * @param array $rows Original rowset + * @param array $columns List of columns to decode + * @return array Decoded rowset + */ + protected function decode_rowset(array $rows, array $columns) + { + foreach ($rows as &$row) + { + foreach ($columns as $column) + { + $row[$column] = htmlspecialchars_decode($row[$column]); + } + } + + return $rows; + } + + /** + * Fetch all rows for given query and decode plain text columns + * + * @param string $sql SELECT query + * @param array $columns List of columns to decode + * @return array + */ + protected function fetch_decoded_rowset($sql, array $columns = []) + { $result = $this->db->sql_query($sql); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); - return $rows; + return $this->decode_rowset($rows, $columns); } } diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 55149b8e63..5cbf2712f7 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -333,8 +333,7 @@ class factory implements \phpbb\textformatter\cache_interface $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']); } } -- cgit v1.2.1 From 15315ac87a68834e2d560acf62756f628a26da45 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 14 Jan 2017 14:27:38 +0100 Subject: [ticket/15008] Disable emoji when smilies are disabled Will effectively disable emoji shortname and won't replace emoji with images but will not prevent a browser or OS from displaying emoji as images. PHPBB3-15008 --- phpBB/phpbb/textformatter/s9e/parser.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index e2653d60f0..05ddfffa11 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -142,6 +142,7 @@ class parser implements \phpbb\textformatter\parser_interface public function disable_smilies() { $this->parser->disablePlugin('Emoticons'); + $this->parser->disablePlugin('Emoji'); } /** @@ -183,6 +184,7 @@ class parser implements \phpbb\textformatter\parser_interface public function enable_smilies() { $this->parser->enablePlugin('Emoticons'); + $this->parser->enablePlugin('Emoji'); } /** -- cgit v1.2.1 From d3eb85dd5d04463f78f77d371eddc89ac3985659 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 15 Mar 2017 02:36:20 +0100 Subject: [ticket/15126] Disable HTML entities in quote helper PHPBB3-15126 --- phpBB/phpbb/textformatter/s9e/quote_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/quote_helper.php b/phpBB/phpbb/textformatter/s9e/quote_helper.php index 24109ac8cc..86c33c7591 100644 --- a/phpBB/phpbb/textformatter/s9e/quote_helper.php +++ b/phpBB/phpbb/textformatter/s9e/quote_helper.php @@ -39,8 +39,8 @@ class quote_helper */ public function __construct(\phpbb\user $user, $root_path, $php_ext) { - $this->post_url = append_sid($root_path . 'viewtopic.' . $php_ext, 'p={POST_ID}#p{POST_ID}'); - $this->profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=viewprofile&u={USER_ID}'); + $this->post_url = append_sid($root_path . 'viewtopic.' . $php_ext, 'p={POST_ID}#p{POST_ID}', false); + $this->profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=viewprofile&u={USER_ID}', false); $this->user = $user; } -- cgit v1.2.1 From ddcd0f243791ea64373b53f077689df0c46c713a Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 7 Apr 2017 08:49:56 +0200 Subject: [ticket/15163] Escape curly braces in smilies HTML attributes PHPBB3-15163 --- phpBB/phpbb/textformatter/s9e/factory.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 5cbf2712f7..7719ce5afa 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -311,7 +311,7 @@ class factory implements \phpbb\textformatter\cache_interface { $configurator->Emoticons->set( $row['code'], - '{.}' + '{.}' ); } @@ -441,6 +441,20 @@ class factory implements \phpbb\textformatter\cache_interface ->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'); + } + /** * Return the default BBCodes configuration * -- cgit v1.2.1 From 329e5c5e052588b0f22c9046b9fbc19c9e551c81 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 3 Jul 2017 16:06:50 +0200 Subject: [ticket/15261] Fix censoring HTML tags PHPBB3-15261 --- phpBB/phpbb/textformatter/s9e/renderer.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 9be20b7f53..6fcd2b0a98 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -247,14 +247,12 @@ class renderer implements \phpbb\textformatter\renderer_interface $vars = array('renderer', 'xml'); extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_before', compact($vars))); + $html = $this->renderer->render($xml); if (isset($this->censor) && $this->viewcensors) { - // NOTE: censorHtml() is XML-safe - $xml = $this->censor->censorHtml($xml, true); + $html = $this->censor->censorHtml($html, true); } - $html = $this->renderer->render($xml); - /** * Modify a rendered text * -- cgit v1.2.1 From 7f45062466b201e607db93e7f523f2a6d7057649 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 22 Jul 2017 08:36:48 +0200 Subject: [ticket/15290] Add core.text_formatter_s9e_configure_finalize event PHPBB3-15290 --- phpBB/phpbb/textformatter/s9e/factory.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 7719ce5afa..71d39b6819 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -382,7 +382,18 @@ class factory implements \phpbb\textformatter\cache_interface 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']; -- cgit v1.2.1 From aabb9d2e488e465d48d9910f98a861ab96f55f74 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 15 Aug 2017 15:41:56 +0700 Subject: [ticket/15323] Allow Twig syntax in bbcode.html PHPBB3-15323 --- phpBB/phpbb/textformatter/s9e/factory.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 7719ce5afa..13bfc7b5e9 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -518,7 +518,9 @@ class factory implements \phpbb\textformatter\cache_interface protected function extract_templates($template) { // Capture the template fragments - preg_match_all('#(.*?)#s', $template, $matches, PREG_SET_ORDER); + // Allow either phpBB template or the Twig syntax + preg_match_all('#(.*?)#s', $template, $matches, PREG_SET_ORDER) ?: + preg_match_all('#{% for (.*?) in .*? %}(.*?){% endfor %}#s', $template, $matches, PREG_SET_ORDER); $fragments = array(); foreach ($matches as $match) -- cgit v1.2.1 From e1e94683bdc57430b2205ae4b1f1b32e7d0c66e2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 24 Aug 2017 14:17:42 +0200 Subject: [ticket/15301] Remove quote limits when creating a parser PHPBB3-15301 --- phpBB/phpbb/textformatter/s9e/factory.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 7719ce5afa..81afeafd56 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -273,6 +273,11 @@ class factory implements \phpbb\textformatter\cache_interface { $configurator->BBCodes->addCustom($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 foreach (array('FLASH', 'IMG') as $name) -- cgit v1.2.1 From 837dc9b3a737e68d12eef033572894a81a2c0de7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 6 Sep 2017 03:35:26 +0200 Subject: [ticket/15348] Ignore smilies that are immediately followed by a word PHPBB3-15348 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/phpbb/textformatter') diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 7719ce5afa..3f2e0ab8cb 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -323,6 +323,9 @@ class factory implements \phpbb\textformatter\cache_interface // 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 -- cgit v1.2.1