]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_resource_php.php
Merge pull request #4233 from MrPetovan/task/4116-move-smarty-to-composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_resource_php.php
1 <?php
2
3 /**
4  * Smarty Internal Plugin Resource PHP
5  * Implements the file system as resource for PHP templates
6  *
7  * @package    Smarty
8  * @subpackage TemplateResources
9  * @author     Uwe Tews
10  * @author     Rodney Rehm
11  */
12 class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
13 {
14     /**
15      * Flag that it's an uncompiled resource
16      *
17      * @var bool
18      */
19     public $uncompiled = true;
20
21     /**
22      * container for short_open_tag directive's value before executing PHP templates
23      *
24      * @var string
25      */
26     protected $short_open_tag;
27
28     /**
29      * Resource does implement populateCompiledFilepath() method
30      *
31      * @var bool
32      */
33     public $hasCompiledHandler = true;
34
35     /**
36      * Create a new PHP Resource
37      */
38     public function __construct()
39     {
40         $this->short_open_tag = ini_get('short_open_tag');
41     }
42
43     /**
44      * Load template's source from file into current template object
45      *
46      * @param  Smarty_Template_Source $source source object
47      *
48      * @return string                 template source
49      * @throws SmartyException        if source cannot be loaded
50      */
51     public function getContent(Smarty_Template_Source $source)
52     {
53         if ($source->exists) {
54             return '';
55         }
56         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
57     }
58
59     /**
60      * Render and output the template (without using the compiler)
61      *
62      * @param  Smarty_Template_Source   $source    source object
63      * @param  Smarty_Internal_Template $_template template object
64      *
65      * @return void
66      * @throws SmartyException          if template cannot be loaded or allow_php_templates is disabled
67      */
68     public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
69     {
70         if (!$source->smarty->allow_php_templates) {
71             throw new SmartyException("PHP templates are disabled");
72         }
73         if (!$source->exists) {
74             throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" .
75                                       ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : ''));
76         }
77
78         // prepare variables
79         extract($_template->getTemplateVars());
80
81         // include PHP template with short open tags enabled
82         ini_set('short_open_tag', '1');
83         /** @var Smarty_Internal_Template $_smarty_template
84          * used in included file
85          */
86         $_smarty_template = $_template;
87         include($source->filepath);
88         ini_set('short_open_tag', $this->short_open_tag);
89     }
90
91     /**
92      * populate compiled object with compiled filepath
93      *
94      * @param Smarty_Template_Compiled $compiled  compiled object
95      * @param Smarty_Internal_Template $_template template object (is ignored)
96      */
97     public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
98     {
99         $compiled->filepath = $_template->source->filepath;
100         $compiled->timestamp = $_template->source->timestamp;
101         $compiled->exists = $_template->source->exists;
102         $compiled->file_dependency[ $_template->source->uid ] =
103             array($compiled->filepath, $compiled->timestamp,
104                   $_template->source->type,);
105     }
106 }