PageRenderTime 86ms CodeModel.GetById 82ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_include_php.php

http://zoop.googlecode.com/
PHP | 68 lines | 38 code | 9 blank | 21 comment | 9 complexity | 3a3a143923af51553648fe45bf865bd0 MD5 | raw file
 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*/
15class 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
33        $_smarty_tpl = $compiler->template; 
34        eval('$_file = ' . $_attr['file'] . ';'); 
35        
36        $_file = realpath($_file);
37
38        if ($this->compiler->smarty->security) {
39            $this->compiler->smarty->security_handler->isTrustedPHPDir($_file);
40        } 
41
42        if ($_file === false) {
43            $this->compiler->trigger_template_error('include_php: file "' . $_attr['file'] . '" is not readable');
44        } 
45
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        } 
59
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} 
67
68?>