smarty_internal_resource_php.php (3126B)
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 * container for short_open_tag directive's value before executing PHP templates 22 * 23 * @var string 24 */ 25 protected $short_open_tag; 26 27 /** 28 * Create a new PHP Resource 29 30 */ 31 public function __construct() 32 { 33 $this->short_open_tag = ini_get('short_open_tag'); 34 } 35 36 /** 37 * Load template's source from file into current template object 38 * 39 * @param Smarty_Template_Source $source source object 40 * 41 * @return string template source 42 * @throws SmartyException if source cannot be loaded 43 */ 44 public function getContent(Smarty_Template_Source $source) 45 { 46 if ($source->timestamp) { 47 return ''; 48 } 49 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); 50 } 51 52 /** 53 * Render and output the template (without using the compiler) 54 * 55 * @param Smarty_Template_Source $source source object 56 * @param Smarty_Internal_Template $_template template object 57 * 58 * @return void 59 * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled 60 */ 61 public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) 62 { 63 if (!$source->smarty->allow_php_templates) { 64 throw new SmartyException("PHP templates are disabled"); 65 } 66 if (!$source->exists) { 67 if ($_template->parent instanceof Smarty_Internal_Template) { 68 $parent_resource = " in '{$_template->parent->template_resource}'"; 69 } else { 70 $parent_resource = ''; 71 } 72 throw new SmartyException("Unable to load template {$source->type} '{$source->name}'{$parent_resource}"); 73 } 74 75 // prepare variables 76 extract($_template->getTemplateVars()); 77 78 // include PHP template with short open tags enabled 79 ini_set('short_open_tag', '1'); 80 /** @var Smarty_Internal_Template $_smarty_template 81 * used in included file 82 */ 83 $_smarty_template = $_template; 84 include($source->filepath); 85 ini_set('short_open_tag', $this->short_open_tag); 86 } 87 88 /** 89 * populate compiled object with compiled filepath 90 * 91 * @param Smarty_Template_Compiled $compiled compiled object 92 * @param Smarty_Internal_Template $_template template object (is ignored) 93 */ 94 public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) 95 { 96 $compiled->filepath = false; 97 $compiled->timestamp = false; 98 $compiled->exists = false; 99 } 100 }