diff --git a/change_log.txt b/change_log.txt index 15151175..deaf20af 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,6 @@ - +10/01/2009 +- reactivated PHP resource for simple PHP templates. Must set allow_php_templates = true to enable +- {PHP} tag can be enabled by allow_php_tag = true 09/30/2009 - fixed handling template_exits methode for all resource types diff --git a/demo/index.php b/demo/index.php index 0da1b9d8..8bada438 100644 --- a/demo/index.php +++ b/demo/index.php @@ -6,13 +6,11 @@ $smarty = new Smarty; //$smarty->force_compile = true; -//$smarty->debugging = true; +$smarty->debugging = true; $smarty->caching = true; -$smarty->caching_lifetime = 120; +$smarty->cache_lifetime = 120; - - -$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill"); +$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill",true); $smarty->assign("FirstName",array("John","Mary","James","Henry")); $smarty->assign("LastName",array("Doe","Smith","Johnson","Case")); $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"), diff --git a/demo/index_php_template.php b/demo/index_php_template.php index f7971ea5..2f95bf67 100644 --- a/demo/index_php_template.php +++ b/demo/index_php_template.php @@ -5,7 +5,6 @@ * @package SmartyTestScripts */ require('../libs/Smarty.class.php'); -ini_set('short_open_tag','1'); class Person { @@ -31,11 +30,13 @@ ini_set('short_open_tag','1'); } $smarty = new Smarty(); +$smarty->allow_php_templates= true; $smarty->force_compile = false; -$smarty->caching = false; -$smarty->cache_lifetime = 10; +$smarty->caching = true; +$smarty->cache_lifetime = 100; +//$smarty->debugging = true; -$smarty->assign('foo',''); +$smarty->assign('foo',"'bar'"); $person = new Person; diff --git a/demo/templates/index_view.php b/demo/templates/index_view.php index ad760aa1..833fe961 100644 --- a/demo/templates/index_view.php +++ b/demo/templates/index_view.php @@ -1,11 +1,13 @@ PHP file test $foo is -
Test modifier chaining -trim()->escape('html')?> +
Test functions +
Test objects -setName('Paul')->setAge(39)->introduce()->trim()->truncate(10)?> +setName('Paul')->setAge(39)->introduce()?>
Test Arrays -truncate(5)?> -
Function -trim($array['a']['aa'])->truncate(10)?> -DONE + +
function time + +
nocache function time +';?> +
DONE diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index cb750687..89debee6 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -135,6 +135,8 @@ class Smarty extends Smarty_Internal_TemplateBase { public $right_delimiter = "}"; // security public $php_handling = SMARTY_PHP_PASSTHRU; + public $allow_php_tag = false; + public $allow_php_templates = false; public $security = false; public $security_policy = null; public $security_handler = null; diff --git a/libs/plugins/block.php.php b/libs/plugins/block.php.php index 371d4a77..cb7d5cba 100644 --- a/libs/plugins/block.php.php +++ b/libs/plugins/block.php.php @@ -25,9 +25,9 @@ function smarty_block_php($params, $content, $smarty, &$repeat, $template) $sec_obj = $smarty; } if (is_null($content)) { - if ($sec_obj->php_handling != SMARTY_PHP_ALLOW) { - trigger_error("{php} is deprecated, set php_handling = SMARTY_PHP_ALLOW to enable",E_USER_WARNING); - } + if (!$smarty->allow_php_tag) { + trigger_error("{php} is deprecated, set allow_php_tag = true to enable", E_USER_WARNING); + } return; } diff --git a/libs/sysplugins/internal.resource_stream.php b/libs/sysplugins/internal.resource_stream.php index 27527825..bfcf9167 100644 --- a/libs/sysplugins/internal.resource_stream.php +++ b/libs/sysplugins/internal.resource_stream.php @@ -30,7 +30,7 @@ class Smarty_Internal_Resource_Stream { */ public function isExisting($template) { - if ($template->getTemplateSource() === false) { + if ($template->getTemplateSource() == '') { return false; } else { return true; diff --git a/libs/sysplugins/internal.template.php b/libs/sysplugins/internal.template.php index fdae24f3..c00b9d63 100644 --- a/libs/sysplugins/internal.template.php +++ b/libs/sysplugins/internal.template.php @@ -461,10 +461,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { } } } else { - throw new Exception("Resource '$this->resource_type' must use compiler"); + if (is_callable(array($this->resource_objects[$this->resource_type], 'renderUncompiled'))) { + $_start_time = $this->_get_time(); + ob_start(); + $this->resource_objects[$this->resource_type]->renderUncompiled($this); + } else { + throw new Exception("Resource '$this->resource_type' must have 'renderUncompiled' methode"); + } } - $this->render_time += $this->_get_time() - $_start_time; $this->rendered_content = ob_get_clean(); + $this->render_time += $this->_get_time() - $_start_time; if (!$this->isEvaluated) { $this->properties['file_dependency']['F' . abs(crc32($this->getTemplateFilepath()))] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp()); } @@ -476,10 +482,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { if (!$this->isEvaluated() && $this->caching) { // write rendered template $this->writeCachedContent($this); - if ($this->usesCompiler()) { // cache file may contain nocache code. read it back for processing $this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this); - } } }