mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-16 12:29:43 +02:00
[ticket/10733] Extending get_source_file_for_handle
Extending resource locator's function get_source_file_for_handle to find all files. This modified function should be used by template events to locate all templates before compiling them. PHPBB3-10733
This commit is contained in:
parent
b3f46b9565
commit
2ce73baeab
@ -185,9 +185,12 @@ class phpbb_style_resource_locator
|
|||||||
* handle to a path without any filesystem or styles tree checks.
|
* handle to a path without any filesystem or styles tree checks.
|
||||||
*
|
*
|
||||||
* @param string $handle Template handle (i.e. "friendly" template name)
|
* @param string $handle Template handle (i.e. "friendly" template name)
|
||||||
|
* @param bool $find_all If true, each root path will be checked and function
|
||||||
|
* will return array of files instead of string and will not
|
||||||
|
* trigger a error if template does not exist
|
||||||
* @return string Source file path
|
* @return string Source file path
|
||||||
*/
|
*/
|
||||||
public function get_source_file_for_handle($handle)
|
public function get_source_file_for_handle($handle, $find_all = false)
|
||||||
{
|
{
|
||||||
// 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['style'][0][$handle]))
|
if (!isset($this->files['style'][0][$handle]))
|
||||||
@ -198,20 +201,40 @@ class phpbb_style_resource_locator
|
|||||||
// locate a source file that exists
|
// locate a source file that exists
|
||||||
$source_file = $this->files['style'][0][$handle];
|
$source_file = $this->files['style'][0][$handle];
|
||||||
$tried = $source_file;
|
$tried = $source_file;
|
||||||
|
$found = false;
|
||||||
|
$found_all = array();
|
||||||
foreach ($this->roots as $root_key => $root_paths)
|
foreach ($this->roots as $root_key => $root_paths)
|
||||||
{
|
{
|
||||||
foreach ($root_paths as $root_index => $root)
|
foreach ($root_paths as $root_index => $root)
|
||||||
{
|
{
|
||||||
$source_file = $this->files[$root_key][$root_index][$handle];
|
$source_file = $this->files[$root_key][$root_index][$handle];
|
||||||
|
$tried .= ', ' . $source_file;
|
||||||
if (file_exists($source_file))
|
if (file_exists($source_file))
|
||||||
{
|
{
|
||||||
return $source_file;
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($found)
|
||||||
|
{
|
||||||
|
if ($find_all)
|
||||||
|
{
|
||||||
|
$found_all[] = $source_file;
|
||||||
|
$found = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$tried .= ', ' . $source_file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// search failed
|
// search failed
|
||||||
trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR);
|
if (!$found && !$find_all)
|
||||||
|
{
|
||||||
|
trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($find_all) ? $found_all : $source_file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user