From 30a1f21735227a72c8d676db3d0c8d695b150007 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 14 Jun 2013 01:00:38 -0500 Subject: [feature/twig] Use twig loader filesystem with namespaces to add paths Twig now handles loading style files on its own PHPBB3-11598 --- phpBB/includes/style/style.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/style') diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 4703c3a219..5aeeac40e4 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -135,15 +135,29 @@ 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); + + $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); } $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; -- cgit v1.2.1 From a1f957af84130963ef20855dfee03ba86ab1a9b6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 24 Jun 2013 15:28:54 -0500 Subject: [feature/twig] Working on fixing tests PHPBB3-11598 --- phpBB/includes/style/style.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/style') diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 5aeeac40e4..493c4512a6 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -160,7 +160,7 @@ class phpbb_style $this->template->set_style_names($names, $appended_paths); } - $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; + //$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; return true; } -- cgit v1.2.1 From 985a233a78af7350387dfb9b8a924d09df767f05 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 2 Jul 2013 12:22:42 -0500 Subject: [feature/twig] Remove reference to cachepath, it is not used publicly anymore PHPBB3-11598 --- phpBB/includes/style/style.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/style') diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 493c4512a6..29cdcf0f7f 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -160,8 +160,6 @@ class phpbb_style $this->template->set_style_names($names, $appended_paths); } - //$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; - return true; } -- cgit v1.2.1 From 36f25ea09bd42de7bc705332edc5ce3c402bd844 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 10:12:09 -0500 Subject: [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 --- phpBB/includes/style/style.php | 83 ++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 32 deletions(-) (limited to 'phpBB/includes/style') 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 @@ -84,29 +84,57 @@ class phpbb_style $this->template = $template; } + /** + * 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; } /** -- cgit v1.2.1 From c1a600277d07c2dbb3ebd410f87acb22627a9d60 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Jul 2013 09:57:55 -0500 Subject: [feature/twig] Nicer code for get_user_style.php() PHPBB3-11598 --- phpBB/includes/style/style.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/style') diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index b0bf3c1019..06c16fdef4 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -91,11 +91,16 @@ class phpbb_style */ 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() + $style_list = array( + $this->user->style['style_path'], ); + + if ($this->user->style['style_parent_id']) + { + $style_list = array_merge($style_list, array_reverse(explode('/', $this->user->style['style_parent_tree']))); + } + + return $style_list; } /** -- cgit v1.2.1 From bc4b5c87a9e899968a0f7af115fa1844348ddaac Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 11 Jul 2013 10:45:23 -0500 Subject: [ticket/11388] Do not modify by reference PHPBB3-11388 --- phpBB/includes/style/style.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/style') diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 06c16fdef4..7001d10f21 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -132,12 +132,13 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - foreach ($paths as &$path) + $new_paths = array(); + foreach ($paths as $path) { - $path .= '/template/'; + $new_paths = $path . '/template/'; } - $this->template->set_style_names($this->names, $paths, ($style_directories === array('styles'))); + $this->template->set_style_names($this->names, $new_paths1, ($style_directories === array('styles'))); return true; } @@ -174,12 +175,13 @@ class phpbb_style $this->locator->set_template_path($template_path); } - foreach ($paths as &$path) + $new_paths = array(); + foreach ($paths as $path) { - $path .= '/' . (($template_path !== false) ? $template_path : 'template/'); + $new_paths = $path . '/' . (($template_path !== false) ? $template_path : 'template/'); } - $this->template->set_style_names($names, $paths); + $this->template->set_style_names($names, $new_paths); return true; } -- cgit v1.2.1 From abd4159f87db8db5030afc439f072d6aa7b715e3 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 11 Jul 2013 11:26:38 -0500 Subject: [ticket/11388] Fix typo PHPBB3-11388 --- phpBB/includes/style/style.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/style') diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 7001d10f21..034f518091 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -135,10 +135,10 @@ class phpbb_style $new_paths = array(); foreach ($paths as $path) { - $new_paths = $path . '/template/'; + $new_paths[] = $path . '/template/'; } - $this->template->set_style_names($this->names, $new_paths1, ($style_directories === array('styles'))); + $this->template->set_style_names($this->names, $new_paths, ($style_directories === array('styles'))); return true; } @@ -178,7 +178,7 @@ class phpbb_style $new_paths = array(); foreach ($paths as $path) { - $new_paths = $path . '/' . (($template_path !== false) ? $template_path : 'template/'); + $new_paths[] = $path . '/' . (($template_path !== false) ? $template_path : 'template/'); } $this->template->set_style_names($names, $new_paths); -- cgit v1.2.1