- added registerDefaultTemplateHandler methode and functionallity

- added registerDefaultPluginHandler methode and functionallity
- added {append} tag to extend Smarty array variabled
This commit is contained in:
Uwe.Tews
2009-04-03 15:59:40 +00:00
parent b46b973b8e
commit 3c5f0d56d3
9 changed files with 714 additions and 588 deletions

View File

@@ -1,3 +1,8 @@
04/03/2006
- added registerDefaultTemplateHandler methode and functionallity
- added registerDefaultPluginHandler methode and functionallity
- added {append} tag to extend Smarty array variabled
04/02/2009 04/02/2009
- added setter/getter methodes - added setter/getter methodes
- added $foo@first and $foo@last properties at {for} tag - added $foo@first and $foo@last properties at {for} tag

View File

@@ -57,6 +57,8 @@ class Smarty extends Smarty_Internal_TemplateBase {
static $error_unassigned = false; static $error_unassigned = false;
// template directory // template directory
public $template_dir = null; public $template_dir = null;
// default template handler
public $default_template_handler_func = null;
// compile directory // compile directory
public $compile_dir = null; public $compile_dir = null;
// plugins directory // plugins directory
@@ -139,6 +141,8 @@ class Smarty extends Smarty_Internal_TemplateBase {
public $plugin_search_order = array('function', 'block', 'compiler', 'class'); public $plugin_search_order = array('function', 'block', 'compiler', 'class');
// plugin handler object // plugin handler object
public $plugin_handler = null; public $plugin_handler = null;
// default plugin handler
public $default_plugin_handler_func = null;
// registered objects // registered objects
public $registered_objects = array(); public $registered_objects = array();
// registered filters // registered filters

View File

@@ -24,7 +24,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->required_attributes = array('var', 'value'); $this->required_attributes = array('var', 'value');
$this->optional_attributes = array('global','nocache'); $this->optional_attributes = array('global', 'nocache', 'index');
$_nocache = 'null'; $_nocache = 'null';
$_global = 'null'; $_global = 'null';
@@ -44,9 +44,20 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
$_global = 'true'; $_global = 'true';
$_global_boolean = true; $_global_boolean = true;
} }
if (isset($_attr['index'])) {
$_index = $_attr['index'];
}
// compiled output // compiled output
if (isset($_attr['index'])) {
if ($_attr['index'] == '') {
return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_global);?>";
} else {
return "<?php \$_smarty_tpl->append($_attr[var],array($_attr[index] => $_attr[value]),true,$_nocache,$_global);?>";
}
} else {
return "<?php \$_smarty_tpl->assign($_attr[var],$_attr[value],$_nocache,$_global);?>"; return "<?php \$_smarty_tpl->assign($_attr[var],$_attr[value],$_nocache,$_global);?>";
} }
}
} }
?> ?>

View File

@@ -56,6 +56,13 @@ class Smarty_Internal_Plugin_Handler extends Smarty_Internal_Base {
} }
} }
} }
if (!empty($this->smarty->default_plugin_handler_func)) {
if (!is_callable($this->smarty->default_plugin_handler_func)) {
throw new Exception("Default template handler not callable");
} else {
return call_user_func_array($this->smarty->default_plugin_handler_func, array($name, $type, &$this));
}
}
return false; return false;
} }
} }

View File

@@ -388,6 +388,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
if ($this->isEvaluated()) { if ($this->isEvaluated()) {
$this->caching = false; $this->caching = false;
} }
// checks if template exists
$this->getTemplateFilepath();
// read from cache or render // read from cache or render
if ($this->rendered_content === null && !$this->isCached()) { if ($this->rendered_content === null && !$this->isCached()) {
// render template (not loaded and not in cache) // render template (not loaded and not in cache)
@@ -488,7 +490,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// load resource handler if required // load resource handler if required
if (!isset($this->resource_objects[$this->resource_type])) { if (!isset($this->resource_objects[$this->resource_type])) {
// is this an internal or custom resource? // is this an internal or custom resource?
if (in_array($this->resource_type, array('file', 'php', 'string','extend'))) { if (in_array($this->resource_type, array('file', 'php', 'string', 'extend'))) {
// internal, get from sysplugins dir // internal, get from sysplugins dir
$_resource_class = "Smarty_Internal_Resource_{$this->resource_type}"; $_resource_class = "Smarty_Internal_Resource_{$this->resource_type}";
} else { } else {
@@ -526,6 +528,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
} }
if (file_exists($file)) return $file; if (file_exists($file)) return $file;
// no tpl file found // no tpl file found
if (!empty($this->smarty->default_template_handler_func)) {
if (!is_callable($this->smarty->default_template_handler_func)) {
throw new Exception("Default template handler not callable");
} else {
$_return = call_user_func_array($this->smarty->default_template_handler_func,
array($this->resource_type, $this->resource_name, &$this->template_source, &$this));
if ($_return == true) {
$this->isEvaluated = true;
return $_filepath;
}
}
}
throw new Exception("Unable to load template \"{$file}\""); throw new Exception("Unable to load template \"{$file}\"");
return false; return false;
} }

View File

@@ -76,7 +76,7 @@ class Smarty_Internal_TemplateBase {
* @param mixed $value the value to append * @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
*/ */
public function append($tpl_var, $value = null, $merge = false) public function append($tpl_var, $value = null, $merge = false, $nocache = false, $global = false)
{ {
if (is_array($tpl_var)) { if (is_array($tpl_var)) {
// $tpl_var is an array, ignore $value // $tpl_var is an array, ignore $value
@@ -84,7 +84,7 @@ class Smarty_Internal_TemplateBase {
if ($_key != '') { if ($_key != '') {
if (!isset($this->tpl_vars[$_key])) { if (!isset($this->tpl_vars[$_key])) {
$this->check_tplvar($_key); $this->check_tplvar($_key);
$this->tpl_vars[$_key] = new Smarty_variable(); $this->tpl_vars[$_key] = new Smarty_variable(null, $nocache, $global);
} }
if (!is_array($this->tpl_vars[$_key]->value)) { if (!is_array($this->tpl_vars[$_key]->value)) {
settype($this->tpl_vars[$_key]->value, 'array'); settype($this->tpl_vars[$_key]->value, 'array');
@@ -102,7 +102,7 @@ class Smarty_Internal_TemplateBase {
if ($tpl_var != '' && isset($value)) { if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) { if (!isset($this->tpl_vars[$tpl_var])) {
$this->check_tplvar($tpl_var); $this->check_tplvar($tpl_var);
$this->tpl_vars[$tpl_var] = new Smarty_variable(); $this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $global);
} }
if (!is_array($this->tpl_vars[$tpl_var]->value)) { if (!is_array($this->tpl_vars[$tpl_var]->value)) {
settype($this->tpl_vars[$tpl_var]->value, 'array'); settype($this->tpl_vars[$tpl_var]->value, 'array');

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty method registerDefaultPluginhandlerHandler
*
* Registers a default plugin handler
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class registerDefaultPluginHandler
*
* Registers a default plugin handler
*/
class Smarty_Method_registerDefaultPluginhandlerHandler extends Smarty_Internal_Base {
/**
* Registers a default plugin handler
*
* @param string $ |array $plugin class/methode name
*/
public function execute($plugin)
{
if (is_callable($plugin)) {
$this->smarty->default_plugin_handler_func = $plugin;
} else {
throw new Exception("Default plugin handler not callable");
}
}
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty method registerDefaultTemplateHandler
*
* Registers a default template handler
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class registerDefaultTemplateHandler
*
* Registers a default template handler
*/
class Smarty_Method_registerDefaultTemplateHandler extends Smarty_Internal_Base {
/**
* Registers a default template handler
*
* @param string $ |array $plugin class/methode name
*/
public function execute($plugin)
{
if (is_callable($plugin)) {
$this->smarty->default_template_handler_func = $plugin;
} else {
throw new Exception("Default template handler not callable");
}
}
}
?>