From f53af6715b0e196768397a1a591c802c6fcf0f07 Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 1 Feb 2001 21:11:14 +0000 Subject: [PATCH] *** empty log message *** --- Smarty.class.php | 19 ++++++++++++------- demo/index.php | 11 +++++++++++ demo/templates/index.tpl | 5 +++++ index.php | 11 +++++++++++ libs/Smarty.class.php | 19 ++++++++++++------- templates/index.tpl | 5 +++++ 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Smarty.class.php b/Smarty.class.php index 414b29cc..5b316814 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -102,6 +102,7 @@ class Smarty var $_literal_blocks = array(); // keeps literal template blocks var $_current_file = null; // the current template being compiled var $_current_line_no = 1; // line number for error messages + var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' /*======================================================================*\ @@ -483,10 +484,14 @@ class Smarty return true; } +/*======================================================================*\ + Function: _process_cached_inserts + Purpose: Replace cached inserts with the actual results +\*======================================================================*/ function _process_cached_inserts($results) { - preg_match_all('!\{\{\{insert_cache (.*)\}\}\}!Uis', $results, $match); - + preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', + $results, $match); list($cached_inserts, $insert_args) = $match; for ($i = 0; $i < count($cached_inserts); $i++) { @@ -505,7 +510,7 @@ class Smarty $function_name = 'insert_' . $name; $replace = $function_name($arg_list); - + $results = str_replace($cached_inserts[$i], $replace, $results); } @@ -622,7 +627,7 @@ class Smarty } if($this->caching) - return "{{{insert_cache $tag_args}}}"; + return $this->_smarty_md5."{insert_cache $tag_args}".$this->_smarty_md5; foreach ($attrs as $arg_name => $arg_value) { if ($arg_name == 'name') continue; @@ -909,8 +914,8 @@ class Smarty )+ | [=] /x', $tag_args, $match); - $tokens = $match[0]; - $var_delims = array('$', '#', '%'); + $tokens = $match[0]; + $var_delims = array('$', '#', '%'); $attrs = array(); /* Parse state: @@ -924,7 +929,7 @@ class Smarty case 0: /* If the token is a valid identifier, we set attribute name and go to state 1. */ - if (preg_match('!\w+!', $token)) { + if (preg_match('!^\w+$!', $token)) { $attr_name = $token; $state = 1; } else diff --git a/demo/index.php b/demo/index.php index a0b5ac15..21a70831 100644 --- a/demo/index.php +++ b/demo/index.php @@ -4,6 +4,10 @@ require("Smarty.class.php"); $smarty = new Smarty; +$smarty->caching = false; + +$smarty->assign(now, time()); + $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); $smarty->assign("FirstName",array("John","Mary","James","Henry")); $smarty->assign("LastName",array("Doe","Smith","Johnson","Case")); @@ -15,4 +19,11 @@ $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => $smarty->display("index.tpl"); +function insert_foo($args) +{ + extract($args); + + return "test $arg1"; +} + ?> diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl index dd9d0b93..aa01ba3e 100644 --- a/demo/templates/index.tpl +++ b/demo/templates/index.tpl @@ -46,3 +46,8 @@ testing strip tags {/strip} + +test: {$now|date_format:"%I:%M %p"} + +{insert name = foo arg1=5} + diff --git a/index.php b/index.php index a0b5ac15..21a70831 100644 --- a/index.php +++ b/index.php @@ -4,6 +4,10 @@ require("Smarty.class.php"); $smarty = new Smarty; +$smarty->caching = false; + +$smarty->assign(now, time()); + $smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); $smarty->assign("FirstName",array("John","Mary","James","Henry")); $smarty->assign("LastName",array("Doe","Smith","Johnson","Case")); @@ -15,4 +19,11 @@ $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => $smarty->display("index.tpl"); +function insert_foo($args) +{ + extract($args); + + return "test $arg1"; +} + ?> diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 414b29cc..5b316814 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -102,6 +102,7 @@ class Smarty var $_literal_blocks = array(); // keeps literal template blocks var $_current_file = null; // the current template being compiled var $_current_line_no = 1; // line number for error messages + var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' /*======================================================================*\ @@ -483,10 +484,14 @@ class Smarty return true; } +/*======================================================================*\ + Function: _process_cached_inserts + Purpose: Replace cached inserts with the actual results +\*======================================================================*/ function _process_cached_inserts($results) { - preg_match_all('!\{\{\{insert_cache (.*)\}\}\}!Uis', $results, $match); - + preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', + $results, $match); list($cached_inserts, $insert_args) = $match; for ($i = 0; $i < count($cached_inserts); $i++) { @@ -505,7 +510,7 @@ class Smarty $function_name = 'insert_' . $name; $replace = $function_name($arg_list); - + $results = str_replace($cached_inserts[$i], $replace, $results); } @@ -622,7 +627,7 @@ class Smarty } if($this->caching) - return "{{{insert_cache $tag_args}}}"; + return $this->_smarty_md5."{insert_cache $tag_args}".$this->_smarty_md5; foreach ($attrs as $arg_name => $arg_value) { if ($arg_name == 'name') continue; @@ -909,8 +914,8 @@ class Smarty )+ | [=] /x', $tag_args, $match); - $tokens = $match[0]; - $var_delims = array('$', '#', '%'); + $tokens = $match[0]; + $var_delims = array('$', '#', '%'); $attrs = array(); /* Parse state: @@ -924,7 +929,7 @@ class Smarty case 0: /* If the token is a valid identifier, we set attribute name and go to state 1. */ - if (preg_match('!\w+!', $token)) { + if (preg_match('!^\w+$!', $token)) { $attr_name = $token; $state = 1; } else diff --git a/templates/index.tpl b/templates/index.tpl index dd9d0b93..aa01ba3e 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -46,3 +46,8 @@ testing strip tags {/strip} + +test: {$now|date_format:"%I:%M %p"} + +{insert name = foo arg1=5} +