- 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
This commit is contained in:
Uwe.Tews
2009-09-30 22:03:41 +00:00
parent 25d4535be6
commit 898819dd2b
8 changed files with 34 additions and 25 deletions

View File

@@ -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

View File

@@ -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"),

View File

@@ -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','<bar>');
$smarty->assign('foo',"'bar'");
$person = new Person;

View File

@@ -1,11 +1,13 @@
PHP file test
$foo is <?=$foo?>
<br> Test modifier chaining
<?=$foo->trim()->escape('html')?>
<br> Test functions
<? echo trim($foo,"'");?>
<br>Test objects
<?=$person->setName('Paul')->setAge(39)->introduce()->trim()->truncate(10)?>
<?=$person->setName('Paul')->setAge(39)->introduce()?>
<br>Test Arrays
<?=$array['a']['aa']->truncate(5)?><?=$array['b']?>
<br>Function
<?=$_f->trim($array['a']['aa'])->truncate(10)?>
DONE
<?=$array['a']['aa']?> <?=$array['b']?>
<br>function time
<? echo time();?>
<br>nocache function time
<? echo '<? echo time();?>';?>
<br>DONE

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);
}
}
}