From d5896239068e1063970f398a12ffb5a0707fb286 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 7 Jul 2012 22:43:52 +0100 Subject: [ticket/10970] Paths of the form {FOO}/a/{BAR}/b parsed correctly A new method to handle this type of path was added and compile_tag_include, compile_tag_include_php and compile_tag_include_js were modified to use it appropriately. Tests were added for these three macros also. PHPBB3-10970 --- phpBB/includes/template/filter.php | 70 ++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index ad2e35de6a..a8985a771c 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -361,6 +361,52 @@ class phpbb_template_filter extends php_user_filter return $text_blocks; } + /** + * Parse paths of the form {FOO}/a/{BAR}/b + * Note: this method assumes at least one variable in the path, this should + * be checked before this method is called. + * + * @param string $path The path to parse + * @param string $include_type The type of template function to call + * @return string An appropriately formatted string to include in the + * template + */ + private function parse_dynamic_path($path, $include_type) + { + $segments = explode('/', $path); + $is_expr = true; + $str = array(); + $vars = array(); + + foreach ($segments as $segment) + { + 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/'"; + } + } + + // 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); }'; + } + else + { + return ''; + } + } + /** * Compile variables * @@ -774,15 +820,9 @@ class phpbb_template_filter extends php_user_filter private function compile_tag_include($tag_args) { // Process dynamic includes - if ($tag_args[0] == '{') + if (strpos($tag_args, '{') !== false) { - $var = $this->get_varref($tag_args, $is_expr); - - // Make sure someone didn't try to include S_FIRST_ROW or similar - if (!$is_expr) - { - return "if (isset($var)) { \$_template->_tpl_include($var); }"; - } + return $this->parse_dynamic_path($tag_args, '_tpl_include'); } return "\$_template->_tpl_include('$tag_args');"; @@ -796,6 +836,11 @@ class phpbb_template_filter extends php_user_filter */ private function compile_tag_include_php($tag_args) { + if (strpos($tag_args, '{') !== false) + { + return $this->parse_dynamic_path($tag_args, '_php_include'); + } + return "\$_template->_php_include('$tag_args');"; } @@ -883,14 +928,9 @@ class phpbb_template_filter extends php_user_filter private function compile_tag_include_js($tag_args) { // Process dynamic includes - if ($tag_args[0] == '{') + if (strpos($tag_args, '{') !== false) { - $var = $this->get_varref($tag_args, $is_expr); - if (!$is_expr) - { - return " \$_template->_js_include($var, true);"; - } - return ''; + return $this->parse_dynamic_path($tag_args, '_js_include'); } // Locate file -- cgit v1.2.1 From d0cb5bb093d09a15f422f84e19d781a8260512a0 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 15:12:08 +0100 Subject: [ticket/10970] Added support for forms such as {FOO}bar.{EXT} PHPBB3-10970 --- phpBB/includes/template/filter.php | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'phpBB/includes') 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 { -- cgit v1.2.1 From 47c67b6d021c6488106bb0d327600b35e08bf94b Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 24 Jul 2012 11:54:46 +0100 Subject: [ticket/10970] Added missing initialisations and modified the regex Non-existent variables now become empty strings. PHPBB3-10970 --- phpBB/includes/template/filter.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 568727be82..596b83cc75 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -375,10 +375,13 @@ class phpbb_template_filter extends php_user_filter { $matches = array(); $replace = array(); + $vars = array(); + $is_expr = true; - preg_match_all('/{[^}]+}/', $path, $matches); + preg_match_all('#\{((?:' . self::REGEX_NS . '\.)*)(\$)?(' . self::REGEX_VAR . ')\}#', $path, $matches); foreach ($matches[0] as $var_str) { + $tmp_is_expr = false; $var = $this->get_varref($var_str, $tmp_is_expr); $is_expr = $is_expr && $tmp_is_expr; $vars[] = "isset($var)"; @@ -387,7 +390,7 @@ class phpbb_template_filter extends php_user_filter if (!$is_expr) { - return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true); }"; + return " \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true);"; } else { -- cgit v1.2.1 From 003220dc7c781df38fde75f0007c3b3e48803162 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 24 Jul 2012 11:55:38 +0100 Subject: [ticket/10970] Fixed a problem with prepending root paths PHPBB3-10970 --- phpBB/includes/template/template.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 8ab3c44be3..861a5e28e7 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -503,7 +503,11 @@ class phpbb_template // Locate file if ($locate) { - $file = $this->locator->get_first_file_location(array($file), true, true); + $located = $this->locator->get_first_file_location(array($file), false, true); + if ($located) + { + $file = $located; + } } else if ($relative) { -- cgit v1.2.1 From 02ccf392fa11c7c2210f5ba1e8923e82e62a66cf Mon Sep 17 00:00:00 2001 From: Fyorl Date: Fri, 10 Aug 2012 13:42:38 +0100 Subject: [ticket/10970] Removed unused $vars PHPBB3-10970 --- phpBB/includes/template/filter.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 596b83cc75..e4c3184565 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -375,7 +375,6 @@ class phpbb_template_filter extends php_user_filter { $matches = array(); $replace = array(); - $vars = array(); $is_expr = true; preg_match_all('#\{((?:' . self::REGEX_NS . '\.)*)(\$)?(' . self::REGEX_VAR . ')\}#', $path, $matches); @@ -384,7 +383,6 @@ class phpbb_template_filter extends php_user_filter $tmp_is_expr = false; $var = $this->get_varref($var_str, $tmp_is_expr); $is_expr = $is_expr && $tmp_is_expr; - $vars[] = "isset($var)"; $replace[] = "' . $var . '"; } -- cgit v1.2.1 From e9bdca7a8bc8c36b6d55806b1337e5d32409cb9d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 19 Aug 2012 17:12:08 +0800 Subject: [ticket/10970] Added newline in docblock PHPBB3-10970 --- phpBB/includes/template/filter.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index e4c3184565..471ca0c777 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -363,6 +363,7 @@ class phpbb_template_filter extends php_user_filter /** * Parse paths of the form {FOO}/a/{BAR}/b + * * Note: this method assumes at least one variable in the path, this should * be checked before this method is called. * -- cgit v1.2.1 From a05f354fdf903d00e85d8e4ad1d50f9ef906534d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 10 Nov 2012 09:36:02 +0000 Subject: [ticket/10970] Added extra documentation to parse_dynamic_path. PHPBB3-10970 --- phpBB/includes/template/filter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 471ca0c777..3e90190db7 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -370,7 +370,8 @@ class phpbb_template_filter extends php_user_filter * @param string $path The path to parse * @param string $include_type The type of template function to call * @return string An appropriately formatted string to include in the - * template + * template or an empty string if an expression like S_FIRST_ROW was + * incorrectly used */ private function parse_dynamic_path($path, $include_type) { -- cgit v1.2.1