diff --git a/change_log.txt b/change_log.txt
index 8dc968b6..1505c073 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,6 +1,7 @@
===== 3.1.22-dev ===== (xx.xx.2015)
05.05.2015
- optimization on cache update when main template is modified
+ - optimization move handling from parser to new compiler module
05.05.2015
- bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex
index d988c12b..c41fe10b 100644
--- a/lexer/smarty_internal_templatelexer.plex
+++ b/lexer/smarty_internal_templatelexer.plex
@@ -61,6 +61,12 @@ class Smarty_Internal_Templatelexer
* @var bool
*/
public $is_phpScript = false;
+ /**
+ * php code type
+ *
+ * @var string
+ */
+ public $phpType = '';
/**
* escaped left delimiter
*
@@ -227,11 +233,12 @@ class Smarty_Internal_Templatelexer
namespace = /([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+/
all = /[\S\s]+/
emptyjava = /\{\}/
- phpstarttag = /(' tag (only for PHP)
-template_element(res)::= PHPENDSCRIPT(st). {
- if (!$this->lex->is_phpScript) {
- res = new Smarty_Internal_ParseTree_Text($this, st);
+ // php tags
+template_element(res)::= PHP(o). {
+ $code = $this->compiler->compileTag('private_php',array(array('code' => o), array('type' => $this->lex->phpType )),array());
+ if ($this->compiler->has_code && !empty($code)) {
+ $tmp =''; foreach ($this->compiler->prefix_code as $code) {$tmp.=$code;} $this->compiler->prefix_code=array();
+ res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode($tmp.$code,true));
} else {
- $this->lex->is_phpScript = false;
- if ($this->php_handling == Smarty::PHP_PASSTHRU) {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- } elseif ($this->php_handling == Smarty::PHP_QUOTE) {
- res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars(st, ENT_QUOTES));
- } elseif ($this->php_handling == Smarty::PHP_ALLOW) {
- res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('?>', true));
- } elseif ($this->php_handling == Smarty::PHP_REMOVE) {
- res = null;
- }
+ res = null;
}
}
- // '<%' tag
-template_element(res)::= ASPSTARTTAG(st). {
- if ($this->php_handling == Smarty::PHP_PASSTHRU) {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- } elseif ($this->php_handling == Smarty::PHP_QUOTE) {
- res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars(st, ENT_QUOTES));
- } elseif ($this->php_handling == Smarty::PHP_ALLOW) {
- if ($this->asp_tags) {
- if (!($this->smarty instanceof SmartyBC)) {
- $this->compiler->trigger_template_error (self::Err3);
- }
- res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('<%', true));
- } else {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- }
- } elseif ($this->php_handling == Smarty::PHP_REMOVE) {
- if ($this->asp_tags) {
- res = null;
- } else {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- }
- }
-}
-
- // '%>' tag
-template_element(res)::= ASPENDTAG(st). {
- if ($this->php_handling == Smarty::PHP_PASSTHRU) {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- } elseif ($this->php_handling == Smarty::PHP_QUOTE) {
- res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars('%>', ENT_QUOTES));
- } elseif ($this->php_handling == Smarty::PHP_ALLOW) {
- if ($this->asp_tags) {
- res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('%>', true));
- } else {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- }
- } elseif ($this->php_handling == Smarty::PHP_REMOVE) {
- if ($this->asp_tags) {
- res = null;
- } else {
- res = new Smarty_Internal_ParseTree_Text($this, st);
- }
- }
-}
// XML tag
-template_element(res)::= XMLTAG. {
+template_element(res)::= XMLTAG(x). {
$this->compiler->tag_nocache = true;
- $this->is_xml = true;
+ $xml = x;
$save = $this->template->has_nocache_code;
- res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode("", $this->compiler, true));
+ res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode("", $this->compiler, true));
$this->template->has_nocache_code = $save;
}
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 8c41f7ad..7b15be37 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
- const SMARTY_VERSION = '3.1.22-dev/25';
+ const SMARTY_VERSION = '3.1.22-dev/26';
/**
* define variable scopes
diff --git a/libs/SmartyBC.class.php b/libs/SmartyBC.class.php
index cec94674..76dd8bd0 100644
--- a/libs/SmartyBC.class.php
+++ b/libs/SmartyBC.class.php
@@ -52,8 +52,6 @@ class SmartyBC extends Smarty
public function __construct(array $options = array())
{
parent::__construct($options);
- // register {php} tag
- $this->registerPlugin('block', 'php', 'smarty_php_tag');
}
/**
@@ -115,10 +113,10 @@ class SmartyBC extends Smarty
/**
* Registers object to be used in templates
*
- * @param string $object name of template object
- * @param object $object_impl the referenced PHP object to register
- * @param array $allowed list of allowed methods (empty = all)
- * @param boolean $smarty_args smarty argument format, else traditional
+ * @param string $object name of template object
+ * @param object $object_impl the referenced PHP object to register
+ * @param array $allowed list of allowed methods (empty = all)
+ * @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of methods that are block format
*
* @throws SmartyException
@@ -448,20 +446,3 @@ class SmartyBC extends Smarty
trigger_error("Smarty error: $error_msg", $error_type);
}
}
-
-/**
- * Smarty {php}{/php} block function
- *
- * @param array $params parameter list
- * @param string $content contents of the block
- * @param object $template template object
- * @param boolean &$repeat repeat flag
- *
- * @return string content re-formatted
- */
-function smarty_php_tag($params, $content, $template, &$repeat)
-{
- eval($content);
-
- return '';
-}
diff --git a/libs/sysplugins/smarty_internal_compile_private_php.php b/libs/sysplugins/smarty_internal_compile_private_php.php
new file mode 100644
index 00000000..a6ae8fac
--- /dev/null
+++ b/libs/sysplugins/smarty_internal_compile_private_php.php
@@ -0,0 +1,92 @@
+getAttributes($compiler, $args);
+ $compiler->has_code = false;
+ $this->asp_tags = (ini_get('asp_tags') != '0');
+ if ($_attr['type'] == 'tag' && !($compiler->smarty instanceof SmartyBC)) {
+ $compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', $compiler->lex->taglineno);
+ }
+ if ($_attr['type'] != 'tag') {
+ if (isset($compiler->smarty->security_policy)) {
+ $this->php_handling = $compiler->smarty->security_policy->php_handling;
+ } else {
+ $this->php_handling = $compiler->smarty->php_handling;
+ }
+ if ($this->php_handling == Smarty::PHP_REMOVE) {
+ $output = preg_replace(array('#^(<\?(?:php|=)?)|(<%)|(