From d0cb5bb093d09a15f422f84e19d781a8260512a0 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 15:12:08 +0100 Subject: [PATCH] [ticket/10970] Added support for forms such as {FOO}bar.{EXT} PHPBB3-10970 --- phpBB/includes/template/filter.php | 30 +++++++--------------- tests/template/template_includejs_test.php | 3 ++- tests/template/templates/includejs.html | 1 + 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index a8985a771c..568727be82 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -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 { diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index d8c7170e94..22b020208b 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -23,10 +23,11 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes '', '', '', + '', ); // 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); } } diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html index dbcf6e04a8..ef73700eeb 100644 --- a/tests/template/templates/includejs.html +++ b/tests/template/templates/includejs.html @@ -4,4 +4,5 @@ + {SCRIPTS}