mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-07 16:15:22 +02:00
[ticket/10735] Changing locator paths structure
Changing locator paths to 2 dimensional array PHPBB3-10735
This commit is contained in:
parent
7e2f16aafa
commit
b3f46b9565
@ -270,11 +270,12 @@ class phpbb_extension_finder
|
|||||||
* Finds all directories matching the configured options
|
* Finds all directories matching the configured options
|
||||||
*
|
*
|
||||||
* @param bool $cache Whether the result should be cached
|
* @param bool $cache Whether the result should be cached
|
||||||
|
* @param bool $extension_keys Whether the result should have extension name as array key
|
||||||
* @return array An array of paths to found directories
|
* @return array An array of paths to found directories
|
||||||
*/
|
*/
|
||||||
public function get_directories($cache = true)
|
public function get_directories($cache = true, $extension_keys = false)
|
||||||
{
|
{
|
||||||
return $this->find_with_root_path($cache, true);
|
return $this->find_with_root_path($cache, true, $extension_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -294,17 +295,26 @@ class phpbb_extension_finder
|
|||||||
* @param bool $cache Whether the result should be cached
|
* @param bool $cache Whether the result should be cached
|
||||||
* @param bool $is_dir Directories will be returned when true, only files
|
* @param bool $is_dir Directories will be returned when true, only files
|
||||||
* otherwise
|
* otherwise
|
||||||
|
* @param bool $extension_keys If true, result will be associative array
|
||||||
|
* with extension name as key
|
||||||
* @return array An array of paths to found items
|
* @return array An array of paths to found items
|
||||||
*/
|
*/
|
||||||
protected function find_with_root_path($cache = true, $is_dir = false)
|
protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false)
|
||||||
{
|
{
|
||||||
$items = $this->find($cache, $is_dir);
|
$items = $this->find($cache, $is_dir);
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($items as $item => $ext_name)
|
foreach ($items as $item => $ext_name)
|
||||||
|
{
|
||||||
|
if ($extension_keys)
|
||||||
|
{
|
||||||
|
$result[$ext_name] = $this->phpbb_root_path . $item;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$result[] = $this->phpbb_root_path . $item;
|
$result[] = $this->phpbb_root_path . $item;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -82,20 +82,24 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple
|
|||||||
$directories = array();
|
$directories = array();
|
||||||
|
|
||||||
$finder = $this->extension_manager->get_finder();
|
$finder = $this->extension_manager->get_finder();
|
||||||
foreach ($this->base_path_provider as $path)
|
foreach ($this->base_path_provider as $key => $paths)
|
||||||
{
|
{
|
||||||
|
if ($key == 'style')
|
||||||
|
{
|
||||||
|
foreach ($paths as $path)
|
||||||
|
{
|
||||||
|
$directories['style'][] = $path;
|
||||||
if ($path && !phpbb_is_absolute($path))
|
if ($path && !phpbb_is_absolute($path))
|
||||||
{
|
{
|
||||||
$directories = array_merge($directories, $finder
|
$result = $finder->directory('/' . $this->ext_dir_prefix . $path)
|
||||||
->directory('/' . $this->ext_dir_prefix . $path)
|
->get_directories(true, true);
|
||||||
->get_directories()
|
foreach ($result as $ext => $ext_path)
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->base_path_provider as $path)
|
|
||||||
{
|
{
|
||||||
$directories[] = $path;
|
$directories[$ext][] = $ext_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $directories;
|
return $directories;
|
||||||
@ -112,14 +116,4 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple
|
|||||||
$this->base_path_provider->set_styles($styles);
|
$this->base_path_provider->set_styles($styles);
|
||||||
$this->items = null;
|
$this->items = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the path to the main style passed into set_styles()
|
|
||||||
*
|
|
||||||
* @return string Main style path
|
|
||||||
*/
|
|
||||||
public function get_main_style_path()
|
|
||||||
{
|
|
||||||
return $this->base_path_provider->get_main_style_path();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ if (!defined('IN_PHPBB'))
|
|||||||
*/
|
*/
|
||||||
class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface
|
class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface
|
||||||
{
|
{
|
||||||
protected $main_style_name = '';
|
|
||||||
protected $paths = array();
|
protected $paths = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,25 +40,14 @@ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_p
|
|||||||
* Overwrites the current style paths
|
* Overwrites the current style paths
|
||||||
*
|
*
|
||||||
* The first element of the passed styles map, is considered the main
|
* The first element of the passed styles map, is considered the main
|
||||||
* style and can be retrieved through get_main_style_path().
|
* style.
|
||||||
*
|
*
|
||||||
* @param array $styles An array of style paths. The first element is the main style.
|
* @param array $styles An array of style paths. The first element is the main style.
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function set_styles(array $styles)
|
public function set_styles(array $styles)
|
||||||
{
|
{
|
||||||
$this->paths = $styles;
|
$this->paths = array('style' => $styles);
|
||||||
$this->main_style_path = $this->paths[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the path to the main style passed into set_styles()
|
|
||||||
*
|
|
||||||
* @return string Main style path
|
|
||||||
*/
|
|
||||||
public function get_main_style_path()
|
|
||||||
{
|
|
||||||
return $this->main_style_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,11 +39,4 @@ interface phpbb_style_path_provider_interface extends Traversable
|
|||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function set_styles(array $styles);
|
public function set_styles(array $styles);
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the path to the main style passed into set_styles()
|
|
||||||
*
|
|
||||||
* @return string Main style path
|
|
||||||
*/
|
|
||||||
public function get_main_style_path();
|
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,6 @@ class phpbb_style_resource_locator
|
|||||||
*/
|
*/
|
||||||
private $roots = array();
|
private $roots = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Index of the main style in the roots array.
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $main_root_id = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location of templates directory within style directories.
|
* Location of templates directory within style directories.
|
||||||
* Must have trailing slash. Empty if templates are stored in root
|
* Must have trailing slash. Empty if templates are stored in root
|
||||||
@ -69,17 +63,6 @@ class phpbb_style_resource_locator
|
|||||||
*/
|
*/
|
||||||
private $filenames = array();
|
private $filenames = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Set main style location (must have been added through set_paths first).
|
|
||||||
*
|
|
||||||
* @param string $style_path Path to style directory
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_main_style($style_path)
|
|
||||||
{
|
|
||||||
$this->main_root_id = array_search($style_path, $this->roots, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the list of style paths
|
* Sets the list of style paths
|
||||||
*
|
*
|
||||||
@ -95,16 +78,18 @@ class phpbb_style_resource_locator
|
|||||||
$this->roots = array();
|
$this->roots = array();
|
||||||
$this->files = array();
|
$this->files = array();
|
||||||
$this->filenames = array();
|
$this->filenames = array();
|
||||||
$this->main_root_id = 0;
|
|
||||||
|
|
||||||
foreach ($style_paths as $path)
|
foreach ($style_paths as $key => $paths)
|
||||||
|
{
|
||||||
|
foreach ($paths as $path)
|
||||||
{
|
{
|
||||||
// Make sure $path has no ending slash
|
// Make sure $path has no ending slash
|
||||||
if (substr($path, -1) === '/')
|
if (substr($path, -1) === '/')
|
||||||
{
|
{
|
||||||
$path = substr($path, 0, -1);
|
$path = substr($path, 0, -1);
|
||||||
}
|
}
|
||||||
$this->roots[] = $path;
|
$this->roots[$key][] = $path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +110,12 @@ class phpbb_style_resource_locator
|
|||||||
|
|
||||||
$this->filename[$handle] = $filename;
|
$this->filename[$handle] = $filename;
|
||||||
|
|
||||||
foreach ($this->roots as $root_index => $root)
|
foreach ($this->roots as $root_key => $root_paths)
|
||||||
{
|
{
|
||||||
$this->files[$root_index][$handle] = $root . '/' . $this->template_path . $filename;
|
foreach ($root_paths as $root_index => $root)
|
||||||
|
{
|
||||||
|
$this->files[$root_key][$root_index][$handle] = $root . '/' . $this->template_path . $filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,12 +162,12 @@ class phpbb_style_resource_locator
|
|||||||
public function get_virtual_source_file_for_handle($handle)
|
public function get_virtual_source_file_for_handle($handle)
|
||||||
{
|
{
|
||||||
// If we don't have a file assigned to this handle, die.
|
// If we don't have a file assigned to this handle, die.
|
||||||
if (!isset($this->files[$this->main_root_id][$handle]))
|
if (!isset($this->files['style'][0][$handle]))
|
||||||
{
|
{
|
||||||
trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR);
|
trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$source_file = $this->files[$this->main_root_id][$handle];
|
$source_file = $this->files['style'][0][$handle];
|
||||||
return $source_file;
|
return $source_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,26 +190,28 @@ class phpbb_style_resource_locator
|
|||||||
public function get_source_file_for_handle($handle)
|
public function get_source_file_for_handle($handle)
|
||||||
{
|
{
|
||||||
// If we don't have a file assigned to this handle, die.
|
// If we don't have a file assigned to this handle, die.
|
||||||
if (!isset($this->files[$this->main_root_id][$handle]))
|
if (!isset($this->files['style'][0][$handle]))
|
||||||
{
|
{
|
||||||
trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR);
|
trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// locate a source file that exists
|
// locate a source file that exists
|
||||||
$source_file = $this->files[0][$handle];
|
$source_file = $this->files['style'][0][$handle];
|
||||||
$tried = $source_file;
|
$tried = $source_file;
|
||||||
for ($i = 1, $n = count($this->roots); $i < $n && !file_exists($source_file); $i++)
|
foreach ($this->roots as $root_key => $root_paths)
|
||||||
{
|
{
|
||||||
$source_file = $this->files[$i][$handle];
|
foreach ($root_paths as $root_index => $root)
|
||||||
|
{
|
||||||
|
$source_file = $this->files[$root_key][$root_index][$handle];
|
||||||
|
if (file_exists($source_file))
|
||||||
|
{
|
||||||
|
return $source_file;
|
||||||
|
}
|
||||||
$tried .= ', ' . $source_file;
|
$tried .= ', ' . $source_file;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// search failed
|
// search failed
|
||||||
if (!file_exists($source_file))
|
|
||||||
{
|
|
||||||
trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR);
|
trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $source_file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,9 @@ class phpbb_style
|
|||||||
$paths[] = $this->get_style_path($dir);
|
$paths[] = $this->get_style_path($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add 'all' path, used as last fallback path by hooks and extensions
|
||||||
|
$paths[] = $this->get_style_path('all');
|
||||||
|
|
||||||
return $this->set_custom_style($style_name, $paths);
|
return $this->set_custom_style($style_name, $paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +116,6 @@ class phpbb_style
|
|||||||
|
|
||||||
$this->provider->set_styles($paths);
|
$this->provider->set_styles($paths);
|
||||||
$this->locator->set_paths($this->provider);
|
$this->locator->set_paths($this->provider);
|
||||||
$this->locator->set_main_style($this->provider->get_main_style_path());
|
|
||||||
|
|
||||||
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
|
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user