659b3f12056cd3549142d79465b4d63d5225bc11
[GitHub/Stricted/Domain-Control-Panel.git] / lib / api / smarty / sysplugins / smarty_internal_compile_insert.php
1 <?php
2
3 /**
4 * Smarty Internal Plugin Compile Insert
5 * Compiles the {insert} 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_Insert 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('name');
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 * Attribute definition: Overwrites base class.
36 *
37 * @var array
38 * @see Smarty_Internal_CompileBase
39 */
40 public $optional_attributes = array('_any');
41
42 /**
43 * Compiles code for the {insert} tag
44 *
45 * @param array $args array with attributes from parser
46 * @param object $compiler compiler object
47 *
48 * @return string compiled code
49 */
50 public function compile($args, $compiler)
51 {
52 // check and get attributes
53 $_attr = $this->getAttributes($compiler, $args);
54 $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
55 if (!$nocacheParam) {
56 // do not compile as nocache code
57 $compiler->suppressNocacheProcessing = true;
58 }
59 $compiler->tag_nocache = true;
60 $_smarty_tpl = $compiler->template;
61 $_name = null;
62 $_script = null;
63
64 $_output = '<?php ';
65 // save possible attributes
66 eval('$_name = ' . $_attr['name'] . ';');
67 if (isset($_attr['assign'])) {
68 // output will be stored in a smarty variable instead of being displayed
69 $_assign = $_attr['assign'];
70 // create variable to make sure that the compiler knows about its nocache status
71 $compiler->template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true);
72 }
73 if (isset($_attr['script'])) {
74 // script which must be included
75 $_function = "smarty_insert_{$_name}";
76 $_smarty_tpl = $compiler->template;
77 $_filepath = false;
78 eval('$_script = ' . $_attr['script'] . ';');
79 if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
80 $_filepath = $_script;
81 } else {
82 if (isset($compiler->smarty->security_policy)) {
83 $_dir = $compiler->smarty->security_policy->trusted_dir;
84 } else {
85 $_dir = $compiler->smarty->trusted_dir;
86 }
87 if (!empty($_dir)) {
88 foreach ((array) $_dir as $_script_dir) {
89 $_script_dir = rtrim($_script_dir, '/\\') . DS;
90 if (file_exists($_script_dir . $_script)) {
91 $_filepath = $_script_dir . $_script;
92 break;
93 }
94 }
95 }
96 }
97 if ($_filepath == false) {
98 $compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno);
99 }
100 // code for script file loading
101 $_output .= "require_once '{$_filepath}' ;";
102 require_once $_filepath;
103 if (!is_callable($_function)) {
104 $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->lex->taglineno);
105 }
106 } else {
107 $_filepath = 'null';
108 $_function = "insert_{$_name}";
109 // function in PHP script ?
110 if (!is_callable($_function)) {
111 // try plugin
112 if (!$_function = $compiler->getPlugin($_name, 'insert')) {
113 $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->lex->taglineno);
114 }
115 }
116 }
117 // delete {insert} standard attributes
118 unset($_attr['name'], $_attr['assign'], $_attr['script'], $_attr['nocache']);
119 // convert attributes into parameter array string
120 $_paramsArray = array();
121 foreach ($_attr as $_key => $_value) {
122 $_paramsArray[] = "'$_key' => $_value";
123 }
124 $_params = 'array(' . implode(", ", $_paramsArray) . ')';
125 // call insert
126 if (isset($_assign)) {
127 if ($_smarty_tpl->caching && !$nocacheParam) {
128 $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>";
129 } else {
130 $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>";
131 }
132 } else {
133 $compiler->has_output = true;
134 if ($_smarty_tpl->caching && !$nocacheParam) {
135 $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>";
136 } else {
137 $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
138 }
139 }
140
141 return $_output;
142 }
143 }