50 public function compile($args, $compiler, $parameter)
55 if ($_attr[
'nocache'] ===
true) {
56 $compiler->trigger_template_error(
'nocache option not allowed', $compiler->lex->taglineno);
58 unset($_attr[
'nocache']);
59 $save = array($_attr, $compiler->parser->current_buffer,
60 $compiler->template->has_nocache_code, $compiler->template->required_plugins);
61 $this->
openTag($compiler,
'function', $save);
62 $_name = trim($_attr[
'name'],
"'\"");
63 unset($_attr[
'name']);
65 $compiler->compiles_template_function =
true;
66 $compiler->template->properties[
'function'][$_name][
'parameter'] = array();
67 $_smarty_tpl = $compiler->template;
68 foreach ($_attr as $_key => $_data) {
69 eval (
'$tmp='.$_data.
';');
70 $compiler->template->properties[
'function'][$_name][
'parameter'][$_key] = $tmp;
72 $compiler->smarty->template_functions[$_name][
'parameter'] = $compiler->template->properties[
'function'][$_name][
'parameter'];
73 if ($compiler->template->caching) {
76 $output =
"<?php if (!function_exists('smarty_template_function_{$_name}')) {
77 function smarty_template_function_{$_name}(\$_smarty_tpl,\$params) {
78 \$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
79 foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};
80 foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
83 $compiler->template->required_plugins = array(
'compiled' => array(),
'nocache' => array());
85 $compiler->parser->current_buffer->append_subtree(
new _smarty_tag($compiler->parser,
$output));
86 $compiler->template->has_nocache_code =
false;
87 $compiler->has_code =
false;
88 $compiler->template->properties[
'function'][$_name][
'compiled'] =
'';
110 public function compile($args, $compiler, $parameter)
113 $saved_data = $this->
closeTag($compiler, array(
'function'));
114 $_name = trim($saved_data[0][
'name'],
"'\"");
116 $plugins_string =
'';
117 if (!empty($compiler->template->required_plugins[
'compiled'])) {
118 $plugins_string =
'<?php ';
119 foreach($compiler->template->required_plugins[
'compiled'] as $tmp) {
120 foreach($tmp as
$data) {
121 $plugins_string .=
"if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
124 $plugins_string .=
'?>';
126 if (!empty($compiler->template->required_plugins[
'nocache'])) {
127 $plugins_string .=
"<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
128 foreach($compiler->template->required_plugins[
'nocache'] as $tmp) {
129 foreach($tmp as
$data) {
130 $plugins_string .=
"if (!is_callable(\'{$data['function']}\')) include \'{$data['file']}\';\n";
133 $plugins_string .=
"?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n";
136 $last = count($compiler->parser->current_buffer->subtrees) - 1;
137 if ($compiler->parser->current_buffer->subtrees[$last] instanceof
_smarty_linebreak) {
138 unset($compiler->parser->current_buffer->subtrees[$last]);
141 if ($compiler->template->caching) {
142 $compiler->template->properties[
'function'][$_name][
'compiled'] .= $plugins_string
143 . $compiler->parser->current_buffer->to_smarty_php();
144 $compiler->template->properties[
'function'][$_name][
'nocache_hash'] = $compiler->template->properties[
'nocache_hash'];
145 $compiler->template->properties[
'function'][$_name][
'has_nocache_code'] = $compiler->template->has_nocache_code;
146 $compiler->template->properties[
'function'][$_name][
'called_functions'] = $compiler->called_functions;
147 $compiler->called_functions = array();
148 $compiler->smarty->template_functions[$_name] = $compiler->template->properties[
'function'][$_name];
149 $compiler->has_code =
false;
152 $output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() .
"<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;
153 foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;}}?>\n";
156 $compiler->compiles_template_function =
false;
158 $compiler->parser->current_buffer = $saved_data[1];
159 $compiler->template->has_nocache_code = $compiler->template->has_nocache_code | $saved_data[2];
160 $compiler->template->required_plugins = $saved_data[3];
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
openTag($compiler, $openTag, $data=null)
Push opening tag name on stack.
getAttributes($compiler, $attributes)
This function checks if the attributes passed are valid.
compile($args, $compiler, $parameter)
Compiles code for the {/function} tag.
closeTag($compiler, $expectedTag)
Pop closing tag.
compile($args, $compiler, $parameter)
Compiles code for the {function} tag.