From 1c8c03c4dbd74f2f2abf6d2968bc33a234df5a4e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 25 Jun 2013 16:51:50 -0500 Subject: [PATCH] [feature/twig] INCLUDEPHP token abs paths & fix test PHPBB3-11598 --- phpBB/includes/template/twig/node/includephp.php | 14 +++++++++++--- tests/template/includephp_test.php | 13 ++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/template/twig/node/includephp.php b/phpBB/includes/template/twig/node/includephp.php index 6e77fac55d..5315d136d7 100644 --- a/phpBB/includes/template/twig/node/includephp.php +++ b/phpBB/includes/template/twig/node/includephp.php @@ -50,9 +50,17 @@ class phpbb_template_twig_node_includephp extends Twig_Node $expr = preg_replace('#{{ ([a-zA-Z0-9_]+) }}#', '\' . ((isset($context["$1"])) ? $context["$1"] : null) . \'', $this->getNode('expr')->getAttribute('value')); $compiler - ->write("require(\$this->getEnvironment()->get_phpbb_root_path() . '") - ->raw($expr) - ->raw("');\n") + ->write("if (phpbb_is_absolute('$expr')) {\n") + ->indent() + ->write("require('$expr');\n") + ->outdent() + ->write("} else {\n") + ->indent() + ->write("require(\$this->getEnvironment()->get_phpbb_root_path() . '") + ->raw($expr) + ->raw("');\n") + ->outdent() + ->write("}\n") ; if ($this->getAttribute('ignore_missing')) { diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index f1012b6939..edf1e40bb8 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -15,9 +15,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case { $this->setup_engine(array('tpl_allow_php' => true)); - $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - - $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); + $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_relative.html')); $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); @@ -27,9 +25,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case { $this->setup_engine(array('tpl_allow_php' => true)); - $cache_file = $this->template->cachepath . 'includephp_variables.html.php'; - - $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file); + $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_variables.html')); $this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); @@ -37,7 +33,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case public function test_includephp_absolute() { - $path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc'; + $path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc'; $this->assertTrue(phpbb_is_absolute($path_to_php)); $template_text = "Path is absolute.\n"; @@ -49,9 +45,8 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); $this->style->set_custom_style('tests', $cache_dir, array(), ''); - $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; - $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); + $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php"); $this->template->set_filenames(array('test' => 'includephp_absolute.html')); $this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");