aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--phpBB/includes/template/twig/extension.php14
-rw-r--r--phpBB/includes/template/twig/lexer.php7
-rw-r--r--phpBB/includes/template/twig/node/expression/binary/equalequal.php16
-rw-r--r--phpBB/includes/template/twig/node/expression/binary/notequalequal.php16
-rw-r--r--phpBB/includes/template/twig/twig.php6
6 files changed, 55 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index c757210654..06b13923f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
*~
/phpunit.xml
+/phpBB/cache/twig/*
/phpBB/cache/*.html
/phpBB/cache/*.php
/phpBB/cache/*.lock
diff --git a/phpBB/includes/template/twig/extension.php b/phpBB/includes/template/twig/extension.php
index c121a21800..718909ee50 100644
--- a/phpBB/includes/template/twig/extension.php
+++ b/phpBB/includes/template/twig/extension.php
@@ -39,8 +39,20 @@ class phpbb_template_twig_extension extends Twig_Extension
return array(
array(),
array(
+ // @todo check if all these are needed (or others)
'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
- '!==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ 'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ '===' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_equalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ '!==' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_notequalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ 'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
),
);
}
diff --git a/phpBB/includes/template/twig/lexer.php b/phpBB/includes/template/twig/lexer.php
index 71e3e9c27e..ea161bf730 100644
--- a/phpBB/includes/template/twig/lexer.php
+++ b/phpBB/includes/template/twig/lexer.php
@@ -45,7 +45,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer
// This strips the $ inside of a tag directly after the token, which was used in <!-- DEFINE $NAME
$code = preg_replace('#<!-- DEFINE \$(.*)-->#', '<!-- DEFINE $1-->', $code);
- // This strips the . inside of a tag directly before a variable name, which was used in <!-- IF .blah
+ // This strips the . or $ inside of a tag directly before a variable name, which was used in <!-- IF .blah
$code = preg_replace_callback('#<!-- IF((.*)[\s][\$|\.]([^\s]+)(.*))-->#', array($this, 'tag_if_cleanup'), $code);
// Replace all of our starting tokens, <!-- TOKEN --> with Twig style, {% TOKEN %}
@@ -61,12 +61,13 @@ class phpbb_template_twig_lexer extends Twig_Lexer
/**
* preg_replace_callback to clean up IF statements
*
- * This strips the . inside of a tag directly before a variable name, which was used in <!-- IF .blah
+ * This strips the . or $ inside of a tag directly before a variable name.
+ * Was used in <!-- IF .blah or <!-- IF $BLAH
*
* @param mixed $matches
*/
protected function tag_if_cleanup($matches)
{
- return '<!-- IF ' . preg_replace('#\s\.([a-zA-Z_0-9]+)#', ' $1', $matches[1]) . ' -->';
+ return '<!-- IF ' . preg_replace('#\s[\.|\$]([a-zA-Z_0-9]+)#', ' $1', $matches[1]) . ' -->';
}
}
diff --git a/phpBB/includes/template/twig/node/expression/binary/equalequal.php b/phpBB/includes/template/twig/node/expression/binary/equalequal.php
new file mode 100644
index 0000000000..3a0c79c839
--- /dev/null
+++ b/phpBB/includes/template/twig/node/expression/binary/equalequal.php
@@ -0,0 +1,16 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_template_twig_node_expression_binary_equalequal extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('===');
+ }
+}
diff --git a/phpBB/includes/template/twig/node/expression/binary/notequalequal.php b/phpBB/includes/template/twig/node/expression/binary/notequalequal.php
new file mode 100644
index 0000000000..b53bc56b2d
--- /dev/null
+++ b/phpBB/includes/template/twig/node/expression/binary/notequalequal.php
@@ -0,0 +1,16 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_template_twig_node_expression_binary_notequalequal extends Twig_Node_Expression_Binary
+{
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('!==');
+ }
+}
diff --git a/phpBB/includes/template/twig/twig.php b/phpBB/includes/template/twig/twig.php
index a067827f70..e12b62be63 100644
--- a/phpBB/includes/template/twig/twig.php
+++ b/phpBB/includes/template/twig/twig.php
@@ -108,13 +108,17 @@ class phpbb_template_twig implements phpbb_template
$this->extension_manager = $extension_manager;
$loader = new Twig_Loader_Filesystem($phpbb_root_path . 'styles/prosilver/template/');
+ //$loader = new Twig_Loader_Filesystem($phpbb_root_path . 'adm/style/');
$this->twig = new Twig_Environment($loader, array(
- //'cache' => $phpbb_root_path . 'cache/twig/',
+ 'cache' => $phpbb_root_path . 'cache/twig/',
'debug' => true,
'auto_reload' => true,
'autoescape' => false,
));
+ // Clear previous cache files (while WIP)
+ $this->twig->clearCacheFiles();
+
$this->twig->addExtension(new phpbb_template_twig_extension);
$lexer = new phpbb_template_twig_lexer($this->twig);