К новейшей редакции | Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Smarty Internal Plugin Compile Include PHP |
||
5 | * |
||
6 | * Compiles the {include_php} 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_Include_Php extends Smarty_Internal_CompileBase { |
||
16 | /** |
||
17 | * Compiles code for the {include_php} 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('file'); |
||
27 | $this->optional_attributes = array('once', 'assign'); |
||
28 | // check and get attributes |
||
29 | $_attr = $this->_get_attributes($args); |
||
30 | |||
31 | $_output = '<?php '; |
||
32 | // save posible attributes |
||
33 | $_file = $_attr['file']; |
||
34 | $_file = realpath(trim($_file, "'")); |
||
35 | |||
36 | if ($this->smarty->security) { |
||
37 | $this->smarty->security_handler->isTrustedPHPDir($_file); |
||
38 | } |
||
39 | |||
40 | if ($_file === false) { |
||
41 | $this->compiler->trigger_template_error('include_php: file "' . $_attr['file'] . '" is not readable'); |
||
42 | } |
||
43 | |||
44 | if ($this->smarty->security) { |
||
45 | $this->smarty->security_handler->isTrustedPHPDir($_file); |
||
46 | } |
||
47 | |||
48 | if (isset($_attr['assign'])) { |
||
49 | // output will be stored in a smarty variable instead of being displayed |
||
50 | $_assign = $_attr['assign']; |
||
51 | } |
||
52 | $_once = '_once'; |
||
53 | if (isset($_attr['once'])) { |
||
54 | if ($_attr['once'] == 'false') { |
||
55 | $_once = ''; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | $_output = '<?php '; |
||
60 | if (isset($_assign)) { |
||
61 | $_output .= 'ob_start(); include' . $_once . ' (\'' . $_file . '\'); $_smarty_tpl->assign(' . $_assign . ',ob_get_contents()); ob_end_clean();?>'; |
||
62 | } else { |
||
63 | $this->compiler->has_output = true; |
||
64 | $_output .= 'include' . $once . ' (' . $_file . '); ?>'; |
||
65 | } |
||
66 | return $_output; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | ?> |