diff options
Diffstat (limited to 'phpBB/phpbb/template')
| -rw-r--r-- | phpBB/phpbb/template/asset.php | 27 | ||||
| -rw-r--r-- | phpBB/phpbb/template/exception/user_object_not_available.php | 22 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/environment.php | 27 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/extension.php | 12 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/loader.php | 3 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/node/definenode.php | 3 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/node/includeasset.php | 2 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/node/includephp.php | 6 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/tokenparser/defineparser.php | 7 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/tokenparser/includephp.php | 3 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/twig.php | 19 | 
11 files changed, 103 insertions, 28 deletions
| diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php index 4729685459..cb00f16549 100644 --- a/phpBB/phpbb/template/asset.php +++ b/phpBB/phpbb/template/asset.php @@ -20,15 +20,20 @@ class asset  	/** @var \phpbb\path_helper **/  	protected $path_helper; +	/** @var \phpbb\filesystem\filesystem */ +	protected $filesystem; +  	/**  	* Constructor  	*  	* @param string $url URL  	* @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->filesystem = $filesystem;  		$this->set_url($url);  	} @@ -152,10 +157,22 @@ class asset  	*/  	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. -		$real_root_path = 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))); +		// Since 1.7.0 Twig returns the real path of the file. We need it to be relative. +		$real_root_path = $this->filesystem->realpath($this->path_helper->get_phpbb_root_path()) . DIRECTORY_SEPARATOR; + +		// 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))); +			}  		}  		if ($urlencode) diff --git a/phpBB/phpbb/template/exception/user_object_not_available.php b/phpBB/phpbb/template/exception/user_object_not_available.php new file mode 100644 index 0000000000..62fd2743c1 --- /dev/null +++ b/phpBB/phpbb/template/exception/user_object_not_available.php @@ -0,0 +1,22 @@ +<?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. + * + */ + +namespace phpbb\template\exception; + +/** + * This exception is thrown when the user object was not set but it is required by the called method + */ +class user_object_not_available extends \phpbb\exception\runtime_exception +{ + +} diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 0ba7a265e4..6e75403159 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -18,6 +18,9 @@ class environment extends \Twig_Environment  	/** @var \phpbb\config\config */  	protected $phpbb_config; +	/** @var \phpbb\filesystem\filesystem */ +	protected $filesystem; +  	/** @var \phpbb\path_helper */  	protected $phpbb_path_helper; @@ -40,6 +43,7 @@ class environment extends \Twig_Environment  	* Constructor  	*  	* @param \phpbb\config\config $phpbb_config The phpBB configuration +	* @param \phpbb\filesystem\filesystem $filesystem  	* @param \phpbb\path_helper $path_helper phpBB path helper  	* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container  	* @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 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->filesystem = $filesystem;  		$this->phpbb_path_helper = $path_helper;  		$this->extension_manager = $extension_manager;  		$this->container = $container; @@ -60,7 +65,7 @@ class environment extends \Twig_Environment  		$options = array_merge(array(  			'cache'			=> (defined('IN_INSTALL')) ? false : $cache_path, -			'debug'			=> defined('DEBUG'), +			'debug'			=> false,  			'auto_reload'	=> (bool) $this->phpbb_config['load_tplcompile'],  			'autoescape'	=> false,  		), $options); @@ -106,16 +111,26 @@ class environment extends \Twig_Environment  	}  	/** -	* Get the phpBB root path -	* -	* @return string -	*/ +	 * Get the phpBB root path +	 * +	 * @return string +	 */  	public function get_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  	*  	* @return string diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 14d1258c09..92f87a0331 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -18,20 +18,20 @@ class extension extends \Twig_Extension  	/** @var \phpbb\template\context */  	protected $context; -	/** @var \phpbb\user */ -	protected $user; +	/** @var \phpbb\language\language */ +	protected $language;  	/**  	* Constructor  	*  	* @param \phpbb\template\context $context -	* @param \phpbb\user $user +	* @param \phpbb\language\language $language  	* @return \phpbb\template\twig\extension  	*/ -	public function __construct(\phpbb\template\context $context, $user) +	public function __construct(\phpbb\template\context $context, $language)  	{  		$this->context = $context; -		$this->user = $user; +		$this->language = $language;  	}  	/** @@ -181,6 +181,6 @@ class extension extends \Twig_Extension  		// LA_ is transformed into lang(\'$1\')|escape('js'), so we should not  		// need to check for it -		return call_user_func_array(array($this->user, 'lang'), $args); +		return call_user_func_array(array($this->language, 'lang'), $args);  	}  } diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index df8183c019..8b12188a77 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -115,7 +115,8 @@ class loader extends \Twig_Loader_Filesystem  		// If this is in the cache we can skip the entire process below  		//	as it should have already been validated -		if (isset($this->cache[$name])) { +		if (isset($this->cache[$name])) +		{  			return $this->cache[$name];  		} diff --git a/phpBB/phpbb/template/twig/node/definenode.php b/phpBB/phpbb/template/twig/node/definenode.php index 695ec4281f..c110785c4b 100644 --- a/phpBB/phpbb/template/twig/node/definenode.php +++ b/phpBB/phpbb/template/twig/node/definenode.php @@ -31,7 +31,8 @@ class definenode extends \Twig_Node  	{  		$compiler->addDebugInfo($this); -		if ($this->getAttribute('capture')) { +		if ($this->getAttribute('capture')) +		{  			$compiler  				->write("ob_start();\n")  				->subcompile($this->getNode('value')) diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 15195a226b..324823b8d7 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -39,7 +39,7 @@ abstract class includeasset extends \Twig_Node  			->write("\$asset_file = ")  			->subcompile($this->getNode('expr'))  			->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")  			->indent()  				->write("\$asset_path = \$asset->get_path();") diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php index 826617e8e8..659495fd9e 100644 --- a/phpBB/phpbb/template/twig/node/includephp.php +++ b/phpBB/phpbb/template/twig/node/includephp.php @@ -47,7 +47,8 @@ class includephp extends \Twig_Node  			return;  		} -		if ($this->getAttribute('ignore_missing')) { +		if ($this->getAttribute('ignore_missing')) +		{  			$compiler  				->write("try {\n")  				->indent() @@ -76,7 +77,8 @@ class includephp extends \Twig_Node  			->write("}\n")  		; -		if ($this->getAttribute('ignore_missing')) { +		if ($this->getAttribute('ignore_missing')) +		{  			$compiler  				->outdent()  				->write("} catch (\Twig_Error_Loader \$e) {\n") diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index cfee84a363..2b88d61118 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -33,7 +33,8 @@ class defineparser extends \Twig_TokenParser  		$name = $this->parser->getExpressionParser()->parseExpression();  		$capture = false; -		if ($stream->test(\Twig_Token::OPERATOR_TYPE, '=')) { +		if ($stream->test(\Twig_Token::OPERATOR_TYPE, '=')) +		{  			$stream->next();  			$value = $this->parser->getExpressionParser()->parseExpression(); @@ -45,7 +46,9 @@ class defineparser extends \Twig_TokenParser  			}  			$stream->expect(\Twig_Token::BLOCK_END_TYPE); -		} else { +		} +		else +		{  			$capture = true;  			$stream->expect(\Twig_Token::BLOCK_END_TYPE); diff --git a/phpBB/phpbb/template/twig/tokenparser/includephp.php b/phpBB/phpbb/template/twig/tokenparser/includephp.php index 38196c5290..c09f7729b0 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includephp.php +++ b/phpBB/phpbb/template/twig/tokenparser/includephp.php @@ -31,7 +31,8 @@ class includephp extends \Twig_TokenParser  		$stream = $this->parser->getStream();  		$ignoreMissing = false; -		if ($stream->test(\Twig_Token::NAME_TYPE, 'ignore')) { +		if ($stream->test(\Twig_Token::NAME_TYPE, 'ignore')) +		{  			$stream->next();  			$stream->expect(\Twig_Token::NAME_TYPE, 'missing'); diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 0e4c619029..6b3cf32bc8 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -13,6 +13,8 @@  namespace phpbb\template\twig; +use phpbb\template\exception\user_object_not_available; +  /**  * Twig Template class.  */ @@ -76,14 +78,14 @@ class twig extends \phpbb\template\base  	*  	* @param \phpbb\path_helper $path_helper  	* @param \phpbb\config\config $config -	* @param \phpbb\user $user  	* @param \phpbb\template\context $context template context  	* @param \phpbb\template\twig\environment $twig_environment  	* @param string $cache_path +	* @param \phpbb\user|null $user  	* @param array|\ArrayAccess $extensions  	* @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked  	*/ -	public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, $extensions = array(), \phpbb\extension\manager $extension_manager = null) +	public function __construct(\phpbb\path_helper $path_helper, $config, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, \phpbb\user $user = null, $extensions = array(), \phpbb\extension\manager $extension_manager = null)  	{  		$this->path_helper = $path_helper;  		$this->phpbb_root_path = $path_helper->get_phpbb_root_path(); @@ -126,9 +128,16 @@ class twig extends \phpbb\template\base  	* Get the style tree of the style preferred by the current user  	*  	* @return array Style tree, most specific first +	* +	* @throws \phpbb\template\exception\user_object_not_available	When user service was not set  	*/  	public function get_user_style()  	{ +		if ($this->user === null) +		{ +			throw new user_object_not_available(); +		} +  		$style_list = array(  			$this->user->style['style_path'],  		); @@ -344,11 +353,15 @@ class twig extends \phpbb\template\base  			$context_vars['.'][0], // To get normal vars  			array(  				'definition'	=> new \phpbb\template\twig\definition(), -				'user'			=> $this->user,  				'loops'			=> $context_vars, // To get loops  			)  		); +		if ($this->user instanceof \phpbb\user) +		{ +			$vars['user'] = $this->user; +		} +  		// cleanup  		unset($vars['loops']['.']); | 
