mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-13 04:04:12 +02:00
[ticket/10735] Changing locator paths structure
Changing locator paths to 2 dimensional array PHPBB3-10735
This commit is contained in:
@@ -38,12 +38,6 @@ class phpbb_style_resource_locator
|
||||
*/
|
||||
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.
|
||||
* Must have trailing slash. Empty if templates are stored in root
|
||||
@@ -69,17 +63,6 @@ class phpbb_style_resource_locator
|
||||
*/
|
||||
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
|
||||
*
|
||||
@@ -95,16 +78,18 @@ class phpbb_style_resource_locator
|
||||
$this->roots = array();
|
||||
$this->files = array();
|
||||
$this->filenames = array();
|
||||
$this->main_root_id = 0;
|
||||
|
||||
foreach ($style_paths as $path)
|
||||
foreach ($style_paths as $key => $paths)
|
||||
{
|
||||
// Make sure $path has no ending slash
|
||||
if (substr($path, -1) === '/')
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$path = substr($path, 0, -1);
|
||||
// Make sure $path has no ending slash
|
||||
if (substr($path, -1) === '/')
|
||||
{
|
||||
$path = substr($path, 0, -1);
|
||||
}
|
||||
$this->roots[$key][] = $path;
|
||||
}
|
||||
$this->roots[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +110,12 @@ class phpbb_style_resource_locator
|
||||
|
||||
$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)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
$source_file = $this->files[$this->main_root_id][$handle];
|
||||
$source_file = $this->files['style'][0][$handle];
|
||||
return $source_file;
|
||||
}
|
||||
|
||||
@@ -202,26 +190,28 @@ class phpbb_style_resource_locator
|
||||
public function get_source_file_for_handle($handle)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// locate a source file that exists
|
||||
$source_file = $this->files[0][$handle];
|
||||
$source_file = $this->files['style'][0][$handle];
|
||||
$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];
|
||||
$tried .= ', ' . $source_file;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return $source_file;
|
||||
trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user