mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Merge pull request #3432 from Nicofuma/ticket/13638
[ticket/13638] Prepend the assets path phpbb root
This commit is contained in:
commit
de687f32ed
15 changed files with 120 additions and 17 deletions
|
@ -6,6 +6,7 @@ services:
|
||||||
class: phpbb\template\twig\environment
|
class: phpbb\template\twig\environment
|
||||||
arguments:
|
arguments:
|
||||||
- @config
|
- @config
|
||||||
|
- @filesystem
|
||||||
- @path_helper
|
- @path_helper
|
||||||
- @service_container
|
- @service_container
|
||||||
- %core.template.cache_path%
|
- %core.template.cache_path%
|
||||||
|
|
|
@ -142,6 +142,7 @@ class bbcode
|
||||||
new \phpbb\template\context(),
|
new \phpbb\template\context(),
|
||||||
new \phpbb\template\twig\environment(
|
new \phpbb\template\twig\environment(
|
||||||
$phpbb_container->get('config'),
|
$phpbb_container->get('config'),
|
||||||
|
$phpbb_container->get('filesystem'),
|
||||||
$phpbb_container->get('path_helper'),
|
$phpbb_container->get('path_helper'),
|
||||||
$phpbb_container,
|
$phpbb_container,
|
||||||
$phpbb_container->getParameter('core.root_path') . 'cache/',
|
$phpbb_container->getParameter('core.root_path') . 'cache/',
|
||||||
|
|
|
@ -637,6 +637,7 @@ class messenger
|
||||||
new \phpbb\template\context(),
|
new \phpbb\template\context(),
|
||||||
new \phpbb\template\twig\environment(
|
new \phpbb\template\twig\environment(
|
||||||
$phpbb_container->get('config'),
|
$phpbb_container->get('config'),
|
||||||
|
$phpbb_container->get('filesystem'),
|
||||||
$phpbb_container->get('path_helper'),
|
$phpbb_container->get('path_helper'),
|
||||||
$phpbb_container,
|
$phpbb_container,
|
||||||
$phpbb_container->getParameter('core.root_path') . 'cache/',
|
$phpbb_container->getParameter('core.root_path') . 'cache/',
|
||||||
|
|
|
@ -280,6 +280,7 @@ $cache_path = $phpbb_root_path . 'cache/';
|
||||||
|
|
||||||
$twig_environment = new \phpbb\template\twig\environment(
|
$twig_environment = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
|
$phpbb_filesystem,
|
||||||
$phpbb_path_helper,
|
$phpbb_path_helper,
|
||||||
$phpbb_container,
|
$phpbb_container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
|
@ -20,15 +20,20 @@ class asset
|
||||||
/** @var \phpbb\path_helper **/
|
/** @var \phpbb\path_helper **/
|
||||||
protected $path_helper;
|
protected $path_helper;
|
||||||
|
|
||||||
|
/** @var \phpbb\filesystem\filesystem */
|
||||||
|
protected $filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param \phpbb\path_helper $path_helper Path helper object
|
* @param \phpbb\path_helper $path_helper Path helper object
|
||||||
|
* @param \phpbb\filesystem\filesystem $filesystem
|
||||||
*/
|
*/
|
||||||
public function __construct($url, \phpbb\path_helper $path_helper)
|
public function __construct($url, \phpbb\path_helper $path_helper, \phpbb\filesystem\filesystem $filesystem)
|
||||||
{
|
{
|
||||||
$this->path_helper = $path_helper;
|
$this->path_helper = $path_helper;
|
||||||
|
$this->filesystem = $filesystem;
|
||||||
|
|
||||||
$this->set_url($url);
|
$this->set_url($url);
|
||||||
}
|
}
|
||||||
|
@ -152,11 +157,23 @@ class asset
|
||||||
*/
|
*/
|
||||||
public function set_path($path, $urlencode = false)
|
public function set_path($path, $urlencode = false)
|
||||||
{
|
{
|
||||||
// Since 1.7.0 Twig returns the real path of the file. We need it to be relative to the working directory.
|
// Since 1.7.0 Twig returns the real path of the file. We need it to be relative.
|
||||||
$real_root_path = realpath('.') . DIRECTORY_SEPARATOR;
|
$real_root_path = $this->filesystem->realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR;
|
||||||
if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path) {
|
|
||||||
|
// If the asset is under the phpBB root path we need to remove its path and then prepend $phpbb_root_path
|
||||||
|
if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
|
||||||
|
{
|
||||||
|
$path = $this->path_helper->get_phpbb_root_path() . str_replace('\\', '/', substr($path, strlen($real_root_path)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Else we make the path relative to the current working directory
|
||||||
|
$real_root_path = $this->filesystem->realpath('.') . DIRECTORY_SEPARATOR;
|
||||||
|
if ($real_root_path && substr($path . DIRECTORY_SEPARATOR, 0, strlen($real_root_path)) === $real_root_path)
|
||||||
|
{
|
||||||
$path = str_replace('\\', '/', substr($path, strlen($real_root_path)));
|
$path = str_replace('\\', '/', substr($path, strlen($real_root_path)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($urlencode)
|
if ($urlencode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,9 @@ class environment extends \Twig_Environment
|
||||||
/** @var \phpbb\config\config */
|
/** @var \phpbb\config\config */
|
||||||
protected $phpbb_config;
|
protected $phpbb_config;
|
||||||
|
|
||||||
|
/** @var \phpbb\filesystem\filesystem */
|
||||||
|
protected $filesystem;
|
||||||
|
|
||||||
/** @var \phpbb\path_helper */
|
/** @var \phpbb\path_helper */
|
||||||
protected $phpbb_path_helper;
|
protected $phpbb_path_helper;
|
||||||
|
|
||||||
|
@ -40,6 +43,7 @@ class environment extends \Twig_Environment
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param \phpbb\config\config $phpbb_config The phpBB configuration
|
* @param \phpbb\config\config $phpbb_config The phpBB configuration
|
||||||
|
* @param \phpbb\filesystem\filesystem $filesystem
|
||||||
* @param \phpbb\path_helper $path_helper phpBB path helper
|
* @param \phpbb\path_helper $path_helper phpBB path helper
|
||||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container
|
||||||
* @param string $cache_path The path to the cache directory
|
* @param string $cache_path The path to the cache directory
|
||||||
|
@ -47,10 +51,11 @@ class environment extends \Twig_Environment
|
||||||
* @param \Twig_LoaderInterface $loader Twig loader interface
|
* @param \Twig_LoaderInterface $loader Twig loader interface
|
||||||
* @param array $options Array of options to pass to Twig
|
* @param array $options Array of options to pass to Twig
|
||||||
*/
|
*/
|
||||||
public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
|
public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
|
||||||
{
|
{
|
||||||
$this->phpbb_config = $phpbb_config;
|
$this->phpbb_config = $phpbb_config;
|
||||||
|
|
||||||
|
$this->filesystem = $filesystem;
|
||||||
$this->phpbb_path_helper = $path_helper;
|
$this->phpbb_path_helper = $path_helper;
|
||||||
$this->extension_manager = $extension_manager;
|
$this->extension_manager = $extension_manager;
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
@ -115,6 +120,16 @@ class environment extends \Twig_Environment
|
||||||
return $this->phpbb_root_path;
|
return $this->phpbb_root_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the filesystem object
|
||||||
|
*
|
||||||
|
* @return \phpbb\filesystem\filesystem
|
||||||
|
*/
|
||||||
|
public function get_filesystem()
|
||||||
|
{
|
||||||
|
return $this->filesystem;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the web root path
|
* Get the web root path
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,7 +39,7 @@ abstract class includeasset extends \Twig_Node
|
||||||
->write("\$asset_file = ")
|
->write("\$asset_file = ")
|
||||||
->subcompile($this->getNode('expr'))
|
->subcompile($this->getNode('expr'))
|
||||||
->raw(";\n")
|
->raw(";\n")
|
||||||
->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper());\n")
|
->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper(), \$this->getEnvironment()->get_filesystem());\n")
|
||||||
->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
|
->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$asset_path = \$asset->get_path();")
|
->write("\$asset_path = \$asset->get_path();")
|
||||||
|
|
|
@ -94,6 +94,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
|
||||||
$loader = new \phpbb\template\twig\loader($this->filesystem, '');
|
$loader = new \phpbb\template\twig\loader($this->filesystem, '');
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$this->config,
|
$this->config,
|
||||||
|
$this->filesystem,
|
||||||
$this->phpbb_path_helper,
|
$this->phpbb_path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
|
@ -51,17 +51,19 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
|
||||||
$cache_path = $this->phpbb_root_path . 'cache/twig';
|
$cache_path = $this->phpbb_root_path . 'cache/twig';
|
||||||
$context = new \phpbb\template\context();
|
$context = new \phpbb\template\context();
|
||||||
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
||||||
$phpbb_path_helper =new \phpbb\path_helper(
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
|
$phpbb_path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
new phpbb_mock_request()
|
new phpbb_mock_request()
|
||||||
),
|
),
|
||||||
new \phpbb\filesystem\filesystem(),
|
$filesystem,
|
||||||
$this->getMock('\phpbb\request\request'),
|
$this->getMock('\phpbb\request\request'),
|
||||||
$this->phpbb_root_path,
|
$this->phpbb_root_path,
|
||||||
$this->phpEx
|
$this->phpEx
|
||||||
);
|
);
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$this->config,
|
$this->config,
|
||||||
|
$filesystem,
|
||||||
$phpbb_path_helper,
|
$phpbb_path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
49
tests/template/asset_test.php
Normal file
49
tests/template/asset_test.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use phpbb\template\asset;
|
||||||
|
|
||||||
|
class phpbb_template_asset_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
public function set_path_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// array(phpbb_root_path, given path, expected path),
|
||||||
|
array('.', 'foo/bar', 'foo/bar'),
|
||||||
|
array('../', 'foo/bar', 'foo/bar'),
|
||||||
|
array('./phpBB/', 'foo/bar', 'foo/bar'),
|
||||||
|
array('../', __DIR__ . '/foo/bar', '../phpbb/tests/template/foo/bar'),
|
||||||
|
array('./', __DIR__ . '/foo/bar', './tests/template/foo/bar'),
|
||||||
|
array('./phpBB/', __DIR__ . '/foo/bar', 'tests/template/foo/bar'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider set_path_data
|
||||||
|
*/
|
||||||
|
public function test_set_path($phpbb_root_path, $path, $expected)
|
||||||
|
{
|
||||||
|
$path_helper = $this->getMockBuilder('\phpbb\path_helper')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(array())
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$path_helper->method('get_phpbb_root_path')
|
||||||
|
->willReturn($phpbb_root_path);
|
||||||
|
|
||||||
|
$asset = new asset('', $path_helper, new phpbb\filesystem\filesystem());
|
||||||
|
|
||||||
|
$asset->set_path($path, true);
|
||||||
|
$this->assertEquals($expected, $asset->get_path());
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,11 +33,13 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
|
||||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
||||||
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
|
|
||||||
$path_helper = new \phpbb\path_helper(
|
$path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
new phpbb_mock_request()
|
new phpbb_mock_request()
|
||||||
),
|
),
|
||||||
new \phpbb\filesystem\filesystem(),
|
$filesystem,
|
||||||
$this->getMock('\phpbb\request\request'),
|
$this->getMock('\phpbb\request\request'),
|
||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
$phpEx
|
$phpEx
|
||||||
|
@ -60,6 +62,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
|
||||||
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
|
$filesystem,
|
||||||
$path_helper,
|
$path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
|
@ -138,6 +138,8 @@ Zeta test event in all',
|
||||||
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
|
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
|
||||||
dirname(__FILE__) . "/datasets/$dataset/"
|
dirname(__FILE__) . "/datasets/$dataset/"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
$path_helper = new \phpbb\path_helper(
|
$path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
new phpbb_mock_request()
|
new phpbb_mock_request()
|
||||||
|
@ -154,6 +156,7 @@ Zeta test event in all',
|
||||||
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
|
$filesystem,
|
||||||
$path_helper,
|
$path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
|
@ -28,11 +28,13 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
|
||||||
$defaults = $this->config_defaults();
|
$defaults = $this->config_defaults();
|
||||||
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
|
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
|
||||||
|
|
||||||
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
|
|
||||||
$this->phpbb_path_helper = new \phpbb\path_helper(
|
$this->phpbb_path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
new phpbb_mock_request()
|
new phpbb_mock_request()
|
||||||
),
|
),
|
||||||
new \phpbb\filesystem\filesystem(),
|
$filesystem,
|
||||||
$this->getMock('\phpbb\request\request'),
|
$this->getMock('\phpbb\request\request'),
|
||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
$phpEx
|
$phpEx
|
||||||
|
@ -46,6 +48,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
|
||||||
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
|
$filesystem,
|
||||||
$this->phpbb_path_helper,
|
$this->phpbb_path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
|
@ -82,11 +82,13 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
||||||
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
|
|
||||||
$path_helper = new \phpbb\path_helper(
|
$path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
new phpbb_mock_request()
|
new phpbb_mock_request()
|
||||||
),
|
),
|
||||||
new \phpbb\filesystem\filesystem(),
|
$filesystem,
|
||||||
$this->getMock('\phpbb\request\request'),
|
$this->getMock('\phpbb\request\request'),
|
||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
$phpEx
|
$phpEx
|
||||||
|
@ -100,6 +102,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
|
$filesystem,
|
||||||
$path_helper,
|
$path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
|
@ -22,11 +22,13 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||||
$defaults = $this->config_defaults();
|
$defaults = $this->config_defaults();
|
||||||
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
|
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
|
||||||
|
|
||||||
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
|
|
||||||
$this->phpbb_path_helper = new \phpbb\path_helper(
|
$this->phpbb_path_helper = new \phpbb\path_helper(
|
||||||
new \phpbb\symfony_request(
|
new \phpbb\symfony_request(
|
||||||
new phpbb_mock_request()
|
new phpbb_mock_request()
|
||||||
),
|
),
|
||||||
new \phpbb\filesystem\filesystem(),
|
$filesystem,
|
||||||
$this->getMock('\phpbb\request\request'),
|
$this->getMock('\phpbb\request\request'),
|
||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
$phpEx
|
$phpEx
|
||||||
|
@ -41,6 +43,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||||
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
$loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
|
||||||
$twig = new \phpbb\template\twig\environment(
|
$twig = new \phpbb\template\twig\environment(
|
||||||
$config,
|
$config,
|
||||||
|
$filesystem,
|
||||||
$this->phpbb_path_helper,
|
$this->phpbb_path_helper,
|
||||||
$container,
|
$container,
|
||||||
$cache_path,
|
$cache_path,
|
||||||
|
|
Loading…
Add table
Reference in a new issue