From e1fc008d15b14b383934c6a0291105377a852b53 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 17 Oct 2013 14:20:59 +0200 Subject: [PATCH 1/5] [ticket/11930] Use \phpbb\path_helper for avatar URLs This will ensure that avatars still properly display on extension pages supplied via app.php. PHPBB3-11930 --- phpBB/config/avatars.yml | 4 ++++ phpBB/phpbb/avatar/driver/driver.php | 9 ++++++++- phpBB/phpbb/avatar/driver/local.php | 2 +- phpBB/phpbb/avatar/driver/upload.php | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/phpBB/config/avatars.yml b/phpBB/config/avatars.yml index 31ae1ecef9..5dae067642 100644 --- a/phpBB/config/avatars.yml +++ b/phpBB/config/avatars.yml @@ -6,6 +6,7 @@ services: - %core.root_path% - %core.php_ext% - @cache.driver + - @path_helper calls: - [set_name, [avatar.driver.gravatar]] tags: @@ -18,6 +19,7 @@ services: - %core.root_path% - %core.php_ext% - @cache.driver + - @path_helper calls: - [set_name, [avatar.driver.local]] tags: @@ -30,6 +32,7 @@ services: - %core.root_path% - %core.php_ext% - @cache.driver + - @path_helper calls: - [set_name, [avatar.driver.remote]] tags: @@ -42,6 +45,7 @@ services: - %core.root_path% - %core.php_ext% - @cache.driver + - @path_helper calls: - [set_name, [avatar.driver.upload]] tags: diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 0c54951cbd..95585ab13f 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -53,6 +53,12 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface */ protected $cache; + /** + * Path Helper + * @var \phpbb\path_helper + */ + protected $path_helper; + /** * Array of allowed avatar image extensions * Array is used for setting the allowed extensions in the fileupload class @@ -77,12 +83,13 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface * @param string $php_ext PHP file extension * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ - public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null, \phpbb\path_helper $path_helper) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->cache = $cache; + $this->path_helper = $path_helper; } /** diff --git a/phpBB/phpbb/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php index d779099c46..0686ffe79a 100644 --- a/phpBB/phpbb/avatar/driver/local.php +++ b/phpBB/phpbb/avatar/driver/local.php @@ -29,7 +29,7 @@ class local extends \phpbb\avatar\driver\driver public function get_data($row) { return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'src' => $this->path_helper->get_web_root_path() . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 377c9a0b04..bda872df7a 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -29,7 +29,7 @@ class upload extends \phpbb\avatar\driver\driver public function get_data($row, $ignore_config = false) { return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'], + 'src' => $this->path_helper->get_web_root_path() . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'], 'width' => $row['avatar_width'], 'height' => $row['avatar_height'], ); From 3f0ce78a25e433287e36bb92ff2c531e5a5b4743 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 17 Oct 2013 20:49:10 +0200 Subject: [PATCH 2/5] [ticket/11930] Fix tests after adding phpbb\path_helper to avatar drivers PHPBB3-11930 --- tests/avatar/manager_test.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index ba1fb04b33..ccb6a1085c 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -25,9 +25,17 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $config = new \phpbb\config\config(array()); $request = $this->getMock('\phpbb\request\request'); $cache = $this->getMock('\phpbb\cache\driver\driver_interface'); + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + new \phpbb\filesystem(), + $this->phpbb_root_path, + $this->phpEx + ); // $this->avatar_foobar will be needed later on - $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); + $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache, $path_helper)); $this->avatar_foobar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); @@ -40,7 +48,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase foreach ($this->avatar_drivers() as $driver) { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache, $path_helper)); $cur_avatar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.' . $driver)); From d7bf50bc8073dbfe52c686066fcdd156550ab7f0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 21 Oct 2013 10:20:12 +0200 Subject: [PATCH 3/5] [ticket/11930] Move path_helper in front of optional cache argument Optional method arguments should be after any mandatory ones. PHPBB3-11930 --- phpBB/config/avatars.yml | 8 ++++---- phpBB/phpbb/avatar/driver/driver.php | 2 +- tests/avatar/manager_test.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/config/avatars.yml b/phpBB/config/avatars.yml index 5dae067642..d22a5db2ae 100644 --- a/phpBB/config/avatars.yml +++ b/phpBB/config/avatars.yml @@ -5,8 +5,8 @@ services: - @config - %core.root_path% - %core.php_ext% - - @cache.driver - @path_helper + - @cache.driver calls: - [set_name, [avatar.driver.gravatar]] tags: @@ -18,8 +18,8 @@ services: - @config - %core.root_path% - %core.php_ext% - - @cache.driver - @path_helper + - @cache.driver calls: - [set_name, [avatar.driver.local]] tags: @@ -31,8 +31,8 @@ services: - @config - %core.root_path% - %core.php_ext% - - @cache.driver - @path_helper + - @cache.driver calls: - [set_name, [avatar.driver.remote]] tags: @@ -44,8 +44,8 @@ services: - @config - %core.root_path% - %core.php_ext% - - @cache.driver - @path_helper + - @cache.driver calls: - [set_name, [avatar.driver.upload]] tags: diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 95585ab13f..d682d7d114 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -83,7 +83,7 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface * @param string $php_ext PHP file extension * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ - public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null, \phpbb\path_helper $path_helper) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index ccb6a1085c..4afa594beb 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -35,7 +35,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase ); // $this->avatar_foobar will be needed later on - $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache, $path_helper)); + $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache)); $this->avatar_foobar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); @@ -48,7 +48,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase foreach ($this->avatar_drivers() as $driver) { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache, $path_helper)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache)); $cur_avatar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.' . $driver)); From acbb1ed3ee4c01f4379dfdefbec40f59e427c95f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 21 Oct 2013 10:47:40 +0200 Subject: [PATCH 4/5] [ticket/11930] Modify order of properties to fit constructor method PHPBB3-11930 --- phpBB/phpbb/avatar/driver/driver.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index d682d7d114..68c30d36a5 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -47,18 +47,18 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface */ protected $php_ext; - /** - * Cache driver - * @var \phpbb\cache\driver\driver_interface - */ - protected $cache; - /** * Path Helper * @var \phpbb\path_helper */ protected $path_helper; + /** + * Cache driver + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; + /** * Array of allowed avatar image extensions * Array is used for setting the allowed extensions in the fileupload class @@ -88,8 +88,8 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->cache = $cache; $this->path_helper = $path_helper; + $this->cache = $cache; } /** From a80d5c93e354aa1e4dff548a89129ccd7f5488ee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 21 Oct 2013 11:02:59 +0200 Subject: [PATCH 5/5] [ticket/11930] Update docblock of avatar driver constructor PHPBB3-11930 --- phpBB/phpbb/avatar/driver/driver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 68c30d36a5..206df86543 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -81,6 +81,7 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface * @param \phpbb\request\request $request Request object * @param string $phpbb_root_path Path to the phpBB root * @param string $php_ext PHP file extension + * @param \phpbb_path_helper $path_helper phpBB path helper * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null)