From 147a713cc066d493b50b82a9d475aa9af940e2b4 Mon Sep 17 00:00:00 2001 From: s9e Date: Sat, 22 Nov 2014 20:00:58 +0100 Subject: [PATCH 01/82] [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/composer.lock | 108 +++- phpBB/config/default/container/services.yml | 2 +- .../container/services_text_formatter.yml | 58 ++ phpBB/config/default/container/tables.yml | 4 + phpBB/includes/acp/acp_bbcodes.php | 2 + phpBB/includes/acp/acp_icons.php | 6 +- phpBB/includes/acp/acp_main.php | 5 + phpBB/includes/acp/acp_words.php | 2 + phpBB/includes/functions_content.php | 127 +++-- phpBB/includes/message_parser.php | 131 ++--- 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 ++ tests/notification/group_request_test.php | 1 + .../phpbb_test_case_helpers.php | 210 +++++++ .../s9e/default_formatting_test.php | 200 +++++++ tests/text_formatter/s9e/factory_test.php | 182 ++++++ .../s9e/fixtures/default_formatting.xml | 466 +++++++++++++++ .../s9e/fixtures/default_lang.xml | 20 + tests/text_formatter/s9e/fixtures/factory.xml | 115 ++++ .../s9e/fixtures/inttext_token.xml | 27 + .../text_formatter/s9e/fixtures/local_url.xml | 28 + .../s9e/fixtures/smilies_special_chars.xml | 23 + .../s9e/fixtures/style_inheritance.xml | 66 +++ tests/text_formatter/s9e/fixtures/styles.xml | 36 ++ .../fixtures/styles/bar/template/bbcode.html | 40 ++ .../styles/barplus/template/bbcode.html | 40 ++ .../fixtures/styles/foo/template/bbcode.html | 40 ++ tests/text_formatter/s9e/parser_test.php | 162 ++++++ tests/text_formatter/s9e/renderer_test.php | 355 ++++++++++++ tests/text_formatter/s9e/utils_test.php | 157 ++++++ tests/text_processing/decode_message_test.php | 87 +++ tests/text_processing/fixtures/empty.xml | 3 + tests/text_processing/fixtures/smilies.xml | 443 +++++++++++++++ .../generate_text_for_display_test.php | 174 +++++- .../generate_text_for_edit_test.php | 90 +++ .../generate_text_for_storage_test.php | 70 +++ tests/text_processing/message_parser_test.php | 532 ++++++++++++++++++ tests/text_processing/smilies_test.php | 48 ++ tests/text_processing/strip_bbcode_test.php | 38 ++ .../tickets_data/PHPBB3-10002.html | 2 + .../tickets_data/PHPBB3-10002.txt | 2 + .../tickets_data/PHPBB3-10425.html | 3 + .../tickets_data/PHPBB3-10425.txt | 3 + .../tickets_data/PHPBB3-10587.html | 2 + .../tickets_data/PHPBB3-10587.txt | 2 + .../tickets_data/PHPBB3-10922.html | 1 + .../tickets_data/PHPBB3-10922.txt | 1 + .../tickets_data/PHPBB3-10989.html | 8 + .../tickets_data/PHPBB3-10989.txt | 8 + .../tickets_data/PHPBB3-11153.html | 1 + .../tickets_data/PHPBB3-11153.txt | 1 + .../tickets_data/PHPBB3-11153.xml | 28 + .../tickets_data/PHPBB3-12195.html | 1 + .../tickets_data/PHPBB3-12195.txt | 1 + .../tickets_data/PHPBB3-3981.before.php | 17 + .../tickets_data/PHPBB3-3981.html | 1 + .../tickets_data/PHPBB3-3981.txt | 1 + .../tickets_data/PHPBB3-7187.html | 1 + .../tickets_data/PHPBB3-7187.txt | 1 + .../tickets_data/PHPBB3-7187.xml | 33 ++ .../tickets_data/PHPBB3-7275.after.php | 15 + .../tickets_data/PHPBB3-7275.html | 1 + .../tickets_data/PHPBB3-7275.txt | 1 + .../tickets_data/PHPBB3-7275.xml | 49 ++ .../tickets_data/PHPBB3-9377.html | 1 + .../tickets_data/PHPBB3-9377.txt | 1 + .../tickets_data/PHPBB3-9377.xml | 41 ++ tests/text_processing/tickets_test.php | 91 +++ 75 files changed, 5967 insertions(+), 161 deletions(-) create mode 100644 phpBB/config/default/container/services_text_formatter.yml 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 create mode 100644 tests/text_formatter/s9e/default_formatting_test.php create mode 100644 tests/text_formatter/s9e/factory_test.php create mode 100644 tests/text_formatter/s9e/fixtures/default_formatting.xml create mode 100644 tests/text_formatter/s9e/fixtures/default_lang.xml create mode 100644 tests/text_formatter/s9e/fixtures/factory.xml create mode 100644 tests/text_formatter/s9e/fixtures/inttext_token.xml create mode 100644 tests/text_formatter/s9e/fixtures/local_url.xml create mode 100644 tests/text_formatter/s9e/fixtures/smilies_special_chars.xml create mode 100644 tests/text_formatter/s9e/fixtures/style_inheritance.xml create mode 100644 tests/text_formatter/s9e/fixtures/styles.xml create mode 100644 tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html create mode 100644 tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html create mode 100644 tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html create mode 100644 tests/text_formatter/s9e/parser_test.php create mode 100644 tests/text_formatter/s9e/renderer_test.php create mode 100644 tests/text_formatter/s9e/utils_test.php create mode 100644 tests/text_processing/decode_message_test.php create mode 100644 tests/text_processing/fixtures/empty.xml create mode 100644 tests/text_processing/fixtures/smilies.xml create mode 100644 tests/text_processing/generate_text_for_edit_test.php create mode 100644 tests/text_processing/generate_text_for_storage_test.php create mode 100644 tests/text_processing/message_parser_test.php create mode 100644 tests/text_processing/smilies_test.php create mode 100644 tests/text_processing/strip_bbcode_test.php create mode 100644 tests/text_processing/tickets_data/PHPBB3-10002.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-10002.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-10425.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-10425.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-10587.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-10587.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-10922.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-10922.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-10989.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-10989.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-11153.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-11153.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-11153.xml create mode 100644 tests/text_processing/tickets_data/PHPBB3-12195.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-12195.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-3981.before.php create mode 100644 tests/text_processing/tickets_data/PHPBB3-3981.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-3981.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-7187.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-7187.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-7187.xml create mode 100644 tests/text_processing/tickets_data/PHPBB3-7275.after.php create mode 100644 tests/text_processing/tickets_data/PHPBB3-7275.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-7275.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-7275.xml create mode 100644 tests/text_processing/tickets_data/PHPBB3-9377.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-9377.txt create mode 100644 tests/text_processing/tickets_data/PHPBB3-9377.xml create mode 100644 tests/text_processing/tickets_test.php diff --git a/phpBB/composer.lock b/phpBB/composer.lock index b6957aa667..e6dd12e8f0 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -145,7 +145,7 @@ "Psr\\Log\\": "" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "http://packagist.org/downloads/", "license": [ "MIT" ], @@ -163,6 +163,63 @@ ], "time": "2012-12-21 11:40:51" }, + { + "name": "s9e/text-formatter", + "version": "dev-release/php5.3", + "source": { + "type": "git", + "url": "https://github.com/s9e/TextFormatter.git", + "reference": "872ed9d9204986668afc0b3e633be99e397e201b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/872ed9d9204986668afc0b3e633be99e397e201b", + "reference": "872ed9d9204986668afc0b3e633be99e397e201b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-filter": "*", + "php": ">=5.3.3" + }, + "suggest": { + "ext-intl": "Allows international URLs to be accepted by the URL filter", + "ext-json": "Enables the generation of a JavaScript parser", + "ext-mbstring": "Enables some optimizations in the PHP renderer", + "ext-tokenizer": "Enables optimizations in the PHP renderer", + "ext-xsl": "Enables the XSLT renderer", + "ext-zlib": "Enables gzip compression when scraping content via the MediaEmbed plugin" + }, + "type": "library", + "autoload": { + "psr-4": { + "s9e\\TextFormatter\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Multi-purpose text formatting and markup library. Plugins offer support for BBCodes, Markdown, emoticons, HTML, embedding media (YouTube, etc...), enhanced typography and more.", + "keywords": [ + "bbcode", + "bbcodes", + "blog", + "censor", + "embed", + "emoji", + "emoticons", + "engine", + "forum", + "html", + "markdown", + "markup", + "media", + "parser", + "shortcodes" + ], + "time": "2014-11-22 14:23:43" + }, { "name": "symfony/config", "version": "2.7.x-dev", @@ -960,16 +1017,14 @@ "Twig_": "lib/" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "http://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" + "email": "fabien@symfony.com" }, { "name": "Armin Ronacher", @@ -993,21 +1048,21 @@ "packages-dev": [ { "name": "fabpot/goutte", - "version": "v1.0.7", + "version": "v1.0.3", "source": { "type": "git", - "url": "https://github.com/FriendsOfPHP/Goutte.git", - "reference": "794b196e76bdd37b5155cdecbad311f0a3b07625" + "url": "https://github.com/fabpot/Goutte.git", + "reference": "75c9f23c4122caf4ea3e87a42a00b471366e707f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/Goutte/zipball/794b196e76bdd37b5155cdecbad311f0a3b07625", - "reference": "794b196e76bdd37b5155cdecbad311f0a3b07625", + "url": "https://api.github.com/repos/fabpot/Goutte/zipball/75c9f23c4122caf4ea3e87a42a00b471366e707f", + "reference": "75c9f23c4122caf4ea3e87a42a00b471366e707f", "shasum": "" }, "require": { "ext-curl": "*", - "guzzle/http": "~3.1", + "guzzle/http": ">=3.0.5,<3.8-dev", "php": ">=5.3.0", "symfony/browser-kit": "~2.1", "symfony/css-selector": "~2.1", @@ -1016,8 +1071,8 @@ "symfony/process": "~2.1" }, "require-dev": { - "guzzle/plugin-history": "~3.1", - "guzzle/plugin-mock": "~3.1" + "guzzle/plugin-history": ">=3.0.5,<3.8-dev", + "guzzle/plugin-mock": ">=3.0.5,<3.8-dev" }, "type": "application", "extra": { @@ -1037,7 +1092,9 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" } ], "description": "A simple PHP Web Scraper", @@ -1045,7 +1102,7 @@ "keywords": [ "scraper" ], - "time": "2014-10-09 15:52:51" + "time": "2013-08-16 06:03:22" }, { "name": "guzzle/common", @@ -1376,8 +1433,7 @@ "authors": [ { "name": "Michiel Rook", - "email": "mrook@php.net", - "role": "Lead" + "email": "mrook@php.net" }, { "name": "Phing Community", @@ -1881,16 +1937,16 @@ }, { "name": "sami/sami", - "version": "v1.4", + "version": "v1.3", "source": { "type": "git", - "url": "https://github.com/FriendsOfPHP/Sami.git", - "reference": "70f29c781f7bef30181c814b9471b2ceac694454" + "url": "https://github.com/fabpot/Sami.git", + "reference": "76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/70f29c781f7bef30181c814b9471b2ceac694454", - "reference": "70f29c781f7bef30181c814b9471b2ceac694454", + "url": "https://api.github.com/repos/fabpot/Sami/zipball/76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110", + "reference": "76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110", "shasum": "" }, "require": { @@ -1911,7 +1967,7 @@ "type": "application", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -1926,7 +1982,9 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" } ], "description": "Sami, an API documentation generator", @@ -1934,7 +1992,7 @@ "keywords": [ "phpdoc" ], - "time": "2014-06-25 11:24:03" + "time": "2013-11-30 17:16:25" }, { "name": "sebastian/comparator", diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 36f22d72d6..2b4aa52571 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -13,9 +13,9 @@ imports: - { resource: services_notification.yml } - { resource: services_password.yml } - { resource: services_profilefield.yml } + - { resource: services_text_formatter.yml } - { resource: services_twig.yml } - { resource: services_user.yml } - - { resource: tables.yml } - { resource: parameters.yml } diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml new file mode 100644 index 0000000000..7d21e4498e --- /dev/null +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -0,0 +1,58 @@ +parameters: + text_formatter.cache.dir: %core.root_path%cache/ + text_formatter.cache.parser.key: _text_formatter_parser + text_formatter.cache.renderer.key: _text_formatter_renderer + +services: + text_formatter.cache: + alias: text_formatter.s9e.factory + + text_formatter.data_access: + class: phpbb\textformatter\data_access + arguments: + - @dbal.conn + - %tables.bbcodes% + - %tables.smilies% + - %tables.styles% + - %tables.words% + - %core.root_path%styles/ + + text_formatter.parser: + alias: text_formatter.s9e.parser + + text_formatter.renderer: + alias: text_formatter.s9e.renderer + + text_formatter.utils: + alias: text_formatter.s9e.utils + + text_formatter.s9e.factory: + class: phpbb\textformatter\s9e\factory + arguments: + - @text_formatter.data_access + - @cache.driver + - %text_formatter.cache.dir% + - %text_formatter.cache.parser.key% + - %text_formatter.cache.renderer.key% + + text_formatter.s9e.parser: + class: phpbb\textformatter\s9e\parser + arguments: + - @cache.driver + - %text_formatter.cache.parser.key% + - @user + - @service_container + + text_formatter.s9e.renderer: + class: phpbb\textformatter\s9e\renderer + arguments: + - @cache.driver + - %text_formatter.cache.dir% + - %text_formatter.cache.renderer.key% + - @service_container + calls: + - [configure_smilies_path, [@config, @path_helper]] + - [configure_user, [@user, @config, @auth]] + + text_formatter.s9e.utils: + class: phpbb\textformatter\s9e\utils diff --git a/phpBB/config/default/container/tables.yml b/phpBB/config/default/container/tables.yml index 2fe2a33be8..00067d5abe 100644 --- a/phpBB/config/default/container/tables.yml +++ b/phpBB/config/default/container/tables.yml @@ -1,6 +1,7 @@ parameters: tables.auth_provider_oauth_token_storage: %core.table_prefix%oauth_tokens tables.auth_provider_oauth_account_assoc: %core.table_prefix%oauth_accounts + tables.bbcodes: %core.table_prefix%bbcodes tables.captcha_qa_questions: %core.table_prefix%captcha_questions tables.captcha_qa_answers: %core.table_prefix%captcha_answers tables.captcha_qa_confirm: %core.table_prefix%qa_confirm @@ -18,6 +19,9 @@ parameters: tables.profile_fields_options_language: %core.table_prefix%profile_fields_lang tables.profile_fields_language: %core.table_prefix%profile_lang tables.posts: %core.table_prefix%posts + tables.smilies: %core.table_prefix%smilies + tables.styles: %core.table_prefix%styles tables.topics: %core.table_prefix%topics tables.user_notifications: %core.table_prefix%user_notifications tables.users: %core.table_prefix%users + tables.words: %core.table_prefix%words diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index a5cd48c444..327af0e0bc 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -269,6 +269,7 @@ class acp_bbcodes $db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary)); $cache->destroy('sql', BBCODES_TABLE); + $phpbb_container->get('text_formatter.cache')->invalidate(); $lang = 'BBCODE_ADDED'; $log_action = 'LOG_BBCODE_ADD'; @@ -280,6 +281,7 @@ class acp_bbcodes WHERE bbcode_id = ' . $bbcode_id; $db->sql_query($sql); $cache->destroy('sql', BBCODES_TABLE); + $phpbb_container->get('text_formatter.cache')->invalidate(); $lang = 'BBCODE_EDITED'; $log_action = 'LOG_BBCODE_EDIT'; diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php index fdf366097a..5d1756de45 100644 --- a/phpBB/includes/acp/acp_icons.php +++ b/phpBB/includes/acp/acp_icons.php @@ -28,7 +28,7 @@ class acp_icons function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $phpbb_container; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; global $request, $phpbb_container; @@ -486,6 +486,7 @@ class acp_icons $cache->destroy('_icons'); $cache->destroy('sql', $table); + $phpbb_container->get('text_formatter.cache')->invalidate(); $level = ($icons_updated) ? E_USER_NOTICE : E_USER_WARNING; $errormsgs = ''; @@ -661,6 +662,7 @@ class acp_icons $cache->destroy('_icons'); $cache->destroy('sql', $table); + $phpbb_container->get('text_formatter.cache')->invalidate(); trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action)); } @@ -783,6 +785,7 @@ class acp_icons $cache->destroy('_icons'); $cache->destroy('sql', $table); + $phpbb_container->get('text_formatter.cache')->invalidate(); if ($request->is_ajax()) { @@ -848,6 +851,7 @@ class acp_icons $cache->destroy('_icons'); $cache->destroy('sql', $table); + $phpbb_container->get('text_formatter.cache')->invalidate(); if ($request->is_ajax()) { diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index c49ccdf479..9a99666c75 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -352,6 +352,11 @@ class acp_main $config->increment('assets_version', 1); $cache->purge(); + // Remove old renderers from the text_formatter service. Since this + // operation is performed after the cache is purged, there is not "current" + // renderer and in effect all renderers will be purged + $phpbb_container->get('text_formatter.cache')->tidy(); + // Clear permissions $auth->acl_clear_prefetch(); phpbb_cache_moderators($db, $cache, $auth); diff --git a/phpBB/includes/acp/acp_words.php b/phpBB/includes/acp/acp_words.php index d28aa8e60b..1ba247be4d 100644 --- a/phpBB/includes/acp/acp_words.php +++ b/phpBB/includes/acp/acp_words.php @@ -115,6 +115,7 @@ class acp_words } $cache->destroy('_word_censors'); + $phpbb_container->get('text_formatter.cache')->invalidate(); $log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD'; @@ -148,6 +149,7 @@ class acp_words $db->sql_query($sql); $cache->destroy('_word_censors'); + $phpbb_container->get('text_formatter.cache')->invalidate(); $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WORD_DELETE', false, array($deleted_word)); diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index bdbc8a92fa..60511d89a4 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -389,46 +389,68 @@ function phpbb_clean_search_string($search_string) /** * Decode text whereby text is coming from the db and expected to be pre-parsed content * We are placing this outside of the message parser because we are often in need of it... +* +* NOTE: special chars are kept encoded +* +* @param string &$message Original message, passed by reference +* @param string $bbcode_uid BBCode UID +* @return null */ function decode_message(&$message, $bbcode_uid = '') { - global $config; + global $phpbb_container; - if ($bbcode_uid) + if (preg_match('#^<[rt][ >]#', $message)) { - $match = array('
', "[/*:m:$bbcode_uid]", ":u:$bbcode_uid", ":o:$bbcode_uid", ":$bbcode_uid"); - $replace = array("\n", '', '', '', ''); + $message = htmlspecialchars($phpbb_container->get('text_formatter.utils')->unparse($message), ENT_COMPAT); } else { - $match = array('
'); - $replace = array("\n"); + if ($bbcode_uid) + { + $match = array('
', "[/*:m:$bbcode_uid]", ":u:$bbcode_uid", ":o:$bbcode_uid", ":$bbcode_uid"); + $replace = array("\n", '', '', '', ''); + } + else + { + $match = array('
'); + $replace = array("\n"); + } + + $message = str_replace($match, $replace, $message); + + $match = get_preg_expression('bbcode_htm'); + $replace = array('\1', '\1', '\2', '\1', '', ''); + + $message = preg_replace($match, $replace, $message); } - - $message = str_replace($match, $replace, $message); - - $match = get_preg_expression('bbcode_htm'); - $replace = array('\1', '\1', '\2', '\1', '', ''); - - $message = preg_replace($match, $replace, $message); } /** -* Strips all bbcode from a text and returns the plain content +* Strips all bbcode from a text in place */ function strip_bbcode(&$text, $uid = '') { - if (!$uid) + global $phpbb_container; + + if (preg_match('#^<[rt][ >]#', $text)) { - $uid = '[0-9a-z]{5,}'; + $text = $phpbb_container->get('text_formatter.utils')->clean_formatting($text); } + else + { + if (!$uid) + { + $uid = '[0-9a-z]{5,}'; + } - $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:".*"|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text); + $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:".*"|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text); - $match = get_preg_expression('bbcode_htm'); - $replace = array('\1', '\1', '\2', '\1', '', ''); + $match = get_preg_expression('bbcode_htm'); + $replace = array('\1', '\1', '\2', '\1', '', ''); - $text = preg_replace($match, $replace, $text); + $text = preg_replace($match, $replace, $text); + } } /** @@ -438,7 +460,7 @@ function strip_bbcode(&$text, $uid = '') function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true) { static $bbcode; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $phpbb_container; if ($text === '') { @@ -459,35 +481,57 @@ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); - if ($censor_text) + if (preg_match('#^<[rt][ >]#', $text)) { - $text = censor_text($text); - } + $renderer = $phpbb_container->get('text_formatter.renderer'); - // Parse bbcode if bbcode uid stored and bbcode enabled - if ($uid && ($flags & OPTION_FLAG_BBCODE)) + // Temporarily switch off viewcensors if applicable + $old_censor = $renderer->get_viewcensors(); + if ($old_censor !== $censor_text) + { + $renderer->set_viewcensors($censor_text); + } + + $text = $renderer->render($text); + + // Restore the previous value + if ($old_censor !== $censor_text) + { + $renderer->set_viewcensors($old_censor); + } + } + else { - if (!class_exists('bbcode')) + if ($censor_text) { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/bbcode.' . $phpEx); + $text = censor_text($text); } - if (empty($bbcode)) + // Parse bbcode if bbcode uid stored and bbcode enabled + if ($uid && ($flags & OPTION_FLAG_BBCODE)) { - $bbcode = new bbcode($bitfield); - } - else - { - $bbcode->bbcode($bitfield); + if (!class_exists('bbcode')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/bbcode.' . $phpEx); + } + + if (empty($bbcode)) + { + $bbcode = new bbcode($bitfield); + } + else + { + $bbcode->bbcode($bitfield); + } + + $bbcode->bbcode_second_pass($text, $uid); } - $bbcode->bbcode_second_pass($text, $uid); + $text = bbcode_nl2br($text); + $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); } - $text = bbcode_nl2br($text); - $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); - /** * Use this event to modify the text after it is parsed * @@ -550,11 +594,6 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb $uid = $bitfield = ''; $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0); - if ($text === '') - { - return; - } - if (!class_exists('parse_message')) { include($phpbb_root_path . 'includes/message_parser.' . $phpEx); diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index ccb953adbe..e4c35f8bca 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1094,7 +1094,7 @@ class parse_message extends bbcode_firstpass function parse_message($message = '') { // Init BBCode UID - $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN); + $this->bbcode_uid = ''; $this->message = $message; } @@ -1103,7 +1103,7 @@ class parse_message extends bbcode_firstpass */ function parse($allow_bbcode, $allow_magic_url, $allow_smilies, $allow_img_bbcode = true, $allow_flash_bbcode = true, $allow_quote_bbcode = true, $allow_url_bbcode = true, $update_this_message = true, $mode = 'post') { - global $config, $db, $user, $phpbb_dispatcher; + global $config, $db, $user, $phpbb_dispatcher, $phpbb_container; $this->mode = $mode; @@ -1132,12 +1132,6 @@ class parse_message extends bbcode_firstpass $this->decode_message(); } - // Do some general 'cleanup' first before processing message, - // e.g. remove excessive newlines(?), smilies(?) - $match = array('#(script|about|applet|activex|chrome):#i'); - $replace = array("\\1:"); - $this->message = preg_replace($match, $replace, trim($this->message)); - // Store message length... $message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message)); @@ -1210,47 +1204,29 @@ class parse_message extends bbcode_firstpass return (!$update_this_message) ? $return_message : $this->warn_msg; } - // Prepare BBcode (just prepares some tags for better parsing) - if ($allow_bbcode && strpos($this->message, '[') !== false) - { - $this->bbcode_init(); - $disallow = array('img', 'flash', 'quote', 'url'); - foreach ($disallow as $bool) - { - if (!${'allow_' . $bool . '_bbcode'}) - { - $this->bbcodes[$bool]['disabled'] = true; - } - } + // Get the parser + $parser = $phpbb_container->get('text_formatter.parser'); - $this->prepare_bbcodes(); - } + // Set the parser's options + ($allow_bbcode) ? $parser->enable_bbcodes() : $parser->disable_bbcodes(); + ($allow_magic_url) ? $parser->enable_magic_url() : $parser->disable_magic_url(); + ($allow_smilies) ? $parser->enable_smilies() : $parser->disable_smilies(); + ($allow_img_bbcode) ? $parser->enable_bbcode('img') : $parser->disable_bbcode('img'); + ($allow_flash_bbcode) ? $parser->enable_bbcode('flash') : $parser->disable_bbcode('flash'); + ($allow_quote_bbcode) ? $parser->enable_bbcode('quote') : $parser->disable_bbcode('quote'); + ($allow_url_bbcode) ? $parser->enable_bbcode('url') : $parser->disable_bbcode('url'); - // Parse smilies - if ($allow_smilies) - { - $this->smilies($config['max_' . $mode . '_smilies']); - } + // Set some config values + $parser->set_vars(array( + 'max_font_size' => $config['max_' . $this->mode . '_font_size'], + 'max_img_height' => $config['max_' . $this->mode . '_img_height'], + 'max_img_width' => $config['max_' . $this->mode . '_img_width'], + 'max_smilies' => $config['max_' . $this->mode . '_smilies'], + 'max_urls' => $config['max_' . $this->mode . '_urls'] + )); - $num_urls = 0; - - // Parse BBCode - if ($allow_bbcode && strpos($this->message, '[') !== false) - { - $this->parse_bbcode(); - $num_urls += $this->parsed_items['url']; - } - - // Parse URL's - if ($allow_magic_url) - { - $this->magic_url(generate_board_url()); - - if ($config['max_' . $mode . '_urls']) - { - $num_urls += 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); +} diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index 0d532882c6..6a56a38c45 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -51,6 +51,7 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas )); $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $phpbb_log = new \phpbb\log\null(); + $this->get_test_case_helpers()->set_s9e_services(); // Now on to the actual test diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index dee70ad016..d0b1573e61 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -11,6 +11,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerInterface; + class phpbb_test_case_helpers { protected $expectedTriggerError = false; @@ -298,4 +300,212 @@ class phpbb_test_case_helpers } } } + + /** + * Set working instances of the text_formatter.* services + * + * If no container is passed, the global $phpbb_container will be used and/or + * created if applicable + * + * @param ContainerInterface $container Service container + * @param string $fixture Path to the XML fixture + * @param string $styles_path Path to the styles dir + * @return ContainerInterface + */ + public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null) + { + static $first_run; + global $phpbb_container, $phpbb_root_path, $phpEx; + + $cache_dir = __DIR__ . '/../tmp/'; + + // Remove old cache files on first run + if (!isset($first_run)) + { + $first_run = 1; + + array_map('unlink', array_merge( + glob($cache_dir . 'data_s9e_*'), + glob($cache_dir . 's9e_*') + )); + } + + if (!isset($container)) + { + if (!isset($phpbb_container)) + { + $phpbb_container = new phpbb_mock_container_builder; + } + + $container = $phpbb_container; + } + + if (!isset($fixture)) + { + $fixture = __DIR__ . '/../text_formatter/s9e/fixtures/default_formatting.xml'; + } + + if (!isset($styles_path)) + { + $styles_path = $phpbb_root_path . 'styles/'; + } + + $dataset = new DOMDocument; + $dataset->load($fixture); + + $tables = array( + 'phpbb_bbcodes' => array(), + 'phpbb_smilies' => array(), + 'phpbb_styles' => array(), + 'phpbb_words' => array() + ); + foreach ($dataset->getElementsByTagName('table') as $table) + { + $name = $table->getAttribute('name'); + $columns = array(); + + foreach ($table->getElementsByTagName('column') as $column) + { + $columns[] = $column->textContent; + } + + foreach ($table->getElementsByTagName('row') as $row) + { + $values = array(); + + foreach ($row->getElementsByTagName('value') as $value) + { + $values[] = $value->textContent; + } + + $tables[$name][] = array_combine($columns, $values); + } + } + + // Set up a default style if there's none set + if (empty($tables['phpbb_styles'])) + { + $tables['phpbb_styles'][] = array( + 'style_id' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'kNg=' + ); + } + + // Mock the DAL, make it return data from the fixture + $mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access'); + $mb->setMethods(array('get_bbcodes', 'get_smilies', 'get_styles', 'get_words')); + $mb->setConstructorArgs(array( + $this->test_case->getMock('phpbb\\db\\driver\\driver'), + 'phpbb_bbcodes', + 'phpbb_smilies', + 'phpbb_styles', + 'phpbb_words', + $styles_path + )); + + $dal = $mb->getMock(); + $container->set('text_formatter.data_access', $dal); + + $dal->expects($this->test_case->any()) + ->method('get_bbcodes') + ->will($this->test_case->returnValue($tables['phpbb_bbcodes'])); + $dal->expects($this->test_case->any()) + ->method('get_smilies') + ->will($this->test_case->returnValue($tables['phpbb_smilies'])); + $dal->expects($this->test_case->any()) + ->method('get_styles') + ->will($this->test_case->returnValue($tables['phpbb_styles'])); + $dal->expects($this->test_case->any()) + ->method('get_words') + ->will($this->test_case->returnValue($tables['phpbb_words'])); + + // Cache the parser and renderer with a key based on this method's arguments + $cache = new \phpbb\cache\driver\file($cache_dir); + $prefix = '_s9e_' . md5(serialize(func_get_args())); + $cache_key_parser = $prefix . '_parser'; + $cache_key_renderer = $prefix . '_renderer'; + + // Create a path_helper + if (!$container->has('path_helper')) + { + $container->set( + 'path_helper', + new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + new \phpbb\filesystem(), + $this->test_case->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ) + ); + } + + // Create and register the text_formatter.s9e.factory service + $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $cache_dir, $cache_key_parser, $cache_key_renderer); + $container->set('text_formatter.s9e.factory', $factory); + + // Create a user if none was provided, and add the common lang strings + if ($container->has('user')) + { + $user = $container->get('user'); + } + else + { + $user = new \phpbb\user('\phpbb\datetime'); + $user->optionset('viewcensors', true); + $user->optionset('viewflash', true); + $user->optionset('viewimg', true); + $user->optionset('viewsmilies', true); + } + $user->add_lang('common'); + + if (!isset($user->style)) + { + $user->style = array('style_id' => 1); + } + + // Create and register the text_formatter.s9e.parser service and its alias + $parser = new \phpbb\textformatter\s9e\parser( + $cache, + $cache_key_parser, + $user, + $container + ); + + $container->set('text_formatter.parser', $parser); + $container->set('text_formatter.s9e.parser', $parser); + + // Create and register the text_formatter.s9e.renderer service and its alias + $renderer = new \phpbb\textformatter\s9e\renderer( + $cache, + $cache_dir, + $cache_key_renderer, + $container + ); + + $root_path = ($container->hasParameter('core.root_path')) + ? $container->getParameter('core.root_path') + : './'; + $config = ($container->has('config')) + ? $container->get('config') + : new \phpbb\config\config(array('smilies_path' => 'images/smilies', 'allow_nocensors' => false)); + $auth = ($container->has('auth')) ? $container->get('auth') : new \phpbb\auth\auth; + + // Calls configured in services.yml + $renderer->configure_smilies_path($config, $container->get('path_helper')); + $renderer->configure_user($user, $config, $auth); + + $container->set('text_formatter.renderer', $renderer); + $container->set('text_formatter.s9e.renderer', $renderer); + + // Create and register the text_formatter.s9e.utils service and its alias + $utils = new \phpbb\textformatter\s9e\utils; + $container->set('text_formatter.utils', $utils); + $container->set('text_formatter.s9e.utils', $utils); + + return $container; + } } diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php new file mode 100644 index 0000000000..be258868dd --- /dev/null +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -0,0 +1,200 @@ +get_test_case_helpers()->set_s9e_services(null, $fixture); + + $parser = $container->get('text_formatter.parser'); + $renderer = $container->get('text_formatter.renderer'); + + $parsed_text = $parser->parse($original); + + $this->assertSame($expected, $renderer->render($parsed_text)); + } + + public function get_default_formatting_tests() + { + return array( + array( + '[b]bold[/b]', + 'bold' + ), + array( + '[u]underlined[/u]', + 'underlined' + ), + array( + '[i]italic[/i]', + 'italic' + ), + array( + '[color=#FF0000]colored[/color]', + 'colored' + ), + array( + '[color=red]colored[/color]', + 'colored' + ), + array( + '[size=75]smaller[/size]', + 'smaller' + ), + array( + '[quote]quoted[/quote]', + '
quoted
' + ), + array( + '[quote="username"]quoted[/quote]', + '
username wrote:quoted
' + ), + array( + '[code]unparsed code[/code]', + '

CODE: Select all

unparsed code
' + ), + array( + '[list]no item[/list]', + '
    ' + ), + array( + '[*]unparsed', + '[*]unparsed' + ), + array( + '[list][*]item[/list]', + '
    • item
    ' + ), + array( + '[list][*]item[/*][/list]', + '
    • item
    ' + ), + array( + '[list=1][*]item[/list]', + '
    1. item
    ' + ), + array( + '[list=a][*]item[/list]', + '
    1. item
    ' + ), + array( + '[list=i][*]item[/list]', + '
    1. item
    ' + ), + array( + '[list=I][*]item[/list]', + '
    1. item
    ' + ), + array( + '[list=disc][*]item[/list]', + '
    • item
    ' + ), + array( + '[list=circle][*]item[/list]', + '
    • item
    ' + ), + array( + '[list=square][*]item[/list]', + '
    • item
    ' + ), + array( + '[img]https://area51.phpbb.com/images/area51.png[/img]', + 'Image' + ), + array( + '[url]https://area51.phpbb.com/[/url]', + 'https://area51.phpbb.com/' + ), + array( + '[url=https://area51.phpbb.com/]Area51[/url]', + 'Area51' + ), + array( + '[email]bbcode-test@phpbb.com[/email]', + 'bbcode-test@phpbb.com' + ), + array( + '[email=bbcode-test@phpbb.com]Email[/email]', + 'Email' + ), + array( + '[attachment=0]filename[/attachment]', + '
    filename
    ' + ), + array( + // PHPBB3-1401 - correct: parsed + '[quote="[test]test"]test [ test[/quote]', + '
    [test]test wrote:test [ test
    ' + ), + array( + // PHPBB3-6117 - correct: parsed + '[quote]test[/quote] test ] and [ test [quote]test[/quote]', + '
    test
    test ] and [ test
    test
    ' + ), + array( + // PHPBB3-6200 - correct: parsed + '[quote="["]test[/quote]', + '
    [ wrote:test
    ' + ), + array( + // PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted + '[quote]test[/[/b]quote] test [/quote][/quote] test', + '
    test[/[/b]quote] test
    [/quote] test' + ), + array( + // PHPBB3-8096 - first quote tag parsed, second quote tag unparsed + '[quote="a"]a[/quote][quote="a]a[/quote]', + '
    a wrote:a
    [quote="a]a[/quote]' + ), + array( + // Allow textual bbcodes in textual bbcodes + '[b]bold [i]bold + italic[/i][/b]', + 'bold bold + italic' + ), + array( + // Allow textual bbcodes in url with description + '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]', + 'Area51 italic' + ), + array( + // Allow url with description in textual bbcodes + '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]', + 'italic Area51' + ), + array( + // Do not parse textual bbcodes in code + '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]', + '

    CODE: Select all

    unparsed code [b]bold [i]bold + italic[/i][/b]
    ' + ), + array( + // Do not parse quote bbcodes in code + '[code]unparsed code [quote="username"]quoted[/quote][/code]', + '

    CODE: Select all

    unparsed code [quote="username"]quoted[/quote]
    ' + ), +/* + array( + // Textual bbcode nesting into textual bbcode + '[b]bold [i]bold + italic[/b] italic[/i]', + 'bold bold + italic italic' + ), +*/ + array( + "[code]\tline1\n line2[/code]", + '

    CODE: Select all

       line1
    ' . "\n" . '  line2
    ' + ), + ); + } +} diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php new file mode 100644 index 0000000000..2ea4b3031b --- /dev/null +++ b/tests/text_formatter/s9e/factory_test.php @@ -0,0 +1,182 @@ +createXMLDataSet(__DIR__ . '/fixtures/factory.xml'); + } + + public function get_cache_dir() + { + return __DIR__ . '/../../tmp/'; + } + + public function get_factory() + { + global $phpbb_root_path; + + $this->cache = new phpbb_mock_cache; + + $dal = new \phpbb\textformatter\data_access( + $this->new_dbal(), + 'phpbb_bbcodes', + 'phpbb_smilies', + 'phpbb_styles', + 'phpbb_words', + $phpbb_root_path . 'styles/' + ); + + $factory = new \phpbb\textformatter\s9e\factory( + $dal, + $this->cache, + $this->get_cache_dir(), + '_foo_parser', + '_foo_renderer' + ); + + return $factory; + } + + public function test_get_configurator() + { + $configurator = $this->get_factory()->get_configurator(); + + $this->assertInstanceOf('s9e\\TextFormatter\\Configurator', $configurator); + + $this->assertTrue(isset($configurator->plugins['Autoemail'])); + $this->assertTrue(isset($configurator->plugins['Autolink'])); + + $this->assertTrue(isset($configurator->BBCodes['B'])); + $this->assertTrue(isset($configurator->BBCodes['CODE'])); + $this->assertTrue(isset($configurator->BBCodes['COLOR'])); + $this->assertTrue(isset($configurator->BBCodes['EMAIL'])); + $this->assertTrue(isset($configurator->BBCodes['FLASH'])); + $this->assertTrue(isset($configurator->BBCodes['I'])); + $this->assertTrue(isset($configurator->BBCodes['IMG'])); + $this->assertTrue(isset($configurator->BBCodes['LIST'])); + $this->assertTrue(isset($configurator->BBCodes['*'])); + $this->assertTrue(isset($configurator->BBCodes['QUOTE'])); + $this->assertTrue(isset($configurator->BBCodes['SIZE'])); + $this->assertTrue(isset($configurator->BBCodes['U'])); + $this->assertTrue(isset($configurator->BBCodes['URL'])); + + // This custom BBCode should be set + $this->assertTrue(isset($configurator->BBCodes['CUSTOM'])); + + // This unsafe custom BBCode will trigger an exception and should be ignored + $this->assertFalse(isset($configurator->BBCodes['UNSAFE'])); + + $this->assertTrue(isset($configurator->Emoticons[':D'])); + } + + public function test_regenerate() + { + list($parser, $renderer) = $this->get_factory()->regenerate(); + + $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser); + $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer); + + $this->assertEquals($parser, $this->cache->get('_foo_parser'), 'The parser was not cached'); + $this->assertEquals( + array( + 'class' => get_class($renderer), + 'renderer' => serialize($renderer) + ), + $this->cache->get('_foo_renderer'), + 'The renderer was not cached' + ); + + $file = $this->get_cache_dir() . get_class($renderer) . '.php'; + $this->assertFileExists($file); + unlink($file); + } + + public function test_tidy() + { + $factory = $this->get_factory(); + + // Create a fake "old" cache file + $old_file = $this->get_cache_dir() . 's9e_foo.php'; + touch($old_file); + + // Create a current renderer + list($parser, $renderer) = $factory->regenerate(); + $new_file = $this->get_cache_dir() . get_class($renderer) . '.php'; + + // Tidy the cache + $factory->tidy(); + + $this->assertFileExists($new_file, 'The current renderer has been deleted'); + $this->assertFileNotExists($old_file, 'The old renderer has not been deleted'); + + unlink($new_file); + } + + public function test_local_url() + { + global $config, $user, $request; + + $config = array( + 'force_server_vars' => true, + 'server_protocol' => 'http://', + 'server_name' => 'path', + 'server_port' => 80, + 'script_path' => '/to', + 'cookie_secure' => false + ); + $user = new phpbb_mock_user; + $request = new phpbb_mock_request; + + $fixture = __DIR__ . '/fixtures/local_url.xml'; + $renderer = $this->get_test_case_helpers()->set_s9e_services(null, $fixture)->get('text_formatter.renderer'); + + $this->assertSame( + 'http://path/to/foo', + $renderer->render('[local]foo[/local]') + ); + } + + public function test_smilies_special_chars() + { + // Use a smiley that contains every special chars in every field + $fixture = __DIR__ . '/fixtures/smilies_special_chars.xml'; + $renderer = $this->get_test_case_helpers()->set_s9e_services(null, $fixture)->get('text_formatter.renderer'); + + $this->assertSame( + '"\'<&>', + $renderer->render('"\'<&>') + ); + } + + /** + * @testdox {INTTEXT} is supported in custom BBCodes + */ + public function test_inttext_token() + { + $fixture = __DIR__ . '/fixtures/inttext_token.xml'; + $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); + $parser = $container->get('text_formatter.parser'); + $renderer = $container->get('text_formatter.renderer'); + + $original = '[spoiler=ɎɆS]text[/spoiler]'; + $expected = '
    ɎɆS
    text
    '; + $this->assertSame($expected, $renderer->render($parser->parse($original))); + + $original = '[spoiler=N:O:P:E]text[/spoiler]'; + $expected = $original; + $this->assertSame($expected, $renderer->render($parser->parse($original))); + } +} diff --git a/tests/text_formatter/s9e/fixtures/default_formatting.xml b/tests/text_formatter/s9e/fixtures/default_formatting.xml new file mode 100644 index 0000000000..2b7236fb30 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/default_formatting.xml @@ -0,0 +1,466 @@ + + + + smiley_id + code + emotion + smiley_url + smiley_width + smiley_height + smiley_order + display_on_posting + + 1 + :D + Very Happy + icon_e_biggrin.gif + 15 + 17 + 1 + 1 + + + 2 + :-D + Very Happy + icon_e_biggrin.gif + 15 + 17 + 2 + 1 + + + 3 + :grin: + Very Happy + icon_e_biggrin.gif + 15 + 17 + 3 + 1 + + + 4 + :) + Smile + icon_e_smile.gif + 15 + 17 + 4 + 1 + + + 5 + :-) + Smile + icon_e_smile.gif + 15 + 17 + 5 + 1 + + + 6 + :smile: + Smile + icon_e_smile.gif + 15 + 17 + 6 + 1 + + + 7 + ;) + Wink + icon_e_wink.gif + 15 + 17 + 7 + 1 + + + 8 + ;-) + Wink + icon_e_wink.gif + 15 + 17 + 8 + 1 + + + 9 + :wink: + Wink + icon_e_wink.gif + 15 + 17 + 9 + 1 + + + 10 + :( + Sad + icon_e_sad.gif + 15 + 17 + 10 + 1 + + + 11 + :-( + Sad + icon_e_sad.gif + 15 + 17 + 11 + 1 + + + 12 + :sad: + Sad + icon_e_sad.gif + 15 + 17 + 12 + 1 + + + 13 + :o + Surprised + icon_e_surprised.gif + 15 + 17 + 13 + 1 + + + 14 + :-o + Surprised + icon_e_surprised.gif + 15 + 17 + 14 + 1 + + + 15 + :eek: + Surprised + icon_e_surprised.gif + 15 + 17 + 15 + 1 + + + 16 + :shock: + Shocked + icon_eek.gif + 15 + 17 + 16 + 1 + + + 17 + :? + Confused + icon_e_confused.gif + 15 + 17 + 17 + 1 + + + 18 + :-? + Confused + icon_e_confused.gif + 15 + 17 + 18 + 1 + + + 19 + :???: + Confused + icon_e_confused.gif + 15 + 17 + 19 + 1 + + + 20 + 8-) + Cool + icon_cool.gif + 15 + 17 + 20 + 1 + + + 21 + :cool: + Cool + icon_cool.gif + 15 + 17 + 21 + 1 + + + 22 + :lol: + Laughing + icon_lol.gif + 15 + 17 + 22 + 1 + + + 23 + :x + Mad + icon_mad.gif + 15 + 17 + 23 + 1 + + + 24 + :-x + Mad + icon_mad.gif + 15 + 17 + 24 + 1 + + + 25 + :mad: + Mad + icon_mad.gif + 15 + 17 + 25 + 1 + + + 26 + :P + Razz + icon_razz.gif + 15 + 17 + 26 + 1 + + + 27 + :-P + Razz + icon_razz.gif + 15 + 17 + 27 + 1 + + + 28 + :razz: + Razz + icon_razz.gif + 15 + 17 + 28 + 1 + + + 29 + :oops: + Embarrassed + icon_redface.gif + 15 + 17 + 29 + 1 + + + 30 + :cry: + Crying or Very Sad + icon_cry.gif + 15 + 17 + 30 + 1 + + + 31 + :evil: + Evil or Very Mad + icon_evil.gif + 15 + 17 + 31 + 1 + + + 32 + :twisted: + Twisted Evil + icon_twisted.gif + 15 + 17 + 32 + 1 + + + 33 + :roll: + Rolling Eyes + icon_rolleyes.gif + 15 + 17 + 33 + 1 + + + 34 + :!: + Exclamation + icon_exclaim.gif + 15 + 17 + 34 + 1 + + + 35 + :?: + Question + icon_question.gif + 15 + 17 + 35 + 1 + + + 36 + :idea: + Idea + icon_idea.gif + 15 + 17 + 36 + 1 + + + 37 + :arrow: + Arrow + icon_arrow.gif + 15 + 17 + 37 + 1 + + + 38 + :| + Neutral + icon_neutral.gif + 15 + 17 + 38 + 1 + + + 39 + :-| + Neutral + icon_neutral.gif + 15 + 17 + 39 + 1 + + + 40 + :mrgreen: + Mr. Green + icon_mrgreen.gif + 15 + 17 + 40 + 1 + + + 41 + :geek: + Geek + icon_e_geek.gif + 17 + 17 + 41 + 1 + + + 42 + :ugeek: + Uber Geek + icon_e_ugeek.gif + 17 + 18 + 42 + 1 + +
    + + + style_id + style_name + style_copyright + style_active + style_path + bbcode_bitfield + style_parent_id + style_parent_tree + + 1 + prosilver + &copy; phpBB Group + 1 + prosilver + kNg= + 0 + + +
    + + + word_id + word + replacement + + + 1 + apple + banana + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/default_lang.xml b/tests/text_formatter/s9e/fixtures/default_lang.xml new file mode 100644 index 0000000000..2cfde4aab2 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/default_lang.xml @@ -0,0 +1,20 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + + + 13 + foo + + 1 + [foo]{TEXT}[/foo] + {L_FOO_BAR} + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/factory.xml b/tests/text_formatter/s9e/fixtures/factory.xml new file mode 100644 index 0000000000..9ae52e9747 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/factory.xml @@ -0,0 +1,115 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + custom + + 1 + [custom]{TEXT}[/custom] + <span style="color:red">{TEXT}</span> + !\[custom\](.*?)\[/custom\]!ies + '[custom:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/custom:$uid]' + !\[custom:$uid\](.*?)\[/custom:$uid\]!s + <span style="color:red">${1}</span> + + + 14 + unsafe + + 1 + [unsafe]{TEXT}[/unsafe] + <script>{TEXT}</script> + !\[unsafe\](.*?)\[/unsafe\]!ies + '[unsafe:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/unsafe:$uid]' + !\[unsafe:$uid\](.*?)\[/unsafe:$uid\]!s + <script>${1}</script> + +
    + + + smiley_id + code + emotion + smiley_url + smiley_width + smiley_height + smiley_order + display_on_posting + + 1 + :D + Very Happy + icon_e_biggrin.gif + 15 + 17 + 2 + 1 + + + 4 + :) + Smile + icon_e_smile.gif + 15 + 17 + 4 + 1 + + + 10 + :( + Sad + icon_e_sad.gif + 15 + 17 + 10 + 1 + +
    + + + style_id + style_name + style_copyright + style_active + style_path + bbcode_bitfield + style_parent_id + style_parent_tree + + + 1 + prosilver + &copy; phpBB Group + 1 + prosilver + kNg= + 0 + + +
    + + + word_id + word + replacement + + + 1 + apple + banana + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/inttext_token.xml b/tests/text_formatter/s9e/fixtures/inttext_token.xml new file mode 100644 index 0000000000..30b971f315 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/inttext_token.xml @@ -0,0 +1,27 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + spoiler= + + 1 + [spoiler={INTTEXT}]{TEXT}[/spoiler] +
    {INTTEXT}
    {TEXT}
    ]]>
    + + +
    ${1}
    ${2}
    ]]>
    +
    +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/local_url.xml b/tests/text_formatter/s9e/fixtures/local_url.xml new file mode 100644 index 0000000000..9db2bf4710 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/local_url.xml @@ -0,0 +1,28 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + local + + 1 + [local]{LOCAL_URL}[/local] + {LOCAL_URL}]]> + + bbcode_specialchars('${1}').'[/local:$uid]']]> + + http://path/to/phpBB/${1}]]> + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml b/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml new file mode 100644 index 0000000000..d3a7cfa4f7 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml @@ -0,0 +1,23 @@ + + + + smiley_id + code + emotion + smiley_url + smiley_width + smiley_height + smiley_order + display_on_posting + + 1 + "'<&> + "'<&> + "'<&>.png + 15 + 17 + 2 + 1 + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/style_inheritance.xml b/tests/text_formatter/s9e/fixtures/style_inheritance.xml new file mode 100644 index 0000000000..a692d0ef2d --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/style_inheritance.xml @@ -0,0 +1,66 @@ + + + + style_id + style_name + style_copyright + style_active + style_path + bbcode_bitfield + style_parent_id + style_parent_tree + + + 1 + foo + + 1 + foo + + QA== + 0 + + + + 2 + fooplus + + 1 + fooplus + QA== + 1 + + + + 3 + fooplusplus + + 1 + fooplusplus + QA== + 2 + + + + 4 + bar + + 1 + bar + + QA== + 0 + + + + 5 + barplus + + 1 + barplus + QA== + 4 + + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/styles.xml b/tests/text_formatter/s9e/fixtures/styles.xml new file mode 100644 index 0000000000..8004412aea --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles.xml @@ -0,0 +1,36 @@ + + + + style_id + style_name + style_copyright + style_active + style_path + bbcode_bitfield + style_parent_id + style_parent_tree + + + 1 + foo + + 1 + foo + + QA== + 0 + + + + 2 + bar + + 1 + bar + + QA== + 0 + + +
    +
    diff --git a/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html new file mode 100644 index 0000000000..a17446581a --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html @@ -0,0 +1,40 @@ +
      +
        +
      + +
        +
      + +
    • +
    • + +
      {USERNAME} {L_WROTE}{L_COLON} +
      +
      + +

      {L_CODE}{L_COLON} {L_SELECT_ALL_CODE}

      +
      + +
      +
      + + + + + + + + + + +{TEXT} + +{TEXT} + +{L_IMAGE} + +{DESCRIPTION} + +{DESCRIPTION} + + diff --git a/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html new file mode 100644 index 0000000000..cd2f0acae3 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html @@ -0,0 +1,40 @@ +
        +
          +
        + +
          +
        + +
      • +
      • + +
        {USERNAME} {L_WROTE}{L_COLON} +
        +
        + +

        {L_CODE}{L_COLON} {L_SELECT_ALL_CODE}

        +
        + +
        +
        + + + + + + + + + + +{TEXT} + +{TEXT} + +{L_IMAGE} + +{DESCRIPTION} + +{DESCRIPTION} + + diff --git a/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html new file mode 100644 index 0000000000..909c09df5a --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html @@ -0,0 +1,40 @@ +
          +
            +
          + +
            +
          + +
        • +
        • + +
          {USERNAME} {L_WROTE}{L_COLON} +
          +
          + +

          {L_CODE}{L_COLON} {L_SELECT_ALL_CODE}

          +
          + +
          +
          + + + + + + + + + + +{TEXT} + +{TEXT} + +{L_IMAGE} + +{DESCRIPTION} + +{DESCRIPTION} + + diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php new file mode 100644 index 0000000000..528305a11c --- /dev/null +++ b/tests/text_formatter/s9e/parser_test.php @@ -0,0 +1,162 @@ +getMockBuilder('s9e\\TextFormatter\\Parser') + ->disableOriginalConstructor() + ->getMock(); + + $cache = $this->getMock('phpbb_mock_cache'); + $cache->expects($this->once()) + ->method('get') + ->with('_foo_parser') + ->will($this->returnValue($mock)); + + $parser = new \phpbb\textformatter\s9e\parser( + $cache, + '_foo_parser', + $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), + new phpbb_mock_container_builder + ); + } + + public function test_use_from_cache() + { + $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') + ->disableOriginalConstructor() + ->getMock(); + + $mock->expects($this->once()) + ->method('parse') + ->with('test') + ->will($this->returnValue('test')); + + $cache = new phpbb_mock_cache; + $cache->put('_foo_parser', $mock); + + $parser = new \phpbb\textformatter\s9e\parser( + $cache, + '_foo_parser', + $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), + new phpbb_mock_container_builder + ); + + $this->assertSame('test', $parser->parse('test')); + } + + public function test_regenerate_on_cache_miss() + { + $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') + ->disableOriginalConstructor() + ->getMock(); + + $mock->expects($this->once()) + ->method('parse') + ->with('test') + ->will($this->returnValue('test')); + + $factory = $this->getMock('stdClass', array('regenerate')); + $factory->expects($this->once()) + ->method('regenerate') + ->will($this->returnValue(array($mock, false))); + + $container = new phpbb_mock_container_builder; + $container->set('text_formatter.s9e.factory', $factory); + + $parser = new \phpbb\textformatter\s9e\parser( + new phpbb_mock_cache, + '_foo_parser', + $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), + $container + ); + + $this->assertSame('test', $parser->parse('test')); + } + + /** + * @dataProvider get_options_tests() + */ + public function test_options($adapter_method, $adapter_arg, $concrete_method, $concrete_arg) + { + $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser') + ->setMethods(array($concrete_method)) + ->disableOriginalConstructor() + ->getMock(); + foreach ((array) $concrete_arg as $i => $concrete_arg) + { + $mock->expects($this->at($i)) + ->method($concrete_method) + ->with($concrete_arg); + } + + $cache = new phpbb_mock_cache; + $cache->put('_foo_parser', $mock); + + $parser = new \phpbb\textformatter\s9e\parser( + $cache, + '_foo_parser', + $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), + new phpbb_mock_container_builder + ); + + call_user_func_array(array($parser, $adapter_method), (array) $adapter_arg); + } + + public function get_options_tests() + { + return array( + array( + 'disable_bbcode', 'url', + 'disableTag', 'URL' + ), + array( + 'disable_bbcodes', null, + 'disablePlugin', 'BBCodes' + ), + array( + 'disable_censor', null, + 'disablePlugin', 'Censor' + ), + array( + 'disable_magic_url', null, + 'disablePlugin', array('Autoemail', 'Autolink') + ), + array( + 'disable_smilies', null, + 'disablePlugin', 'Emoticons' + ), + array( + 'enable_bbcode', 'url', + 'enableTag', 'URL' + ), + array( + 'enable_bbcodes', null, + 'enablePlugin', 'BBCodes' + ), + array( + 'enable_censor', null, + 'enablePlugin', 'Censor' + ), + array( + 'enable_magic_url', null, + 'enablePlugin', array('Autoemail', 'Autolink') + ), + array( + 'enable_smilies', null, + 'enablePlugin', 'Emoticons' + ) + ); + } +} diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php new file mode 100644 index 0000000000..76babbfdf3 --- /dev/null +++ b/tests/text_formatter/s9e/renderer_test.php @@ -0,0 +1,355 @@ +get_cache_dir() . 'renderer_foo.php', + 'getMockForAbstractClass('s9e\\TextFormatter\\Renderer'); + + $cache = $this->getMock('phpbb_mock_cache'); + $cache->expects($this->once()) + ->method('get') + ->with('_foo_renderer') + ->will($this->returnValue(array('class' => 'renderer_foo', 'renderer' => serialize($mock)))); + + $container = new phpbb_mock_container_builder; + $container->set('text_formatter.s9e.factory', $factory); + + $renderer = new \phpbb\textformatter\s9e\renderer( + $cache, + $this->get_cache_dir(), + '_foo_renderer', + $container + ); + } + + public function test_regenerate_on_cache_miss() + { + $mock = $this->getMockForAbstractClass('s9e\\TextFormatter\\Renderer'); + + $cache = $this->getMock('phpbb_mock_cache'); + $cache->expects($this->once()) + ->method('get') + ->with('_foo_renderer') + ->will($this->returnValue(false)); + + $factory = $this->getMock('stdClass', array('regenerate')); + $factory->expects($this->once()) + ->method('regenerate') + ->will($this->returnValue(array($mock, false))); + + $container = new phpbb_mock_container_builder; + $container->set('text_formatter.s9e.factory', $factory); + + $renderer = new \phpbb\textformatter\s9e\renderer( + $cache, + $this->get_cache_dir(), + '_foo_renderer', + $container + ); + } + + /** + * @dataProvider get_options_cases + */ + public function test_options($original, $expected, $calls) + { + $container = new phpbb_mock_container_builder; + $this->get_test_case_helpers()->set_s9e_services($container); + + $renderer = $container->get('text_formatter.renderer'); + + foreach ($calls as $method => $arg) + { + $renderer->$method($arg); + } + + $this->assertSame($expected, $renderer->render($original)); + } + + public function get_options_cases() + { + return array( + array( + 'apple', + 'banana', + array('set_viewcensors' => true) + ), + array( + 'apple', + 'apple', + array('set_viewcensors' => false) + ), + array( + '[flash=123,456]http://example.org/foo.swf[/flash]', + '', + array('set_viewflash' => true) + ), + array( + '[img]http://example.org/foo.png[/img]', + 'Image', + array('set_viewimg' => true) + ), + array( + ':)', + ':)', + array('set_viewsmilies' => true) + ), + array( + ':)', + ':)', + array('set_viewsmilies' => false) + ), + ); + } + + /** + * @dataProvider get_default_options_cases + */ + public function test_default_options($original, $expected, $setup = null) + { + $container = new phpbb_mock_container_builder; + + if (isset($setup)) + { + $setup($container, $this); + } + + $this->get_test_case_helpers()->set_s9e_services($container); + + $this->assertSame($expected, $container->get('text_formatter.renderer')->render($original)); + } + + public function get_default_options_cases() + { + return array( + array( + 'apple', + 'banana' + ), + array( + 'apple', + 'banana', + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewcensors', false); + + $phpbb_container->set('user', $user); + } + ), + array( + 'apple', + 'banana', + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewcensors', false); + + $config = new \phpbb\config\config(array('allow_nocensors' => true)); + + $phpbb_container->set('user', $user); + $phpbb_container->set('config', $config); + } + ), + array( + 'apple', + 'apple', + function ($phpbb_container, $test) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewcensors', false); + + $config = new \phpbb\config\config(array('allow_nocensors' => true)); + + $auth = $test->getMock('phpbb\\auth\\auth'); + $auth->expects($test->any()) + ->method('acl_get') + ->with('u_chgcensors') + ->will($test->returnValue(true)); + + $phpbb_container->set('user', $user); + $phpbb_container->set('config', $config); + $phpbb_container->set('auth', $auth); + } + ), + array( + '[flash=123,456]http://localhost/foo.swf[/flash]', + '' + ), + array( + '[flash=123,456]http://localhost/foo.swf[/flash]', + 'http://localhost/foo.swf', + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewflash', false); + + $phpbb_container->set('user', $user); + } + ), + array( + '[img]http://localhost/mrgreen.gif[/img]', + 'Image' + ), + array( + '[img]http://localhost/mrgreen.gif[/img]', + 'http://localhost/mrgreen.gif', + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewimg', false); + + $phpbb_container->set('user', $user); + } + ), + array( + ':)', + ':)' + ), + array( + ':)', + ':)', + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('smilies', false); + + $phpbb_container->set('user', $user); + } + ), + ); + } + + public function test_default_lang() + { + global $phpbb_container; + $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/default_lang.xml'); + + $renderer = $phpbb_container->get('text_formatter.renderer'); + + $this->assertSame('FOO_BAR', $renderer->render('')); + } + + /** + * @dataProvider get_option_names + */ + public function test_get_option($option_name) + { + global $phpbb_container; + $this->get_test_case_helpers()->set_s9e_services(); + + $renderer = $phpbb_container->get('text_formatter.renderer'); + + $renderer->{'set_' . $option_name}(false); + $this->assertFalse($renderer->{'get_' . $option_name}()); + $renderer->{'set_' . $option_name}(true); + $this->assertTrue($renderer->{'get_' . $option_name}()); + } + + public function get_option_names() + { + return array( + array('viewcensors'), + array('viewflash'), + array('viewimg'), + array('viewsmilies') + ); + } + + public function test_styles() + { + global $phpbb_container; + + $tests = array( + 1 => 'bold', + 2 => 'bold' + ); + + foreach ($tests as $style_id => $expected) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->style = array('style_id' => $style_id); + + $phpbb_container = new phpbb_mock_container_builder; + $phpbb_container->set('user', $user); + + $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/styles.xml', __DIR__ . '/fixtures/styles/'); + + $renderer = $phpbb_container->get('text_formatter.renderer'); + $this->assertSame( + $expected, + $renderer->render('[b]bold[/b]') + ); + } + } + + public function test_style_inheritance1() + { + global $phpbb_container; + + // Style 3 inherits from 2 which inherits from 1. Only style 1 has a bbcode.html + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->style = array('style_id' => 3); + + $phpbb_container = new phpbb_mock_container_builder; + $phpbb_container->set('user', $user); + + $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/style_inheritance.xml', __DIR__ . '/fixtures/styles/'); + + $renderer = $phpbb_container->get('text_formatter.renderer'); + $this->assertSame( + 'bold', + $renderer->render('[b]bold[/b]') + ); + } + + public function test_style_inheritance2() + { + global $phpbb_container; + + // Style 5 inherits from 4, but both have a bbcode.html + $tests = array( + 4 => 'bold', + 5 => 'bold' + ); + + foreach ($tests as $style_id => $expected) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->style = array('style_id' => $style_id); + + $phpbb_container = new phpbb_mock_container_builder; + $phpbb_container->set('user', $user); + + $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/style_inheritance.xml', __DIR__ . '/fixtures/styles/'); + + $renderer = $phpbb_container->get('text_formatter.renderer'); + $this->assertSame( + $expected, + $renderer->render('[b]bold[/b]') + ); + } + } +} diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php new file mode 100644 index 0000000000..510beba817 --- /dev/null +++ b/tests/text_formatter/s9e/utils_test.php @@ -0,0 +1,157 @@ +get_test_case_helpers()->set_s9e_services(); + $utils = $container->get('text_formatter.utils'); + + $this->assertSame($expected, $utils->unparse($original)); + } + + public function get_unparse_tests() + { + return array( + array( + 'Plain text', + 'Plain text' + ), + array( + "Multi
          \nline
          ", + "Multi\nline" + ), + array( + '[b]bold[/b]', + '[b]bold[/b]' + ) + ); + } + + /** + * @dataProvider get_remove_formatting_tests + */ + public function test_remove_formatting($original, $expected) + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $utils = $container->get('text_formatter.utils'); + + $this->assertSame($expected, $utils->remove_formatting($original)); + } + + public function get_remove_formatting_tests() + { + return array( + array( + 'Plain text', + 'Plain text' + ), + array( + "Multi
          \nline
          ", + "Multi\nline" + ), + array( + '[b]bold[/b]', + 'bold' + ) + ); + } + + /** + * @dataProvider get_clean_formatting_tests + */ + public function test_clean_formatting($original, $expected) + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $utils = $container->get('text_formatter.utils'); + + $this->assertSame($expected, $utils->clean_formatting($original)); + } + + public function get_clean_formatting_tests() + { + return array( + array( + 'Plain text', + 'Plain text' + ), + array( + "Multi
          \nline
          ", + "Multi\nline" + ), + array( + '[b]bold[/b]', + ' bold ' + ) + ); + } + + /** + * @dataProvider get_remove_bbcode_tests + */ + public function test_remove_bbcode($original, $name, $depth, $expected) + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $utils = $container->get('text_formatter.utils'); + + $this->assertSame($expected, $utils->remove_bbcode($original, $name, $depth)); + } + + public function get_remove_bbcode_tests() + { + return array( + array( + 'Plain text', + 'b', + 1, + 'Plain text' + ), + array( + '[quote="u0"][quote="u1"][quote="u2"]q2[/quote] +q1[/quote] +q0[/quote] +[b]bold[/b]', + 'quote', + 0, + ' +[b]bold[/b]' + ), + array( + '[quote="u0"][quote="u1"][quote="u2"]q2[/quote] +q1[/quote] +q0[/quote] +[b]bold[/b]', + 'quote', + 1, + '[quote="u0"] +q0[/quote] +[b]bold[/b]' + ), + array( + '[quote="u0"][quote="u1"][quote="u2"]q2[/quote] +q1[/quote] +q0[/quote] +[b]bold[/b]', + 'quote', + 2, + '[quote="u0"][quote="u1"] +q1[/quote] +q0[/quote] +[b]bold[/b]' + ), + ); + } +} diff --git a/tests/text_processing/decode_message_test.php b/tests/text_processing/decode_message_test.php new file mode 100644 index 0000000000..855b3c6c57 --- /dev/null +++ b/tests/text_processing/decode_message_test.php @@ -0,0 +1,87 @@ +assertSame($expected, $actual); + } + + public function get_legacy_tests() + { + return array( + array( + "&<>"'", + "&<>"'" + ), + array( + ':)', + ':)' + ), + /** + * Fails as per PHPBB3-8420 + * @link http://tracker.phpbb.com/browse/PHPBB3-8420 + * + array( + '[url=http://example.com:2cpxwbdy]:arrow: here[/url:2cpxwbdy]', + '[url=http://example.com] :arrow: here[/url]', + '2cpxwbdy' + ), + */ + ); + } + + /** + * @dataProvider get_text_formatter_tests + */ + public function test_text_formatter($original, $expected) + { + $this->get_test_case_helpers()->set_s9e_services(); + + $actual = $original; + decode_message($actual); + + $this->assertSame($expected, $actual); + } + + public function get_text_formatter_tests() + { + return array( + array( + "&<>\"'", + "&<>"'" + ), + array( + ':)', + ':)' + ), + array( + "a
          \nb
          ", + "a\nb" + ), + /** + * @link http://tracker.phpbb.com/browse/PHPBB3-8420 + */ + array( + '[url=http://example.com] :arrow: here[/url]', + '[url=http://example.com] :arrow: here[/url]' + ), + ); + } +} diff --git a/tests/text_processing/fixtures/empty.xml b/tests/text_processing/fixtures/empty.xml new file mode 100644 index 0000000000..d8206ad124 --- /dev/null +++ b/tests/text_processing/fixtures/empty.xml @@ -0,0 +1,3 @@ + + + diff --git a/tests/text_processing/fixtures/smilies.xml b/tests/text_processing/fixtures/smilies.xml new file mode 100644 index 0000000000..25b2e60836 --- /dev/null +++ b/tests/text_processing/fixtures/smilies.xml @@ -0,0 +1,443 @@ + + + + smiley_id + code + emotion + smiley_url + smiley_width + smiley_height + smiley_order + display_on_posting + + 1 + :D + Very Happy + icon_e_biggrin.gif + 15 + 17 + 1 + 1 + + + 2 + :-D + Very Happy + icon_e_biggrin.gif + 15 + 17 + 2 + 1 + + + 3 + :grin: + Very Happy + icon_e_biggrin.gif + 15 + 17 + 3 + 1 + + + 4 + :) + Smile + icon_e_smile.gif + 15 + 17 + 4 + 1 + + + 5 + :-) + Smile + icon_e_smile.gif + 15 + 17 + 5 + 1 + + + 6 + :smile: + Smile + icon_e_smile.gif + 15 + 17 + 6 + 1 + + + 7 + ;) + Wink + icon_e_wink.gif + 15 + 17 + 7 + 1 + + + 8 + ;-) + Wink + icon_e_wink.gif + 15 + 17 + 8 + 1 + + + 9 + :wink: + Wink + icon_e_wink.gif + 15 + 17 + 9 + 1 + + + 10 + :( + Sad + icon_e_sad.gif + 15 + 17 + 10 + 1 + + + 11 + :-( + Sad + icon_e_sad.gif + 15 + 17 + 11 + 1 + + + 12 + :sad: + Sad + icon_e_sad.gif + 15 + 17 + 12 + 1 + + + 13 + :o + Surprised + icon_e_surprised.gif + 15 + 17 + 13 + 1 + + + 14 + :-o + Surprised + icon_e_surprised.gif + 15 + 17 + 14 + 1 + + + 15 + :eek: + Surprised + icon_e_surprised.gif + 15 + 17 + 15 + 1 + + + 16 + :shock: + Shocked + icon_eek.gif + 15 + 17 + 16 + 1 + + + 17 + :? + Confused + icon_e_confused.gif + 15 + 17 + 17 + 1 + + + 18 + :-? + Confused + icon_e_confused.gif + 15 + 17 + 18 + 1 + + + 19 + :???: + Confused + icon_e_confused.gif + 15 + 17 + 19 + 1 + + + 20 + 8-) + Cool + icon_cool.gif + 15 + 17 + 20 + 1 + + + 21 + :cool: + Cool + icon_cool.gif + 15 + 17 + 21 + 1 + + + 22 + :lol: + Laughing + icon_lol.gif + 15 + 17 + 22 + 1 + + + 23 + :x + Mad + icon_mad.gif + 15 + 17 + 23 + 1 + + + 24 + :-x + Mad + icon_mad.gif + 15 + 17 + 24 + 1 + + + 25 + :mad: + Mad + icon_mad.gif + 15 + 17 + 25 + 1 + + + 26 + :P + Razz + icon_razz.gif + 15 + 17 + 26 + 1 + + + 27 + :-P + Razz + icon_razz.gif + 15 + 17 + 27 + 1 + + + 28 + :razz: + Razz + icon_razz.gif + 15 + 17 + 28 + 1 + + + 29 + :oops: + Embarrassed + icon_redface.gif + 15 + 17 + 29 + 1 + + + 30 + :cry: + Crying or Very Sad + icon_cry.gif + 15 + 17 + 30 + 1 + + + 31 + :evil: + Evil or Very Mad + icon_evil.gif + 15 + 17 + 31 + 1 + + + 32 + :twisted: + Twisted Evil + icon_twisted.gif + 15 + 17 + 32 + 1 + + + 33 + :roll: + Rolling Eyes + icon_rolleyes.gif + 15 + 17 + 33 + 1 + + + 34 + :!: + Exclamation + icon_exclaim.gif + 15 + 17 + 34 + 1 + + + 35 + :?: + Question + icon_question.gif + 15 + 17 + 35 + 1 + + + 36 + :idea: + Idea + icon_idea.gif + 15 + 17 + 36 + 1 + + + 37 + :arrow: + Arrow + icon_arrow.gif + 15 + 17 + 37 + 1 + + + 38 + :| + Neutral + icon_neutral.gif + 15 + 17 + 38 + 1 + + + 39 + :-| + Neutral + icon_neutral.gif + 15 + 17 + 39 + 1 + + + 40 + :mrgreen: + Mr. Green + icon_mrgreen.gif + 15 + 17 + 40 + 1 + + + 41 + :geek: + Geek + icon_e_geek.gif + 17 + 17 + 41 + 1 + + + 42 + :ugeek: + Uber Geek + icon_e_ugeek.gif + 17 + 18 + 42 + 1 + + + 43 + 8) + 8) + custom.gif + 17 + 18 + 42 + 1 + +
          +
          diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php index 057416da33..fe83938c0b 100644 --- a/tests/text_processing/generate_text_for_display_test.php +++ b/tests/text_processing/generate_text_for_display_test.php @@ -11,10 +11,8 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../mock/user.php'; -require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case { @@ -24,21 +22,175 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca parent::setUp(); - $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $config = new \phpbb\config\config(array()); + set_config(null, null, null, $config); + } - $user = new phpbb_mock_user; + /** + * @dataProvider get_legacy_tests + */ + public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true) + { + global $cache, $user; + + $cache = new phpbb_mock_cache; + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewcensors', true); + $user->optionset('viewflash', true); + $user->optionset('viewimg', true); + $user->optionset('viewsmilies', true); + + $actual = generate_text_for_display($original, $uid, $bitfield, $flags, $censor_text); + + $this->assertSame($expected, $actual); + } + + public function get_legacy_tests() + { + return array( + array( + '', + '' + ), + array( + '0', + '0' + ), + ); + } + + public function test_censor_is_restored() + { + global $phpbb_container; + + $phpbb_container = new phpbb_mock_container_builder; + + $user = new \phpbb\user('\\phpbb\\datetime'); $user->optionset('viewcensors', false); - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $config = new \phpbb\config\config(array('allow_nocensors' => true)); + + $auth = $this->getMock('phpbb\\auth\\auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with('u_chgcensors') + ->will($this->returnValue(true)); + + $phpbb_container->set('user', $user); + $phpbb_container->set('config', $config); + $phpbb_container->set('auth', $auth); + + $this->get_test_case_helpers()->set_s9e_services($phpbb_container); + $renderer = $phpbb_container->get('text_formatter.renderer'); + + $original = 'apple'; + + $renderer->set_viewcensors(false); + $this->assertSame('apple', $renderer->render($original)); + $renderer->set_viewcensors(true); + $this->assertSame('banana', $renderer->render($original)); + $this->assertSame('apple', generate_text_for_display($original, '', '', 0, false)); + $this->assertSame('banana', $renderer->render($original), 'The original setting was not restored'); + + $renderer->set_viewcensors(false); + $this->assertSame('apple', $renderer->render($original)); + $this->assertSame('banana', generate_text_for_display($original, '', '', 0, truee)); + $this->assertSame('apple', $renderer->render($original), 'The original setting was not restored'); } - public function test_empty_string() + /** + * @dataProvider get_text_formatter_tests + */ + public function test_text_formatter($original, $expected, $censor_text = true, $setup = null) { - $this->assertSame('', generate_text_for_display('', '', '', 0)); + global $phpbb_container; + + $phpbb_container = new phpbb_mock_container_builder; + + if (isset($setup)) + { + $setup($phpbb_container, $this); + } + + $this->get_test_case_helpers()->set_s9e_services($phpbb_container); + + $this->assertSame($expected, generate_text_for_display($original, '', '', 0, $censor_text)); } - public function test_zero_string() + public function get_text_formatter_tests() { - $this->assertSame('0', generate_text_for_display('0', '', '', 0)); + return array( + array( + 'Plain text', + 'Plain text' + ), + array( + 'Hello [url=http://example.org]world[/url]', + 'Hello world' + ), + array( + '&<>"\'', + '&<>"\'' + ), + array( + 'apple', + 'banana', + true + ), + array( + 'apple', + 'apple', + false + ), + array( + '[flash=123,456]http://localhost/foo.swf[/flash]', + '' + ), + array( + '[flash=123,456]http://localhost/foo.swf[/flash]', + 'http://localhost/foo.swf', + true, + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewflash', false); + + $phpbb_container->set('user', $user); + } + ), + array( + '[img]http://localhost/mrgreen.gif[/img]', + 'Image' + ), + array( + '[img]http://localhost/mrgreen.gif[/img]', + 'http://localhost/mrgreen.gif', + true, + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('viewimg', false); + + $phpbb_container->set('user', $user); + } + ), + array( + ':)', + ':)' + ), + array( + ':)', + ':)', + true, + function ($phpbb_container) + { + $user = new \phpbb\user('\\phpbb\\datetime'); + $user->optionset('smilies', false); + + $phpbb_container->set('user', $user); + } + ), + ); } } diff --git a/tests/text_processing/generate_text_for_edit_test.php b/tests/text_processing/generate_text_for_edit_test.php new file mode 100644 index 0000000000..85b3a6a0ab --- /dev/null +++ b/tests/text_processing/generate_text_for_edit_test.php @@ -0,0 +1,90 @@ +optionset('viewcensors', false); + + $return = generate_text_for_edit($original, $uid, $flags); + + $this->assertSame($expected, $return['text']); + } + + public function get_legacy_tests() + { + return array( + array( + '', + '' + ), + array( + '0', + '0' + ), + array( + 'Hello [url=http://example.org:1f4coh9x]world[/url:1f4coh9x] :)', + 'Hello [url=http://example.org]world[/url] :)', + '1f4coh9x', + 0 + ), + array( + "&<>"'", + "&<>"'" + ) + ); + } + + /** + * @dataProvider get_text_formatter_tests + */ + public function test_text_formatter($original, $expected) + { + global $phpbb_dispatcher; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->get_test_case_helpers()->set_s9e_services(); + + $return = generate_text_for_edit($original, '', 0); + + $this->assertSame($expected, $return['text']); + } + + public function get_text_formatter_tests() + { + return array( + array( + 'Plain text', + 'Plain text' + ), + array( + 'Hello [url=http://example.org]world[/url] :)', + 'Hello [url=http://example.org]world[/url] :)' + ), + array( + '&<>"\'', + "&<>"'" + ) + ); + } +} diff --git a/tests/text_processing/generate_text_for_storage_test.php b/tests/text_processing/generate_text_for_storage_test.php new file mode 100644 index 0000000000..0bacaacfb8 --- /dev/null +++ b/tests/text_processing/generate_text_for_storage_test.php @@ -0,0 +1,70 @@ +set('config', $config); + $this->get_test_case_helpers()->set_s9e_services($phpbb_container); + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + } + + /** + * @dataProvider get_text_formatter_tests + */ + public function test_text_formatter($original, $expected, $allow_bbcode = true, $allow_urls = true, $allow_smilies = true, $setup = null) + { + $actual = $original; + $uid = ''; + $bitfield = ''; + $flags = 0; + + if (isset($setup)) + { + $setup(); + } + + generate_text_for_storage($actual, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies); + + $this->assertSame($expected, $actual); + } + + public function get_text_formatter_tests() + { + return array( + array( + 'Hello world', + 'Hello world' + ), + array( + 'Hello [url=http://example.org]world[/url] :)', + 'Hello [url=http://example.org]world[/url] :)' + ), + array( + '&<>"\'', + '&<>"\'' + ), + ); + } +} diff --git a/tests/text_processing/message_parser_test.php b/tests/text_processing/message_parser_test.php new file mode 100644 index 0000000000..59af2553f8 --- /dev/null +++ b/tests/text_processing/message_parser_test.php @@ -0,0 +1,532 @@ + 999)); + + $map = array( + array('MAX_FLASH_HEIGHT_EXCEEDED', 123, 'Your flash files may only be up to 123 pixels high.'), + array('MAX_FLASH_WIDTH_EXCEEDED', 456, 'Your flash files may only be up to 456 pixels wide.'), + array('MAX_FONT_SIZE_EXCEEDED', 120, 'You may only use fonts up to size 120.'), + array('MAX_FONT_SIZE_EXCEEDED', 200, 'You may only use fonts up to size 200.'), + array('MAX_IMG_HEIGHT_EXCEEDED', 12, 'Your images may only be up to 12 pixels high.'), + array('MAX_IMG_WIDTH_EXCEEDED', 34, 'Your images may only be up to 34 pixels wide.'), + array('TOO_MANY_SMILIES', 3, 'Your message contains too many smilies. The maximum number of smilies allowed is 3.'), + array('TOO_MANY_URLS', 2, 'Your message contains too many URLs. The maximum number of URLs allowed is 2.'), + array('UNAUTHORISED_BBCODE', '[flash]', 'You cannot use certain BBCodes: [flash].'), + array('UNAUTHORISED_BBCODE', '[img]', 'You cannot use certain BBCodes: [img].'), + array('UNAUTHORISED_BBCODE', '[quote]', 'You cannot use certain BBCodes: [quote].'), + array('UNAUTHORISED_BBCODE', '[url]', 'You cannot use certain BBCodes: [url].'), + ); + + $user = $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(); + $user->expects($this->any()) + ->method('lang') + ->will($this->returnValueMap($map)); + + $user->lang = array( + 'NO_POLL_TITLE' => 'You have to enter a poll title.', + 'POLL_TITLE_TOO_LONG' => 'The poll title must contain fewer than 100 characters.', + 'POLL_TITLE_COMP_TOO_LONG' => 'The parsed size of your poll title is too large, consider removing BBCodes or smilies.', + 'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options.', + 'TOO_MANY_POLL_OPTIONS' => 'You have tried to enter too many poll options.', + 'TOO_MANY_USER_OPTIONS' => 'You cannot specify more options per user than existing poll options.', + 'UNABLE_GET_IMAGE_SIZE' => 'It was not possible to determine the dimensions of the image.' + ); + + $phpbb_container = new phpbb_mock_container_builder; + $phpbb_container->set('user', $user); + $phpbb_container->set('config', $config); + + if (isset($setup)) + { + $setup($parser, $phpbb_container, $this); + } + + $this->get_test_case_helpers()->set_s9e_services($phpbb_container); + } + + /** + * @dataProvider get_test_polls + */ + public function test_parse_poll($poll, $expected, $warn_msg = array()) + { + $this->prepare_s9e_services(); + + $message_parser = new parse_message('Me[i]s[/i]sage'); + + // Add some default values + $poll += array( + 'poll_length' => 123, + 'poll_start' => 123, + 'poll_last_vote' => 123, + 'poll_vote_change' => true, + 'enable_bbcode' => true, + 'enable_urls' => true, + 'enable_smilies' => true, + 'img_status' => true + ); + + $message_parser->parse_poll($poll); + $this->assertSame($expected, array_intersect_key($poll, $expected)); + + $this->assertSame( + 'Me[i]s[/i]sage', + $message_parser->parse(true, true, true, true, true, true, true, false) + ); + + $this->assertSame($warn_msg, $message_parser->warn_msg); + } + + public function get_test_polls() + { + return array( + array( + array( + 'poll_title' => 'foo [b]bar[/b] baz', + 'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]", + 'poll_max_options' => 3, + 'poll_options_size' => 3 + ), + array( + 'poll_title' => 'foo [b]bar[/b] baz', + 'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]", + 'poll_options' => array( + '[i]foo[/i]', + 'bar', + '[i]baz[/i]' + ) + ) + ), + array( + array( + 'poll_title' => 'xxx', + 'poll_option_text' => "[quote]quote[/quote]\n:)", + 'poll_max_options' => 2, + 'poll_options_size' => 2 + ), + array( + 'poll_title' => 'xxx', + 'poll_option_text' => "[quote]quote[/quote]\n:)", + 'poll_options' => array( + '[quote]quote[/quote]', + ':)' + ) + ), + array('You cannot use certain BBCodes: [quote].') + ), + array( + array( + 'poll_title' => 'xxx', + 'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)", + 'poll_max_options' => 2, + 'poll_options_size' => 2 + ), + array( + 'poll_title' => 'xxx', + 'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)", + 'poll_options' => array( + '[flash=12,34]http://example.org/x.swf[/flash]', + ':)' + ) + ), + array('You cannot use certain BBCodes: [flash].') + ), + array( + array( + 'poll_title' => 'xxx', + 'poll_option_text' => "[b]x\ny[/b]", + 'poll_max_options' => 2, + 'poll_options_size' => 2 + ), + array( + 'poll_title' => 'xxx', + 'poll_option_text' => "[b]x\ny[/b]", + 'poll_options' => array( + '[b]x', + 'y[/b]', + ) + ) + ), + ); + } + + /** + * @dataProvider get_test_cases + */ + public function test_options($original, $expected, array $args, $setup = null, $warn_msg = array()) + { + $this->prepare_s9e_services($setup); + + $message_parser = new parse_message($original); + call_user_func_array(array($message_parser, 'parse'), $args); + + $this->assertSame($expected, $message_parser->message); + $this->assertSame($warn_msg, $message_parser->warn_msg); + } + + public function get_test_cases() + { + return array( + array( + '[b]bold[/b]', + '[b]bold[/b]', + array(true, true, true, true, true, true, true) + ), + array( + '[b]bold[/b]', + '[b]bold[/b]', + array(false, true, true, true, true, true, true) + ), + array( + 'http://example.org', + 'http://example.org', + array(true, true, true, true, true, true, true) + ), + array( + 'http://example.org', + 'http://example.org', + array(true, false, true, true, true, true, true) + ), + array( + ':)', + ':)', + array(true, true, true, true, true, true, true) + ), + array( + ':)', + ':)', + array(true, true, false, true, true, true, true) + ), + array( + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + array(true, true, true, true, true, true, true) + ), + array( + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + array(true, true, true, false, true, true, true), + null, + array('You cannot use certain BBCodes: [img].') + ), + array( + '[flash=12,34]http://example.org/foo.swf[/flash]', + '[flash=12,34]http://example.org/foo.swf[/flash]', + array(true, true, true, true, true, true, true) + ), + array( + '[flash=12,34]http://example.org/foo.swf[/flash]', + '[flash=12,34]http://example.org/foo.swf[/flash]', + array(true, true, true, true, false, true, true), + null, + array('You cannot use certain BBCodes: [flash].') + ), + array( + '[quote="foo"]bar :)[/quote]', + '[quote="foo"]bar :)[/quote]', + array(true, true, true, true, true, true, true) + ), + array( + '[quote="foo"]bar :)[/quote]', + '[quote="foo"]bar :)[/quote]', + array(true, true, true, true, true, false, true), + null, + array('You cannot use certain BBCodes: [quote].') + ), + array( + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + array(true, true, true, true, true, true, true) + ), + array( + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + '[url=http://example.org][img]http://example.org/img.png[/img][/url]', + array(true, true, true, true, true, true, false), + null, + array('You cannot use certain BBCodes: [url].') + ), + array( + '[size=200]200[/size]', + '[size=200]200[/size]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_font_size', 200); + } + ), + array( + '[size=200]200[/size]', + '[size=200]200[/size]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_font_size', 0); + } + ), + array( + '[size=2000]2000[/size]', + '[size=2000]2000[/size]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_font_size', 200); + }, + array('You may only use fonts up to size 200.') + ), + array( + '[size=0]0[/size]', + '[size=0]0[/size]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_font_size', 200); + } + ), + array( + '[size=200]200[/size]', + '[size=200]200[/size]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_sig_font_size', 200); + } + ), + array( + '[size=200]200[/size]', + '[size=200]200[/size]', + array(true, true, true, true, true, true, true, true, 'sig'), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_sig_font_size', 120); + }, + array('You may only use fonts up to size 120.') + ), + array( + '[img]http://example.org/100x100.png[/img]', + '[img]http://example.org/100x100.png[/img]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_height', 12); + }, + array('Your images may only be up to 12 pixels high.') + ), + array( + '[img]http://example.org/100x100.png[/img]', + '[img]http://example.org/100x100.png[/img]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_width', 34); + }, + array('Your images may only be up to 34 pixels wide.') + ), + array( + '[img]http://example.org/100x100.png[/img]', + '[img]http://example.org/100x100.png[/img]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_height', 0); + $phpbb_container->get('config')->set('max_post_img_width', 0); + } + ), + array( + '[img]http://example.org/100x100.png[/img]', + '[img]http://example.org/100x100.png[/img]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_height', 100); + $phpbb_container->get('config')->set('max_post_img_width', 100); + } + ), + array( + '[img]http://example.org/100x100.png[/img]', + '[img]http://example.org/100x100.png[/img]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_sig_img_height', 12); + $phpbb_container->get('config')->set('max_sig_img_width', 34); + } + ), + array( + '[img]http://example.org/404.png[/img]', + '[img]http://example.org/404.png[/img]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_height', 12); + }, + array('It was not possible to determine the dimensions of the image.') + ), + array( + '[flash=999,999]http://example.org/foo.swf[/flash]', + '[flash=999,999]http://example.org/foo.swf[/flash]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_height', 123); + }, + array('Your flash files may only be up to 123 pixels high.') + ), + array( + '[flash=999,999]http://example.org/foo.swf[/flash]', + '[flash=999,999]http://example.org/foo.swf[/flash]', + array(true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_img_width', 456); + }, + array('Your flash files may only be up to 456 pixels wide.') + ), + array( + ':) :) :)', + ':) :) :)', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_smilies', 3); + } + ), + array( + ':) :) :) :)', + ':) :) :) :)', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_smilies', 3); + }, + array('Your message contains too many smilies. The maximum number of smilies allowed is 3.') + ), + array( + ':) :) :) :)', + ':) :) :) :)', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_smilies', 0); + } + ), + array( + ':) :) :) :)', + ':) :) :) :)', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_sig_smilies', 3); + } + ), + array( + ':) :) :) :)', + ':) :) :) :)', + array(true, true, true, true, true, true, true, true, 'sig'), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_sig_smilies', 3); + }, + array('Your message contains too many smilies. The maximum number of smilies allowed is 3.') + ), + array( + 'http://example.org http://example.org http://example.org', + 'http://example.org http://example.org http://example.org', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_urls', 2); + }, + array('Your message contains too many URLs. The maximum number of URLs allowed is 2.') + ), + array( + 'http://example.org http://example.org http://example.org', + 'http://example.org http://example.org http://example.org', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_post_urls', 0); + } + ), + array( + 'http://example.org http://example.org http://example.org', + 'http://example.org http://example.org http://example.org', + array(true, true, true, true, true, true, true, true), + function ($parser, $phpbb_container) + { + $phpbb_container->get('config')->set('max_sig_urls', 2); + } + ), + ); + } +} + +class phpbb_text_processing_message_parser_test_proxy +{ + protected $response; + + public function stream_open($url) + { + if (strpos($url, '100x100')) + { + // Return a 100 x 100 PNG image + $this->response = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAE0lEQVR4AWOgKxgFo2AUjIJRAAAFeAABHs0ozQAAAABJRU5ErkJggg=='); + } + else + { + $this->response = '404 not found'; + } + + return true; + } + + public function stream_stat() + { + return false; + } + + public function stream_read($len) + { + $chunk = substr($this->response, 0, $len); + $this->response = substr($this->response, $len); + + return $chunk; + } + + public function stream_eof() + { + return ($this->response === false); + } +} diff --git a/tests/text_processing/smilies_test.php b/tests/text_processing/smilies_test.php new file mode 100644 index 0000000000..cd35c25525 --- /dev/null +++ b/tests/text_processing/smilies_test.php @@ -0,0 +1,48 @@ +get_test_case_helpers()->set_s9e_services(null, __DIR__ . '/fixtures/smilies.xml'); + $parser = $container->get('text_formatter.parser'); + $renderer = $container->get('text_formatter.renderer'); + + $this->assertSame($expected, $renderer->render($parser->parse($original))); + } + + public function get_text_formatter_tests() + { + return array( + array( + ':) beginning', + ':) beginning' + ), + array( + 'end :)', + 'end :)' + ), + array( + ':)', + ':)' + ), + array( + 'xx (18) 8) xx', + 'xx (18) 8) xx' + ), + ); + } +} diff --git a/tests/text_processing/strip_bbcode_test.php b/tests/text_processing/strip_bbcode_test.php new file mode 100644 index 0000000000..d0dda89167 --- /dev/null +++ b/tests/text_processing/strip_bbcode_test.php @@ -0,0 +1,38 @@ +assertSame($expected, $actual, '20m4ill1'); + } + + public function test_s9e() + { + $phpbb_container = $this->get_test_case_helpers()->set_s9e_services(); + + $original = '[b]bold[/b]'; + $expected = ' bold '; + + $actual = $original; + strip_bbcode($actual); + + $this->assertSame($expected, $actual); + } +} diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.html b/tests/text_processing/tickets_data/PHPBB3-10002.html new file mode 100644 index 0000000000..82990b2253 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10002.html @@ -0,0 +1,2 @@ +
          • one +
            • two
          \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.txt b/tests/text_processing/tickets_data/PHPBB3-10002.txt new file mode 100644 index 0000000000..fe2f29073f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10002.txt @@ -0,0 +1,2 @@ +[quote][list][*]one +[quote][list][*]two[/list][/quote] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.html b/tests/text_processing/tickets_data/PHPBB3-10425.html new file mode 100644 index 0000000000..522b2f8858 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10425.html @@ -0,0 +1,3 @@ +http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
          +http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
          +link \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.txt b/tests/text_processing/tickets_data/PHPBB3-10425.txt new file mode 100644 index 0000000000..d93c0446b6 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10425.txt @@ -0,0 +1,3 @@ +http://ar.wikipedia.org/wiki/الصفحة_الرئيسية +[url]http://ar.wikipedia.org/wiki/الصفحة_الرئيسية[/url] +[url=http://ar.wikipedia.org/wiki/الصفحة_الرئيسية]link[/url] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.html b/tests/text_processing/tickets_data/PHPBB3-10587.html new file mode 100644 index 0000000000..dd0a483244 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10587.html @@ -0,0 +1,2 @@ +http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets
          +link \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.txt b/tests/text_processing/tickets_data/PHPBB3-10587.txt new file mode 100644 index 0000000000..f81a35eb5f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10587.txt @@ -0,0 +1,2 @@ +[url]http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets[/url] +[url="http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets"]link[/url] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.html b/tests/text_processing/tickets_data/PHPBB3-10922.html new file mode 100644 index 0000000000..cdf8316df0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10922.html @@ -0,0 +1 @@ +user@example.org... \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.txt b/tests/text_processing/tickets_data/PHPBB3-10922.txt new file mode 100644 index 0000000000..348f8a1541 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10922.txt @@ -0,0 +1 @@ +[email]user@example.org[/email][email=user@example.org]...[/email] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.html b/tests/text_processing/tickets_data/PHPBB3-10989.html new file mode 100644 index 0000000000..f003ad3dfa --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10989.html @@ -0,0 +1,8 @@ +
          Lorem wrote:[quote="Lorem"
          Suspendisse iaculis porta tempor. Nulla.
          + Nullam a tortor sit amet.
          + Proin ac mi eget magna. + +
          Lorem wrote:Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.
          + +
          +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper. \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.txt b/tests/text_processing/tickets_data/PHPBB3-10989.txt new file mode 100644 index 0000000000..dc2430f210 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10989.txt @@ -0,0 +1,8 @@ +[quote="Lorem"][quote="Lorem"[quote] Suspendisse iaculis porta tempor. Nulla.[/quote] + Nullam a tortor sit amet.[/quote] + Proin ac mi eget magna. + +[quote="Lorem"]Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.[/quote] + + +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper. \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.html b/tests/text_processing/tickets_data/PHPBB3-11153.html new file mode 100644 index 0000000000..0f67ac4bc0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11153.html @@ -0,0 +1 @@ +... \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.txt b/tests/text_processing/tickets_data/PHPBB3-11153.txt new file mode 100644 index 0000000000..d2794978d9 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11153.txt @@ -0,0 +1 @@ +[myemail=user@example.org]...[/myemail] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.xml b/tests/text_processing/tickets_data/PHPBB3-11153.xml new file mode 100644 index 0000000000..a7fc69520b --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11153.xml @@ -0,0 +1,28 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + myemail + + 1 + [myemail={EMAIL}]{TEXT}[/myemail] + {TEXT}]]> + + bbcode_specialchars('${1}').':$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${2}')).'[/myemail:$uid]']]> + + ${2}]]> + +
          +
          diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.html b/tests/text_processing/tickets_data/PHPBB3-12195.html new file mode 100644 index 0000000000..d8e0f8d523 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-12195.html @@ -0,0 +1 @@ +Image \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.txt b/tests/text_processing/tickets_data/PHPBB3-12195.txt new file mode 100644 index 0000000000..b66dbd5d96 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-12195.txt @@ -0,0 +1 @@ +[url=//example.org/][img]//example.org/img.png[/img][/url] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.before.php b/tests/text_processing/tickets_data/PHPBB3-3981.before.php new file mode 100644 index 0000000000..20c96d163c --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-3981.before.php @@ -0,0 +1,17 @@ +markTestSkipped('International URLs need idn_to_ascii()'); + } +} diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.html b/tests/text_processing/tickets_data/PHPBB3-3981.html new file mode 100644 index 0000000000..e5f1b4561d --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-3981.html @@ -0,0 +1 @@ +http://www.ööö.com \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.txt b/tests/text_processing/tickets_data/PHPBB3-3981.txt new file mode 100644 index 0000000000..976823f1d1 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-3981.txt @@ -0,0 +1 @@ +[url]http://www.ööö.com[/url] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.html b/tests/text_processing/tickets_data/PHPBB3-7187.html new file mode 100644 index 0000000000..9138779d29 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7187.html @@ -0,0 +1 @@ +
          :geek: :ugeek:
          \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.txt b/tests/text_processing/tickets_data/PHPBB3-7187.txt new file mode 100644 index 0000000000..584151a083 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7187.txt @@ -0,0 +1 @@ +[quote]:geek: :ugeek:[/quote] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.xml b/tests/text_processing/tickets_data/PHPBB3-7187.xml new file mode 100644 index 0000000000..d270b12619 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7187.xml @@ -0,0 +1,33 @@ + + + + smiley_id + code + emotion + smiley_url + smiley_width + smiley_height + smiley_order + display_on_posting + + 41 + :geek: + Geek + icon_e_geek.gif + 17 + 17 + 41 + 1 + + + 42 + :ugeek: + Uber Geek + icon_e_ugeek.gif + 17 + 18 + 42 + 1 + +
          +
          diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.after.php b/tests/text_processing/tickets_data/PHPBB3-7275.after.php new file mode 100644 index 0000000000..a824cb9b84 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.after.php @@ -0,0 +1,15 @@ +assertSame($original, $parsed_text); +} diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.html b/tests/text_processing/tickets_data/PHPBB3-7275.html new file mode 100644 index 0000000000..12502833fd --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.html @@ -0,0 +1 @@ +
          :)
          \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.txt b/tests/text_processing/tickets_data/PHPBB3-7275.txt new file mode 100644 index 0000000000..8de97d67e0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.txt @@ -0,0 +1 @@ +[center]:)[/center] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.xml b/tests/text_processing/tickets_data/PHPBB3-7275.xml new file mode 100644 index 0000000000..9e979afffb --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-7275.xml @@ -0,0 +1,49 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + center + + 1 + [center]{TEXT}[/center] + {TEXT}]]> + !\[center\](.*?)\[/center\]!ies + + !\[center:$uid\](.*?)\[/center:$uid\]!s + ${1}]]> + +
          + + + smiley_id + code + emotion + smiley_url + smiley_width + smiley_height + smiley_order + display_on_posting + + 4 + :) + Smile + icon_e_smile.gif + 15 + 17 + 4 + 1 + +
          +
          diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.html b/tests/text_processing/tickets_data/PHPBB3-9377.html new file mode 100644 index 0000000000..dcfb79c173 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9377.html @@ -0,0 +1 @@ +red blue red \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.txt b/tests/text_processing/tickets_data/PHPBB3-9377.txt new file mode 100644 index 0000000000..dfd71492c5 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9377.txt @@ -0,0 +1 @@ +[red]red [blue]blue[/blue] red[/red] \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.xml b/tests/text_processing/tickets_data/PHPBB3-9377.xml new file mode 100644 index 0000000000..1d8ee3d53f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-9377.xml @@ -0,0 +1,41 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + red + + 1 + [red]{TEXT}[/red] + <span style="color:red">{TEXT}</span> + !\[red\](.*?)\[/red\]!ies + '[red:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/red:$uid]' + !\[red:$uid\](.*?)\[/red:$uid\]!s + <span style="color:red">${1}</span> + + + + 14 + blue + + 1 + [blue]{TEXT}[/blue] + <span style="color:blue">{TEXT}</span> + !\[blue\](.*?)\[/blue\]!ies + '[blue:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/blue:$uid]' + !\[blue:$uid\](.*?)\[/blue:$uid\]!s + <span style="color:blue">${1}</span> + +
          +
          diff --git a/tests/text_processing/tickets_test.php b/tests/text_processing/tickets_test.php new file mode 100644 index 0000000000..d2072a10f5 --- /dev/null +++ b/tests/text_processing/tickets_test.php @@ -0,0 +1,91 @@ +get_test_case_helpers()->set_s9e_services($phpbb_container, $fixture); + + $parser = $phpbb_container->get('text_formatter.parser'); + $renderer = $phpbb_container->get('text_formatter.renderer'); + + if (isset($before_assert)) + { + $test = $this; + $before_assert(get_defined_vars()); + } + + $parsed_text = $parser->parse($original); + + $this->assertSame($expected, $renderer->render($parsed_text)); + + if (isset($after_assert)) + { + $test = $this; + $after_assert(get_defined_vars()); + } + } + + public function get_tickets_data() + { + $tests = array(); + + foreach (glob(__DIR__ . '/tickets_data/*.txt') as $txt_filename) + { + $ticket_id = basename($txt_filename, '.txt'); + $html_filename = substr($txt_filename, 0, -3) . 'html'; + $xml_filename = substr($txt_filename, 0, -3) . 'xml'; + $before_filename = substr($txt_filename, 0, -3) . 'before.php'; + $after_filename = substr($txt_filename, 0, -3) . 'after.php'; + + if (!file_exists($xml_filename)) + { + $xml_filename = __DIR__ . '/../fixtures/empty.xml'; + } + + $before_assert = null; + if (file_exists($before_filename)) + { + include($before_filename); + $before_assert = 'before_assert_' . strtolower(str_replace('-', '_', $ticket_id)); + } + + $after_assert = null; + if (file_exists($after_filename)) + { + include($after_filename); + $after_assert = 'after_assert_' . strtolower(str_replace('-', '_', $ticket_id)); + } + + $tests[] = array( + $ticket_id, + file_get_contents($txt_filename), + file_get_contents($html_filename), + $xml_filename, + $before_assert, + $after_assert + ); + } + + return $tests; + } +} From 261f7eec9c781eedae612418343e7a08341be9ce Mon Sep 17 00:00:00 2001 From: s9e Date: Sat, 22 Nov 2014 20:07:09 +0100 Subject: [PATCH 02/82] [ticket/11768] Updated composer.lock PHPBB3-11768 --- phpBB/composer.lock | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index e6dd12e8f0..0489eac83a 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1048,21 +1048,21 @@ "packages-dev": [ { "name": "fabpot/goutte", - "version": "v1.0.3", + "version": "v1.0.7", "source": { "type": "git", - "url": "https://github.com/fabpot/Goutte.git", - "reference": "75c9f23c4122caf4ea3e87a42a00b471366e707f" + "url": "https://github.com/FriendsOfPHP/Goutte.git", + "reference": "794b196e76bdd37b5155cdecbad311f0a3b07625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fabpot/Goutte/zipball/75c9f23c4122caf4ea3e87a42a00b471366e707f", - "reference": "75c9f23c4122caf4ea3e87a42a00b471366e707f", + "url": "https://api.github.com/repos/FriendsOfPHP/Goutte/zipball/794b196e76bdd37b5155cdecbad311f0a3b07625", + "reference": "794b196e76bdd37b5155cdecbad311f0a3b07625", "shasum": "" }, "require": { "ext-curl": "*", - "guzzle/http": ">=3.0.5,<3.8-dev", + "guzzle/http": "~3.1", "php": ">=5.3.0", "symfony/browser-kit": "~2.1", "symfony/css-selector": "~2.1", @@ -1071,8 +1071,8 @@ "symfony/process": "~2.1" }, "require-dev": { - "guzzle/plugin-history": ">=3.0.5,<3.8-dev", - "guzzle/plugin-mock": ">=3.0.5,<3.8-dev" + "guzzle/plugin-history": "~3.1", + "guzzle/plugin-mock": "~3.1" }, "type": "application", "extra": { @@ -1092,9 +1092,7 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" + "email": "fabien@symfony.com" } ], "description": "A simple PHP Web Scraper", @@ -1102,7 +1100,7 @@ "keywords": [ "scraper" ], - "time": "2013-08-16 06:03:22" + "time": "2014-10-09 15:52:51" }, { "name": "guzzle/common", @@ -1937,16 +1935,16 @@ }, { "name": "sami/sami", - "version": "v1.3", + "version": "v1.4", "source": { "type": "git", - "url": "https://github.com/fabpot/Sami.git", - "reference": "76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110" + "url": "https://github.com/FriendsOfPHP/Sami.git", + "reference": "70f29c781f7bef30181c814b9471b2ceac694454" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fabpot/Sami/zipball/76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110", - "reference": "76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110", + "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/70f29c781f7bef30181c814b9471b2ceac694454", + "reference": "70f29c781f7bef30181c814b9471b2ceac694454", "shasum": "" }, "require": { @@ -1967,7 +1965,7 @@ "type": "application", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -1982,9 +1980,7 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" + "email": "fabien@symfony.com" } ], "description": "Sami, an API documentation generator", @@ -1992,7 +1988,7 @@ "keywords": [ "phpdoc" ], - "time": "2013-11-30 17:16:25" + "time": "2014-06-25 11:24:03" }, { "name": "sebastian/comparator", From d779ae340ad893ae4d4ac8a03dccdad3e11c1799 Mon Sep 17 00:00:00 2001 From: s9e Date: Mon, 24 Nov 2014 18:54:04 +0100 Subject: [PATCH 03/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 0489eac83a..027cbf36ae 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "872ed9d9204986668afc0b3e633be99e397e201b" + "reference": "001dc34bccf85b75a374e2da96d363c470c798a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/872ed9d9204986668afc0b3e633be99e397e201b", - "reference": "872ed9d9204986668afc0b3e633be99e397e201b", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/001dc34bccf85b75a374e2da96d363c470c798a2", + "reference": "001dc34bccf85b75a374e2da96d363c470c798a2", "shasum": "" }, "require": { @@ -218,7 +218,7 @@ "parser", "shortcodes" ], - "time": "2014-11-22 14:23:43" + "time": "2014-11-24 17:50:45" }, { "name": "symfony/config", From ca9f5344097eff5efef4ab6392109c9df737cf25 Mon Sep 17 00:00:00 2001 From: s9e Date: Thu, 8 Jan 2015 02:02:58 +0100 Subject: [PATCH 04/82] [ticket/11768] Restored blank line from develop PHPBB3-11768 --- phpBB/config/default/container/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 2b4aa52571..4f1aba953f 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -16,6 +16,7 @@ imports: - { resource: services_text_formatter.yml } - { resource: services_twig.yml } - { resource: services_user.yml } + - { resource: tables.yml } - { resource: parameters.yml } From cf39b02891d5ab021e4abc0932e1bb964cbd680c Mon Sep 17 00:00:00 2001 From: s9e Date: Thu, 8 Jan 2015 11:28:23 +0100 Subject: [PATCH 05/82] [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(-) 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) From dc303cbc993755ec446fcc3f060659668e5073f8 Mon Sep 17 00:00:00 2001 From: s9e Date: Fri, 16 Jan 2015 02:31:14 +0100 Subject: [PATCH 06/82] [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(-) 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 From e0bb446c57d692b3e968a7a3ccd9d726f0779391 Mon Sep 17 00:00:00 2001 From: s9e Date: Fri, 16 Jan 2015 03:54:42 +0100 Subject: [PATCH 07/82] [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(-) 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 From 72fb380c9fbb0d6fa51236bdc179ba7ef6126a5a Mon Sep 17 00:00:00 2001 From: s9e Date: Wed, 4 Feb 2015 23:07:58 +0100 Subject: [PATCH 08/82] [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 --- .../default/container/services_text_formatter.yml | 4 ++-- phpBB/phpbb/textformatter/s9e/parser.php | 6 +++--- phpBB/phpbb/textformatter/s9e/renderer.php | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml index 7d21e4498e..3d5fb3766d 100644 --- a/phpBB/config/default/container/services_text_formatter.yml +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -41,7 +41,7 @@ services: - @cache.driver - %text_formatter.cache.parser.key% - @user - - @service_container + - @text_formatter.s9e.factory text_formatter.s9e.renderer: class: phpbb\textformatter\s9e\renderer @@ -49,7 +49,7 @@ services: - @cache.driver - %text_formatter.cache.dir% - %text_formatter.cache.renderer.key% - - @service_container + - @text_formatter.s9e.factory calls: - [configure_smilies_path, [@config, @path_helper]] - [configure_user, [@user, @config, @auth]] 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; From c4a58bce890869f3d44d145cd43cb036ad99ac74 Mon Sep 17 00:00:00 2001 From: s9e Date: Wed, 4 Feb 2015 23:27:04 +0100 Subject: [PATCH 09/82] [ticket/11768] Updated test case helper with new signature PHPBB3-11768 --- tests/test_framework/phpbb_test_case_helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index d0b1573e61..3423d83bb1 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -472,7 +472,7 @@ class phpbb_test_case_helpers $cache, $cache_key_parser, $user, - $container + $factory ); $container->set('text_formatter.parser', $parser); @@ -483,7 +483,7 @@ class phpbb_test_case_helpers $cache, $cache_dir, $cache_key_renderer, - $container + $factory ); $root_path = ($container->hasParameter('core.root_path')) From 90d1a431bde5aaed1e925c3124d081576c759376 Mon Sep 17 00:00:00 2001 From: s9e Date: Thu, 5 Feb 2015 00:01:10 +0100 Subject: [PATCH 10/82] [ticket/11768] Updated tests to use the new constructor signature PHPBB3-11768 --- tests/text_formatter/s9e/parser_test.php | 29 ++++++++++++++++------ tests/text_formatter/s9e/renderer_test.php | 17 +++++++------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 528305a11c..aee906e213 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -24,11 +24,16 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case ->with('_foo_parser') ->will($this->returnValue($mock)); + $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') + ->disableOriginalConstructor() + ->getMock(); + $factory->expects($this->never())->method('regenerate'); + $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - new phpbb_mock_container_builder + $factory ); } @@ -46,11 +51,16 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $cache = new phpbb_mock_cache; $cache->put('_foo_parser', $mock); + $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') + ->disableOriginalConstructor() + ->getMock(); + $factory->expects($this->never())->method('regenerate'); + $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - new phpbb_mock_container_builder + $factory ); $this->assertSame('test', $parser->parse('test')); @@ -67,19 +77,18 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case ->with('test') ->will($this->returnValue('test')); - $factory = $this->getMock('stdClass', array('regenerate')); + $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') + ->disableOriginalConstructor() + ->getMock(); $factory->expects($this->once()) ->method('regenerate') ->will($this->returnValue(array($mock, false))); - $container = new phpbb_mock_container_builder; - $container->set('text_formatter.s9e.factory', $factory); - $parser = new \phpbb\textformatter\s9e\parser( new phpbb_mock_cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - $container + $factory ); $this->assertSame('test', $parser->parse('test')); @@ -104,11 +113,15 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $cache = new phpbb_mock_cache; $cache->put('_foo_parser', $mock); + $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') + ->disableOriginalConstructor() + ->getMock(); + $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - new phpbb_mock_container_builder + $factory ); call_user_func_array(array($parser, $adapter_method), (array) $adapter_arg); diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 76babbfdf3..977c165177 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -33,14 +33,16 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ->with('_foo_renderer') ->will($this->returnValue(array('class' => 'renderer_foo', 'renderer' => serialize($mock)))); - $container = new phpbb_mock_container_builder; - $container->set('text_formatter.s9e.factory', $factory); + $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') + ->disableOriginalConstructor() + ->getMock(); + $factory->expects($this->never())->method('regenerate'); $renderer = new \phpbb\textformatter\s9e\renderer( $cache, $this->get_cache_dir(), '_foo_renderer', - $container + $factory ); } @@ -54,19 +56,18 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ->with('_foo_renderer') ->will($this->returnValue(false)); - $factory = $this->getMock('stdClass', array('regenerate')); + $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') + ->disableOriginalConstructor() + ->getMock(); $factory->expects($this->once()) ->method('regenerate') ->will($this->returnValue(array($mock, false))); - $container = new phpbb_mock_container_builder; - $container->set('text_formatter.s9e.factory', $factory); - $renderer = new \phpbb\textformatter\s9e\renderer( $cache, $this->get_cache_dir(), '_foo_renderer', - $container + $factory ); } From 3b115a903a5651f05ac388dea774d1b4022e2ed8 Mon Sep 17 00:00:00 2001 From: s9e Date: Thu, 5 Feb 2015 00:59:29 +0100 Subject: [PATCH 11/82] [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(-) 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 From cfbf02bcbad7b00fb81d45260f2fb4bdcbe2ed7f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 8 Feb 2015 13:35:07 +0100 Subject: [PATCH 12/82] [ticket/11768] Re-added the code that got lost in rebase PHPBB3-11768 --- phpBB/composer.json | 1 + phpBB/composer.lock | 11 ++++++----- phpBB/includes/acp/acp_bbcodes.php | 3 ++- phpBB/includes/acp/acp_words.php | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index dcb4000d34..2c734847cf 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -28,6 +28,7 @@ "php": ">=5.3.9", "lusitanian/oauth": "0.2.*", "patchwork/utf8": "1.1.*", + "s9e/text-formatter": "dev-release/php5.3", "symfony/config": "2.7.*@dev", "symfony/console": "2.7.*@dev", "symfony/dependency-injection": "2.7.*@dev", diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 027cbf36ae..c619b74f15 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2038bc8bd0fea66b22774ca7bca11a79", + "hash": "25df57c9c90534dcc86d31175b248719", "packages": [ { "name": "lusitanian/oauth", @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "001dc34bccf85b75a374e2da96d363c470c798a2" + "reference": "3659ed8d9209a4a42f23f7169dbcc0a114fd601f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/001dc34bccf85b75a374e2da96d363c470c798a2", - "reference": "001dc34bccf85b75a374e2da96d363c470c798a2", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/3659ed8d9209a4a42f23f7169dbcc0a114fd601f", + "reference": "3659ed8d9209a4a42f23f7169dbcc0a114fd601f", "shasum": "" }, "require": { @@ -218,7 +218,7 @@ "parser", "shortcodes" ], - "time": "2014-11-24 17:50:45" + "time": "2015-02-06 19:38:34" }, { "name": "symfony/config", @@ -2584,6 +2584,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { + "s9e/text-formatter": 20, "symfony/config": 20, "symfony/console": 20, "symfony/dependency-injection": 20, diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 327af0e0bc..d451b4d899 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -25,7 +25,7 @@ class acp_bbcodes function main($id, $mode) { - global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher; + global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher, $phpbb_container; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_log; $user->add_lang('acp/posting'); @@ -321,6 +321,7 @@ class acp_bbcodes { $db->sql_query('DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_id = $bbcode_id"); $cache->destroy('sql', BBCODES_TABLE); + $phpbb_container->get('text_formatter.cache')->invalidate(); $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_BBCODE_DELETE', false, array($row['bbcode_tag'])); if ($request->is_ajax()) diff --git a/phpBB/includes/acp/acp_words.php b/phpBB/includes/acp/acp_words.php index 1ba247be4d..ea8d47a109 100644 --- a/phpBB/includes/acp/acp_words.php +++ b/phpBB/includes/acp/acp_words.php @@ -28,7 +28,7 @@ class acp_words function main($id, $mode) { - global $db, $user, $auth, $template, $cache, $phpbb_log, $request; + global $db, $user, $auth, $template, $cache, $phpbb_log, $request, $phpbb_container; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); From 6540918ffa3d7203da1f55dc2d08674b378663f3 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 10 Feb 2015 02:24:06 +0100 Subject: [PATCH 13/82] [ticket/11768] Added test files PHPBB3-11768 --- tests/text_processing/tickets_data/PHPBB3-10122.html | 1 + tests/text_processing/tickets_data/PHPBB3-10122.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/text_processing/tickets_data/PHPBB3-10122.html create mode 100644 tests/text_processing/tickets_data/PHPBB3-10122.txt diff --git a/tests/text_processing/tickets_data/PHPBB3-10122.html b/tests/text_processing/tickets_data/PHPBB3-10122.html new file mode 100644 index 0000000000..f0fb6115b2 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10122.html @@ -0,0 +1 @@ +
          • This is my indented text
          \ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-10122.txt b/tests/text_processing/tickets_data/PHPBB3-10122.txt new file mode 100644 index 0000000000..a5e059df66 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-10122.txt @@ -0,0 +1 @@ +[list=none][*]This is my indented text[/list] \ No newline at end of file From 63753bbf1a7a695938c7196fb7c1d9318d7a7375 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 13 Feb 2015 11:17:44 +0100 Subject: [PATCH 14/82] [ticket/11768] Uncommented disabled test PHPBB3-11768 --- tests/text_formatter/s9e/default_formatting_test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index be258868dd..a7d3235c12 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -184,13 +184,11 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case '[code]unparsed code [quote="username"]quoted[/quote][/code]', '

          CODE: Select all

          unparsed code [quote="username"]quoted[/quote]
          ' ), -/* array( // Textual bbcode nesting into textual bbcode '[b]bold [i]bold + italic[/b] italic[/i]', 'bold bold + italic italic' ), -*/ array( "[code]\tline1\n line2[/code]", '

          CODE: Select all

             line1
          ' . "\n" . '  line2
          ' From f6e3e41717e71fb43ea63785cfe7980e33be3fbf Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 13 Feb 2015 11:28:51 +0100 Subject: [PATCH 15/82] [ticket/11768] Added support for magic links that start with "www." PHPBB3-11768 --- phpBB/composer.lock | 9 +++++---- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- tests/text_formatter/s9e/default_formatting_test.php | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index c619b74f15..7538a8a83c 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,17 +169,18 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "3659ed8d9209a4a42f23f7169dbcc0a114fd601f" + "reference": "2cfaacd8619ecaebb6de5674b94580689f062f66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/3659ed8d9209a4a42f23f7169dbcc0a114fd601f", - "reference": "3659ed8d9209a4a42f23f7169dbcc0a114fd601f", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/2cfaacd8619ecaebb6de5674b94580689f062f66", + "reference": "2cfaacd8619ecaebb6de5674b94580689f062f66", "shasum": "" }, "require": { "ext-dom": "*", "ext-filter": "*", + "lib-pcre": ">=7.2", "php": ">=5.3.3" }, "suggest": { @@ -218,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-02-06 19:38:34" + "time": "2015-02-13 10:24:14" }, { "name": "symfony/config", 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 diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index a7d3235c12..99a89a8d2e 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -193,6 +193,14 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case "[code]\tline1\n line2[/code]", '

          CODE: Select all

             line1
          ' . "\n" . '  line2
          ' ), + array( + '... http://example.org ...', + '... http://example.org ...' + ), + array( + '... www.example.org ...', + '... www.example.org ...' + ), ); } } From 6bd86a8e8a7c8e2ccf90d02343132c085978cd44 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 15 Feb 2015 03:08:36 +0100 Subject: [PATCH 16/82] [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 +- tests/text_formatter/s9e/factory_test.php | 4 ++-- tests/text_formatter/s9e/parser_test.php | 2 +- tests/text_formatter/s9e/renderer_test.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) 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; diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 2ea4b3031b..9542da8d9a 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -84,7 +84,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case public function test_regenerate() { - list($parser, $renderer) = $this->get_factory()->regenerate(); + extract($this->get_factory()->regenerate()); $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser); $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer); @@ -113,7 +113,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case touch($old_file); // Create a current renderer - list($parser, $renderer) = $factory->regenerate(); + extract($factory->regenerate()); $new_file = $this->get_cache_dir() . get_class($renderer) . '.php'; // Tidy the cache diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index aee906e213..f422e5425a 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -82,7 +82,7 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case ->getMock(); $factory->expects($this->once()) ->method('regenerate') - ->will($this->returnValue(array($mock, false))); + ->will($this->returnValue(array('parser' => $mock))); $parser = new \phpbb\textformatter\s9e\parser( new phpbb_mock_cache, diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 977c165177..464bcf8eed 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -61,7 +61,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ->getMock(); $factory->expects($this->once()) ->method('regenerate') - ->will($this->returnValue(array($mock, false))); + ->will($this->returnValue(array('parser' => $mock))); $renderer = new \phpbb\textformatter\s9e\renderer( $cache, From 42c1297345cf7b025a82a7c1de7b7f6714de7cb8 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 17 Feb 2015 00:17:57 +0100 Subject: [PATCH 17/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 7538a8a83c..f006de8b8b 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "2cfaacd8619ecaebb6de5674b94580689f062f66" + "reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/2cfaacd8619ecaebb6de5674b94580689f062f66", - "reference": "2cfaacd8619ecaebb6de5674b94580689f062f66", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/6d0fad50f73f386a45ec6fefdc8d039df93637ab", + "reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-02-13 10:24:14" + "time": "2015-02-16 09:55:05" }, { "name": "symfony/config", From 6578e1c6ec7172016fbfa375dd2fce5cb20f3ce1 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 17 Feb 2015 09:18:31 +0100 Subject: [PATCH 18/82] [ticket/11768] Added limited support for [url] in [quote] author PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 23 +++++++++++++++++-- .../s9e/default_formatting_test.php | 12 ++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) 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; } diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index 99a89a8d2e..b28c8b157e 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -201,6 +201,18 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case '... www.example.org ...', '... www.example.org ...' ), + array( + '[quote="[url=http://example.org]xxx[/url]"]...[/quote]', + '
          xxx wrote:...
          ' + ), + array( + '[quote="[url]http://example.org[/url]"]...[/quote]', + '
          ' + ), + array( + '[quote="http://example.org"]...[/quote]', + '
          ' + ), ); } } From f721b85a7835c18459b310e4db74cc0f654b05ec Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 19 Feb 2015 06:05:39 +0100 Subject: [PATCH 19/82] [ticket/11768] Replaced the Censor plugin ...with something that is run at rendering time. PHPBB3-11768 --- phpBB/composer.lock | 8 ++--- phpBB/phpbb/textformatter/s9e/factory.php | 38 ++++++++++++---------- phpBB/phpbb/textformatter/s9e/renderer.php | 21 +++++++++++- tests/text_formatter/s9e/parser_test.php | 8 ----- tests/text_formatter/s9e/renderer_test.php | 12 +++---- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index f006de8b8b..73b41a9e60 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab" + "reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/6d0fad50f73f386a45ec6fefdc8d039df93637ab", - "reference": "6d0fad50f73f386a45ec6fefdc8d039df93637ab", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/0a6bfe116bf348acf209e0d50bd3b3fad86d219e", + "reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-02-16 09:55:05" + "time": "2015-02-19 04:58:59" }, { "name": "symfony/config", 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() */ diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index f422e5425a..09af6c22ad 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -138,10 +138,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case 'disable_bbcodes', null, 'disablePlugin', 'BBCodes' ), - array( - 'disable_censor', null, - 'disablePlugin', 'Censor' - ), array( 'disable_magic_url', null, 'disablePlugin', array('Autoemail', 'Autolink') @@ -158,10 +154,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case 'enable_bbcodes', null, 'enablePlugin', 'BBCodes' ), - array( - 'enable_censor', null, - 'enablePlugin', 'Censor' - ), array( 'enable_magic_url', null, 'enablePlugin', array('Autoemail', 'Autolink') diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 464bcf8eed..fbf17c8f68 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -93,12 +93,12 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case { return array( array( - 'apple', + 'apple', 'banana', array('set_viewcensors' => true) ), array( - 'apple', + 'apple', 'apple', array('set_viewcensors' => false) ), @@ -146,11 +146,11 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case { return array( array( - 'apple', + 'apple', 'banana' ), array( - 'apple', + 'apple', 'banana', function ($phpbb_container) { @@ -161,7 +161,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case } ), array( - 'apple', + 'apple', 'banana', function ($phpbb_container) { @@ -175,7 +175,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case } ), array( - 'apple', + 'apple', 'apple', function ($phpbb_container, $test) { From 93c53ed52da7ec2e26bf97b3cc5bba1f1ca403bb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 19 Feb 2015 06:31:56 +0100 Subject: [PATCH 20/82] [ticket/11768] Fixed test PHPBB3-11768 --- tests/text_formatter/s9e/factory_test.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 9542da8d9a..7c26443579 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -89,15 +89,11 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser); $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer); + $renderer_data = $this->cache->get('_foo_renderer'); $this->assertEquals($parser, $this->cache->get('_foo_parser'), 'The parser was not cached'); - $this->assertEquals( - array( - 'class' => get_class($renderer), - 'renderer' => serialize($renderer) - ), - $this->cache->get('_foo_renderer'), - 'The renderer was not cached' - ); + $this->assertEquals(get_class($renderer), $renderer_data['class']); + $this->assertEquals(serialize($renderer), $renderer_data['renderer']); + $this->assertInstanceOf('s9e\\TextFormatter\\Plugins\\Censor\\Helper', $renderer_data['censor']); $file = $this->get_cache_dir() . get_class($renderer) . '.php'; $this->assertFileExists($file); From 3e5ee87b15c70fbfc246b6d8f6d18a186d11d83a Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 20 Feb 2015 06:03:05 +0100 Subject: [PATCH 21/82] [ticket/11768] Allowed text in places where text is not valid HTML PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 +++ tests/text_formatter/s9e/default_formatting_test.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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; diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index b28c8b157e..94d46a58b7 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -68,7 +68,7 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case ), array( '[list]no item[/list]', - '
            ' + '
              no item
            ' ), array( '[*]unparsed', From 414dcae422d21693aad746b4a7a0d49517e478d9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 21 Feb 2015 11:59:54 +0100 Subject: [PATCH 22/82] [ticket/11768] Updated the cache dir to point to the current environment PHPBB3-11768 --- phpBB/config/default/container/services_text_formatter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml index 3d5fb3766d..ec5421695d 100644 --- a/phpBB/config/default/container/services_text_formatter.yml +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -1,5 +1,5 @@ parameters: - text_formatter.cache.dir: %core.root_path%cache/ + text_formatter.cache.dir: %core.root_path%cache/%core.environment%/ text_formatter.cache.parser.key: _text_formatter_parser text_formatter.cache.renderer.key: _text_formatter_renderer From c1ba3a678d5a565b74d893c57eb5133623702350 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Feb 2015 19:03:41 +0100 Subject: [PATCH 23/82] [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 ++++++++++ tests/text_formatter/s9e/parser_test.php | 8 ++++++++ tests/text_formatter/s9e/renderer_test.php | 7 +++++++ 4 files changed, 35 insertions(+) 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} */ diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 09af6c22ad..a3c86e8350 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -7,6 +7,7 @@ * */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; require_once __DIR__ . '/../../mock/user.php'; require_once __DIR__ . '/../../mock/cache.php'; @@ -164,4 +165,11 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case ) ); } + + public function test_get_parser() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $parser = $container->get('text_formatter.parser'); + $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser->get_parser()); + } } diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index fbf17c8f68..486b17d03f 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -353,4 +353,11 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ); } } + + public function test_get_renderer() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $renderer = $container->get('text_formatter.renderer'); + $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer->get_renderer()); + } } From 73ce09b73a97e351197005ac89113d3451b41da0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Feb 2015 19:34:10 +0100 Subject: [PATCH 24/82] [ticket/11768] Fixed censored words being escaped twice PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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'])); } } From 5fe74cd3944387831fb1949198409481a1358ee5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Feb 2015 19:35:49 +0100 Subject: [PATCH 25/82] [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(-) 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() */ From baadc2a6e52437d9d5912c828a337a3c2866c9eb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:38:35 +0100 Subject: [PATCH 26/82] [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(-) 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 { From b12043d4b076b1e214fd85da28358ba829d47a76 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:43:46 +0100 Subject: [PATCH 27/82] [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 +- tests/test_framework/phpbb_test_case_helpers.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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 diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 3423d83bb1..8e49dca40c 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -394,7 +394,7 @@ class phpbb_test_case_helpers // Mock the DAL, make it return data from the fixture $mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access'); - $mb->setMethods(array('get_bbcodes', 'get_smilies', 'get_styles', 'get_words')); + $mb->setMethods(array('get_bbcodes', 'get_censored_words', 'get_smilies', 'get_styles')); $mb->setConstructorArgs(array( $this->test_case->getMock('phpbb\\db\\driver\\driver'), 'phpbb_bbcodes', @@ -417,7 +417,7 @@ class phpbb_test_case_helpers ->method('get_styles') ->will($this->test_case->returnValue($tables['phpbb_styles'])); $dal->expects($this->test_case->any()) - ->method('get_words') + ->method('get_censored_words') ->will($this->test_case->returnValue($tables['phpbb_words'])); // Cache the parser and renderer with a key based on this method's arguments From 694e515f7c812a470a9a1890aa49ba6ad59385fb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:52:31 +0100 Subject: [PATCH 28/82] [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(-) 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 * From 3d9596be79cc68bc4caa2263c0bd996606ab3543 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:54:37 +0100 Subject: [PATCH 29/82] [ticket/11768] Updated renderer annotation PHPBB3-11768 --- phpBB/phpbb/textformatter/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 825bc45983f961b4d84f5d869dc0cb6111902aa7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:56:14 +0100 Subject: [PATCH 30/82] [ticket/11768] Removed comments PHPBB3-11768 --- phpBB/phpbb/textformatter/renderer.php | 3 --- 1 file changed, 3 deletions(-) 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 From 458cf95b1e0614b8dbecaca36c57f21e8a3a7bb7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:58:38 +0100 Subject: [PATCH 31/82] [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(-) 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 */ From 70b7e57497e8822dc237268c54d859125cdea4d0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 00:59:44 +0100 Subject: [PATCH 32/82] [ticket/11768] Renamed property PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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) { From 0dd5e62382047f9e256eb148ab199c04a05914b2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 01:10:58 +0100 Subject: [PATCH 33/82] [ticket/11768] Replaced headers in test files PHPBB3-11768 --- tests/text_formatter/s9e/default_formatting_test.php | 10 +++++++--- tests/text_formatter/s9e/factory_test.php | 10 +++++++--- tests/text_formatter/s9e/parser_test.php | 10 +++++++--- tests/text_formatter/s9e/renderer_test.php | 10 +++++++--- tests/text_formatter/s9e/utils_test.php | 10 +++++++--- tests/text_processing/generate_text_for_edit_test.php | 10 +++++++--- .../text_processing/generate_text_for_storage_test.php | 10 +++++++--- tests/text_processing/smilies_test.php | 10 +++++++--- .../tickets_data/PHPBB3-3981.before.php | 10 +++++++--- .../text_processing/tickets_data/PHPBB3-7275.after.php | 10 +++++++--- tests/text_processing/tickets_test.php | 10 +++++++--- 11 files changed, 77 insertions(+), 33 deletions(-) diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index 94d46a58b7..79232562cf 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 7c26443579..2930826a78 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index a3c86e8350..4b1a23e254 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 486b17d03f..aa0b036c87 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php index 510beba817..3de9b707c5 100644 --- a/tests/text_formatter/s9e/utils_test.php +++ b/tests/text_formatter/s9e/utils_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/generate_text_for_edit_test.php b/tests/text_processing/generate_text_for_edit_test.php index 85b3a6a0ab..d1db1c6ce1 100644 --- a/tests/text_processing/generate_text_for_edit_test.php +++ b/tests/text_processing/generate_text_for_edit_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/generate_text_for_storage_test.php b/tests/text_processing/generate_text_for_storage_test.php index 0bacaacfb8..2a33e2e7be 100644 --- a/tests/text_processing/generate_text_for_storage_test.php +++ b/tests/text_processing/generate_text_for_storage_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/smilies_test.php b/tests/text_processing/smilies_test.php index cd35c25525..3bbe065d36 100644 --- a/tests/text_processing/smilies_test.php +++ b/tests/text_processing/smilies_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.before.php b/tests/text_processing/tickets_data/PHPBB3-3981.before.php index 20c96d163c..1c326b52af 100644 --- a/tests/text_processing/tickets_data/PHPBB3-3981.before.php +++ b/tests/text_processing/tickets_data/PHPBB3-3981.before.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.after.php b/tests/text_processing/tickets_data/PHPBB3-7275.after.php index a824cb9b84..99f41d7839 100644 --- a/tests/text_processing/tickets_data/PHPBB3-7275.after.php +++ b/tests/text_processing/tickets_data/PHPBB3-7275.after.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/tickets_test.php b/tests/text_processing/tickets_test.php index d2072a10f5..1f7aa58ebb 100644 --- a/tests/text_processing/tickets_test.php +++ b/tests/text_processing/tickets_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ From ed29972e76d4dfd9a670582421c8dff0f470411e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 01:28:48 +0100 Subject: [PATCH 34/82] [ticket/11768] Removed require_once calls that target mock classes PHPBB3-11768 --- tests/text_formatter/s9e/factory_test.php | 2 -- tests/text_formatter/s9e/parser_test.php | 2 -- tests/text_formatter/s9e/renderer_test.php | 1 - tests/text_processing/generate_text_for_edit_test.php | 2 -- tests/text_processing/generate_text_for_storage_test.php | 1 - tests/text_processing/tickets_test.php | 1 - 6 files changed, 9 deletions(-) diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 2930826a78..d78765b7d5 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -12,8 +12,6 @@ */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../../mock/user.php'; -require_once __DIR__ . '/../../mock/cache.php'; require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 4b1a23e254..725ff42bfd 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -12,8 +12,6 @@ */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../../mock/user.php'; -require_once __DIR__ . '/../../mock/cache.php'; class phpbb_textformatter_s9e_parser_test extends phpbb_test_case { diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index aa0b036c87..17d358c3ce 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -12,7 +12,6 @@ */ require_once __DIR__ . '/../../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../../mock/cache.php'; class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case { diff --git a/tests/text_processing/generate_text_for_edit_test.php b/tests/text_processing/generate_text_for_edit_test.php index d1db1c6ce1..105e8da86b 100644 --- a/tests/text_processing/generate_text_for_edit_test.php +++ b/tests/text_processing/generate_text_for_edit_test.php @@ -13,8 +13,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../mock/user.php'; -require_once __DIR__ . '/../mock/cache.php'; class phpbb_text_processing_generate_text_for_edit_test extends phpbb_test_case { diff --git a/tests/text_processing/generate_text_for_storage_test.php b/tests/text_processing/generate_text_for_storage_test.php index 2a33e2e7be..ffa06e4e02 100644 --- a/tests/text_processing/generate_text_for_storage_test.php +++ b/tests/text_processing/generate_text_for_storage_test.php @@ -14,7 +14,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; -require_once __DIR__ . '/../mock/container_builder.php'; class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_case { diff --git a/tests/text_processing/tickets_test.php b/tests/text_processing/tickets_test.php index 1f7aa58ebb..8c48a3f4a9 100644 --- a/tests/text_processing/tickets_test.php +++ b/tests/text_processing/tickets_test.php @@ -14,7 +14,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; -require_once __DIR__ . '/../mock/container_builder.php'; class phpbb_text_processing_tickets_test extends phpbb_test_case { From 462696aa4787112b67b2ea8febf6a9f40a461baa Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 01:42:54 +0100 Subject: [PATCH 35/82] [ticket/11768] Replaced headers in test files PHPBB3-11768 --- tests/text_processing/decode_message_test.php | 10 +++++++--- tests/text_processing/message_parser_test.php | 10 +++++++--- tests/text_processing/strip_bbcode_test.php | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/text_processing/decode_message_test.php b/tests/text_processing/decode_message_test.php index 855b3c6c57..c9c1da52d5 100644 --- a/tests/text_processing/decode_message_test.php +++ b/tests/text_processing/decode_message_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/message_parser_test.php b/tests/text_processing/message_parser_test.php index 59af2553f8..cdbd6c0ca7 100644 --- a/tests/text_processing/message_parser_test.php +++ b/tests/text_processing/message_parser_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/text_processing/strip_bbcode_test.php b/tests/text_processing/strip_bbcode_test.php index d0dda89167..827d8d4a52 100644 --- a/tests/text_processing/strip_bbcode_test.php +++ b/tests/text_processing/strip_bbcode_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ From 6cb3fb614022fe4e56a6651ffad4f476056ae520 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 01:44:48 +0100 Subject: [PATCH 36/82] [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(-) 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; From d37f2d10f02b6a7a2b12e4b21284df310f39d3e6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 02:14:09 +0100 Subject: [PATCH 37/82] [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 +- tests/text_formatter/s9e/factory_test.php | 1 - tests/text_formatter/s9e/renderer_test.php | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) 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'])) diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index d78765b7d5..a1378514b4 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -94,7 +94,6 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $renderer_data = $this->cache->get('_foo_renderer'); $this->assertEquals($parser, $this->cache->get('_foo_parser'), 'The parser was not cached'); $this->assertEquals(get_class($renderer), $renderer_data['class']); - $this->assertEquals(serialize($renderer), $renderer_data['renderer']); $this->assertInstanceOf('s9e\\TextFormatter\\Plugins\\Censor\\Helper', $renderer_data['censor']); $file = $this->get_cache_dir() . get_class($renderer) . '.php'; diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 17d358c3ce..248b38206a 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -34,7 +34,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case $cache->expects($this->once()) ->method('get') ->with('_foo_renderer') - ->will($this->returnValue(array('class' => 'renderer_foo', 'renderer' => serialize($mock)))); + ->will($this->returnValue(array('class' => 'renderer_foo'))); $factory = $this->getMockBuilder('phpbb\\textformatter\\s9e\\factory') ->disableOriginalConstructor() From 5fe8c6b6f5080c7e174882d279beb2b84ddd01ab Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 02:24:51 +0100 Subject: [PATCH 38/82] [ticket/11768] Removed unused var PHPBB3-11768 --- tests/text_formatter/s9e/renderer_test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 248b38206a..b93fd8bbe6 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -28,8 +28,6 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case 'getMockForAbstractClass('s9e\\TextFormatter\\Renderer'); - $cache = $this->getMock('phpbb_mock_cache'); $cache->expects($this->once()) ->method('get') From 40340004aac7ac1752c90a1dbca1faa486e668b9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 02:52:40 +0100 Subject: [PATCH 39/82] [ticket/11768] Replaced some references PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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) From dc9a28d346370b38c10def92358170a5cef23b36 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 03:07:23 +0100 Subject: [PATCH 40/82] [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(-) 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)) From 78b544920c0d3984dd814cfe59f43c46feac6f12 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 04:18:17 +0100 Subject: [PATCH 41/82] [ticket/11768] Added support for creating unsafe BBCodes PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 3 +- tests/text_formatter/s9e/factory_test.php | 18 ++++++++++-- .../s9e/fixtures/unsafe_bbcode.xml | 28 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml 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) { diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index a1378514b4..8df841605d 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -78,9 +78,6 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case // This custom BBCode should be set $this->assertTrue(isset($configurator->BBCodes['CUSTOM'])); - // This unsafe custom BBCode will trigger an exception and should be ignored - $this->assertFalse(isset($configurator->BBCodes['UNSAFE'])); - $this->assertTrue(isset($configurator->Emoticons[':D'])); } @@ -176,4 +173,19 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $expected = $original; $this->assertSame($expected, $renderer->render($parser->parse($original))); } + + /** + * @testdox Accepts unsafe custom BBCodes + */ + public function test_unsafe_bbcode() + { + $fixture = __DIR__ . '/fixtures/unsafe_bbcode.xml'; + $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); + $parser = $container->get('text_formatter.parser'); + $renderer = $container->get('text_formatter.renderer'); + + $original = '[xss=javascript:alert(1)]text[/xss]'; + $expected = 'text'; + $this->assertSame($expected, $renderer->render($parser->parse($original))); + } } diff --git a/tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml b/tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml new file mode 100644 index 0000000000..55a2e689b6 --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/unsafe_bbcode.xml @@ -0,0 +1,28 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + xss= + + 1 + [xss={TEXT1}]{TEXT2}[/xss] + {TEXT2}]]> + + + + ${2}]]> + +
            +
            From aed9ece1bcf5dfb55037b01306da5f6cda8e6824 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 04:19:21 +0100 Subject: [PATCH 42/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 73b41a9e60..a56036cf8f 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e" + "reference": "ad2faea5ccbfd2e98cb617abd4c53d263cb84c45" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/0a6bfe116bf348acf209e0d50bd3b3fad86d219e", - "reference": "0a6bfe116bf348acf209e0d50bd3b3fad86d219e", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/ad2faea5ccbfd2e98cb617abd4c53d263cb84c45", + "reference": "ad2faea5ccbfd2e98cb617abd4c53d263cb84c45", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-02-19 04:58:59" + "time": "2015-03-02 08:49:17" }, { "name": "symfony/config", From 1a133d548712f16801ed2a8617aa7eed7f30688c Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 3 Mar 2015 23:38:37 +0100 Subject: [PATCH 43/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index a56036cf8f..f9c113ded6 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "ad2faea5ccbfd2e98cb617abd4c53d263cb84c45" + "reference": "ddd653042fccea77b4ead018492ca7de9196bc77" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/ad2faea5ccbfd2e98cb617abd4c53d263cb84c45", - "reference": "ad2faea5ccbfd2e98cb617abd4c53d263cb84c45", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/ddd653042fccea77b4ead018492ca7de9196bc77", + "reference": "ddd653042fccea77b4ead018492ca7de9196bc77", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-02 08:49:17" + "time": "2015-03-03 22:19:32" }, { "name": "symfony/config", From ec77ff7838e317deb5facacfae31402af08a9902 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 5 Mar 2015 00:06:52 +0100 Subject: [PATCH 44/82] [ticket/11768] Invalidate the text_formatter cache whenever a style is installed The acp_styles module purges the cache every time a style is uninstalled, modified or made default, but it does not purge the cache when a new style is installed. Here we invalidate the text_formatter cache (not purge the whole cache) so that new styles take effect immediately. PHPBB3-11768 --- phpBB/includes/acp/acp_styles.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 45f224f8b1..904769f0d1 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -53,6 +53,9 @@ class acp_styles /** @var \phpbb\auth\auth */ protected $auth; + /** @var \phpbb\textformatter\cache */ + protected $text_formatter_cache; + /** @var string */ protected $phpbb_root_path; @@ -61,7 +64,7 @@ class acp_styles public function main($id, $mode) { - global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; + global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config, $phpbb_container; $this->db = $db; $this->user = $user; @@ -69,6 +72,7 @@ class acp_styles $this->request = $request; $this->cache = $cache; $this->auth = $auth; + $this->text_formatter_cache = $phpbb_container->get('text_formatter.cache'); $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; @@ -216,6 +220,12 @@ class acp_styles } } + // Invalidate the text formatter's cache for the new styles to take effect + if (!empty($installed_names)) + { + $this->text_formatter_cache->invalidate(); + } + // Show message if (!count($messages)) { From 8411db62576a73beb921d58953bb5b767d4ee079 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:21:15 +0100 Subject: [PATCH 45/82] [ticket/11768] Renamed interfaces PHPBB3-11768 --- .../{cache.php => cache_interface.php} | 2 +- phpBB/phpbb/textformatter/data_access.php | 2 +- .../{parser.php => parser_interface.php} | 2 +- phpBB/phpbb/textformatter/renderer.php | 129 ------------------ .../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 ++++- 8 files changed, 129 insertions(+), 137 deletions(-) rename phpBB/phpbb/textformatter/{cache.php => cache_interface.php} (96%) rename phpBB/phpbb/textformatter/{parser.php => parser_interface.php} (98%) delete mode 100644 phpBB/phpbb/textformatter/renderer.php create mode 100644 phpBB/phpbb/textformatter/renderer_interface.php diff --git a/phpBB/phpbb/textformatter/cache.php b/phpBB/phpbb/textformatter/cache_interface.php similarity index 96% rename from phpBB/phpbb/textformatter/cache.php rename to phpBB/phpbb/textformatter/cache_interface.php index a2f7ff7d7b..f6b5f195c7 100644 --- a/phpBB/phpbb/textformatter/cache.php +++ b/phpBB/phpbb/textformatter/cache_interface.php @@ -17,7 +17,7 @@ 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 cache_interface { /** * Invalidate and/or regenerate this text formatter's cache(s) 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_interface.php similarity index 98% rename from phpBB/phpbb/textformatter/parser.php rename to phpBB/phpbb/textformatter/parser_interface.php index 922226cf44..37d538470d 100644 --- a/phpBB/phpbb/textformatter/parser.php +++ b/phpBB/phpbb/textformatter/parser_interface.php @@ -13,7 +13,7 @@ namespace phpbb\textformatter; -interface parser +interface parser_interface { /** * Parse given text 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) From a611366bd398c02b47aa71b0fdaa9c16765d0f6b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:24:03 +0100 Subject: [PATCH 46/82] [ticket/11768] Whitespace [ci skip] PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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')); From 44fc3d64dafdadd1959ab53dd7e0d1be67c75c1b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:46:59 +0100 Subject: [PATCH 47/82] [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(-) 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]; From 20a1646fc6336635cee89426e3a60bb22cb138de Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 10:50:05 +0100 Subject: [PATCH 48/82] [ticket/11768] Renamed utils PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/utils.php | 2 +- .../textformatter/{utils.php => utils_interface.php} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename phpBB/phpbb/textformatter/{utils.php => utils_interface.php} (80%) 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_interface.php similarity index 80% rename from phpBB/phpbb/textformatter/utils.php rename to phpBB/phpbb/textformatter/utils_interface.php index 13942b9248..45610f7ecb 100644 --- a/phpBB/phpbb/textformatter/utils.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -16,7 +16,7 @@ namespace phpbb\textformatter; /** * Used to manipulate a parsed text */ -abstract class utils +interface utils_interface { /** * Replace BBCodes and other formatting elements with whitespace @@ -26,7 +26,7 @@ abstract class utils * @param string $text * @return string */ - abstract public function clean_formatting($text); + public function clean_formatting($text); /** * Remove given BBCode at given nesting depth @@ -36,7 +36,7 @@ abstract class utils * @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); + public function remove_bbcode($text, $bbcode_name, $depth = 0); /** * Remove BBCodes and other formatting from a parsed text @@ -46,7 +46,7 @@ abstract class utils * @param string $text * @return string */ - abstract public function remove_formatting($text); + public function remove_formatting($text); /** * Return a parsed text to its original form @@ -54,5 +54,5 @@ abstract class utils * @param string $text * @return string */ - abstract public function unparse($text); + public function unparse($text); } From 89d87a99db403d7045406b869a92258e61122f67 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 11:11:07 +0100 Subject: [PATCH 49/82] [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(-) 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); } } From 1b4bdff3b3d01cd422f7a49a1de14b3edbd76804 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 13:00:03 +0100 Subject: [PATCH 50/82] [ticket/11768] Fixed test double PHPBB3-11768 --- tests/text_processing/message_parser_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/text_processing/message_parser_test.php b/tests/text_processing/message_parser_test.php index cdbd6c0ca7..691c0d5b8a 100644 --- a/tests/text_processing/message_parser_test.php +++ b/tests/text_processing/message_parser_test.php @@ -53,6 +53,7 @@ class phpbb_text_processing_message_parser_test extends phpbb_test_case array('UNAUTHORISED_BBCODE', '[img]', 'You cannot use certain BBCodes: [img].'), array('UNAUTHORISED_BBCODE', '[quote]', 'You cannot use certain BBCodes: [quote].'), array('UNAUTHORISED_BBCODE', '[url]', 'You cannot use certain BBCodes: [url].'), + array('UNABLE_GET_IMAGE_SIZE', 'It was not possible to determine the dimensions of the image.'), ); $user = $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(); @@ -67,7 +68,6 @@ class phpbb_text_processing_message_parser_test extends phpbb_test_case 'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options.', 'TOO_MANY_POLL_OPTIONS' => 'You have tried to enter too many poll options.', 'TOO_MANY_USER_OPTIONS' => 'You cannot specify more options per user than existing poll options.', - 'UNABLE_GET_IMAGE_SIZE' => 'It was not possible to determine the dimensions of the image.' ); $phpbb_container = new phpbb_mock_container_builder; From 40c54898ccd80744ba159784d631328e0338bad2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 13:08:18 +0100 Subject: [PATCH 51/82] [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(-) 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() { From b021225148d8ba14e106dd24a25128e3be36992a Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Mar 2015 13:11:33 +0100 Subject: [PATCH 52/82] [ticket/11768] Removed unused var PHPBB3-11768 --- tests/test_framework/phpbb_test_case_helpers.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 8e49dca40c..e584c238a2 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -486,9 +486,6 @@ class phpbb_test_case_helpers $factory ); - $root_path = ($container->hasParameter('core.root_path')) - ? $container->getParameter('core.root_path') - : './'; $config = ($container->has('config')) ? $container->get('config') : new \phpbb\config\config(array('smilies_path' => 'images/smilies', 'allow_nocensors' => false)); From 709d5023324da66543bbea2f62e4d50bddc49246 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 8 Mar 2015 21:49:53 +0100 Subject: [PATCH 53/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index f9c113ded6..23160ae541 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "ddd653042fccea77b4ead018492ca7de9196bc77" + "reference": "195202e24258fd38b5c655cc4f3d757688ada7ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/ddd653042fccea77b4ead018492ca7de9196bc77", - "reference": "ddd653042fccea77b4ead018492ca7de9196bc77", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/195202e24258fd38b5c655cc4f3d757688ada7ad", + "reference": "195202e24258fd38b5c655cc4f3d757688ada7ad", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-03 22:19:32" + "time": "2015-03-08 18:49:11" }, { "name": "symfony/config", From b46bf9f02f8d1810bdb95d64603632b6fab06960 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 9 Mar 2015 12:07:10 +0100 Subject: [PATCH 54/82] [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(-) 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 . ''; From 37106bae7a4e3e67143dde9a86f03b3190ed0f4c Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 14 Mar 2015 03:13:04 +0100 Subject: [PATCH 55/82] [ticket/11768] Reverted change to bbcode_uid On the off-chance some other routine expect bbcode_uid to never be empty. PHPBB3-11768 --- phpBB/includes/message_parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index e4c35f8bca..6af1677b58 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1094,7 +1094,7 @@ class parse_message extends bbcode_firstpass function parse_message($message = '') { // Init BBCode UID - $this->bbcode_uid = ''; + $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN); $this->message = $message; } From 4398da234ec75cb95ddab82a0fb8f3567790a60b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 16 Mar 2015 03:03:02 +0100 Subject: [PATCH 56/82] [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(-) 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); From 718ace2121dc5e58bb1c09d730a867cde20518eb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 16 Mar 2015 03:32:20 +0100 Subject: [PATCH 57/82] [ticket/11768] Updated annotation [ci skip] PHPBB3-11768 --- phpBB/includes/acp/acp_styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 904769f0d1..b652fd6587 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -53,7 +53,7 @@ class acp_styles /** @var \phpbb\auth\auth */ protected $auth; - /** @var \phpbb\textformatter\cache */ + /** @var \phpbb\textformatter\cache_interface */ protected $text_formatter_cache; /** @var string */ From 8971805e57c2af152ef62e16c8e5eb67bf343756 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 16 Mar 2015 12:43:10 +0100 Subject: [PATCH 58/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 23160ae541..0c5ff71011 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "195202e24258fd38b5c655cc4f3d757688ada7ad" + "reference": "e6d6fb3518f8e3f202310b9cafe2c660970a5dbe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/195202e24258fd38b5c655cc4f3d757688ada7ad", - "reference": "195202e24258fd38b5c655cc4f3d757688ada7ad", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/e6d6fb3518f8e3f202310b9cafe2c660970a5dbe", + "reference": "e6d6fb3518f8e3f202310b9cafe2c660970a5dbe", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-08 18:49:11" + "time": "2015-03-16 11:12:04" }, { "name": "symfony/config", From f4f5bdbaee48d0ed341ec9b720579a4f751916fc Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 19 Mar 2015 11:38:44 +0100 Subject: [PATCH 59/82] [ticket/11768] Removed whitespace No functional change intended PHPBB3-11768 --- tests/text_formatter/s9e/factory_test.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 8df841605d..7dfa512b28 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -29,9 +29,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case public function get_factory() { global $phpbb_root_path; - $this->cache = new phpbb_mock_cache; - $dal = new \phpbb\textformatter\data_access( $this->new_dbal(), 'phpbb_bbcodes', @@ -40,7 +38,6 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case 'phpbb_words', $phpbb_root_path . 'styles/' ); - $factory = new \phpbb\textformatter\s9e\factory( $dal, $this->cache, @@ -122,7 +119,6 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case public function test_local_url() { global $config, $user, $request; - $config = array( 'force_server_vars' => true, 'server_protocol' => 'http://', From 49b9e8e4eafff93f25a99bf263982fe79b7f0549 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 19 Mar 2015 12:45:12 +0100 Subject: [PATCH 60/82] [ticket/11768] Added configurator events PHPBB3-11768 --- .../container/services_text_formatter.yml | 1 + phpBB/phpbb/textformatter/s9e/factory.php | 30 +++++++++++++- .../phpbb_test_case_helpers.php | 18 ++++++++- tests/text_formatter/s9e/factory_test.php | 39 +++++++++++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml index ec5421695d..05188a5fba 100644 --- a/phpBB/config/default/container/services_text_formatter.yml +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -31,6 +31,7 @@ services: arguments: - @text_formatter.data_access - @cache.driver + - @dispatcher - %text_formatter.cache.dir% - %text_formatter.cache.parser.key% - %text_formatter.cache.renderer.key% 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; } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index e584c238a2..5c6da94014 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -315,7 +315,7 @@ class phpbb_test_case_helpers public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null) { static $first_run; - global $phpbb_container, $phpbb_root_path, $phpEx; + global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; $cache_dir = __DIR__ . '/../tmp/'; @@ -443,8 +443,22 @@ class phpbb_test_case_helpers ); } + // Create an event dispatcher + if ($container->has('dispatcher')) + { + $dispatcher = $container->get('dispatcher'); + } + else if (isset($phpbb_dispatcher)) + { + $dispatcher = $phpbb_dispatcher; + } + else + { + $dispatcher = new phpbb_mock_event_dispatcher; + } + // Create and register the text_formatter.s9e.factory service - $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $cache_dir, $cache_key_parser, $cache_key_renderer); + $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer); $container->set('text_formatter.s9e.factory', $factory); // Create a user if none was provided, and add the common lang strings diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 7dfa512b28..9f7551ef14 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -16,6 +16,13 @@ require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case { + public function setUp() + { + $this->cache = new phpbb_mock_cache; + $this->dispatcher = new phpbb_mock_event_dispatcher; + parent::setUp(); + } + public function getDataSet() { return $this->createXMLDataSet(__DIR__ . '/fixtures/factory.xml'); @@ -41,6 +48,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $factory = new \phpbb\textformatter\s9e\factory( $dal, $this->cache, + $this->dispatcher, $this->get_cache_dir(), '_foo_parser', '_foo_renderer' @@ -184,4 +192,35 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $expected = 'text'; $this->assertSame($expected, $renderer->render($parser->parse($original))); } + + /** + * @testdox get_configurator() triggers events before and after configuration + */ + public function test_configure_events() + { + $this->dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); + $this->dispatcher + ->expects($this->at(0)) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_configure_before', + $this->callback(array($this, 'configure_event_callback')) + ) + ->will($this->returnArgument(1)); + $this->dispatcher + ->expects($this->at(1)) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_configure_after', + $this->callback(array($this, 'configure_event_callback')) + ) + ->will($this->returnArgument(1)); + + $this->get_factory()->get_configurator(); + } + + public function configure_event_callback($vars) + { + return isset($vars['configurator']) && $vars['configurator'] instanceof \s9e\TextFormatter\Configurator; + } } From 3cd5ca8de12f645f3c8664942f0328e18d5a2789 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 21 Mar 2015 12:28:52 +0100 Subject: [PATCH 61/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 0c5ff71011..d5809144a6 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "e6d6fb3518f8e3f202310b9cafe2c660970a5dbe" + "reference": "1a4d347bec744ff2959708fcf24fa40848a66861" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/e6d6fb3518f8e3f202310b9cafe2c660970a5dbe", - "reference": "e6d6fb3518f8e3f202310b9cafe2c660970a5dbe", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/1a4d347bec744ff2959708fcf24fa40848a66861", + "reference": "1a4d347bec744ff2959708fcf24fa40848a66861", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-16 11:12:04" + "time": "2015-03-21 11:18:30" }, { "name": "symfony/config", From 69dae16ba79a82714b3fa24955c5cbc6e372a388 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 21 Mar 2015 12:32:17 +0100 Subject: [PATCH 62/82] [ticket/11768] Preserve comments in custom BBCodes PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/factory.php | 4 +++ tests/text_formatter/s9e/factory_test.php | 15 ++++++++++ .../s9e/fixtures/preserve_comments.xml | 28 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/text_formatter/s9e/fixtures/preserve_comments.xml 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; diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 9f7551ef14..8382097544 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -178,6 +178,21 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $this->assertSame($expected, $renderer->render($parser->parse($original))); } + /** + * @testdox Preserves comments in custom BBCodes + */ + public function test_preserve_comments() + { + $fixture = __DIR__ . '/fixtures/preserve_comments.xml'; + $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); + $parser = $container->get('text_formatter.parser'); + $renderer = $container->get('text_formatter.renderer'); + + $original = '[X]'; + $expected = ''; + $this->assertSame($expected, $renderer->render($parser->parse($original))); + } + /** * @testdox Accepts unsafe custom BBCodes */ diff --git a/tests/text_formatter/s9e/fixtures/preserve_comments.xml b/tests/text_formatter/s9e/fixtures/preserve_comments.xml new file mode 100644 index 0000000000..f81d366aad --- /dev/null +++ b/tests/text_formatter/s9e/fixtures/preserve_comments.xml @@ -0,0 +1,28 @@ + + + + bbcode_id + bbcode_tag + bbcode_helpline + display_on_posting + bbcode_match + bbcode_tpl + first_pass_match + first_pass_replace + second_pass_match + second_pass_replace + + + 13 + X + + 1 + [X][/X] + ]]> + + + + + +
            +
            From c165eaa37ccfa817c3ba1373255efc131f7be509 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Mar 2015 12:34:22 +0100 Subject: [PATCH 63/82] [ticket/11768] Removed superfluous whitespace [ci skip] PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 3 --- 1 file changed, 3 deletions(-) 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']; From 5b2d3fddfda75bcc212c8b9c88ab0d9ccc28b1d5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Mar 2015 21:32:10 +0100 Subject: [PATCH 64/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index d5809144a6..789540534e 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "1a4d347bec744ff2959708fcf24fa40848a66861" + "reference": "59248bbc7edc139e11ff50cc42c2eeddffcb41c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/1a4d347bec744ff2959708fcf24fa40848a66861", - "reference": "1a4d347bec744ff2959708fcf24fa40848a66861", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/59248bbc7edc139e11ff50cc42c2eeddffcb41c5", + "reference": "59248bbc7edc139e11ff50cc42c2eeddffcb41c5", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-21 11:18:30" + "time": "2015-03-23 20:24:43" }, { "name": "symfony/config", From 37fedc656fbdeb36b098375201042eed4c7e7229 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 23 Mar 2015 21:34:49 +0100 Subject: [PATCH 65/82] [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 ++---------- tests/text_formatter/s9e/utils_test.php | 37 +++++++++---------------- 2 files changed, 16 insertions(+), 38 deletions(-) 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); } /** diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php index 3de9b707c5..6f0ef54182 100644 --- a/tests/text_formatter/s9e/utils_test.php +++ b/tests/text_formatter/s9e/utils_test.php @@ -109,52 +109,41 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case public function test_remove_bbcode($original, $name, $depth, $expected) { $container = $this->get_test_case_helpers()->set_s9e_services(); + $parser = $container->get('text_formatter.parser'); $utils = $container->get('text_formatter.utils'); - $this->assertSame($expected, $utils->remove_bbcode($original, $name, $depth)); + $parsed = $parser->parse($original); + $actual = $utils->unparse($utils->remove_bbcode($parsed, $name, $depth)); + + $this->assertSame($expected, $actual); } public function get_remove_bbcode_tests() { return array( array( - 'Plain text', + 'Plain text', 'b', 1, - 'Plain text' + 'Plain text' ), array( - '[quote="u0"][quote="u1"][quote="u2"]q2[/quote] -q1[/quote] -q0[/quote] -[b]bold[/b]', + '[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', 'quote', 0, - ' -[b]bold[/b]' + '[b]bold[/b]', ), array( - '[quote="u0"][quote="u1"][quote="u2"]q2[/quote] -q1[/quote] -q0[/quote] -[b]bold[/b]', + '[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', 'quote', 1, - '[quote="u0"] -q0[/quote] -[b]bold[/b]' + '[quote="u0"]q0[/quote][b]bold[/b]', ), array( - '[quote="u0"][quote="u1"][quote="u2"]q2[/quote] -q1[/quote] -q0[/quote] -[b]bold[/b]', + '[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]', 'quote', 2, - '[quote="u0"][quote="u1"] -q1[/quote] -q0[/quote] -[b]bold[/b]' + '[quote="u0"][quote="u1"]q1[/quote]q0[/quote][b]bold[/b]', ), ); } From 2a462bb7e43b848d0277bd27e14ca4d645230eeb Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 25 Mar 2015 01:13:31 +0100 Subject: [PATCH 66/82] [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 ---------- tests/text_formatter/s9e/parser_test.php | 7 ------- tests/text_formatter/s9e/renderer_test.php | 7 ------- 4 files changed, 34 deletions(-) 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} */ diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 725ff42bfd..71433e209f 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -167,11 +167,4 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case ) ); } - - public function test_get_parser() - { - $container = $this->get_test_case_helpers()->set_s9e_services(); - $parser = $container->get('text_formatter.parser'); - $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser->get_parser()); - } } diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index b93fd8bbe6..ce2fccd9b7 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -354,11 +354,4 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ); } } - - public function test_get_renderer() - { - $container = $this->get_test_case_helpers()->set_s9e_services(); - $renderer = $container->get('text_formatter.renderer'); - $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer->get_renderer()); - } } From a7a53d5a30d4736f8114721c0d7019d64d24cda2 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 25 Mar 2015 01:39:19 +0100 Subject: [PATCH 67/82] [ticket/11768] Added core.text_formatter_s9e_parser_setup event PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 31 ++++++++++-- .../phpbb_test_case_helpers.php | 5 +- tests/text_formatter/s9e/parser_test.php | 47 +++++++++++++++++-- 3 files changed, 75 insertions(+), 8 deletions(-) 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; } /** diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 5c6da94014..d43138d780 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -425,6 +425,7 @@ class phpbb_test_case_helpers $prefix = '_s9e_' . md5(serialize(func_get_args())); $cache_key_parser = $prefix . '_parser'; $cache_key_renderer = $prefix . '_renderer'; + $container->set('cache.driver', $cache); // Create a path_helper if (!$container->has('path_helper')) @@ -473,6 +474,7 @@ class phpbb_test_case_helpers $user->optionset('viewflash', true); $user->optionset('viewimg', true); $user->optionset('viewsmilies', true); + $container->set('user', $user); } $user->add_lang('common'); @@ -486,7 +488,8 @@ class phpbb_test_case_helpers $cache, $cache_key_parser, $user, - $factory + $factory, + $dispatcher ); $container->set('text_formatter.parser', $parser); diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 71433e209f..03b29bef12 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -36,7 +36,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - $factory + $factory, + new phpbb_mock_event_dispatcher ); } @@ -63,7 +64,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - $factory + $factory, + new phpbb_mock_event_dispatcher ); $this->assertSame('test', $parser->parse('test')); @@ -91,7 +93,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case new phpbb_mock_cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - $factory + $factory, + new phpbb_mock_event_dispatcher ); $this->assertSame('test', $parser->parse('test')); @@ -124,7 +127,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $cache, '_foo_parser', $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), - $factory + $factory, + new phpbb_mock_event_dispatcher ); call_user_func_array(array($parser, $adapter_method), (array) $adapter_arg); @@ -167,4 +171,39 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case ) ); } + + /** + * @testdox The constructor triggers a core.text_formatter_s9e_parser_setup event + */ + public function test_setup_event() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); + $dispatcher + ->expects($this->once()) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_parser_setup', + $this->callback(array($this, 'setup_event_callback')) + ) + ->will($this->returnArgument(1)); + + new \phpbb\textformatter\s9e\parser( + $container->get('cache.driver'), + '_foo_parser', + $container->get('user'), + $container->get('text_formatter.s9e.factory'), + $dispatcher + ); + } + + public function setup_event_callback($vars) + { + return isset($vars['parser']) + && $vars['parser'] instanceof \s9e\TextFormatter\Parser + && isset($vars['self']) + && $vars['self'] instanceof \phpbb\textformatter\s9e\parser + && isset($vars['user']) + && $vars['user'] instanceof \phpbb\user; + } } From 7f9639fd248a1f690ac55ddab8939ec84309f129 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 25 Mar 2015 02:22:18 +0100 Subject: [PATCH 68/82] [ticket/11768] Fixed service config PHPBB3-11768 --- phpBB/config/default/container/services_text_formatter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml index 05188a5fba..e95cafcc7e 100644 --- a/phpBB/config/default/container/services_text_formatter.yml +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -43,6 +43,7 @@ services: - %text_formatter.cache.parser.key% - @user - @text_formatter.s9e.factory + - @dispatcher text_formatter.s9e.renderer: class: phpbb\textformatter\s9e\renderer From c89188132114b4d9ff483c5b1579c53cdeb69703 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 25 Mar 2015 03:44:24 +0100 Subject: [PATCH 69/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 789540534e..706dd4ba63 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "59248bbc7edc139e11ff50cc42c2eeddffcb41c5" + "reference": "ad4384b2c792cf55c456de018a525bbaea106fc0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/59248bbc7edc139e11ff50cc42c2eeddffcb41c5", - "reference": "59248bbc7edc139e11ff50cc42c2eeddffcb41c5", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/ad4384b2c792cf55c456de018a525bbaea106fc0", + "reference": "ad4384b2c792cf55c456de018a525bbaea106fc0", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-23 20:24:43" + "time": "2015-03-25 02:37:49" }, { "name": "symfony/config", From af4f9b860f50a562a03f55efad1da7e0854bdfda Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 04:39:36 +0100 Subject: [PATCH 70/82] [ticket/11768] Added core.text_formatter_s9e_renderer_setup event PHPBB3-11768 --- .../container/services_text_formatter.yml | 1 + phpBB/phpbb/textformatter/s9e/renderer.php | 23 +++++++++-- .../phpbb_test_case_helpers.php | 4 +- tests/text_formatter/s9e/renderer_test.php | 39 ++++++++++++++++++- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml index e95cafcc7e..972be31b31 100644 --- a/phpBB/config/default/container/services_text_formatter.yml +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -52,6 +52,7 @@ services: - %text_formatter.cache.dir% - %text_formatter.cache.renderer.key% - @text_formatter.s9e.factory + - @dispatcher calls: - [configure_smilies_path, [@config, @path_helper]] - [configure_user, [@user, @config, @auth]] 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; } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index d43138d780..09fec38013 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -426,6 +426,7 @@ class phpbb_test_case_helpers $cache_key_parser = $prefix . '_parser'; $cache_key_renderer = $prefix . '_renderer'; $container->set('cache.driver', $cache); + $container->setParameter('cache.dir', $cache_dir); // Create a path_helper if (!$container->has('path_helper')) @@ -500,7 +501,8 @@ class phpbb_test_case_helpers $cache, $cache_dir, $cache_key_renderer, - $factory + $factory, + $dispatcher ); $config = ($container->has('config')) diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index ce2fccd9b7..ab89d42620 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -43,7 +43,8 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case $cache, $this->get_cache_dir(), '_foo_renderer', - $factory + $factory, + new phpbb_mock_event_dispatcher ); } @@ -68,7 +69,8 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case $cache, $this->get_cache_dir(), '_foo_renderer', - $factory + $factory, + new phpbb_mock_event_dispatcher ); } @@ -354,4 +356,37 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case ); } } + + /** + * @testdox The constructor triggers a core.text_formatter_s9e_renderer_setup event + */ + public function test_setup_event() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); + $dispatcher + ->expects($this->once()) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_renderer_setup', + $this->callback(array($this, 'setup_event_callback')) + ) + ->will($this->returnArgument(1)); + + new \phpbb\textformatter\s9e\renderer( + $container->get('cache.driver'), + $container->getParameter('cache.dir'), + '_foo_renderer', + $container->get('text_formatter.s9e.factory'), + $dispatcher + ); + } + + public function setup_event_callback($vars) + { + return isset($vars['renderer']) + && $vars['renderer'] instanceof \s9e\TextFormatter\Renderer + && isset($vars['self']) + && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer; + } } From a04fca86ee4fec3cb615f358f3dc914564d9a9b1 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 05:10:25 +0100 Subject: [PATCH 71/82] [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 ++++++++++-- tests/text_formatter/s9e/renderer_test.php | 54 ++++++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) 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; } diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index ab89d42620..c69a93dbc1 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -389,4 +389,58 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case && isset($vars['self']) && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer; } + + /** + * @testdox render() triggers a core.text_formatter_s9e_render_before and core.text_formatter_s9e_render_after events + */ + public function test_render_event() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); + $dispatcher + ->expects($this->any()) + ->method('trigger_event') + ->will($this->returnArgument(1)); + $dispatcher + ->expects($this->at(1)) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_render_before', + $this->callback(array($this, 'render_before_event_callback')) + ) + ->will($this->returnArgument(1)); + $dispatcher + ->expects($this->at(2)) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_render_after', + $this->callback(array($this, 'render_after_event_callback')) + ) + ->will($this->returnArgument(1)); + + $renderer = new \phpbb\textformatter\s9e\renderer( + $container->get('cache.driver'), + $container->getParameter('cache.dir'), + '_foo_renderer', + $container->get('text_formatter.s9e.factory'), + $dispatcher + ); + $renderer->render('...'); + } + + public function render_before_event_callback($vars) + { + return isset($vars['self']) + && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer + && isset($vars['xml']) + && $vars['xml'] === '...'; + } + + public function render_after_event_callback($vars) + { + return isset($vars['html']) + && $vars['html'] === '...' + && isset($vars['self']) + && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer; + } } From f75f63b264b2005faedb699dd867bd1d9c429a09 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 05:20:23 +0100 Subject: [PATCH 72/82] [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 +- tests/text_formatter/s9e/parser_test.php | 54 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) 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 */ diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 03b29bef12..74182bda47 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -206,4 +206,58 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case && isset($vars['user']) && $vars['user'] instanceof \phpbb\user; } + + /** + * @testdox parse() triggers a core.text_formatter_s9e_parse_before and core.text_formatter_s9e_parse_after events + */ + public function test_parse_event() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface'); + $dispatcher + ->expects($this->any()) + ->method('trigger_event') + ->will($this->returnArgument(1)); + $dispatcher + ->expects($this->at(1)) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_parse_before', + $this->callback(array($this, 'parse_before_event_callback')) + ) + ->will($this->returnArgument(1)); + $dispatcher + ->expects($this->at(2)) + ->method('trigger_event') + ->with( + 'core.text_formatter_s9e_parse_after', + $this->callback(array($this, 'parse_after_event_callback')) + ) + ->will($this->returnArgument(1)); + + $parser = new \phpbb\textformatter\s9e\parser( + $container->get('cache.driver'), + '_foo_parser', + $container->get('user'), + $container->get('text_formatter.s9e.factory'), + $dispatcher + ); + $parser->parse('...'); + } + + public function parse_before_event_callback($vars) + { + return isset($vars['self']) + && $vars['self'] instanceof \phpbb\textformatter\s9e\parser + && isset($vars['text']) + && $vars['text'] === '...'; + } + + public function parse_after_event_callback($vars) + { + return isset($vars['self']) + && $vars['self'] instanceof \phpbb\textformatter\s9e\parser + && isset($vars['xml']) + && $vars['xml'] === '...'; + } } From 55c3fc02cfe1ce151bfb65c31ec72fc75f9d7872 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 15:28:04 +0100 Subject: [PATCH 73/82] [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 +++------- tests/text_formatter/s9e/utils_test.php | 29 ------------- 3 files changed, 29 insertions(+), 63 deletions(-) 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); } diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php index 6f0ef54182..69f8682cac 100644 --- a/tests/text_formatter/s9e/utils_test.php +++ b/tests/text_formatter/s9e/utils_test.php @@ -45,35 +45,6 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case ); } - /** - * @dataProvider get_remove_formatting_tests - */ - public function test_remove_formatting($original, $expected) - { - $container = $this->get_test_case_helpers()->set_s9e_services(); - $utils = $container->get('text_formatter.utils'); - - $this->assertSame($expected, $utils->remove_formatting($original)); - } - - public function get_remove_formatting_tests() - { - return array( - array( - 'Plain text', - 'Plain text' - ), - array( - "Multi
            \nline
            ", - "Multi\nline" - ), - array( - '[b]bold[/b]', - 'bold' - ) - ); - } - /** * @dataProvider get_clean_formatting_tests */ From c1bc05a8605ef34c12f42d0ac14e45cca6fbace3 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 17:07:58 +0100 Subject: [PATCH 74/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- phpBB/phpbb/textformatter/s9e/factory.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 706dd4ba63..610a2b5510 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "ad4384b2c792cf55c456de018a525bbaea106fc0" + "reference": "564074d68ec4295b7b9746e5f712366af947d3d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/ad4384b2c792cf55c456de018a525bbaea106fc0", - "reference": "ad4384b2c792cf55c456de018a525bbaea106fc0", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/564074d68ec4295b7b9746e5f712366af947d3d7", + "reference": "564074d68ec4295b7b9746e5f712366af947d3d7", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-25 02:37:49" + "time": "2015-03-26 15:45:58" }, { "name": "symfony/config", 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; /** From 0f30301a0cf01c609cdcd5e4d777a47872a4dcba Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 26 Mar 2015 18:32:13 +0100 Subject: [PATCH 75/82] [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(-) 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; } /** From 3e04e643df4ca5463450df5d94f3caca3e5596c0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 01:12:57 +0100 Subject: [PATCH 76/82] [ticket/11768] Restored get_parser() / get_renderer() PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/parser.php | 10 ++++++++++ phpBB/phpbb/textformatter/s9e/renderer.php | 10 ++++++++++ tests/text_formatter/s9e/parser_test.php | 7 +++++++ tests/text_formatter/s9e/renderer_test.php | 7 +++++++ 4 files changed, 34 insertions(+) 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} */ diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 74182bda47..2904df25b4 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -260,4 +260,11 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case && isset($vars['xml']) && $vars['xml'] === '...'; } + + public function test_get_parser() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $parser = $container->get('text_formatter.parser'); + $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser->get_parser()); + } } diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index c69a93dbc1..8835a80d9d 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -443,4 +443,11 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case && isset($vars['self']) && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer; } + + public function test_get_renderer() + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $renderer = $container->get('text_formatter.renderer'); + $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer->get_renderer()); + } } From d8e7e11ee3a5c49e80a4ec3e0bdf2011ba5e9ce7 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 01:29:09 +0100 Subject: [PATCH 77/82] [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 ++++++++--------- tests/text_formatter/s9e/parser_test.php | 12 +++++------- tests/text_formatter/s9e/renderer_test.php | 12 +++++------- 4 files changed, 26 insertions(+), 32 deletions(-) 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; diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 2904df25b4..71966f9d36 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -200,9 +200,7 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case public function setup_event_callback($vars) { return isset($vars['parser']) - && $vars['parser'] instanceof \s9e\TextFormatter\Parser - && isset($vars['self']) - && $vars['self'] instanceof \phpbb\textformatter\s9e\parser + && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser && isset($vars['user']) && $vars['user'] instanceof \phpbb\user; } @@ -247,16 +245,16 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case public function parse_before_event_callback($vars) { - return isset($vars['self']) - && $vars['self'] instanceof \phpbb\textformatter\s9e\parser + return isset($vars['parser']) + && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser && isset($vars['text']) && $vars['text'] === '...'; } public function parse_after_event_callback($vars) { - return isset($vars['self']) - && $vars['self'] instanceof \phpbb\textformatter\s9e\parser + return isset($vars['parser']) + && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser && isset($vars['xml']) && $vars['xml'] === '...'; } diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index 8835a80d9d..91458541d3 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -385,9 +385,7 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case public function setup_event_callback($vars) { return isset($vars['renderer']) - && $vars['renderer'] instanceof \s9e\TextFormatter\Renderer - && isset($vars['self']) - && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer; + && $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer; } /** @@ -430,8 +428,8 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case public function render_before_event_callback($vars) { - return isset($vars['self']) - && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer + return isset($vars['renderer']) + && $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer && isset($vars['xml']) && $vars['xml'] === '...'; } @@ -440,8 +438,8 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case { return isset($vars['html']) && $vars['html'] === '...' - && isset($vars['self']) - && $vars['self'] instanceof \phpbb\textformatter\s9e\renderer; + && isset($vars['renderer']) + && $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer; } public function test_get_renderer() From 76088d64a69ac8fdd10b8a633e72eefc1e36321b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 01:52:26 +0100 Subject: [PATCH 78/82] [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(-) 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; } /** From 09c19718c0d1ebb8c40aac846760172ed2f13c26 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 27 Mar 2015 13:02:10 +0100 Subject: [PATCH 79/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 610a2b5510..b6208221a2 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "564074d68ec4295b7b9746e5f712366af947d3d7" + "reference": "febd66b686fa35691e181037a97cb33336a6c57a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/564074d68ec4295b7b9746e5f712366af947d3d7", - "reference": "564074d68ec4295b7b9746e5f712366af947d3d7", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/febd66b686fa35691e181037a97cb33336a6c57a", + "reference": "febd66b686fa35691e181037a97cb33336a6c57a", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-26 15:45:58" + "time": "2015-03-27 11:57:24" }, { "name": "symfony/config", From 1d90daf96963de3349cecc54d36ae421a24e0612 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 29 Mar 2015 23:00:29 +0200 Subject: [PATCH 80/82] [ticket/11768] Added some default template parameters PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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'], + )); } /** From b24e0f4f69b6436b3a654502d44d15333b0dfdc3 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 30 Mar 2015 03:31:38 +0200 Subject: [PATCH 81/82] [ticket/11768] Stylistic change. No functional change intended PHPBB3-11768 --- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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))); From 4e80565fe7862da4ea1948c6ece1099a59a1020f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 31 Mar 2015 02:29:16 +0200 Subject: [PATCH 82/82] [ticket/11768] Updated s9e\TextFormatter PHPBB3-11768 --- phpBB/composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index b6208221a2..8a634a1ffd 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -169,12 +169,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "febd66b686fa35691e181037a97cb33336a6c57a" + "reference": "4e0d311a3c56d0db4a7789e31457053be8148283" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/febd66b686fa35691e181037a97cb33336a6c57a", - "reference": "febd66b686fa35691e181037a97cb33336a6c57a", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/4e0d311a3c56d0db4a7789e31457053be8148283", + "reference": "4e0d311a3c56d0db4a7789e31457053be8148283", "shasum": "" }, "require": { @@ -219,7 +219,7 @@ "parser", "shortcodes" ], - "time": "2015-03-27 11:57:24" + "time": "2015-03-30 22:52:16" }, { "name": "symfony/config",