]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/sysplugins/smarty_internal_compile_assign.php
add smarty engine, remove some obsolete zot1 stuff
[friendica.git] / library / Smarty / libs / sysplugins / smarty_internal_compile_assign.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Assign
4  *
5  * Compiles the {assign} tag
6  *
7  * @package Smarty
8  * @subpackage Compiler
9  * @author Uwe Tews
10  */
11
12 /**
13  * Smarty Internal Plugin Compile Assign Class
14  *
15  * @package Smarty
16  * @subpackage Compiler
17  */
18 class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
19
20     /**
21      * Compiles code for the {assign} tag
22      *
23      * @param array  $args      array with attributes from parser
24      * @param object $compiler  compiler object
25      * @param array  $parameter array with compilation parameter
26      * @return string compiled code
27      */
28     public function compile($args, $compiler, $parameter)
29     {
30         // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
31         $this->required_attributes = array('var', 'value');
32         $this->shorttag_order = array('var', 'value');
33         $this->optional_attributes = array('scope');
34         $_nocache = 'null';
35         $_scope = Smarty::SCOPE_LOCAL;
36         // check and get attributes
37         $_attr = $this->getAttributes($compiler, $args);
38         // nocache ?
39         if ($compiler->tag_nocache || $compiler->nocache) {
40             $_nocache = 'true';
41             // create nocache var to make it know for further compiling
42             $compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
43         }
44         // scope setup
45         if (isset($_attr['scope'])) {
46             $_attr['scope'] = trim($_attr['scope'], "'\"");
47             if ($_attr['scope'] == 'parent') {
48                 $_scope = Smarty::SCOPE_PARENT;
49             } elseif ($_attr['scope'] == 'root') {
50                 $_scope = Smarty::SCOPE_ROOT;
51             } elseif ($_attr['scope'] == 'global') {
52                 $_scope = Smarty::SCOPE_GLOBAL;
53             } else {
54                 $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
55             }
56         }
57         // compiled output
58         if (isset($parameter['smarty_internal_index'])) {
59             $output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
60         } else {
61             // implement Smarty2's behaviour of variables assigned by reference
62             if ($compiler->template->smarty instanceof SmartyBC) {
63                 $output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
64                 $output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;";
65                 $output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);";
66             } else {
67                 $output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);";
68             }
69         }
70         if ($_scope == Smarty::SCOPE_PARENT) {
71             $output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
72         } elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) {
73             $output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }";
74         }
75         if ( $_scope == Smarty::SCOPE_GLOBAL) {
76             $output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
77         }
78         $output .= '?>';
79         return $output;
80     }
81
82 }
83
84 ?>