1 | <?php |
---|
2 | /** |
---|
3 | * Smarty Internal Plugin Compile Include PHP |
---|
4 | * |
---|
5 | * Compiles the {include_php} tag |
---|
6 | * |
---|
7 | * @package Smarty |
---|
8 | * @subpackage Compiler |
---|
9 | * @author Uwe Tews |
---|
10 | */ |
---|
11 | |
---|
12 | /** |
---|
13 | * Smarty Internal Plugin Compile Insert Class |
---|
14 | * |
---|
15 | * @package Smarty |
---|
16 | * @subpackage Compiler |
---|
17 | */ |
---|
18 | class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase { |
---|
19 | |
---|
20 | /** |
---|
21 | * Attribute definition: Overwrites base class. |
---|
22 | * |
---|
23 | * @var array |
---|
24 | * @see Smarty_Internal_CompileBase |
---|
25 | */ |
---|
26 | public $required_attributes = array('file'); |
---|
27 | /** |
---|
28 | * Attribute definition: Overwrites base class. |
---|
29 | * |
---|
30 | * @var array |
---|
31 | * @see Smarty_Internal_CompileBase |
---|
32 | */ |
---|
33 | public $shorttag_order = array('file'); |
---|
34 | /** |
---|
35 | * Attribute definition: Overwrites base class. |
---|
36 | * |
---|
37 | * @var array |
---|
38 | * @see Smarty_Internal_CompileBase |
---|
39 | */ |
---|
40 | public $optional_attributes = array('once', 'assign'); |
---|
41 | |
---|
42 | /** |
---|
43 | * Compiles code for the {include_php} tag |
---|
44 | * |
---|
45 | * @param array $args array with attributes from parser |
---|
46 | * @param object $compiler compiler object |
---|
47 | * @return string compiled code |
---|
48 | */ |
---|
49 | public function compile($args, $compiler) |
---|
50 | { |
---|
51 | if (!($compiler->smarty instanceof SmartyBC)) { |
---|
52 | throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable"); |
---|
53 | } |
---|
54 | // check and get attributes |
---|
55 | $_attr = $this->getAttributes($compiler, $args); |
---|
56 | |
---|
57 | $_output = '<?php '; |
---|
58 | |
---|
59 | $_smarty_tpl = $compiler->template; |
---|
60 | $_filepath = false; |
---|
61 | eval('$_file = ' . $_attr['file'] . ';'); |
---|
62 | if (!isset($compiler->smarty->security_policy) && file_exists($_file)) { |
---|
63 | $_filepath = $_file; |
---|
64 | } else { |
---|
65 | if (isset($compiler->smarty->security_policy)) { |
---|
66 | $_dir = $compiler->smarty->security_policy->trusted_dir; |
---|
67 | } else { |
---|
68 | $_dir = $compiler->smarty->trusted_dir; |
---|
69 | } |
---|
70 | if (!empty($_dir)) { |
---|
71 | foreach((array)$_dir as $_script_dir) { |
---|
72 | $_script_dir = rtrim($_script_dir, '/\\') . DS; |
---|
73 | if (file_exists($_script_dir . $_file)) { |
---|
74 | $_filepath = $_script_dir . $_file; |
---|
75 | break; |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | if ($_filepath == false) { |
---|
81 | $compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $compiler->lex->taglineno); |
---|
82 | } |
---|
83 | |
---|
84 | if (isset($compiler->smarty->security_policy)) { |
---|
85 | $compiler->smarty->security_policy->isTrustedPHPDir($_filepath); |
---|
86 | } |
---|
87 | |
---|
88 | if (isset($_attr['assign'])) { |
---|
89 | // output will be stored in a smarty variable instead of being displayed |
---|
90 | $_assign = $_attr['assign']; |
---|
91 | } |
---|
92 | $_once = '_once'; |
---|
93 | if (isset($_attr['once'])) { |
---|
94 | if ($_attr['once'] == 'false') { |
---|
95 | $_once = ''; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | if (isset($_assign)) { |
---|
100 | return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>"; |
---|
101 | } else { |
---|
102 | return "<?php include{$_once} ('{$_filepath}');?>\n"; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | ?> |
---|