Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_compile_include_php.php
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 /**
14  * Smarty Internal Plugin Compile Insert Class
15  */
16 class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase {
17         // attribute definitions
18     public $required_attributes = array('file');
19         public $shorttag_order = array('file');
20     public $optional_attributes = array('once', 'assign'); 
21
22     /**
23      * Compiles code for the {include_php} tag
24      * 
25      * @param array $args array with attributes from parser
26      * @param object $compiler compiler object
27      * @return string compiled code
28      */
29     public function compile($args, $compiler)
30     {
31         if (!$compiler->smarty->allow_php_tag) {
32                 throw new SmartyException("{include_php} is deprecated, set allow_php_tag = true to enable");
33         } 
34         $this->compiler = $compiler;
35         // check and get attributes
36         $_attr = $this->_get_attributes($args);
37
38         $_output = '<?php '; 
39
40         $_smarty_tpl = $compiler->template; 
41         $_filepath = false;
42         eval('$_file = ' . $_attr['file'] . ';'); 
43         if (!isset($this->compiler->smarty->security_policy) && file_exists($_file)) {
44                 $_filepath = $_file;
45         } else {
46             if (isset($this->compiler->smarty->security_policy)) {
47                 $_dir = $this->compiler->smarty->security_policy->trusted_dir;
48             } else {
49                 $_dir = $this->compiler->smarty->trusted_dir;
50             } 
51             if (!empty($_dir)) {
52                 foreach((array)$_dir as $_script_dir) {
53                     if (strpos('/\\', substr($_script_dir, -1)) === false) {
54                         $_script_dir .= DS;
55                     } 
56                     if (file_exists($_script_dir . $_file)) {
57                         $_filepath = $_script_dir .  $_file;
58                         break;
59                     } 
60                 } 
61             } 
62         } 
63         if ($_filepath == false) {
64             $this->compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $this->compiler->lex->taglineno);
65         } 
66
67         if (isset($this->compiler->smarty->security_policy)) {
68             $this->compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
69         } 
70
71         if (isset($_attr['assign'])) {
72             // output will be stored in a smarty variable instead of being displayed
73             $_assign = $_attr['assign'];
74         } 
75         $_once = '_once';
76         if (isset($_attr['once'])) {
77             if ($_attr['once'] == 'false') {
78                 $_once = '';
79             } 
80         } 
81
82         if (isset($_assign)) {
83             return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
84         } else {
85             return "<?php include{$_once} ('{$_filepath}');?>\n";
86         } 
87     } 
88
89
90 ?>