From 6a3d77d76e9a6ee17acbd29da8486742f60a2514 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Apr 2013 10:34:06 +0200 Subject: [PATCH 1/5] [ticket/10844] Add phpbb_root_path to phpbb_style_extension_path_provider The phpbb_root_path needs to be removed from the style path, before giving the path to the finder, because the finder prepends it later again and is therefor unable to find style files when the root path is not ./ PHPBB3-10844 --- phpBB/config/services.yml | 1 + phpBB/includes/bbcode.php | 2 +- phpBB/includes/functions_messenger.php | 2 +- phpBB/includes/style/extension_path_provider.php | 15 ++++++++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index b9c71844dc..6b7b3f2f2b 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -242,6 +242,7 @@ services: arguments: - @ext.manager - @style.path_provider + - %core.root_path% style.path_provider: class: phpbb_style_path_provider diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index e8681420d4..c198abeb54 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -133,7 +133,7 @@ class bbcode $this->template_bitfield = new bitfield($user->style['bbcode_bitfield']); $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()); + $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider(), $phpbb_root_path); $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(); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 821f0d970d..e580f6b675 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -209,7 +209,7 @@ class messenger if (!isset($this->tpl_msg[$template_lang . $template_file])) { $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()); + $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider(), $phpbb_root_path); $tpl = 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, $tpl); diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index 6976a45ed0..e658abcb42 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -40,17 +40,22 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple */ protected $base_path_provider; + /** @var string */ + protected $phpbb_root_path; + /** * Constructor stores extension manager * * @param phpbb_extension_manager $extension_manager phpBB extension manager * @param phpbb_style_path_provider $base_path_provider A simple path provider * to provide paths to be located in extensions + * @param string $phpbb_root_path phpBB root path */ - public function __construct(phpbb_extension_manager $extension_manager, phpbb_style_path_provider $base_path_provider) + public function __construct(phpbb_extension_manager $extension_manager, phpbb_style_path_provider $base_path_provider, $phpbb_root_path) { parent::__construct($extension_manager); $this->base_path_provider = $base_path_provider; + $this->phpbb_root_path = $phpbb_root_path; } /** @@ -91,6 +96,14 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple $directories['style'][] = $path; if ($path && !phpbb_is_absolute($path)) { + // Remove phpBB root path from the style path, + // so the finder is able to find extension styles, + // when the root path is not ./ + if (strpos($path, $this->phpbb_root_path) === 0) + { + $path = substr($path, strlen($this->phpbb_root_path)); + } + $result = $finder->directory('/' . $this->ext_dir_prefix . $path) ->get_directories(true, false, true); foreach ($result as $ext => $ext_path) From bbaa3411b04c06c519e8dd215a0251c97263eac4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 21:19:09 +0200 Subject: [PATCH 2/5] [ticket/10844] Make sure ext_path has no trailing slash PHPBB3-10844 --- phpBB/includes/style/extension_path_provider.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index e658abcb42..ec1d85f821 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -108,6 +108,11 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple ->get_directories(true, false, true); foreach ($result as $ext => $ext_path) { + // Make sure $ext_path has no ending slash + if (substr($ext_path, -1) === '/') + { + $ext_path = substr($ext_path, 0, -1); + } $directories[$ext][] = $ext_path; } } From 06e32e36dff55dffcb60c19e768656db237ee836 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 21:20:34 +0200 Subject: [PATCH 3/5] [ticket/10844] Add unit tests for different root_paths PHPBB3-10844 --- tests/extension/style_path_provider_test.php | 50 +++++++++++++++++++ .../subdir/style_path_provider_test.php | 18 +++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/extension/style_path_provider_test.php create mode 100644 tests/extension/subdir/style_path_provider_test.php diff --git a/tests/extension/style_path_provider_test.php b/tests/extension/style_path_provider_test.php new file mode 100644 index 0000000000..e1021c20ac --- /dev/null +++ b/tests/extension/style_path_provider_test.php @@ -0,0 +1,50 @@ +relative_root_path = './'; + $this->root_path = dirname(__FILE__) . '/'; + } + + public function test_find() + { + $phpbb_style_path_provider = new phpbb_style_path_provider(); + $phpbb_style_path_provider->set_styles(array($this->relative_root_path . 'styles/prosilver')); + $phpbb_style_extension_path_provider = new phpbb_style_extension_path_provider(new phpbb_mock_extension_manager( + $this->root_path, + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => 'ext/bar/', + ), + )), $phpbb_style_path_provider, $this->relative_root_path); + + $this->assertEquals(array( + 'style' => array( + $this->relative_root_path . 'styles/prosilver', + ), + 'bar' => array( + $this->root_path . 'ext/bar/styles/prosilver', + ), + ), $phpbb_style_extension_path_provider->find()); + } +} diff --git a/tests/extension/subdir/style_path_provider_test.php b/tests/extension/subdir/style_path_provider_test.php new file mode 100644 index 0000000000..1b5ce62e5f --- /dev/null +++ b/tests/extension/subdir/style_path_provider_test.php @@ -0,0 +1,18 @@ +relative_root_path = '../'; + $this->root_path = dirname(__FILE__) . '/../'; + } +} From 12c432c5230db49b659498ea4fc3ff8766a0e87f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Apr 2013 00:23:49 +0200 Subject: [PATCH 4/5] [ticket/10844] Add extension template file to locate PHPBB3-10844 --- .../extension/ext/bar/styles/prosilver/template/foobar_body.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/extension/ext/bar/styles/prosilver/template/foobar_body.html diff --git a/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html b/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html new file mode 100644 index 0000000000..00c2a84a18 --- /dev/null +++ b/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html @@ -0,0 +1 @@ +bertie rules! From 10781ce9ae74efd4f04063c78235f4be031b414a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Apr 2013 00:24:30 +0200 Subject: [PATCH 5/5] [ticket/10844] Increase prefix to not match template/ in finder test PHPBB3-10844 --- tests/extension/finder_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index c96b11a73c..c2ac88a76a 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -66,7 +66,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_prefix_get_directories() { $dirs = $this->finder - ->prefix('t') + ->prefix('ty') ->get_directories(); sort($dirs);