[ticket/10970] Added support for forms such as {FOO}bar.{EXT}

PHPBB3-10970
This commit is contained in:
Fyorl 2012-07-08 15:12:08 +01:00
parent d589623906
commit d0cb5bb093
3 changed files with 12 additions and 22 deletions

View file

@ -373,33 +373,21 @@ class phpbb_template_filter extends php_user_filter
*/
private function parse_dynamic_path($path, $include_type)
{
$segments = explode('/', $path);
$is_expr = true;
$str = array();
$vars = array();
$matches = array();
$replace = array();
foreach ($segments as $segment)
preg_match_all('/{[^}]+}/', $path, $matches);
foreach ($matches[0] as $var_str)
{
if ($segment[0] === '{')
{
$var = $this->get_varref($segment, $tmp_is_expr);
$is_expr = $is_expr && $tmp_is_expr;
$vars[] = "isset($var)";
$str[] = "$var . '/'";
}
else
{
$str[] = "'$segment/'";
}
$var = $this->get_varref($var_str, $tmp_is_expr);
$is_expr = $is_expr && $tmp_is_expr;
$vars[] = "isset($var)";
$replace[] = "' . $var . '";
}
// Remove trailing slash from last element
$last = array_pop($str);
$str[] = str_replace('/', '', $last);
if (!$is_expr)
{
return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type(" . implode(' . ', $str) . ', true); }';
return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true); }";
}
else
{

View file

@ -23,10 +23,11 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes
'<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>',
'<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
'<script src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>',
'<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
);
// Run test
$cache_file = $this->template->cachepath . 'includejs.html.php';
$this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir'), array(), array(), implode('', $scripts), $cache_file);
$this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file);
}
}

View file

@ -4,4 +4,5 @@
<!-- INCLUDEJS {$TEST} -->
<!-- INCLUDEJS subdir/{PARENT} -->
<!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} -->
<!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} -->
{SCRIPTS}