]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/sysplugins/smarty_internal_compile_call.php
Changes in api
[friendica.git] / library / Smarty / libs / sysplugins / smarty_internal_compile_call.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Function_Call
4  * Compiles the calls of user defined tags defined by {function}
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile Function_Call Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Attribute definition: Overwrites base class.
21      *
22      * @var array
23      * @see Smarty_Internal_CompileBase
24      */
25     public $required_attributes = array('name');
26     /**
27      * Attribute definition: Overwrites base class.
28      *
29      * @var array
30      * @see Smarty_Internal_CompileBase
31      */
32     public $shorttag_order = array('name');
33     /**
34      * Attribute definition: Overwrites base class.
35      *
36      * @var array
37      * @see Smarty_Internal_CompileBase
38      */
39     public $optional_attributes = array('_any');
40
41     /**
42      * Compiles the calls of user defined tags defined by {function}
43      *
44      * @param  array  $args     array with attributes from parser
45      * @param  object $compiler compiler object
46      *
47      * @return string compiled code
48      */
49     public function compile($args, $compiler)
50     {
51         // check and get attributes
52         $_attr = $this->getAttributes($compiler, $args);
53         // save possible attributes
54         if (isset($_attr['assign'])) {
55             // output will be stored in a smarty variable instead of being displayed
56             $_assign = $_attr['assign'];
57         }
58         $_name = $_attr['name'];
59         if ($compiler->compiles_template_function) {
60             $compiler->called_functions[] = trim($_name, "'\"");
61         }
62         unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
63         // set flag (compiled code of {function} must be included in cache file
64         if ($compiler->nocache || $compiler->tag_nocache) {
65             $_nocache = 'true';
66         } else {
67             $_nocache = 'false';
68         }
69         $_paramsArray = array();
70         foreach ($_attr as $_key => $_value) {
71             if (is_int($_key)) {
72                 $_paramsArray[] = "$_key=>$_value";
73             } else {
74                 $_paramsArray[] = "'$_key'=>$_value";
75             }
76         }
77         if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
78             foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
79                 if (!isset($_attr[$_key])) {
80                     if (is_int($_key)) {
81                         $_paramsArray[] = "$_key=>$_value";
82                     } else {
83                         $_paramsArray[] = "'$_key'=>$_value";
84                     }
85                 }
86             }
87         } elseif (isset($compiler->smarty->template_functions[$_name]['parameter'])) {
88             foreach ($compiler->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
89                 if (!isset($_attr[$_key])) {
90                     if (is_int($_key)) {
91                         $_paramsArray[] = "$_key=>$_value";
92                     } else {
93                         $_paramsArray[] = "'$_key'=>$_value";
94                     }
95                 }
96             }
97         }
98         //variable name?
99         if (!(strpos($_name, '$') === false)) {
100             $call_cache = $_name;
101             $call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
102         } else {
103             $_name = trim($_name, "'\"");
104             $call_cache = "'{$_name}'";
105             $call_function = 'smarty_template_function_' . $_name;
106         }
107
108         $_params = 'array(' . implode(",", $_paramsArray) . ')';
109         $_hash = str_replace('-', '_', $compiler->template->properties['nocache_hash']);
110         // was there an assign attribute
111         if (isset($_assign)) {
112             if ($compiler->template->caching) {
113                 $_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
114             } else {
115                 $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
116             }
117         } else {
118             if ($compiler->template->caching) {
119                 $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
120             } else {
121                 $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";
122             }
123         }
124
125         return $_output;
126     }
127 }