diff options
Diffstat (limited to 'phpBB/includes/style/style.php')
-rw-r--r-- | phpBB/includes/style/style.php | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 4703c3a219..034f518091 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -85,28 +85,62 @@ class phpbb_style } /** - * Set style location based on (current) user's chosen style. + * Get the style tree of the style preferred by the current user + * + * @return array Style tree, most specific first */ - public function set_style() + public function get_user_style() { - $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(); + $style_list = array( + $this->user->style['style_path'], + ); - $names = array($style_path); - foreach ($style_dirs as $dir) + if ($this->user->style['style_parent_id']) { - $names[] = $dir; + $style_list = array_merge($style_list, array_reverse(explode('/', $this->user->style['style_parent_tree']))); } - // Add 'all' path, used as last fallback path by events and extensions - //$names[] = 'all'; + + return $style_list; + } + + /** + * 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($style_directories = array('styles')) + { + $this->names = $this->get_user_style(); $paths = array(); - foreach ($names as $name) + foreach ($style_directories as $directory) { - $paths[] = $this->get_style_path($name); + foreach ($this->names as $name) + { + $path = $this->get_style_path($name, $directory); + + if (is_dir($path)) + { + $paths[] = $path; + } + } } - return $this->set_custom_style($style_path, $paths, $names); + $this->provider->set_styles($paths); + $this->locator->set_paths($this->provider); + + $new_paths = array(); + foreach ($paths as $path) + { + $new_paths[] = $path . '/template/'; + } + + $this->template->set_style_names($this->names, $new_paths, ($style_directories === array('styles'))); + + return true; } /** @@ -118,6 +152,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) { @@ -135,18 +170,18 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - $this->template->set_style_names($names); - if ($template_path !== false) { $this->locator->set_template_path($template_path); } - else + + $new_paths = array(); + foreach ($paths as $path) { - $this->locator->set_default_template_path(); + $new_paths[] = $path . '/' . (($template_path !== false) ? $template_path : 'template/'); } - $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; + $this->template->set_style_names($names, $new_paths); return true; } @@ -155,11 +190,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; } /** |