From b4a374dc73eda55db1c67b87bd65a73f79411ef5 Mon Sep 17 00:00:00 2001
From: Nathan Guse <nathaniel.guse@gmail.com>
Date: Fri, 13 Sep 2013 10:58:03 -0500
Subject: [ticket/11832] Fix INCLUDE(JS/CSS)

PHPBB3-11832
---
 phpBB/phpbb/template/twig/environment.php       | 33 +++++++++++++++++++++++--
 phpBB/phpbb/template/twig/node/includeasset.php |  2 +-
 phpBB/phpbb/template/twig/twig.php              | 25 +++++++++++--------
 3 files changed, 47 insertions(+), 13 deletions(-)

(limited to 'phpBB/phpbb/template')

diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php
index 9a40dc2b15..612519db69 100644
--- a/phpBB/phpbb/template/twig/environment.php
+++ b/phpBB/phpbb/template/twig/environment.php
@@ -23,9 +23,15 @@ class phpbb_template_twig_environment extends Twig_Environment
 	/** @var phpbb_config */
 	protected $phpbb_config;
 
+	/** @var phpbb_filesystem */
+	protected $phpbb_filesystem;
+
 	/** @var string */
 	protected $phpbb_root_path;
 
+	/** @var string */
+	protected $web_root_path;
+
 	/** @var array **/
 	protected $namespace_look_up_order = array('__main__');
 
@@ -38,11 +44,14 @@ class phpbb_template_twig_environment extends Twig_Environment
 	* @param Twig_LoaderInterface $loader
 	* @param array $options Array of options to pass to Twig
 	*/
-	public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array())
+	public function __construct($phpbb_config, $phpbb_extensions, phpbb_filesystem $phpbb_filesystem, Twig_LoaderInterface $loader = null, $options = array())
 	{
 		$this->phpbb_config = $phpbb_config;
 		$this->phpbb_extensions = $phpbb_extensions;
-		$this->phpbb_root_path = $phpbb_root_path;
+
+		$this->phpbb_filesystem = $phpbb_filesystem;
+		$this->phpbb_root_path = $this->phpbb_filesystem->get_phpbb_root_path();
+		$this->web_root_path = $this->phpbb_filesystem->get_web_root_path();
 
 		return parent::__construct($loader, $options);
 	}
@@ -79,6 +88,26 @@ class phpbb_template_twig_environment extends Twig_Environment
 		return $this->phpbb_root_path;
 	}
 
+	/**
+	* Get the web root path
+	*
+	* @return string
+	*/
+	public function get_web_root_path()
+	{
+		return $this->web_root_path;
+	}
+
+	/**
+	* Get the phpbb_filesystem object
+	*
+	* @return phpbb_filesystem
+	*/
+	public function get_filesystem()
+	{
+		return $this->phpbb_filesystem;
+	}
+
 	/**
 	* Get the namespace look up order
 	*
diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php
index 0808e2b10e..2dcd2003a3 100644
--- a/phpBB/phpbb/template/twig/node/includeasset.php
+++ b/phpBB/phpbb/template/twig/node/includeasset.php
@@ -37,7 +37,7 @@ abstract class phpbb_template_twig_node_includeasset extends Twig_Node
 			->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
 			->indent()
 				->write("\$asset_path = \$asset->get_path();")
-				->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n")
+				->write("\$local_file = \$this->getEnvironment()->get_web_root_path() . \$asset_path;\n")
 				->write("if (!file_exists(\$local_file)) {\n")
 				->indent()
 					->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n")
diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php
index 5746cc64a3..3aa063ffc6 100644
--- a/phpBB/phpbb/template/twig/twig.php
+++ b/phpBB/phpbb/template/twig/twig.php
@@ -30,6 +30,12 @@ class phpbb_template_twig extends phpbb_template_base
 	*/
 	private $cachepath = '';
 
+	/**
+	* phpBB filesystem
+	* @var phpbb_filesystem
+	*/
+	protected $phpbb_filesystem;
+
 	/**
 	* phpBB root path
 	* @var string
@@ -71,24 +77,23 @@ class phpbb_template_twig extends phpbb_template_base
 	/**
 	* Constructor.
 	*
-	* @param string $phpbb_root_path phpBB root path
-	* @param string $php_ext php extension (typically 'php')
+	* @param phpbb_filesystem $phpbb_filesystem
 	* @param phpbb_config $config
 	* @param phpbb_user $user
 	* @param phpbb_template_context $context template context
 	* @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked
-	* @param string $adm_relative_path relative path to adm directory
 	*/
-	public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null, $adm_relative_path = null)
+	public function __construct(phpbb_filesystem $phpbb_filesystem, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null)
 	{
-		$this->phpbb_root_path = $phpbb_root_path;
-		$this->php_ext = $php_ext;
+		$this->phpbb_filesystem = $phpbb_filesystem;
+		$this->phpbb_root_path = $phpbb_filesystem->get_phpbb_root_path();
+		$this->php_ext = $phpbb_filesystem->get_php_ext();
 		$this->config = $config;
 		$this->user = $user;
 		$this->context = $context;
 		$this->extension_manager = $extension_manager;
 
-		$this->cachepath = $phpbb_root_path . 'cache/twig/';
+		$this->cachepath = $this->phpbb_root_path . 'cache/twig/';
 
 		// Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
 		$loader = new phpbb_template_twig_loader('');
@@ -96,7 +101,7 @@ class phpbb_template_twig extends phpbb_template_base
 		$this->twig = new phpbb_template_twig_environment(
 			$this->config,
 			($this->extension_manager) ? $this->extension_manager->all_enabled() : array(),
-			$this->phpbb_root_path,
+			$this->phpbb_filesystem,
 			$loader,
 			array(
 				'cache'			=> (defined('IN_INSTALL')) ? false : $this->cachepath,
@@ -118,9 +123,9 @@ class phpbb_template_twig extends phpbb_template_base
 		$this->twig->setLexer($lexer);
 
 		// Add admin namespace
-		if ($adm_relative_path !== null && is_dir($this->phpbb_root_path . $adm_relative_path . 'style/'))
+		if ($this->phpbb_filesystem->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/'))
 		{
-			$this->twig->getLoader()->setPaths($this->phpbb_root_path . $adm_relative_path . 'style/', 'admin');
+			$this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/', 'admin');
 		}
 	}
 
-- 
cgit v1.2.1