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 */
17class 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    /**
28     * Attribute definition: Overwrites base class.
29     *
30     * @var array
31     * @see Smarty_Internal_CompileBase
32     */
33    public $shorttag_order = array('name');
34
35    /**
36     * Attribute definition: Overwrites base class.
37     *
38     * @var array
39     * @see Smarty_Internal_CompileBase
40     */
41    public $optional_attributes = array('_any');
42
43    /**
44     * Compiles the calls of user defined tags defined by {function}
45     *
46     * @param array  $args     array with attributes from parser
47     * @param object $compiler compiler object
48     *
49     * @return string compiled code
50     */
51    public function compile($args, $compiler)
52    {
53        // check and get attributes
54        $_attr = $this->getAttributes($compiler, $args);
55        // save possible attributes
56        if (isset($_attr[ 'assign' ])) {
57            // output will be stored in a smarty variable instead of being displayed
58            $_assign = $_attr[ 'assign' ];
59        }
60        //$_name = trim($_attr['name'], "''");
61        $_name = $_attr[ 'name' ];
62        unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'nocache' ]);
63        // set flag (compiled code of {function} must be included in cache file
64        if (!$compiler->template->caching || $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        $_params = 'array(' . implode(',', $_paramsArray) . ')';
78        //$compiler->suppressNocacheProcessing = true;
79        // was there an assign attribute
80        if (isset($_assign)) {
81            $_output =
82                "<?php ob_start();\n\$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
83        } else {
84            $_output =
85                "<?php \$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
86        }
87        return $_output;
88    }
89}
90