Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Smarty Internal Plugin Compile Internal_Function_Call |
||
5 | * |
||
6 | * Compiles the {internal_function_call} tag |
||
7 | * |
||
8 | * @package Smarty |
||
9 | * @subpackage Compiler |
||
10 | * @author Uwe Tews |
||
11 | */ |
||
12 | /** |
||
13 | * Smarty Internal Plugin Compile Internal_Function_Call Class |
||
14 | */ |
||
15 | class Smarty_Internal_Compile_Internal_Function_Call extends Smarty_Internal_CompileBase { |
||
16 | /** |
||
17 | * Compiles code for the {internal_function_call} tag |
||
18 | * |
||
19 | * @param array $args array with attributes from parser |
||
20 | * @param object $compiler compiler object |
||
21 | * @return string compiled code |
||
22 | */ |
||
23 | public function compile($args, $compiler) |
||
24 | { |
||
25 | $this->compiler = $compiler; |
||
26 | $this->required_attributes = array('name'); |
||
27 | $this->optional_attributes = array('_any'); |
||
28 | // check and get attributes |
||
29 | $_attr = $this->_get_attributes($args); |
||
30 | // save posible attributes |
||
31 | if (isset($_attr['assign'])) { |
||
32 | // output will be stored in a smarty variable instead of beind displayed |
||
33 | $_assign = $_attr['assign']; |
||
34 | } |
||
35 | $_name = trim($_attr['name'], "'"); |
||
36 | // create template object |
||
37 | $_output = "<?php \$_template = new Smarty_Template ('string:', \$_smarty_tpl->smarty, \$_smarty_tpl);\n"; |
||
38 | // assign default paramter |
||
39 | if (isset($this->smarty->template_functions[$_name]['parameter'])) { |
||
40 | // function is already compiled |
||
41 | foreach ($this->smarty->template_functions[$_name]['parameter'] as $_key => $_value) { |
||
42 | if (!isset($_attr[$_key])) { |
||
43 | $_output .= "\$_template->assign('$_key',$_value);\n"; |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | if (isset($compiler->template->properties['function'][$_name]['parameter'])) { |
||
48 | // for recursive call during function compilation |
||
49 | foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) { |
||
50 | if (!isset($_attr[$_key])) { |
||
51 | $_output .= "\$_template->assign('$_key',$_value);\n"; |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | // delete {include} standard attributes |
||
56 | unset($_attr['name'], $_attr['assign']); |
||
57 | // remaining attributes must be assigned as smarty variable |
||
58 | if (!empty($_attr)) { |
||
59 | // create variables |
||
60 | foreach ($_attr as $_key => $_value) { |
||
61 | $_output .= "\$_template->assign('$_key',$_value);\n"; |
||
62 | } |
||
63 | } |
||
64 | // load compiled function |
||
65 | $_output .= "\$_template->compiled_template = \$this->smarty->template_functions['$_name']['compiled'];\n\$_template->mustCompile = false;\n"; |
||
66 | // was there an assign attribute |
||
67 | if (isset($_assign)) { |
||
68 | $_output .= "\$_smarty_tpl->assign($_assign,\$_smarty_tpl->smarty->fetch(\$_template)); ?>"; |
||
69 | } else { |
||
70 | $_output .= "echo \$_smarty_tpl->smarty->fetch(\$_template); ?>"; |
||
71 | } |
||
72 | return $_output; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | ?> |