4 * Smarty Internal Plugin Resource PHP
6 * Implements the file system as resource for PHP templates
9 * @subpackage TemplateResources
13 class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
15 * container for short_open_tag directive's value before executing PHP templates
18 protected $short_open_tag;
21 * Create a new PHP Resource
24 public function __construct()
26 $this->short_open_tag = ini_get( 'short_open_tag' );
30 * populate Source Object with meta data from Resource
32 * @param Smarty_Template_Source $source source object
33 * @param Smarty_Internal_Template $_template template object
36 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
38 $source->filepath = $this->buildFilepath($source, $_template);
40 if ($source->filepath !== false) {
41 if (is_object($source->smarty->security_policy)) {
42 $source->smarty->security_policy->isTrustedResourceDir($source->filepath);
45 $source->uid = sha1($source->filepath);
46 if ($source->smarty->compile_check) {
47 $source->timestamp = @filemtime($source->filepath);
48 $source->exists = !!$source->timestamp;
54 * populate Source Object with timestamp and exists from Resource
56 * @param Smarty_Template_Source $source source object
59 public function populateTimestamp(Smarty_Template_Source $source)
61 $source->timestamp = @filemtime($source->filepath);
62 $source->exists = !!$source->timestamp;
66 * Load template's source from file into current template object
68 * @param Smarty_Template_Source $source source object
69 * @return string template source
70 * @throws SmartyException if source cannot be loaded
72 public function getContent(Smarty_Template_Source $source)
74 if ($source->timestamp) {
77 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
81 * Render and output the template (without using the compiler)
83 * @param Smarty_Template_Source $source source object
84 * @param Smarty_Internal_Template $_template template object
86 * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
88 public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
90 $_smarty_template = $_template;
92 if (!$source->smarty->allow_php_templates) {
93 throw new SmartyException("PHP templates are disabled");
95 if (!$source->exists) {
96 if ($_template->parent instanceof Smarty_Internal_Template) {
97 $parent_resource = " in '{$_template->parent->template_resource}'";
99 $parent_resource = '';
101 throw new SmartyException("Unable to load template {$source->type} '{$source->name}'{$parent_resource}");
105 extract($_template->getTemplateVars());
107 // include PHP template with short open tags enabled
108 ini_set( 'short_open_tag', '1' );
109 include($source->filepath);
110 ini_set( 'short_open_tag', $this->short_open_tag );