From ed548ae8ff0e87035c0c173d40212a96fa642135 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 23 Apr 2011 16:43:55 -0400 Subject: [PATCH 01/58] [feature/template-events] Outline for RUNHOOKS template tag. Ported to the new develop, hopefully this is still sensible. PHPBB3-9550 --- phpBB/includes/template/filter.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 66d28242a3..fc99ba5917 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -317,6 +317,12 @@ class phpbb_template_filter extends php_user_filter return ''; break; + case 'RUNHOOKS': + // return value here will be compiled code (html with embedded php). + // we don't want to wrap it in php tags here. + return 'compile_tag_run_hooks($matches[2]) . '?>'; + break; + default: return $matches[0]; break; @@ -835,6 +841,27 @@ class phpbb_template_filter extends php_user_filter return "\$_template->_php_include('$tag_args');"; } + /** + * Compile RUNHOOKS tag. + * + * $tag_args should be a single string identifying hook location. + */ + private function compile_tag_run_hooks($tag_args) + { + if (!preg_match('/^\w+$/', $tag_args)) + { + // do something + var_dump($tag_args); + } + $location = $tag_args; + // 1. find all mods defining hooks for location + // 2. obtain mods' template fragments + // 3. compile template fragments + // 4. return compiled code + // note: need to make sure we get fragments in the right order + return 'echo "test";'; + } + /** * parse expression * This is from Smarty From d6c881d0c67de80f0b60eab6be0c1dda33296657 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 27 Nov 2011 00:46:36 -0500 Subject: [PATCH 02/58] [feature/template-events] Inject extension manager into template class. Template class passes extension manager to template compiler. Template compiler passes extension manager to template filter. Template filter will use extension manager to locate hooks as it is compiling templates. All extension manager arguments are optional. If an extension manager is not given, template hooks will not be invoked. PHPBB3-9550 --- phpBB/config/services.yml | 1 + phpBB/includes/bbcode.php | 2 +- phpBB/includes/functions_messenger.php | 2 +- phpBB/includes/template/compile.php | 8 +++++--- phpBB/includes/template/filter.php | 8 ++++++++ phpBB/includes/template/template.php | 13 +++++++++++-- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 20aa0546d5..83a1c1fa69 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -128,6 +128,7 @@ services: - @user - @style.resource_locator - @template_context + - @ext.manager template_context: class: phpbb_template_context diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index b9ffa8091c..e8681420d4 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -134,7 +134,7 @@ class bbcode $style_resource_locator = new phpbb_style_resource_locator(); $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, new phpbb_template_context()); + $template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, new phpbb_template_context(), $phpbb_extension_manager); $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $template); $style->set_style(); $template->set_filenames(array('bbcode.html' => 'bbcode.html')); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index cf03de08c4..55884caedb 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -210,7 +210,7 @@ class messenger { $style_resource_locator = new phpbb_style_resource_locator(); $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $tpl = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, new phpbb_template_context()); + $tpl = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, new phpbb_template_context(), $extension_manager); $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $tpl); $this->tpl_msg[$template_lang . $template_file] = $tpl; diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 82b301c1a2..fb7d146701 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -35,16 +35,18 @@ class phpbb_template_compile /** * Constructor. * - * @param bool @allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) + * @param bool $allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) * @param phpbb_style_resource_locator $locator Resource locator * @param string $phpbb_root_path Path to phpBB root directory + * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked */ - public function __construct($allow_php, $locator, $phpbb_root_path) + public function __construct($allow_php, $locator, $phpbb_root_path, $extension_manager = null) { $this->filter_params = array( 'allow_php' => $allow_php, 'locator' => $locator, - 'phpbb_root_path' => $phpbb_root_path + 'phpbb_root_path' => $phpbb_root_path, + 'extension_manager' => $extension_manager, ); } diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index fc99ba5917..911f21ef00 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -87,6 +87,13 @@ class phpbb_template_filter extends php_user_filter */ private $phpbb_root_path; + /** + * Extension manager. + * + * @var phpbb_extension_manager + */ + private $extension_manager; + /** * Stream filter * @@ -148,6 +155,7 @@ class phpbb_template_filter extends php_user_filter $this->allow_php = $this->params['allow_php']; $this->locator = $this->params['locator']; $this->phpbb_root_path = $this->params['phpbb_root_path']; + $this->extension_manager = $this->params['extension_manager']; return true; } diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 5396ddbfad..96a16fee77 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -74,6 +74,13 @@ class phpbb_template */ private $locator; + /** + * Extension manager. + * + * @var phpbb_extension_manager + */ + private $extension_manager; + /** * Constructor. * @@ -81,8 +88,9 @@ class phpbb_template * @param user $user current user * @param phpbb_template_locator $locator template locator * @param phpbb_template_context $context template context + * @param phpbb_extension_manager $extension_manager extension manager, if null then template hooks will not be invoked */ - public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) + public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; @@ -90,6 +98,7 @@ class phpbb_template $this->user = $user; $this->locator = $locator; $this->context = $context; + $this->extension_manager = $extension_manager; } /** @@ -282,7 +291,7 @@ class phpbb_template return new phpbb_template_renderer_include($output_file, $this); } - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path, $this->extension_manager); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { From 09aae1ea30b199630c3972bdc483db476bda9a7e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 3 Dec 2011 21:08:31 -0500 Subject: [PATCH 03/58] [feature/template-events] Inject template compile into template filter. This is needed for hooks in order for the filter to compile template files from extensions. PHPBB3-9550 --- phpBB/includes/template/filter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 911f21ef00..3d39b3b4ed 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -94,6 +94,13 @@ class phpbb_template_filter extends php_user_filter */ private $extension_manager; + /** + * Template compiler. + * + * @var phpbb_template_compile + */ + private $template_compile; + /** * Stream filter * @@ -156,6 +163,7 @@ class phpbb_template_filter extends php_user_filter $this->locator = $this->params['locator']; $this->phpbb_root_path = $this->params['phpbb_root_path']; $this->extension_manager = $this->params['extension_manager']; + $this->template_compile = $this->params['template_compile']; return true; } From 66232031e4c69a0f5ba25699ba908946bd445967 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 27 Nov 2011 00:49:39 -0500 Subject: [PATCH 04/58] [feature/template-events] Really basic template hook implementation. PHPBB3-9550 --- phpBB/includes/template/filter.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 3d39b3b4ed..6151983be0 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -870,6 +870,26 @@ class phpbb_template_filter extends php_user_filter var_dump($tag_args); } $location = $tag_args; + + if ($this->phpbb_extension_manager) + { + $finder = $this->phpbb_extension_manager->get_finder(); + + $files = $finder + ->extension_prefix($location) + ->extension_suffix('.html') + ->extension_directory("/styles/universal/template") + ->get_files(); + + $all_compiled = ''; + foreach ($files as $file) + { + $compiled = $this->template_compile->compile_file($file); + $all_compiled .= $compiled; + } + return '?>' . $all_compiled . ' Date: Fri, 3 Feb 2012 02:21:37 -0500 Subject: [PATCH 05/58] [feature/template-events] Fix property name for extension manager. PHPBB3-9550 --- phpBB/includes/template/filter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 6151983be0..ea5b17c11a 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -871,9 +871,9 @@ class phpbb_template_filter extends php_user_filter } $location = $tag_args; - if ($this->phpbb_extension_manager) + if ($this->extension_manager) { - $finder = $this->phpbb_extension_manager->get_finder(); + $finder = $this->extension_manager->get_finder(); $files = $finder ->extension_prefix($location) From ea094dd91af624c72ac41fde6073dd8918620e68 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 6 Mar 2012 19:45:13 -0500 Subject: [PATCH 06/58] [feature/template-events] Rename universal to all (for template fragments). PHPBB3-9550 --- phpBB/includes/template/filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index ea5b17c11a..08eb9bdd97 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -878,7 +878,7 @@ class phpbb_template_filter extends php_user_filter $files = $finder ->extension_prefix($location) ->extension_suffix('.html') - ->extension_directory("/styles/universal/template") + ->extension_directory("/styles/all/template") ->get_files(); $all_compiled = ''; From dd7c5183fbc5401c85f530a304b70fbb0b5d7fbe Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 19 Apr 2012 00:21:54 -0400 Subject: [PATCH 07/58] [feature/template-events] Add template_compile to template filter params. PHPBB3-9550 --- phpBB/includes/template/compile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index fb7d146701..b63da05394 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -47,6 +47,7 @@ class phpbb_template_compile 'locator' => $locator, 'phpbb_root_path' => $phpbb_root_path, 'extension_manager' => $extension_manager, + 'template_compile' => $this, ); } From a6c7fbc59d02ed44ef90e340c4f957a8c5ac9ca5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 16 Mar 2012 00:22:42 -0400 Subject: [PATCH 08/58] [feature/template-events] Pass top-level template name to template filter. This will be used to invoke template-specific hooks. PHPBB3-9550 --- phpBB/includes/template/compile.php | 4 +++- phpBB/includes/template/filter.php | 13 ++++++++++++- phpBB/includes/template/template.php | 12 +++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index b63da05394..06ff60387a 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -36,14 +36,16 @@ class phpbb_template_compile * Constructor. * * @param bool $allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) + * @param string $template_name Name of top-level template being compiled * @param phpbb_style_resource_locator $locator Resource locator * @param string $phpbb_root_path Path to phpBB root directory * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked */ - public function __construct($allow_php, $locator, $phpbb_root_path, $extension_manager = null) + public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null) { $this->filter_params = array( 'allow_php' => $allow_php, + 'template_name' => $template_name, 'locator' => $locator, 'phpbb_root_path' => $phpbb_root_path, 'extension_manager' => $extension_manager, diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 08eb9bdd97..eca9a0d48c 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -87,6 +87,16 @@ class phpbb_template_filter extends php_user_filter */ private $phpbb_root_path; + /** + * Name of the top-level template being compiled and/or rendered. + * + * This is used by hooks implementation to invoke template-specific + * template hooks. + * + * @var string + */ + private $template_name; + /** * Extension manager. * @@ -152,7 +162,7 @@ class phpbb_template_filter extends php_user_filter /** * Initializer, called on creation. * - * Get the allow_php option, root directory and locator from params, + * Get the allow_php option, template_name, root directory and locator from params, * which are passed to stream_filter_append. */ public function onCreate() @@ -162,6 +172,7 @@ class phpbb_template_filter extends php_user_filter $this->allow_php = $this->params['allow_php']; $this->locator = $this->params['locator']; $this->phpbb_root_path = $this->params['phpbb_root_path']; + $this->template_name = $this->params['template_name']; $this->extension_manager = $this->params['extension_manager']; $this->template_compile = $this->params['template_compile']; return true; diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 96a16fee77..c43c1ddf99 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -81,6 +81,16 @@ class phpbb_template */ private $extension_manager; + /** + * Name of the top-level template being compiled and/or rendered. + * + * This is used by hooks implementation to invoke template-specific + * template hooks. + * + * @var string + */ + private $template_name; + /** * Constructor. * @@ -291,7 +301,7 @@ class phpbb_template return new phpbb_template_renderer_include($output_file, $this); } - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path, $this->extension_manager); + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->template_name, $this->locator, $this->phpbb_root_path, $this->extension_manager); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { From bdbb382a26efb4194e2eb1b6ee5f3913829fc9d1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 16 Mar 2012 00:54:09 -0400 Subject: [PATCH 09/58] [feature/template-events] Invoke template hooks that are template-specific. PHPBB3-9550 --- phpBB/includes/template/filter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index eca9a0d48c..a158dd4074 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -892,6 +892,13 @@ class phpbb_template_filter extends php_user_filter ->extension_directory("/styles/all/template") ->get_files(); + $files = array_merge($files, $finder + ->extension_prefix($location) + ->extension_suffix('.html') + // XXX is this safe? + ->extension_directory("/styles/" . $this->template_name . "/template") + ->get_files()); + $all_compiled = ''; foreach ($files as $file) { From ecdb54fc048a0805f724d7a3931373f99744923a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 16 Mar 2012 02:09:46 -0400 Subject: [PATCH 10/58] [feature/template-events] PHP does not parse , avoid generating it. PHPBB3-9550 --- phpBB/includes/template/filter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index a158dd4074..5129618f03 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -905,7 +905,9 @@ class phpbb_template_filter extends php_user_filter $compiled = $this->template_compile->compile_file($file); $all_compiled .= $compiled; } - return '?>' . $all_compiled . ' sans the spaces + return ' ?>' . $all_compiled . ' Date: Tue, 20 Mar 2012 06:53:48 +0000 Subject: [PATCH 11/58] [feature/template-events] Rename RUNHOOKS to EVENT Rename the way to add template events PHPBB3-9550 --- phpBB/includes/template/filter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 5129618f03..2c0057b64c 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -344,10 +344,10 @@ class phpbb_template_filter extends php_user_filter return ''; break; - case 'RUNHOOKS': + case 'EVENT': // return value here will be compiled code (html with embedded php). // we don't want to wrap it in php tags here. - return 'compile_tag_run_hooks($matches[2]) . '?>'; + return 'compile_tag_event($matches[2]) . '?>'; break; default: @@ -873,7 +873,7 @@ class phpbb_template_filter extends php_user_filter * * $tag_args should be a single string identifying hook location. */ - private function compile_tag_run_hooks($tag_args) + private function compile_tag_event($tag_args) { if (!preg_match('/^\w+$/', $tag_args)) { From 04f55ba3066d4713b6189062f8a61f12ca02ea34 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 17:21:08 -0500 Subject: [PATCH 12/58] [feature/template-events] Correct indentation PHPBB3-9550 --- phpBB/includes/template/filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 2c0057b64c..39317c6bf3 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -348,7 +348,7 @@ class phpbb_template_filter extends php_user_filter // return value here will be compiled code (html with embedded php). // we don't want to wrap it in php tags here. return 'compile_tag_event($matches[2]) . '?>'; - break; + break; default: return $matches[0]; From f83627763839e601db6b077e4f2f76436c263cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Thu, 19 Apr 2012 13:06:28 +0200 Subject: [PATCH 13/58] [feature/template-events] RUNHOOKS -> EVENT PHPBB3-9550 --- phpBB/includes/template/filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 39317c6bf3..f3e0f6017c 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -869,7 +869,7 @@ class phpbb_template_filter extends php_user_filter } /** - * Compile RUNHOOKS tag. + * Compile EVENT tag. * * $tag_args should be a single string identifying hook location. */ From db688c2574fd536e1c5f19ed8797d762713c7b6b Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 14:27:21 +0300 Subject: [PATCH 14/58] [feature/template-events] Template events unit test Adding template events test PHPBB3-9550 --- tests/template/template_events_test.php | 56 +++++++++++++++++++++++++ tests/template/templates/events.html | 4 ++ 2 files changed, 60 insertions(+) create mode 100644 tests/template/template_events_test.php create mode 100644 tests/template/templates/events.html diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php new file mode 100644 index 0000000000..c5b54ebba8 --- /dev/null +++ b/tests/template/template_events_test.php @@ -0,0 +1,56 @@ +setup_engine(); + + // Prepare correct result + $dir = dirname(__FILE__); + $files = array( + $dir . '/templates/child_only.html', + $dir . '/parent_templates/parent_only.html', + $dir . '/templates/parent_and_child.html' + ); + $contents = ''; + foreach ($files as $file) + { + if (file_exists($file)) + { + $contents .= file_get_contents($file); + } + } + $contents = trim($contents); + + // Run test + $cache_file = $this->template->cachepath . 'events.html.php'; + $this->run_template('events.html', array(), array(), array(), $contents, $cache_file); + } + + protected function setup_engine(array $new_config = array()) + { + global $phpbb_root_path, $phpEx, $user; + + $defaults = $this->config_defaults(); + $config = new phpbb_config(array_merge($defaults, $new_config)); + + $this->template_path = dirname(__FILE__) . '/templates'; + $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->style_provider = new phpbb_style_path_provider(); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + } +} diff --git a/tests/template/templates/events.html b/tests/template/templates/events.html new file mode 100644 index 0000000000..c44a7469e7 --- /dev/null +++ b/tests/template/templates/events.html @@ -0,0 +1,4 @@ + + + + From 132bbede2b5ca5e1bbb371bdaef0bb3041c67316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Wed, 18 Apr 2012 15:35:09 +0200 Subject: [PATCH 15/58] [feature/template-events] Handle incorrect template event identifiers If the template event identifier is wrongly formatted phpBB will triggern an `E_USER_NOTICE` if the `DEBUG` constant is set, otherwise the location is ignored. PHPBB3-9550 --- phpBB/includes/template/filter.php | 12 ++++++++++-- phpBB/language/en/common.php | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index f3e0f6017c..50882b2855 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -877,8 +877,16 @@ class phpbb_template_filter extends php_user_filter { if (!preg_match('/^\w+$/', $tag_args)) { - // do something - var_dump($tag_args); + // The hook location is wrongly formatted, + // if the `DEBUG` constant is set then trigger a waring, + // otherwise drop the hook and continue + if (defined('DEBUG')) + { + global $user; + trigger_error($user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_NOTICE); + } + + return; } $location = $tag_args; diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 7ce3b5d2e6..5fc1b21e4f 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -186,6 +186,7 @@ $lang = array_merge($lang, array( 'ERR_CONNECTING_SERVER' => 'Error connecting to the server.', 'ERR_JAB_AUTH' => 'Could not authorise on Jabber server.', 'ERR_JAB_CONNECT' => 'Could not connect to Jabber server.', + 'ERR_TEMPLATE_EVENT_LOCATION' => 'The specified template event location [%s] is wrongly formatted.', 'ERR_UNABLE_TO_LOGIN' => 'The specified username or password is incorrect.', 'ERR_UNWATCHING' => 'An error occured while trying to unsubscribe.', 'ERR_WATCHING' => 'An error occured while trying to subscribe.', From 6fc0c889fd714945613be1c51316b1386f3c88f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Thu, 19 Apr 2012 13:57:11 +0200 Subject: [PATCH 16/58] [feature/template-events] Remove comment Remove comment per Nils in the PR. PHPBB3-9550 --- phpBB/includes/template/filter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 50882b2855..798cadaa2a 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -903,7 +903,6 @@ class phpbb_template_filter extends php_user_filter $files = array_merge($files, $finder ->extension_prefix($location) ->extension_suffix('.html') - // XXX is this safe? ->extension_directory("/styles/" . $this->template_name . "/template") ->get_files()); From 2add66c0ebd49bb2f8beee538676fe34f969b33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Thu, 19 Apr 2012 13:58:41 +0200 Subject: [PATCH 17/58] [feature/template-events] Add additional space for editors Use `' ?'. '>'` rather than `' ?>'` as the latter causes problems in some editors. PHPBB3-9550 --- phpBB/includes/template/filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 798cadaa2a..1ec1467c09 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -914,7 +914,7 @@ class phpbb_template_filter extends php_user_filter } // Need spaces inside php tags as php cannot grok // < ?php? > sans the spaces - return ' ?>' . $all_compiled . '' . $all_compiled . ' Date: Thu, 19 Apr 2012 14:00:42 +0200 Subject: [PATCH 18/58] [feature/template-events] Fix typo (waring -> warning) PHPBB3-9550 --- phpBB/includes/template/filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 1ec1467c09..453e2a05ce 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -878,7 +878,7 @@ class phpbb_template_filter extends php_user_filter if (!preg_match('/^\w+$/', $tag_args)) { // The hook location is wrongly formatted, - // if the `DEBUG` constant is set then trigger a waring, + // if the `DEBUG` constant is set then trigger a warning, // otherwise drop the hook and continue if (defined('DEBUG')) { From f46f48a2cfbc923f4e4734dfd200cc6ddbfd689e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 04:22:39 -0400 Subject: [PATCH 19/58] [feature/template-events] Chase template/style renames and changes. PHPBB3-9550 --- phpBB/includes/template/template.php | 2 +- tests/template/template_compile_test.php | 2 +- tests/template/template_events_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index c43c1ddf99..19ee59323a 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -301,7 +301,7 @@ class phpbb_template return new phpbb_template_renderer_include($output_file, $this); } - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->template_name, $this->locator, $this->phpbb_root_path, $this->extension_manager); + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->template_name, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index 0cfcd6ceb5..7393fc1747 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case protected function setUp() { - $this->template_compile = new phpbb_template_compile(false, null, ''); + $this->template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, ''); $this->template_path = dirname(__FILE__) . '/templates'; } diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index c5b54ebba8..2d6fd4bfb2 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -49,7 +49,7 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); } From 45a1219886b039fbb4bda740accbfbbdbf971022 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 03:53:30 -0400 Subject: [PATCH 20/58] [feature/template-events] Always commit suicide for invalid event names. Note: suicide happens for syntactically invalid event names, e.g. event names containing punctuation. Event names for which there are no events are silently dropped. PHPBB3-9550 --- phpBB/includes/template/filter.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 453e2a05ce..2706eb9040 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -878,15 +878,8 @@ class phpbb_template_filter extends php_user_filter if (!preg_match('/^\w+$/', $tag_args)) { // The hook location is wrongly formatted, - // if the `DEBUG` constant is set then trigger a warning, - // otherwise drop the hook and continue - if (defined('DEBUG')) - { - global $user; - trigger_error($user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_NOTICE); - } - - return; + global $user; + trigger_error($user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR); } $location = $tag_args; From 1b36fc3a6074a661a1b32c015fb9931f3470c61c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 04:23:18 -0400 Subject: [PATCH 21/58] [feature/template-events] Handle user access correctly. Pass through $user from template to filter. Allow $user to be null for standalone usage of the template engine. PHPBB3-9550 --- phpBB/includes/template/compile.php | 4 +++- phpBB/includes/template/filter.php | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 06ff60387a..e2e9a095dc 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -40,8 +40,9 @@ class phpbb_template_compile * @param phpbb_style_resource_locator $locator Resource locator * @param string $phpbb_root_path Path to phpBB root directory * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked + * @param phpbb_user $user Current user */ - public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null) + public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null, $user = null) { $this->filter_params = array( 'allow_php' => $allow_php, @@ -49,6 +50,7 @@ class phpbb_template_compile 'locator' => $locator, 'phpbb_root_path' => $phpbb_root_path, 'extension_manager' => $extension_manager, + 'user' => $user, 'template_compile' => $this, ); } diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 2706eb9040..ed81c4cd8a 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -104,6 +104,12 @@ class phpbb_template_filter extends php_user_filter */ private $extension_manager; + /** + * Current user + * @var phpbb_user + */ + private $user; + /** * Template compiler. * @@ -174,6 +180,10 @@ class phpbb_template_filter extends php_user_filter $this->phpbb_root_path = $this->params['phpbb_root_path']; $this->template_name = $this->params['template_name']; $this->extension_manager = $this->params['extension_manager']; + if (isset($this->params['user'])) + { + $this->user = $this->params['user']; + } $this->template_compile = $this->params['template_compile']; return true; } @@ -878,8 +888,14 @@ class phpbb_template_filter extends php_user_filter if (!preg_match('/^\w+$/', $tag_args)) { // The hook location is wrongly formatted, - global $user; - trigger_error($user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR); + if ($this->user) + { + trigger_error($this->user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR); + } + else + { + trigger_error(sprintf('The specified template event location [%s] is wrongly formatted.', $tag_args), E_USER_ERROR); + } } $location = $tag_args; From bd63b17d0030706e080188ab6bf3bdec8466ae82 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 05:06:00 -0400 Subject: [PATCH 22/58] [feature/template-events] Move comment to the function docblock. PHPBB3-9550 --- phpBB/includes/template/filter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index ed81c4cd8a..9f77c4a1b7 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -266,7 +266,9 @@ class phpbb_template_filter extends php_user_filter } /** - * Callback for replacing matched tokens with PHP code + * Callback for replacing matched tokens with compiled template code. + * + * Compiled template code is an HTML stream with embedded PHP. * * @param array $matches Regular expression matches * @return string compiled template code @@ -355,8 +357,6 @@ class phpbb_template_filter extends php_user_filter break; case 'EVENT': - // return value here will be compiled code (html with embedded php). - // we don't want to wrap it in php tags here. return 'compile_tag_event($matches[2]) . '?>'; break; From faf96a1b4017c2bdceb4458c1d84959cb07da9bb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 05:11:45 -0400 Subject: [PATCH 23/58] [feature/template-events] Delete old comments/test code. PHPBB3-9550 --- phpBB/includes/template/filter.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 9f77c4a1b7..cb0b2b0cd9 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -925,13 +925,6 @@ class phpbb_template_filter extends php_user_filter // < ?php? > sans the spaces return ' ?' . '>' . $all_compiled . ' Date: Thu, 10 May 2012 05:23:54 -0400 Subject: [PATCH 24/58] [feature/template-events] Update EVENT tag documentation. It should now fairly closely reflect what actually happens. PHPBB3-9550 --- phpBB/includes/template/filter.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index cb0b2b0cd9..9f814f5c5f 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -881,7 +881,27 @@ class phpbb_template_filter extends php_user_filter /** * Compile EVENT tag. * - * $tag_args should be a single string identifying hook location. + * $tag_args should be a single string identifying the event. + * The event name can contain letters, numbers and underscores only. + * If an invalid event name is specified, an E_USER_ERROR will be + * triggered. + * + * Event tags are only functional when the template engine has + * an instance of the extension manager. Extension manager would + * be called upon to find all extensions listening for the specified + * event, and to obtain additional template fragments. All such + * template fragments will be compiled and included in the generated + * compiled template code for the current template being compiled. + * + * The above means that whenever an extension is enabled or disabled, + * template cache should be cleared in order to update the compiled + * template code for the active set of template event listeners. + * + * This also means that extensions cannot return different template + * fragments at different times. Once templates are compiled, changing + * such template fragments would have no effect. + * + * @param string $tag_args EVENT tag arguments, as a string - for EVENT this is the event name */ private function compile_tag_event($tag_args) { From 09b4cf2f4c6df4d967f4df66f2bb29e38ee10a1d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 May 2012 13:38:10 -0400 Subject: [PATCH 25/58] [feature/template-events] Report when templates cannot be compiled. PHPBB3-9550 --- phpBB/includes/template/filter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 9f814f5c5f..385612b094 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -939,6 +939,10 @@ class phpbb_template_filter extends php_user_filter foreach ($files as $file) { $compiled = $this->template_compile->compile_file($file); + if ($compiled === false) + { + trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); + } $all_compiled .= $compiled; } // Need spaces inside php tags as php cannot grok From 667f8d581f8534a386e8293caafb4b7b5f063dde Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 May 2012 13:39:38 -0400 Subject: [PATCH 26/58] [feature/template-events] Add a universal template event test. Also drop the irrelevant includejs code and add a simple template event test. The simple test is not working yet however due to the template engine not correctly tracking which template it is rendering. PHPBB3-9550 --- .../styles/all/template/universal.html | 1 + .../styles/silver/template/simple.html | 1 + tests/template/template_events_test.php | 50 +++++++++++-------- tests/template/templates/event_simple.html | 1 + tests/template/templates/event_universal.html | 1 + 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 tests/template/ext/trivial/styles/all/template/universal.html create mode 100644 tests/template/ext/trivial/styles/silver/template/simple.html create mode 100644 tests/template/templates/event_simple.html create mode 100644 tests/template/templates/event_universal.html diff --git a/tests/template/ext/trivial/styles/all/template/universal.html b/tests/template/ext/trivial/styles/all/template/universal.html new file mode 100644 index 0000000000..f2c5762ade --- /dev/null +++ b/tests/template/ext/trivial/styles/all/template/universal.html @@ -0,0 +1 @@ +Universal in trivial extension. diff --git a/tests/template/ext/trivial/styles/silver/template/simple.html b/tests/template/ext/trivial/styles/silver/template/simple.html new file mode 100644 index 0000000000..fe32a1ed3f --- /dev/null +++ b/tests/template/ext/trivial/styles/silver/template/simple.html @@ -0,0 +1 @@ +Simple in trivial extension. diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 2d6fd4bfb2..3ad6e924cb 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -11,31 +11,30 @@ require_once dirname(__FILE__) . '/template_test_case.php'; class phpbb_template_template_events_test extends phpbb_template_template_test_case { - public function test_includejs_compilation() + public function test_simple_event() { // Reset the engine state $this->setup_engine(); // Prepare correct result - $dir = dirname(__FILE__); - $files = array( - $dir . '/templates/child_only.html', - $dir . '/parent_templates/parent_only.html', - $dir . '/templates/parent_and_child.html' - ); - $contents = ''; - foreach ($files as $file) - { - if (file_exists($file)) - { - $contents .= file_get_contents($file); - } - } - $contents = trim($contents); + $contents = "Simple in trivial extension."; // Run test - $cache_file = $this->template->cachepath . 'events.html.php'; - $this->run_template('events.html', array(), array(), array(), $contents, $cache_file); + $cache_file = $this->template->cachepath . 'event_simple.html.php'; + $this->run_template('event_simple.html', array(), array(), array(), $contents, $cache_file); + } + + public function test_universal_event() + { + // Reset the engine state + $this->setup_engine(); + + // Prepare correct result + $contents = "Universal in trivial extension."; + + // Run test + $cache_file = $this->template->cachepath . 'event_universal.html.php'; + $this->run_template('event_universal.html', array(), array(), array(), $contents, $cache_file); } protected function setup_engine(array $new_config = array()) @@ -46,11 +45,20 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'trivial' => array( + 'ext_name' => 'trivial', + 'ext_active' => true, + 'ext_path' => 'ext/trivial/', + ), + ) + ); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->extension_manager); $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + $this->style->set_custom_style('tests', array($this->template_path), ''); } } diff --git a/tests/template/templates/event_simple.html b/tests/template/templates/event_simple.html new file mode 100644 index 0000000000..604c1acdce --- /dev/null +++ b/tests/template/templates/event_simple.html @@ -0,0 +1 @@ + diff --git a/tests/template/templates/event_universal.html b/tests/template/templates/event_universal.html new file mode 100644 index 0000000000..15425cacc3 --- /dev/null +++ b/tests/template/templates/event_universal.html @@ -0,0 +1 @@ + From 0df0c6199b89f154eb6371118b4a796a4d05f36f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 May 2012 13:46:04 -0400 Subject: [PATCH 27/58] [feature/template-events] Switch template event test to data providers. PHPBB3-9550 --- tests/template/template_events_test.php | 50 +++++++++++++++++-------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 3ad6e924cb..f1d13c1fd6 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -11,30 +11,48 @@ require_once dirname(__FILE__) . '/template_test_case.php'; class phpbb_template_template_events_test extends phpbb_template_template_test_case { - public function test_simple_event() + public function template_data() { - // Reset the engine state - $this->setup_engine(); - - // Prepare correct result - $contents = "Simple in trivial extension."; - - // Run test - $cache_file = $this->template->cachepath . 'event_simple.html.php'; - $this->run_template('event_simple.html', array(), array(), array(), $contents, $cache_file); + return array( + /* + array( + '', // File + array(), // vars + array(), // block vars + array(), // destroy + '', // Expected result + ), + */ + array( + 'Simple template event', + 'event_simple.html', + array(), + array(), + array(), + "Simple in trivial extension.", + ), + array( + 'Universal template event ("all" style)', + 'event_universal.html', + array(), + array(), + array(), + "Universal in trivial extension.", + ), + ); } - public function test_universal_event() + /** + * @dataProvider template_data + */ + public function test_event($desc, $file, array $vars, array $block_vars, array $destroy, $expected) { // Reset the engine state $this->setup_engine(); - // Prepare correct result - $contents = "Universal in trivial extension."; - // Run test - $cache_file = $this->template->cachepath . 'event_universal.html.php'; - $this->run_template('event_universal.html', array(), array(), array(), $contents, $cache_file); + $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); } protected function setup_engine(array $new_config = array()) From 9c31a0ffc785e30c4ff87e8d9d66e7989b55d8ef Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 May 2012 14:10:45 -0400 Subject: [PATCH 28/58] [feature/template-events] Rename template_name to style_name. "Style name" makes a lot more sense and should be in line with recent style/template changes. PHPBB3-9550 --- phpBB/includes/template/compile.php | 6 +++--- phpBB/includes/template/filter.php | 20 ++++++++++---------- phpBB/includes/template/template.php | 9 +++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index e2e9a095dc..c2762bfd59 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -36,17 +36,17 @@ class phpbb_template_compile * Constructor. * * @param bool $allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) - * @param string $template_name Name of top-level template being compiled + * @param string $style_name Name of style to which the template being compiled belongs * @param phpbb_style_resource_locator $locator Resource locator * @param string $phpbb_root_path Path to phpBB root directory * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked * @param phpbb_user $user Current user */ - public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null, $user = null) + public function __construct($allow_php, $style_name, $locator, $phpbb_root_path, $extension_manager = null, $user = null) { $this->filter_params = array( 'allow_php' => $allow_php, - 'template_name' => $template_name, + 'style_name' => $style_name, 'locator' => $locator, 'phpbb_root_path' => $phpbb_root_path, 'extension_manager' => $extension_manager, diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 385612b094..a87bfaef34 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -88,14 +88,15 @@ class phpbb_template_filter extends php_user_filter private $phpbb_root_path; /** - * Name of the top-level template being compiled and/or rendered. + * Name of the style that the template being compiled and/or rendered + * belongs to. * - * This is used by hooks implementation to invoke template-specific + * This is used by hooks implementation to invoke style-specific * template hooks. * * @var string */ - private $template_name; + private $style_name; /** * Extension manager. @@ -168,7 +169,7 @@ class phpbb_template_filter extends php_user_filter /** * Initializer, called on creation. * - * Get the allow_php option, template_name, root directory and locator from params, + * Get the allow_php option, style_name, root directory and locator from params, * which are passed to stream_filter_append. */ public function onCreate() @@ -178,7 +179,7 @@ class phpbb_template_filter extends php_user_filter $this->allow_php = $this->params['allow_php']; $this->locator = $this->params['locator']; $this->phpbb_root_path = $this->params['phpbb_root_path']; - $this->template_name = $this->params['template_name']; + $this->style_name = $this->params['style_name']; $this->extension_manager = $this->params['extension_manager']; if (isset($this->params['user'])) { @@ -932,17 +933,16 @@ class phpbb_template_filter extends php_user_filter $files = array_merge($files, $finder ->extension_prefix($location) ->extension_suffix('.html') - ->extension_directory("/styles/" . $this->template_name . "/template") + ->extension_directory("/styles/" . $this->style_name . "/template") ->get_files()); $all_compiled = ''; foreach ($files as $file) { $compiled = $this->template_compile->compile_file($file); - if ($compiled === false) - { - trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); - } + if ($compiled === false) { + trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); + } $all_compiled .= $compiled; } // Need spaces inside php tags as php cannot grok diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 19ee59323a..3de5cd45a5 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -82,14 +82,15 @@ class phpbb_template private $extension_manager; /** - * Name of the top-level template being compiled and/or rendered. + * Name of the style that the template being compiled and/or rendered + * belongs to. * - * This is used by hooks implementation to invoke template-specific + * This is used by hooks implementation to invoke style-specific * template hooks. * * @var string */ - private $template_name; + private $style_name; /** * Constructor. @@ -301,7 +302,7 @@ class phpbb_template return new phpbb_template_renderer_include($output_file, $this); } - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->template_name, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user); + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->style_name, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { From 2fb40060562dc7efcfda06cde05c2abb78a2c3c2 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 31 Oct 2012 11:10:40 -0400 Subject: [PATCH 29/58] [feature/template-events] Indentation fix. PHPBB3-9550 --- phpBB/includes/template/filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index a87bfaef34..8c102ea0fe 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -89,7 +89,7 @@ class phpbb_template_filter extends php_user_filter /** * Name of the style that the template being compiled and/or rendered - * belongs to. + * belongs to. * * This is used by hooks implementation to invoke style-specific * template hooks. From 4ed9e4124e592ddb7fe2696e45261e74edb89ddd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 31 Oct 2012 11:11:33 -0400 Subject: [PATCH 30/58] [feature/template-events] Wording: wrongly -> improperly. PHPBB3-9550 --- phpBB/includes/template/filter.php | 4 ++-- phpBB/language/en/common.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 8c102ea0fe..8df43e5b01 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -908,14 +908,14 @@ class phpbb_template_filter extends php_user_filter { if (!preg_match('/^\w+$/', $tag_args)) { - // The hook location is wrongly formatted, + // The hook location is improperly formatted, if ($this->user) { trigger_error($this->user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR); } else { - trigger_error(sprintf('The specified template event location [%s] is wrongly formatted.', $tag_args), E_USER_ERROR); + trigger_error(sprintf('The specified template event location [%s] is improperly formatted.', $tag_args), E_USER_ERROR); } } $location = $tag_args; diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 5fc1b21e4f..feb5c18d84 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -186,7 +186,7 @@ $lang = array_merge($lang, array( 'ERR_CONNECTING_SERVER' => 'Error connecting to the server.', 'ERR_JAB_AUTH' => 'Could not authorise on Jabber server.', 'ERR_JAB_CONNECT' => 'Could not connect to Jabber server.', - 'ERR_TEMPLATE_EVENT_LOCATION' => 'The specified template event location [%s] is wrongly formatted.', + 'ERR_TEMPLATE_EVENT_LOCATION' => 'The specified template event location [%s] is improperly formatted.', 'ERR_UNABLE_TO_LOGIN' => 'The specified username or password is incorrect.', 'ERR_UNWATCHING' => 'An error occured while trying to unsubscribe.', 'ERR_WATCHING' => 'An error occured while trying to subscribe.', From 6c7f1f7bdeba88fdef27fab537f973464bba6183 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 2 Nov 2012 19:58:01 -0400 Subject: [PATCH 31/58] [feature/template-events] Cosmetic changes. PHPBB3-9550 --- phpBB/includes/template/locator.php | 4 ++-- phpBB/includes/template/template.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/template/locator.php b/phpBB/includes/template/locator.php index 42db91efb2..f6fd20bcc2 100644 --- a/phpBB/includes/template/locator.php +++ b/phpBB/includes/template/locator.php @@ -39,7 +39,7 @@ interface phpbb_template_locator * Sets the template filenames for handles. $filename_array * should be a hash of handle => filename pairs. * - * @param array $filname_array Should be a hash of handle => filename pairs. + * @param array $filename_array Should be a hash of handle => filename pairs. */ public function set_filenames(array $filename_array); @@ -66,7 +66,7 @@ interface phpbb_template_locator * returns actually exists, it is faster than get_source_file_for_handle. * * Use get_source_file_for_handle to obtain the actual path that is - * guaranteed to exist (which might come from the parent style + * guaranteed to exist (which might come from the parent style * directory if primary style has parent styles). * * This function will trigger an error if the handle was never diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 3de5cd45a5..52c08326d5 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -83,7 +83,7 @@ class phpbb_template /** * Name of the style that the template being compiled and/or rendered - * belongs to. + * belongs to. * * This is used by hooks implementation to invoke style-specific * template hooks. @@ -115,7 +115,7 @@ class phpbb_template /** * Sets the template filenames for handles. * - * @param array $filname_array Should be a hash of handle => filename pairs. + * @param array $filename_array Should be a hash of handle => filename pairs. */ public function set_filenames(array $filename_array) { From 0141154ceb58702a308c76b45242cc47f51d3e01 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 31 Oct 2012 12:03:22 -0400 Subject: [PATCH 32/58] [feature/template-events] Indentation fix. PHPBB3-9550 --- phpBB/includes/template/filter.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 8df43e5b01..5d9e00553f 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -940,9 +940,12 @@ class phpbb_template_filter extends php_user_filter foreach ($files as $file) { $compiled = $this->template_compile->compile_file($file); - if ($compiled === false) { - trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); - } + + if ($compiled === false) + { + trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); + } + $all_compiled .= $compiled; } // Need spaces inside php tags as php cannot grok From 48adf8c5de7b946c1b0e10461605373a01d50196 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 31 Oct 2012 11:58:33 -0400 Subject: [PATCH 33/58] [feature/template-events] Create a dataset for template event tests. Having all files in one directory is too much of a mess. PHPBB3-9550 --- .../ext_trivial}/ext/trivial/styles/all/template/universal.html | 0 .../ext_trivial}/ext/trivial/styles/silver/template/simple.html | 0 .../{ => datasets/ext_trivial}/templates/event_simple.html | 0 .../{ => datasets/ext_trivial}/templates/event_universal.html | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/template/{ => datasets/ext_trivial}/ext/trivial/styles/all/template/universal.html (100%) rename tests/template/{ => datasets/ext_trivial}/ext/trivial/styles/silver/template/simple.html (100%) rename tests/template/{ => datasets/ext_trivial}/templates/event_simple.html (100%) rename tests/template/{ => datasets/ext_trivial}/templates/event_universal.html (100%) diff --git a/tests/template/ext/trivial/styles/all/template/universal.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/universal.html similarity index 100% rename from tests/template/ext/trivial/styles/all/template/universal.html rename to tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/universal.html diff --git a/tests/template/ext/trivial/styles/silver/template/simple.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/simple.html similarity index 100% rename from tests/template/ext/trivial/styles/silver/template/simple.html rename to tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/simple.html diff --git a/tests/template/templates/event_simple.html b/tests/template/datasets/ext_trivial/templates/event_simple.html similarity index 100% rename from tests/template/templates/event_simple.html rename to tests/template/datasets/ext_trivial/templates/event_simple.html diff --git a/tests/template/templates/event_universal.html b/tests/template/datasets/ext_trivial/templates/event_universal.html similarity index 100% rename from tests/template/templates/event_universal.html rename to tests/template/datasets/ext_trivial/templates/event_universal.html From 9a7c8721ce2f23dc1bc5080cd8924f29a9545bd5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 31 Oct 2012 11:59:12 -0400 Subject: [PATCH 34/58] [feature/template-events] Adjust template events test to use the dataset. PHPBB3-9550 --- tests/template/template_events_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index f1d13c1fd6..918de445d7 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -62,10 +62,10 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); - $this->template_path = dirname(__FILE__) . '/templates'; + $this->template_path = dirname(__FILE__) . '/datasets/ext_trivial/templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/', + dirname(__FILE__) . '/datasets/ext_trivial/', array( 'trivial' => array( 'ext_name' => 'trivial', From 0a29312d830c65dc293822c291bf2efd6f93a29b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 12:18:39 -0500 Subject: [PATCH 35/58] [feature/template-events] Chase dependency injection for template context. PHPBB3-9550 --- tests/template/template_events_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 918de445d7..274af7d7cf 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -74,7 +74,7 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c ), ) ); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->extension_manager); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); $this->style_provider = new phpbb_style_path_provider(); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('tests', array($this->template_path), ''); From 44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 12:21:06 -0500 Subject: [PATCH 36/58] [feature/template-events] Convert a single style name to array of them. This allows template code to know the entire style hierarchy for templates being rendered. PHPBB3-9550 --- phpBB/adm/index.php | 2 +- phpBB/adm/swatch.php | 2 +- phpBB/includes/functions_messenger.php | 2 +- phpBB/includes/style/style.php | 11 ++++++++++- phpBB/includes/template/compile.php | 6 +++--- phpBB/includes/template/filter.php | 13 ++++++------- phpBB/includes/template/template.php | 11 +++++------ phpBB/install/index.php | 2 +- phpBB/install/install_update.php | 2 +- tests/template/includephp_test.php | 2 +- tests/template/template_events_test.php | 2 +- tests/template/template_test_case.php | 2 +- tests/template/template_test_case_with_tree.php | 2 +- 13 files changed, 33 insertions(+), 26 deletions(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index e20bbe4bec..0f84af6f9e 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -52,7 +52,7 @@ $mode = request_var('mode', ''); // Set custom style for admin area $phpbb_style->set_ext_dir_prefix('adm/'); -$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', ''); +$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), ''); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style'); diff --git a/phpBB/adm/swatch.php b/phpBB/adm/swatch.php index 86498a255f..c01651e0f0 100644 --- a/phpBB/adm/swatch.php +++ b/phpBB/adm/swatch.php @@ -24,7 +24,7 @@ $user->setup(); $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './'; // Set custom template for admin area -$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', ''); +$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), ''); $template->set_filenames(array( 'body' => 'colour_swatch.html') diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 55884caedb..2043e2f7be 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -231,7 +231,7 @@ class messenger } } - $style->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), ''); + $style->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), array(), ''); $tpl->set_filenames(array( 'body' => $template_file . '.txt', diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index effd496fb9..9ce96c5da5 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -110,18 +110,27 @@ class phpbb_style * * @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver" * @param array or string $paths Array of style paths, relative to current root directory + * @param array $names Array of names of templates in inheritance tree order, used by extensions. If empty, $name will be used. * @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/). */ - public function set_custom_style($name, $paths, $template_path = false) + public function set_custom_style($name, $paths, $names = array(), $template_path = false) { if (is_string($paths)) { $paths = array($paths); } + if (empty($names)) + { + $names = array($name); + } + $this->names = $names; + $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); + $this->template->style_names = $names; + if ($template_path !== false) { $this->locator->set_template_path($template_path); diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index c2762bfd59..76ad2317c9 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -36,17 +36,17 @@ class phpbb_template_compile * Constructor. * * @param bool $allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) - * @param string $style_name Name of style to which the template being compiled belongs + * @param array $style_names Name of style to which the template being compiled belongs and parents in style tree order * @param phpbb_style_resource_locator $locator Resource locator * @param string $phpbb_root_path Path to phpBB root directory * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked * @param phpbb_user $user Current user */ - public function __construct($allow_php, $style_name, $locator, $phpbb_root_path, $extension_manager = null, $user = null) + public function __construct($allow_php, $style_names, $locator, $phpbb_root_path, $extension_manager = null, $user = null) { $this->filter_params = array( 'allow_php' => $allow_php, - 'style_name' => $style_name, + 'style_names' => $style_names, 'locator' => $locator, 'phpbb_root_path' => $phpbb_root_path, 'extension_manager' => $extension_manager, diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 5d9e00553f..a5a0865569 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -89,14 +89,13 @@ class phpbb_template_filter extends php_user_filter /** * Name of the style that the template being compiled and/or rendered - * belongs to. + * belongs to, and its parents, in inheritance tree order. * - * This is used by hooks implementation to invoke style-specific - * template hooks. + * Used to invoke style-specific template events. * - * @var string + * @var array */ - private $style_name; + private $style_names; /** * Extension manager. @@ -169,7 +168,7 @@ class phpbb_template_filter extends php_user_filter /** * Initializer, called on creation. * - * Get the allow_php option, style_name, root directory and locator from params, + * Get the allow_php option, style_names, root directory and locator from params, * which are passed to stream_filter_append. */ public function onCreate() @@ -179,7 +178,7 @@ class phpbb_template_filter extends php_user_filter $this->allow_php = $this->params['allow_php']; $this->locator = $this->params['locator']; $this->phpbb_root_path = $this->params['phpbb_root_path']; - $this->style_name = $this->params['style_name']; + $this->style_names = $this->params['style_names']; $this->extension_manager = $this->params['extension_manager']; if (isset($this->params['user'])) { diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 52c08326d5..4d257d2510 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -83,14 +83,13 @@ class phpbb_template /** * Name of the style that the template being compiled and/or rendered - * belongs to. + * belongs to, and its parents, in inheritance tree order. * - * This is used by hooks implementation to invoke style-specific - * template hooks. + * Used to invoke style-specific template events. * - * @var string + * @var array */ - private $style_name; + public $style_names; /** * Constructor. @@ -302,7 +301,7 @@ class phpbb_template return new phpbb_template_renderer_include($output_file, $this); } - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->style_name, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user); + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->style_names, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 09560946a6..2be5adaaac 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -215,7 +215,7 @@ $phpbb_style_path_provider = new phpbb_style_path_provider(); $template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, new phpbb_template_context()); $phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template); $phpbb_style->set_ext_dir_prefix('adm/'); -$phpbb_style->set_custom_style('admin', '../adm/style', ''); +$phpbb_style->set_custom_style('admin', '../adm/style', array(), ''); $template->assign_var('T_ASSETS_PATH', '../assets'); $template->assign_var('T_TEMPLATE_PATH', '../adm/style'); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 8c044550f3..3964dbfe2b 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -131,7 +131,7 @@ class install_update extends module } // Set custom template again. ;) - $phpbb_style->set_custom_style('admin', '../adm/style', ''); + $phpbb_style->set_custom_style('admin', '../adm/style', array(), ''); $template->assign_vars(array( 'S_USER_LANG' => $user->lang['USER_LANG'], diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index c93a53e2ad..f1012b6939 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -48,7 +48,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); - $this->style->set_custom_style('tests', $cache_dir, ''); + $this->style->set_custom_style('tests', $cache_dir, array(), ''); $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 274af7d7cf..22aa2e88d5 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -77,6 +77,6 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); $this->style_provider = new phpbb_style_path_provider(); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path), ''); + $this->style->set_custom_style('silver', array($this->template_path), array(), ''); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 2e6f703eb1..3c997cb00e 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -69,7 +69,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', $this->template_path, ''); + $this->style->set_custom_style('tests', $this->template_path, array(), ''); } protected function setUp() diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 6a226f317a..7585be5728 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -24,6 +24,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), ''); } } From 729eeef2bf4aad74c8170a54098e6679a1e9fadb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 12:22:15 -0500 Subject: [PATCH 37/58] [feature/template-events] Generate style names array in set_style. PHPBB3-9550 --- phpBB/includes/style/style.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 9ce96c5da5..6aec5c6ba4 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -91,16 +91,22 @@ class phpbb_style { $style_path = $this->user->style['style_path']; $style_dirs = ($this->user->style['style_parent_id']) ? array_reverse(explode('/', $this->user->style['style_parent_tree'])) : array(); - $paths = array($this->get_style_path($style_path)); + + $names = array($style_path); foreach ($style_dirs as $dir) { - $paths[] = $this->get_style_path($dir); + $names[] = $dir; + } + // Add 'all' path, used as last fallback path by hooks and extensions + //$names[] = 'all'; + + $paths = array(); + foreach ($names as $name) + { + $paths[] = $this->get_style_path($name); } - // Add 'all' path, used as last fallback path by hooks and extensions - $paths[] = $this->get_style_path('all'); - - return $this->set_custom_style($style_path, $paths); + return $this->set_custom_style($style_path, $names, $paths); } /** From af47779f51e44d34a78087327a3958fb35c50936 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 12:22:39 -0500 Subject: [PATCH 38/58] [feature/template-events] Use style names array in template filter. This provides a straightforward way of iterating over all styles looking for templates in extensions. PHPBB3-9550 --- phpBB/includes/template/filter.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index a5a0865569..fd2ce9d859 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -929,11 +929,19 @@ class phpbb_template_filter extends php_user_filter ->extension_directory("/styles/all/template") ->get_files(); - $files = array_merge($files, $finder - ->extension_prefix($location) - ->extension_suffix('.html') - ->extension_directory("/styles/" . $this->style_name . "/template") - ->get_files()); + foreach ($this->style_names as $style_name) + { + $more_files = $finder + ->extension_prefix($location) + ->extension_suffix('.html') + ->extension_directory("/styles/" . $style_name . "/template") + ->get_files(); + if (!empty($more_files)) + { + $files = array_merge($files, $more_files); + break; + } + } $all_compiled = ''; foreach ($files as $file) From 99d93a3f0f0004b480a0d6b3b82bd59b64d24468 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 31 Oct 2012 13:02:48 -0400 Subject: [PATCH 39/58] [feature/template-events] Dataset for template event testing with inheritance. PHPBB3-9550 --- .../event_inheritance/ext/kappa/styles/all/template/test.html | 1 + .../event_inheritance/ext/kappa/styles/silver/template/test.html | 1 + .../ext/kappa/styles/silver_inherit/template/test.html | 1 + .../event_inheritance/ext/omega/styles/all/template/test.html | 1 + .../event_inheritance/ext/omega/styles/silver/template/test.html | 1 + .../event_inheritance/ext/zeta/styles/all/template/test.html | 1 + .../event_inheritance/styles/silver/template/event_test.html | 1 + .../styles/silver_inherit/template/event_test.html | 1 + 8 files changed, 8 insertions(+) create mode 100644 tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html create mode 100644 tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html create mode 100644 tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html create mode 100644 tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html create mode 100644 tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html create mode 100644 tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html create mode 100644 tests/template/datasets/event_inheritance/styles/silver/template/event_test.html create mode 100644 tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html new file mode 100644 index 0000000000..3eb906a09e --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html @@ -0,0 +1 @@ +Kappa test event in all diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html new file mode 100644 index 0000000000..3b65d80a6d --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html @@ -0,0 +1 @@ +Kappa test event in silver diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html new file mode 100644 index 0000000000..26826d59e3 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html @@ -0,0 +1 @@ +Kappa test event in silver_inherit diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html b/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html new file mode 100644 index 0000000000..003d193dc3 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html @@ -0,0 +1 @@ +Omega test event in all diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html new file mode 100644 index 0000000000..6bf06f5457 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html @@ -0,0 +1 @@ +Omega test event in silver diff --git a/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html b/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html new file mode 100644 index 0000000000..5fc7e5ac12 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html @@ -0,0 +1 @@ +Zeta test event in all diff --git a/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html b/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html new file mode 100644 index 0000000000..4d78dddb12 --- /dev/null +++ b/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html @@ -0,0 +1 @@ + diff --git a/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html b/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html new file mode 100644 index 0000000000..4d78dddb12 --- /dev/null +++ b/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html @@ -0,0 +1 @@ + From 0e6d12dfc41f97348ecf4b04943ed23e40f22f1b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 20:17:44 -0500 Subject: [PATCH 40/58] [feature/template-events] Allow dataset to be correctly selectable. PHPBB3-9550 --- tests/mock/filesystem_extension_manager.php | 31 +++++++++++++++++++++ tests/template/template_events_test.php | 22 ++++++--------- 2 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 tests/mock/filesystem_extension_manager.php diff --git a/tests/mock/filesystem_extension_manager.php b/tests/mock/filesystem_extension_manager.php new file mode 100644 index 0000000000..3332e2b82d --- /dev/null +++ b/tests/mock/filesystem_extension_manager.php @@ -0,0 +1,31 @@ +isDir() && substr($fileinfo->getFilename(), 0, 1) != '.') + { + $name = $fileinfo->getFilename(); + $extension = array( + 'ext_name' => $name, + 'ext_active' => true, + 'ext_path' => 'ext/' . $name . '/', + ); + $extensions[$name] = $extension; + } + } + parent::__construct($phpbb_root_path, $extensions); + } +} diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 22aa2e88d5..9652f341c3 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -17,6 +17,7 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c /* array( '', // File + '', // Dataset array(), // vars array(), // block vars array(), // destroy @@ -25,6 +26,7 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c */ array( 'Simple template event', + 'ext_trivial', 'event_simple.html', array(), array(), @@ -33,6 +35,7 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c ), array( 'Universal template event ("all" style)', + 'ext_trivial', 'event_universal.html', array(), array(), @@ -45,34 +48,27 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c /** * @dataProvider template_data */ - public function test_event($desc, $file, array $vars, array $block_vars, array $destroy, $expected) + public function test_event($desc, $dataset, $file, array $vars, array $block_vars, array $destroy, $expected) { // Reset the engine state - $this->setup_engine(); + $this->setup_engine_with_dataset($dataset); // Run test $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); } - protected function setup_engine(array $new_config = array()) + protected function setup_engine_with_dataset($dataset, array $new_config = array()) { global $phpbb_root_path, $phpEx, $user; $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); - $this->template_path = dirname(__FILE__) . '/datasets/ext_trivial/templates'; + $this->template_path = dirname(__FILE__) . "/datasets/$dataset/templates"; $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/datasets/ext_trivial/', - array( - 'trivial' => array( - 'ext_name' => 'trivial', - 'ext_active' => true, - 'ext_path' => 'ext/trivial/', - ), - ) + $this->extension_manager = new phpbb_mock_filesystem_extension_manager( + dirname(__FILE__) . "/datasets/$dataset/" ); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); $this->style_provider = new phpbb_style_path_provider(); From 21a244543dbe960cdb97da61fa27dc61e6411932 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 20:31:12 -0500 Subject: [PATCH 41/58] [feature/template-events] Normalize expected directory trees. PHPBB3-9550 --- .../{templates => styles/silver/template}/event_simple.html | 0 .../{templates => styles/silver/template}/event_universal.html | 0 tests/template/template_events_test.php | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/template/datasets/ext_trivial/{templates => styles/silver/template}/event_simple.html (100%) rename tests/template/datasets/ext_trivial/{templates => styles/silver/template}/event_universal.html (100%) diff --git a/tests/template/datasets/ext_trivial/templates/event_simple.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html similarity index 100% rename from tests/template/datasets/ext_trivial/templates/event_simple.html rename to tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html diff --git a/tests/template/datasets/ext_trivial/templates/event_universal.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html similarity index 100% rename from tests/template/datasets/ext_trivial/templates/event_universal.html rename to tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 9652f341c3..15c8d846b8 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -65,7 +65,7 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); - $this->template_path = dirname(__FILE__) . "/datasets/$dataset/templates"; + $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template"; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->extension_manager = new phpbb_mock_filesystem_extension_manager( dirname(__FILE__) . "/datasets/$dataset/" From 5f88bbbef3bfed93b4a575a1f2e58635b69f58e5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 20:38:01 -0500 Subject: [PATCH 42/58] [feature/template-events] Specify style names, add inheritance tests. PHPBB3-9550 --- tests/template/template_events_test.php | 44 +++++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 15c8d846b8..642745d53d 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -16,17 +16,19 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c return array( /* array( - '', // File - '', // Dataset + '', // file + '', // dataset + array(), // style names array(), // vars array(), // block vars array(), // destroy - '', // Expected result + '', // expected result ), */ array( 'Simple template event', 'ext_trivial', + array(), 'event_simple.html', array(), array(), @@ -36,29 +38,57 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c array( 'Universal template event ("all" style)', 'ext_trivial', + array(), 'event_universal.html', array(), array(), array(), "Universal in trivial extension.", ), + array( + 'Template event with inheritance - parent', + 'event_inheritance', + array('silver'), + 'event_test.html', + array(), + array(), + array(), +'Kappa test event in all +Omega test event in all +Zeta test event in all +Kappa test event in silver +Omega test event in silver', + ), + array( + 'Template event with inheritance - child', + 'event_inheritance', + array('silver_inherit', 'silver'), + 'event_test.html', + array(), + array(), + array(), +'Kappa test event in all +Omega test event in all +Zeta test event in all +Kappa test event in silver_inherit', + ), ); } /** * @dataProvider template_data */ - public function test_event($desc, $dataset, $file, array $vars, array $block_vars, array $destroy, $expected) + public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) { // Reset the engine state - $this->setup_engine_with_dataset($dataset); + $this->setup_engine_for_events($dataset, $style_names); // Run test $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); } - protected function setup_engine_with_dataset($dataset, array $new_config = array()) + protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) { global $phpbb_root_path, $phpEx, $user; @@ -73,6 +103,6 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); $this->style_provider = new phpbb_style_path_provider(); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('silver', array($this->template_path), array(), ''); + $this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); } } From d42d71b47d76ab36d2c7a985f0b63c9c4686bfd0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 20:53:24 -0500 Subject: [PATCH 43/58] [feature/template-events] Test for event that is defined in parent style only. PHPBB3-9550 --- .../ext/omega/styles/silver/template/two.html | 1 + .../styles/silver/template/event_two.html | 1 + tests/template/template_events_test.php | 10 ++++++++++ 3 files changed, 12 insertions(+) create mode 100644 tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html create mode 100644 tests/template/datasets/event_inheritance/styles/silver/template/event_two.html diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html new file mode 100644 index 0000000000..7f8058f4e4 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html @@ -0,0 +1 @@ +two in silver in omega diff --git a/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html b/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html new file mode 100644 index 0000000000..fe46be3782 --- /dev/null +++ b/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html @@ -0,0 +1 @@ + diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 642745d53d..6cea9b92e3 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -72,6 +72,16 @@ Omega test event in all Zeta test event in all Kappa test event in silver_inherit', ), + array( + 'Definition in parent style', + 'event_inheritance', + array('silver_inherit', 'silver'), + 'event_two.html', + array(), + array(), + array(), +'two in silver in omega', + ), ); } From da7d888448cba2160b16010b982f886be9cb1bcb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 21:02:02 -0500 Subject: [PATCH 44/58] [feature/template-events] Make style names private on template. PHPBB3-9550 --- phpBB/includes/style/style.php | 2 +- phpBB/includes/template/template.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 6aec5c6ba4..7d31df9886 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -135,7 +135,7 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - $this->template->style_names = $names; + $this->template->set_style_names($names); if ($template_path !== false) { diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 4d257d2510..97e23f34e0 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -89,7 +89,7 @@ class phpbb_template * * @var array */ - public $style_names; + private $style_names; /** * Constructor. @@ -123,6 +123,18 @@ class phpbb_template return true; } + /** + * Sets the style names corresponding to style hierarchy being compiled + * and/or rendered. + * + * @param array $style_names List of style names in inheritance tree order + * @return null + */ + public function set_style_names(array $style_names) + { + $this->style_names = $style_names; + } + /** * Clears all variables and blocks assigned to this template. */ From 47a90f815d210d84f0c70ae678cb129e69963436 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 14 Nov 2012 17:31:05 -0500 Subject: [PATCH 45/58] [feature/template-events] Changes per imkingdavid's review. PHPBB3-9550 --- phpBB/includes/style/style.php | 2 +- phpBB/includes/template/compile.php | 2 +- phpBB/includes/template/filter.php | 15 +++++++++++++-- phpBB/includes/template/template.php | 2 +- phpBB/language/en/common.php | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 7d31df9886..7c91edd034 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -97,7 +97,7 @@ class phpbb_style { $names[] = $dir; } - // Add 'all' path, used as last fallback path by hooks and extensions + // Add 'all' path, used as last fallback path by events and extensions //$names[] = 'all'; $paths = array(); diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 76ad2317c9..ba7f45e41d 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -39,7 +39,7 @@ class phpbb_template_compile * @param array $style_names Name of style to which the template being compiled belongs and parents in style tree order * @param phpbb_style_resource_locator $locator Resource locator * @param string $phpbb_root_path Path to phpBB root directory - * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked + * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template events will not be invoked * @param phpbb_user $user Current user */ public function __construct($allow_php, $style_names, $locator, $phpbb_root_path, $extension_manager = null, $user = null) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index fd2ce9d859..f73ad28ba1 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -106,6 +106,7 @@ class phpbb_template_filter extends php_user_filter /** * Current user + * * @var phpbb_user */ private $user; @@ -170,6 +171,8 @@ class phpbb_template_filter extends php_user_filter * * Get the allow_php option, style_names, root directory and locator from params, * which are passed to stream_filter_append. + * + * @return boolean Returns true */ public function onCreate() { @@ -902,12 +905,13 @@ class phpbb_template_filter extends php_user_filter * such template fragments would have no effect. * * @param string $tag_args EVENT tag arguments, as a string - for EVENT this is the event name + * @return string compiled template code */ private function compile_tag_event($tag_args) { if (!preg_match('/^\w+$/', $tag_args)) { - // The hook location is improperly formatted, + // The event location is improperly formatted, if ($this->user) { trigger_error($this->user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR); @@ -950,7 +954,14 @@ class phpbb_template_filter extends php_user_filter if ($compiled === false) { - trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); + if ($this->user) + { + trigger_error($this->user->lang('ERR_TEMPLATE_COMPILATION', phpbb_filter_root_path($file)), E_USER_ERROR); + } + else + { + trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR); + } } $all_compiled .= $compiled; diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 97e23f34e0..bbec768613 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -98,7 +98,7 @@ class phpbb_template * @param user $user current user * @param phpbb_template_locator $locator template locator * @param phpbb_template_context $context template context - * @param phpbb_extension_manager $extension_manager extension manager, if null then template hooks will not be invoked + * @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked */ public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null) { diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index feb5c18d84..6ebbb54c62 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -187,6 +187,7 @@ $lang = array_merge($lang, array( 'ERR_JAB_AUTH' => 'Could not authorise on Jabber server.', 'ERR_JAB_CONNECT' => 'Could not connect to Jabber server.', 'ERR_TEMPLATE_EVENT_LOCATION' => 'The specified template event location [%s] is improperly formatted.', + 'ERR_TEMPLATE_COMPILATION' => 'The file could not be compiled: %s', 'ERR_UNABLE_TO_LOGIN' => 'The specified username or password is incorrect.', 'ERR_UNWATCHING' => 'An error occured while trying to unsubscribe.', 'ERR_WATCHING' => 'An error occured while trying to subscribe.', From 29f7e729ed389f4312dbe8455d927a4bc2204f35 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 11:11:50 -0500 Subject: [PATCH 46/58] [feature/template-events] Order extensions in mock extension manager. PHPBB3-9550 --- tests/mock/filesystem_extension_manager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mock/filesystem_extension_manager.php b/tests/mock/filesystem_extension_manager.php index 3332e2b82d..c5a51bbb3f 100644 --- a/tests/mock/filesystem_extension_manager.php +++ b/tests/mock/filesystem_extension_manager.php @@ -26,6 +26,7 @@ class phpbb_mock_filesystem_extension_manager extends phpbb_mock_extension_manag $extensions[$name] = $extension; } } + ksort($extensions); parent::__construct($phpbb_root_path, $extensions); } } From 70050020699d9eab9b97bda342e0e928d1591de8 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 20:22:19 +0100 Subject: [PATCH 47/58] [ticket/10972] Added methods for creating and deleting basic users Modified the login method to allow logging in of an arbitrary user. Also added tests for the new functionality. PHPBB3-10972 --- tests/functional/new_user_test.php | 45 +++++++++++++++++++ .../phpbb_functional_test_case.php | 45 ++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tests/functional/new_user_test.php diff --git a/tests/functional/new_user_test.php b/tests/functional/new_user_test.php new file mode 100644 index 0000000000..db2f31f450 --- /dev/null +++ b/tests/functional/new_user_test.php @@ -0,0 +1,45 @@ +create_user('user'); + $this->login(); + $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); + $this->assertContains('user', $crawler->filter('#memberlist tr')->eq(1)->text()); + } + + /** + * @depends test_create_user + */ + public function test_delete_user() + { + $this->delete_user('user'); + $this->login(); + $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); + $this->assertEquals(2, $crawler->filter('#memberlist tr')->count()); + } + + /** + * @depends test_delete_user + */ + public function test_login_other() + { + $this->create_user('user'); + $this->login('user'); + $crawler = $this->request('GET', 'index.php'); + $this->assertContains('user', $crawler->filter('.icon-logout')->text()); + $this->delete_user('user'); + } +} diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 7c03f874e9..dfbfe2565e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -194,7 +194,48 @@ class phpbb_functional_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } - protected function login() + /** + * Creates a new user with limited permissions + * + * @param string $username Also doubles up as the user's password + */ + protected function create_user($username) + { + // Required by unique_id + global $config; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + $db = $this->get_db(); + $query = " + INSERT INTO " . self::$config['table_prefix'] . "users + (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) + VALUES + (0, 2, 'user', 'user', 0, '" . phpbb_hash($username) . "', 'nobody@example.com', 'en', 1, 0, '', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', '') + "; + + $db->sql_query($query); + } + + /** + * Deletes a user + * + * @param string $username The username of the user to delete + */ + protected function delete_user($username) + { + $db = $this->get_db(); + $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; + $db->sql_query($query); + } + + protected function login($username = 'admin') { $this->add_lang('ucp'); @@ -202,7 +243,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin')); + $login = $this->client->submit($form, array('username' => $username, 'password' => $username)); $cookies = $this->cookieJar->all(); From cafc7feca12730fce59091bd7a18fb5c3f7ecdc0 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 00:24:28 +0100 Subject: [PATCH 48/58] [ticket/10972] Moved tests into appropriate places and added comments PHPBB3-10972 --- tests/functional/auth_test.php | 9 ++++ tests/functional/new_user_test.php | 45 ------------------- .../phpbb_functional_test_case.php | 4 ++ 3 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 tests/functional/new_user_test.php diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index e955dcb4df..e67118d8f9 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -21,6 +21,15 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } + public function test_login_other() + { + $this->create_user('user'); + $this->login('user'); + $crawler = $this->request('GET', 'index.php'); + $this->assertContains('user', $crawler->filter('.icon-logout')->text()); + $this->delete_user('user'); + } + /** * @depends test_login */ diff --git a/tests/functional/new_user_test.php b/tests/functional/new_user_test.php deleted file mode 100644 index db2f31f450..0000000000 --- a/tests/functional/new_user_test.php +++ /dev/null @@ -1,45 +0,0 @@ -create_user('user'); - $this->login(); - $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); - $this->assertContains('user', $crawler->filter('#memberlist tr')->eq(1)->text()); - } - - /** - * @depends test_create_user - */ - public function test_delete_user() - { - $this->delete_user('user'); - $this->login(); - $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); - $this->assertEquals(2, $crawler->filter('#memberlist tr')->count()); - } - - /** - * @depends test_delete_user - */ - public function test_login_other() - { - $this->create_user('user'); - $this->login('user'); - $crawler = $this->request('GET', 'index.php'); - $this->assertContains('user', $crawler->filter('.icon-logout')->text()); - $this->delete_user('user'); - } -} diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index dfbfe2565e..a72c0940ab 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -197,6 +197,10 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a new user with limited permissions * + * Note that creating two users with the same name results in undefined + * login behaviour. Always call delete_user after running a test that + * requires create_user. + * * @param string $username Also doubles up as the user's password */ protected function create_user($username) From d33accb687ab4266559c12a356e121f3634d780b Mon Sep 17 00:00:00 2001 From: Fyorl Date: Fri, 10 Aug 2012 12:31:53 +0100 Subject: [PATCH 49/58] [ticket/10972] Added explicit checks for creating duplicate users. PHPBB3-10972 --- .../phpbb_functional_test_case.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a72c0940ab..9bc2c96753 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -30,6 +30,11 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected $lang = array(); + /** + * @var array + */ + protected $created_users = array(); + static protected $config = array(); static protected $already_installed = false; @@ -197,14 +202,18 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a new user with limited permissions * - * Note that creating two users with the same name results in undefined - * login behaviour. Always call delete_user after running a test that + * Always call delete_user after running a test that * requires create_user. * * @param string $username Also doubles up as the user's password */ protected function create_user($username) { + if (isset($this->created_users[$username])) + { + return; + } + // Required by unique_id global $config; @@ -225,6 +234,7 @@ class phpbb_functional_test_case extends phpbb_test_case "; $db->sql_query($query); + $this->created_users[$username] = 1; } /** @@ -234,6 +244,11 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function delete_user($username) { + if (isset($this->created_users[$username])) + { + unset($this->created_users[$username]); + } + $db = $this->get_db(); $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; $db->sql_query($query); From ebdd96592a100139c48204ef133e706c0ac465d1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 22:45:12 -0500 Subject: [PATCH 50/58] [ticket/10972] Backport get_db from develop. PHPBB3-10972 --- .../phpbb_functional_test_case.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9bc2c96753..3b6232d091 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -16,7 +16,9 @@ class phpbb_functional_test_case extends phpbb_test_case { protected $client; protected $root_url; + protected $cache = null; + protected $db = null; /** * Session ID for current test's session (each test makes its own) @@ -70,6 +72,23 @@ class phpbb_functional_test_case extends phpbb_test_case { } + protected function get_db() + { + global $phpbb_root_path, $phpEx; + // so we don't reopen an open connection + if (!($this->db instanceof dbal)) + { + if (!class_exists('dbal_' . self::$config['dbms'])) + { + include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); + } + $sql_db = 'dbal_' . self::$config['dbms']; + $this->db = new $sql_db(); + $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); + } + return $this->db; + } + protected function get_cache_driver() { if (!$this->cache) From 771bb957ab4dee865ce1678eb675c37874d04e98 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 23:41:02 -0500 Subject: [PATCH 51/58] [ticket/10972] Add mock null cache. The mock cache has instrumentation methods and therefore is non-trivial to implement. For those times when we don't care that the cache caches, null cache is a simpler implementation. PHPBB3-10972 --- tests/mock/null_cache.php | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/mock/null_cache.php diff --git a/tests/mock/null_cache.php b/tests/mock/null_cache.php new file mode 100644 index 0000000000..aca20ca77b --- /dev/null +++ b/tests/mock/null_cache.php @@ -0,0 +1,42 @@ + Date: Thu, 6 Dec 2012 23:42:13 -0500 Subject: [PATCH 52/58] [ticket/10972] Add destroy method to mock cache. I actually needed the version that destroys tables, therefore I ended up writing a mock null cache. This code is currently unused but will probably be handy at some point. PHPBB3-10972 --- tests/mock/cache.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 650545c3d6..aa0db5ab20 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -34,6 +34,16 @@ class phpbb_mock_cache $this->data[$var_name] = $var; } + public function destroy($var_name, $table = '') + { + if ($table) + { + throw new Exception('Destroying tables is not implemented yet'); + } + + unset($this->data[$var_name]); + } + /** * Obtain active bots */ @@ -41,7 +51,7 @@ class phpbb_mock_cache { return $this->data['_bots']; } - + /** * Obtain list of word censors. We don't need to parse them here, * that is tested elsewhere. From fb5c4440e598f2a775a52299a06e903d3cee5398 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 23:43:22 -0500 Subject: [PATCH 53/58] [ticket/10972] Tweak user addition. Always add users, do not keep track of which users have been added. The tests should know whether users they want exist or not. Use more unique user names in tests for robustness. Added some more assertions here and there. PHPBB3-10972 --- tests/functional/auth_test.php | 12 ++-- .../phpbb_functional_test_case.php | 59 +++++++++++-------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index e67118d8f9..3e218ebd77 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -18,16 +18,18 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // check for logout link $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } public function test_login_other() { - $this->create_user('user'); - $this->login('user'); + $this->create_user('anothertestuser'); + $this->login('anothertestuser'); $crawler = $this->request('GET', 'index.php'); - $this->assertContains('user', $crawler->filter('.icon-logout')->text()); - $this->delete_user('user'); + $this->assert_response_success(); + $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); + $this->delete_user('anothertestuser'); } /** @@ -40,10 +42,12 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // logout $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3b6232d091..b17b2dcd5f 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -32,11 +32,6 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected $lang = array(); - /** - * @var array - */ - protected $created_users = array(); - static protected $config = array(); static protected $already_installed = false; @@ -225,14 +220,10 @@ class phpbb_functional_test_case extends phpbb_test_case * requires create_user. * * @param string $username Also doubles up as the user's password + * @return int ID of created user */ protected function create_user($username) { - if (isset($this->created_users[$username])) - { - return; - } - // Required by unique_id global $config; @@ -243,17 +234,36 @@ class phpbb_functional_test_case extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; - - $db = $this->get_db(); - $query = " - INSERT INTO " . self::$config['table_prefix'] . "users - (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) - VALUES - (0, 2, 'user', 'user', 0, '" . phpbb_hash($username) . "', 'nobody@example.com', 'en', 1, 0, '', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', '') - "; - $db->sql_query($query); - $this->created_users[$username] = 1; + // Required by user_add + global $db, $cache; + $db = $this->get_db(); + if (!function_exists('phpbb_mock_null_cache')) + { + require_once(__DIR__ . '/../mock/null_cache.php'); + } + $cache = new phpbb_mock_null_cache; + + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('user_add')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + + $user_row = array( + 'username' => $username, + 'group_id' => 2, + 'user_email' => 'nobody@example.com', + 'user_type' => 0, + 'user_lang' => 'en', + 'user_timezone' => 0, + 'user_dateformat' => '', + 'user_password' => phpbb_hash($username), + ); + return user_add($user_row); } /** @@ -263,11 +273,6 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function delete_user($username) { - if (isset($this->created_users[$username])) - { - unset($this->created_users[$username]); - } - $db = $this->get_db(); $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; $db->sql_query($query); @@ -281,7 +286,9 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $login = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); From ff993ba9d30f5de49e5231647c5bb76d95c357f8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 23:47:19 -0500 Subject: [PATCH 54/58] [ticket/10972] Drop user deletion. Users should not be deleted in tests that test user creation. Tests should use unique user names to avoid collisions. User deletion should use user_remove anyway. PHPBB3-10972 --- tests/functional/auth_test.php | 1 - .../test_framework/phpbb_functional_test_case.php | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 3e218ebd77..662b1bd38b 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -29,7 +29,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $crawler = $this->request('GET', 'index.php'); $this->assert_response_success(); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); - $this->delete_user('anothertestuser'); } /** diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b17b2dcd5f..71e88fbcf6 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -216,9 +216,6 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a new user with limited permissions * - * Always call delete_user after running a test that - * requires create_user. - * * @param string $username Also doubles up as the user's password * @return int ID of created user */ @@ -266,18 +263,6 @@ class phpbb_functional_test_case extends phpbb_test_case return user_add($user_row); } - /** - * Deletes a user - * - * @param string $username The username of the user to delete - */ - protected function delete_user($username) - { - $db = $this->get_db(); - $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; - $db->sql_query($query); - } - protected function login($username = 'admin') { $this->add_lang('ucp'); From 0446886f91376c258df3729287824e505ff788b3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 10 Dec 2012 13:35:15 -0500 Subject: [PATCH 55/58] [feature/template-events] Pass arguments in correct order. Thank you imkingdavid. PHPBB3-9550 --- phpBB/includes/style/style.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 7c91edd034..1b2e756064 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -106,7 +106,7 @@ class phpbb_style $paths[] = $this->get_style_path($name); } - return $this->set_custom_style($style_path, $names, $paths); + return $this->set_custom_style($style_path, $paths, $paths); } /** From a0211ff2eb3a61f627d4ac4732c6ab68c2529d9e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 10 Dec 2012 13:35:15 -0500 Subject: [PATCH 56/58] [feature/template-events] Pass arguments in correct order. Thank you imkingdavid. PHPBB3-9550 --- phpBB/includes/style/style.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 7c91edd034..4703c3a219 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -106,7 +106,7 @@ class phpbb_style $paths[] = $this->get_style_path($name); } - return $this->set_custom_style($style_path, $names, $paths); + return $this->set_custom_style($style_path, $paths, $names); } /** From 53c4a328a65098eb6cfb281c579906984333d822 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 11 Dec 2012 11:42:34 -0500 Subject: [PATCH 57/58] [ticket/11243] Show download all link on all pages of topic with attachments PHPBB3-11243 --- phpBB/viewtopic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 3fde5b5e03..bd2c7bea77 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1353,7 +1353,7 @@ if (sizeof($attach_list)) } $template->assign_vars(array( - 'S_HAS_ATTACHMENTS' => !empty($attachments), + 'S_HAS_ATTACHMENTS' => $topic_data['topic_attachment'], )); $methods = phpbb_gen_download_links('topic_id', $topic_id, $phpbb_root_path, $phpEx); From ffd531e4fd31fee31c6fbd8c94cb6077cd21a82d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 12 Dec 2012 16:33:30 -0600 Subject: [PATCH 58/58] [ticket/11103] Revert changes to constants.php from my IDE Readd a blank line at the end of the file PHPBB3-11103 --- phpBB/includes/constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 5128321618..68af41ab20 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -278,3 +278,4 @@ define('WORDS_TABLE', $table_prefix . 'words'); define('ZEBRA_TABLE', $table_prefix . 'zebra'); // Additional tables +