From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/style/extension_path_provider.php | 137 ++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 phpBB/phpbb/style/extension_path_provider.php (limited to 'phpBB/phpbb/style/extension_path_provider.php') diff --git a/phpBB/phpbb/style/extension_path_provider.php b/phpBB/phpbb/style/extension_path_provider.php new file mode 100644 index 0000000000..ec1d85f821 --- /dev/null +++ b/phpBB/phpbb/style/extension_path_provider.php @@ -0,0 +1,137 @@ +base_path_provider = $base_path_provider; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Sets a prefix for style paths searched within extensions. + * + * The prefix is inserted between the extension's path e.g. ext/foo/ and + * the looked up style path, e.g. styles/bar/. So it should not have a + * leading slash, but should have a trailing slash. + * + * @param string $ext_dir_prefix The prefix including trailing slash + * @return null + */ + public function set_ext_dir_prefix($ext_dir_prefix) + { + $this->ext_dir_prefix = $ext_dir_prefix; + } + + /** + * Finds style paths using the extension manager + * + * Locates a path (e.g. styles/prosilver/) in all active extensions. + * Then appends the core style paths based in the current working + * directory. + * + * @return array List of style paths + */ + public function find() + { + $directories = array(); + + $finder = $this->extension_manager->get_finder(); + foreach ($this->base_path_provider as $key => $paths) + { + if ($key == 'style') + { + foreach ($paths as $path) + { + $directories['style'][] = $path; + if ($path && !phpbb_is_absolute($path)) + { + // Remove phpBB root path from the style path, + // so the finder is able to find extension styles, + // when the root path is not ./ + if (strpos($path, $this->phpbb_root_path) === 0) + { + $path = substr($path, strlen($this->phpbb_root_path)); + } + + $result = $finder->directory('/' . $this->ext_dir_prefix . $path) + ->get_directories(true, false, true); + foreach ($result as $ext => $ext_path) + { + // Make sure $ext_path has no ending slash + if (substr($ext_path, -1) === '/') + { + $ext_path = substr($ext_path, 0, -1); + } + $directories[$ext][] = $ext_path; + } + } + } + } + } + + return $directories; + } + + /** + * Overwrites the current style paths + * + * @param array $styles An array of style paths. The first element is the main style. + * @return null + */ + public function set_styles(array $styles) + { + $this->base_path_provider->set_styles($styles); + $this->items = null; + } +} -- cgit v1.2.1