- major update including some API changes

This commit is contained in:
uwe.tews@googlemail.com
2010-11-11 21:34:36 +00:00
parent 93686c695d
commit f044178bad
62 changed files with 3249 additions and 3204 deletions
@@ -23,6 +23,8 @@ class Smarty_Internal_TemplateCompilerBase {
public $_tag_stack = array();
// current template
public $template = null;
// optional log of tag/attributes
public $used_tags = array();
/**
* Initialize compiler
@@ -45,9 +47,6 @@ class Smarty_Internal_TemplateCompilerBase {
} else {
$this->nocache_hash = $template->properties['nocache_hash'];
}
/* here is where the compiling takes place. Smarty
tags in the templates are replaces with PHP code,
then written to compiled files. */
// flag for nochache sections
$this->nocache = false;
$this->tag_nocache = false;
@@ -102,20 +101,30 @@ class Smarty_Internal_TemplateCompilerBase {
*
* @param string $tag tag name
* @param array $args array with tag attributes
* @param array $parameter array with compilation parameter
* @return string compiled code
*/
public function compileTag($tag, $args)
public function compileTag($tag, $args, $parameter = array())
{
// $args contains the attributes parsed and compiled by the lexer/parser
// assume that tag does compile into code, but creates no HTML output
$this->has_code = true;
$this->has_output = false;
$this->has_output = false;
// log tag/attributes
if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) {
$this->used_tags[] = array($tag,$args);
}
// check nocache option flag
if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args)
|| in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) {
$this->tag_nocache = true;
}
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
if (($_output = $this->callTagCompiler($tag, $args)) === false) {
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
if (isset($this->smarty->template_functions[$tag])) {
// template defined by {template} tag
$args['name'] = "'" . $tag . "'";
$_output = $this->callTagCompiler('call', $args);
$args['_attr']['name'] = "'" . $tag . "'";
$_output = $this->callTagCompiler('call', $args, $parameter);
}
}
if ($_output !== false) {
@@ -133,47 +142,58 @@ class Smarty_Internal_TemplateCompilerBase {
// tag did not produce compiled code
return '';
} else {
// map_named attributes
if (isset($args['_attr'])) {
foreach ($args['_attr'] as $key => $attribute) {
if (is_array($attribute)) {
$args = array_merge($args, $attribute);
}
}
}
// not an internal compiler tag
if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
// check if tag is a registered object
if (isset($this->smarty->registered_objects[$tag]) && isset($args['object_methode'])) {
$methode = $args['object_methode'];
unset ($args['object_methode']);
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) {
return $this->callTagCompiler('private_object_function', $args, $tag, $methode);
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode);
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $tag, $methode);
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} else {
return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno);
}
}
// check if tag is registered
foreach (array('compiler', 'function', 'block') as $type) {
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $type) {
if (isset($this->smarty->registered_plugins[$type][$tag])) {
// if compiler function plugin call it now
if ($type == 'compiler') {
if ($type == Smarty::PLUGIN_COMPILER) {
$new_args = array();
foreach ($args as $mixed) {
$new_args = array_merge($new_args, $mixed);
}
if (!$this->smarty->registered_plugins[$type][$tag][1]) {
$this->tag_nocache = true;
}
$function = $this->smarty->registered_plugins[$type][$tag][0];
if (!is_array($function)) {
return $function($args, $this);
return $function($new_args, $this);
} else if (is_object($function[0])) {
return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($args, $this);
return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($new_args, $this);
} else {
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($args, $this));
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($new_args, $this));
}
}
// compile registered function or block function
if ($type == 'function' || $type == 'block') {
return $this->callTagCompiler('private_registered_' . $type, $args, $tag);
if ($type == Smarty::PLUGIN_FUNCTION || $type == Smarty::PLUGIN_BLOCK) {
return $this->callTagCompiler('private_registered_' . $type, $args, $parameter, $tag);
}
}
}
// check plugins from plugins folder
foreach ($this->smarty->plugin_search_order as $plugin_type) {
if ($plugin_type == 'compiler' && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
if ($plugin_type == Smarty::PLUGIN_BLOCK && Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) {
$plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) {
return $plugin($args, $this->smarty);
@@ -187,7 +207,7 @@ class Smarty_Internal_TemplateCompilerBase {
throw new SmartyException("Plugin \"{$tag}\" not callable");
} else {
if ($function = $this->getPlugin($tag, $plugin_type)) {
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $tag, $function);
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
}
}
}
@@ -195,24 +215,23 @@ class Smarty_Internal_TemplateCompilerBase {
// compile closing tag of block function
$base_tag = substr($tag, 0, -5);
// check if closing tag is a registered object
if (isset($this->smarty->registered_objects[$base_tag]) && isset($args['object_methode'])) {
$methode = $args['object_methode'];
unset ($args['object_methode']);
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $tag, $methode);
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} else {
return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
}
}
// registered block tag ?
if (isset($this->smarty->registered_plugins['block'][$base_tag])) {
return $this->callTagCompiler('private_registered_block', $args, $tag);
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
}
// block plugin?
if ($function = $this->getPlugin($base_tag, 'block')) {
return $this->callTagCompiler('private_block_plugin', $args, $tag, $function);
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
}
if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) {
$plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) {
return $plugin($args, $this->smarty);
@@ -253,7 +272,7 @@ class Smarty_Internal_TemplateCompilerBase {
}
// lazy load internal compiler plugin
$class_name = 'Smarty_Internal_Compile_' . $tag;
if ($this->smarty->loadPlugin($class_name)) {
if (Smarty_Internal_Plugin_Loader::loadPlugin($class_name, $this->smarty->plugins_dir)) {
// use plugin if found
self::$_tag_objects[$tag] = new $class_name;
// compile this tag
@@ -403,5 +422,6 @@ class Smarty_Internal_TemplateCompilerBase {
}
throw new SmartyCompilerException($error_text);
}
}
}
?>