Code

Updated smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_include_php.php
1 <?php
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);
31         $_output = '<?php '; 
33         $_smarty_tpl = $compiler->template; 
34         eval('$_file = ' . $_attr['file'] . ';'); 
35         
36         $_file = realpath($_file);
38         if ($this->compiler->smarty->security) {
39             $this->compiler->smarty->security_handler->isTrustedPHPDir($_file);
40         } 
42         if ($_file === false) {
43             $this->compiler->trigger_template_error('include_php: file "' . $_attr['file'] . '" is not readable');
44         } 
46         if ($this->compiler->smarty->security) {
47             $this->compiler->smarty->security_handler->isTrustedPHPDir($_file);
48         } 
49         if (isset($_attr['assign'])) {
50             // output will be stored in a smarty variable instead of being displayed
51             $_assign = $_attr['assign'];
52         } 
53         $_once = '_once';
54         if (isset($_attr['once'])) {
55             if ($_attr['once'] == 'false') {
56                 $_once = '';
57             } 
58         } 
60         if (isset($_assign)) {
61             return "<?php ob_start(); include{$_once} ('{$_file}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
62         } else {
63             return "<?php include{$_once} ('{$_file}');?>\n";
64         } 
65     } 
66
68 ?>