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