aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorNathaniel Guse <nathaniel.guse@gmail.com>2013-07-04 10:12:09 -0500
committerNathaniel Guse <nathaniel.guse@gmail.com>2013-07-04 10:12:09 -0500
commit36f25ea09bd42de7bc705332edc5ce3c402bd844 (patch)
treea33f37e895704ed27983b53f5d16cfc3876cf057 /phpBB
parentf1717412f3c222af5c3cfc0b248842ea9ec88c9f (diff)
downloadforums-36f25ea09bd42de7bc705332edc5ce3c402bd844.tar
forums-36f25ea09bd42de7bc705332edc5ce3c402bd844.tar.gz
forums-36f25ea09bd42de7bc705332edc5ce3c402bd844.tar.bz2
forums-36f25ea09bd42de7bc705332edc5ce3c402bd844.tar.xz
forums-36f25ea09bd42de7bc705332edc5ce3c402bd844.zip
[feature/twig] Change style->set_style to accept a list of base directories
set_style now accepts an array containing a list of paths, e.g. array( 'ext/foo/bar/styles', 'styles'). Default: array('styles') Using this option allows us to set the style based on the user's preferred style (including the full tree), but use one or more base directories to add the paths from. The main use for this ability is so that extensions can call set_style, including their path and the phpBB styles path (or any others) and have their template files loaded from those directories (in the order given). PHPBB3-11598
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/includes/style/style.php83
-rw-r--r--phpBB/includes/template/template.php2
-rw-r--r--phpBB/includes/template/twig/twig.php6
3 files changed, 56 insertions, 35 deletions
diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php
index 29cdcf0f7f..b0bf3c1019 100644
--- a/phpBB/includes/style/style.php
+++ b/phpBB/includes/style/style.php
@@ -85,28 +85,56 @@ class phpbb_style
}
/**
+ * Get the style tree of the style preferred by the current user
+ *
+ * @return array Style tree, most specific first
+ */
+ public function get_user_style()
+ {
+ return array_merge(array(
+ $this->user->style['style_path'],
+ ),
+ ($this->user->style['style_parent_id']) ? array_reverse(explode('/', $this->user->style['style_parent_tree'])) : array()
+ );
+ }
+
+ /**
* Set style location based on (current) user's chosen style.
+ *
+ * @param array $style_directories The directories to add style paths for
+ * E.g. array('ext/foo/bar/styles', 'styles')
+ * Default: array('styles') (phpBB's style directory)
+ * @return bool true
*/
- public function set_style()
+ public function set_style($style_directories = array('styles'))
{
- $style_path = $this->user->style['style_path'];
- $style_dirs = ($this->user->style['style_parent_id']) ? array_reverse(explode('/', $this->user->style['style_parent_tree'])) : array();
+ $this->names = $this->get_user_style();
- $names = array($style_path);
- foreach ($style_dirs as $dir)
+ $paths = array();
+ foreach ($style_directories as $directory)
{
- $names[] = $dir;
+ foreach ($this->names as $name)
+ {
+ $path = $this->get_style_path($name, $directory);
+
+ if (is_dir($path))
+ {
+ $paths[] = $path;
+ }
+ }
}
- // Add 'all' path, used as last fallback path by events and extensions
- //$names[] = 'all';
- $paths = array();
- foreach ($names as $name)
+ $this->provider->set_styles($paths);
+ $this->locator->set_paths($this->provider);
+
+ foreach ($paths as &$path)
{
- $paths[] = $this->get_style_path($name);
+ $path .= '/template/';
}
- return $this->set_custom_style($style_path, $paths, $names);
+ $this->template->set_style_names($this->names, $paths, ($style_directories === array('styles')));
+
+ return true;
}
/**
@@ -118,6 +146,7 @@ class phpbb_style
* @param array or string $paths Array of style paths, relative to current root directory
* @param array $names Array of names of templates in inheritance tree order, used by extensions. If empty, $name will be used.
* @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/).
+ * @return bool true
*/
public function set_custom_style($name, $paths, $names = array(), $template_path = false)
{
@@ -138,28 +167,15 @@ class phpbb_style
if ($template_path !== false)
{
$this->locator->set_template_path($template_path);
-
- $appended_paths = array();
- foreach ($paths as $path)
- {
- $appended_paths[] = $path . '/' . $template_path;
- }
-
- $this->template->set_style_names($names, $appended_paths);
}
- else
- {
- $this->locator->set_default_template_path();
-
- $appended_paths = array();
- foreach ($paths as $path)
- {
- $appended_paths[] = $path . '/template/';
- }
- $this->template->set_style_names($names, $appended_paths);
+ foreach ($paths as &$path)
+ {
+ $path .= '/' . (($template_path !== false) ? $template_path : 'template/');
}
+ $this->template->set_style_names($names, $paths);
+
return true;
}
@@ -167,11 +183,14 @@ class phpbb_style
* Get location of style directory for specific style_path
*
* @param string $path Style path, such as "prosilver"
+ * @param string $style_base_directory The base directory the style is in
+ * E.g. 'styles', 'ext/foo/bar/styles'
+ * Default: 'styles'
* @return string Path to style directory, relative to current path
*/
- public function get_style_path($path)
+ public function get_style_path($path, $style_base_directory = 'styles')
{
- return $this->phpbb_root_path . 'styles/' . $path;
+ return $this->phpbb_root_path . trim($style_base_directory, '/') . '/' . $path;
}
/**
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php
index 2b7c36ea7d..89a01e924d 100644
--- a/phpBB/includes/template/template.php
+++ b/phpBB/includes/template/template.php
@@ -41,7 +41,7 @@ interface phpbb_template
* @param array $style_paths List of style paths in inheritance tree order
* @return phpbb_template $this
*/
- public function set_style_names(array $style_names, array $style_paths = array());
+ public function set_style_names(array $style_names, array $style_paths);
/**
* Clears all variables and blocks assigned to this template.
diff --git a/phpBB/includes/template/twig/twig.php b/phpBB/includes/template/twig/twig.php
index 98bd1ab89c..dd2c1a4023 100644
--- a/phpBB/includes/template/twig/twig.php
+++ b/phpBB/includes/template/twig/twig.php
@@ -181,9 +181,11 @@ class phpbb_template_twig implements phpbb_template
*
* @param array $style_names List of style names in inheritance tree order
* @param array $style_paths List of style paths in inheritance tree order
+ * @param bool $is_core True if the style names are the "core" styles for this page load
+ * Core means the main phpBB template files
* @return phpbb_template $this
*/
- public function set_style_names(array $style_names, array $style_paths = array())
+ public function set_style_names(array $style_names, array $style_paths, $is_core = false)
{
$this->style_names = $style_names;
@@ -191,7 +193,7 @@ class phpbb_template_twig implements phpbb_template
$this->twig->getLoader()->setPaths($style_paths);
// Core style namespace from phpbb_style::set_style()
- if (isset($this->user->style['style_path']) && ($style_names === array($this->user->style['style_path']) || $style_names[0] == $this->user->style['style_path']))
+ if ($is_core)
{
$this->twig->getLoader()->setPaths($style_paths, 'core');
}