Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Smarty Internal Plugin Compile Insert |
||
5 | * |
||
6 | * Compiles the {insert} tag |
||
7 | * |
||
8 | * @package Smarty |
||
9 | * @subpackage Compiler |
||
10 | * @author Uwe Tews |
||
11 | */ |
||
12 | /** |
||
13 | * Smarty Internal Plugin Compile Insert Class |
||
14 | */ |
||
15 | class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { |
||
16 | /** |
||
17 | * Compiles code for the {insert} 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 | // this tag must not be cached |
||
31 | $this->compiler->tag_nocache = true; |
||
32 | |||
33 | $_output = '<?php '; |
||
34 | // save posible attributes |
||
35 | $_name = 'insert_' . trim($_attr['name'], "'"); |
||
36 | if (isset($_attr['assign'])) { |
||
37 | // output will be stored in a smarty variable instead of beind displayed |
||
38 | $_assign = $_attr['assign']; |
||
39 | // create variable to make shure that the compiler knows about its nocache status |
||
40 | $this->compiler->template->tpl_vars[trim($_attr['assign'],"'")] = new Smarty_Variable(null,true); |
||
41 | } |
||
42 | if (isset($_attr['script'])) { |
||
43 | // script which must be included |
||
44 | $_script = $_attr['script']; |
||
45 | if (!file_exists($_script)) { |
||
46 | $this->compiler->trigger_template_error('missing file "' . $_script . '"'); |
||
47 | } |
||
48 | // code for script file loading |
||
49 | $_output .= 'require once ' . $_script . ';'; |
||
50 | } else { |
||
51 | if (!is_callable($_name)) { |
||
52 | $this->compiler->trigger_template_error('function "' . $_name . '" is not callable'); |
||
53 | } |
||
54 | } |
||
55 | // delete {insert} standard attributes |
||
56 | unset($_attr['name'], $_attr['assign'], $_attr['script']); |
||
57 | // convert attributes into parameter array string |
||
58 | $_paramsArray = array(); |
||
59 | foreach ($_attr as $_key => $_value) { |
||
60 | $_paramsArray[] = "'$_key'=>$_value"; |
||
61 | } |
||
62 | $_params = 'array(' . implode(",", $_paramsArray) . ')'; |
||
63 | // call insert |
||
64 | if (isset($_assign)) { |
||
65 | $_output .= '$_smarty_tpl->assign(' . $_assign . ',' . $_name . '(' . $_params . '),true); ?>'; |
||
66 | } else { |
||
67 | $this->compiler->has_output = true; |
||
68 | $_output .= 'echo ' . $_name . '(' . $_params . '); ?>'; |
||
69 | } |
||
70 | return $_output; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | ?> |