vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php line 106

  1. <?php
  2. /**
  3.  * Smarty Template Resource Base Object
  4.  *
  5.  * @package    Smarty
  6.  * @subpackage TemplateResources
  7.  * @author     Rodney Rehm
  8.  */
  9. abstract class Smarty_Template_Resource_Base
  10. {
  11.     /**
  12.      * Compiled Filepath
  13.      *
  14.      * @var string
  15.      */
  16.     public $filepath null;
  17.     /**
  18.      * Compiled Timestamp
  19.      *
  20.      * @var integer|bool
  21.      */
  22.     public $timestamp false;
  23.     /**
  24.      * Compiled Existence
  25.      *
  26.      * @var boolean
  27.      */
  28.     public $exists false;
  29.     /**
  30.      * Template Compile Id (Smarty_Internal_Template::$compile_id)
  31.      *
  32.      * @var string
  33.      */
  34.     public $compile_id null;
  35.     /**
  36.      * Compiled Content Loaded
  37.      *
  38.      * @var boolean
  39.      */
  40.     public $processed false;
  41.     /**
  42.      * unique function name for compiled template code
  43.      *
  44.      * @var string
  45.      */
  46.     public $unifunc '';
  47.     /**
  48.      * flag if template does contain nocache code sections
  49.      *
  50.      * @var bool
  51.      */
  52.     public $has_nocache_code false;
  53.     /**
  54.      * resource file dependency
  55.      *
  56.      * @var array
  57.      */
  58.     public $file_dependency = array();
  59.     /**
  60.      * Content buffer
  61.      *
  62.      * @var string
  63.      */
  64.     public $content null;
  65.     /**
  66.      * Included sub templates
  67.      * - index name
  68.      * - value use count
  69.      *
  70.      * @var int[]
  71.      */
  72.     public $includes = array();
  73.     /**
  74.      * Flag if this is a cache resource
  75.      *
  76.      * @var bool
  77.      */
  78.     public $isCache false;
  79.     /**
  80.      * Process resource
  81.      *
  82.      * @param Smarty_Internal_Template $_template template object
  83.      */
  84.     abstract public function process(Smarty_Internal_Template $_template);
  85.     /**
  86.      * get rendered template content by calling compiled or cached template code
  87.      *
  88.      * @param \Smarty_Internal_Template $_template
  89.      * @param string                    $unifunc function with template code
  90.      *
  91.      * @throws \Exception
  92.      */
  93.     public function getRenderedTemplateCode(Smarty_Internal_Template $_template$unifunc null)
  94.     {
  95.         $smarty = &$_template->smarty;
  96.         $_template->isRenderingCache $this->isCache;
  97.         $level ob_get_level();
  98.         try {
  99.             if (!isset($unifunc)) {
  100.                 $unifunc $this->unifunc;
  101.             }
  102.             if (empty($unifunc) || !function_exists($unifunc)) {
  103.                 throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
  104.             }
  105.             if ($_template->startRenderCallbacks) {
  106.                 foreach ($_template->startRenderCallbacks as $callback) {
  107.                     call_user_func($callback$_template);
  108.                 }
  109.             }
  110.             $unifunc($_template);
  111.             foreach ($_template->endRenderCallbacks as $callback) {
  112.                 call_user_func($callback$_template);
  113.             }
  114.             $_template->isRenderingCache false;
  115.         } catch (Exception $e) {
  116.             $_template->isRenderingCache false;
  117.             while (ob_get_level() > $level) {
  118.                 ob_end_clean();
  119.             }
  120.             if (isset($smarty->security_policy)) {
  121.                 $smarty->security_policy->endTemplate();
  122.             }
  123.             throw $e;
  124.         }
  125.     }
  126.     /**
  127.      * Get compiled time stamp
  128.      *
  129.      * @return int
  130.      */
  131.     public function getTimeStamp()
  132.     {
  133.         if ($this->exists && !$this->timestamp) {
  134.             $this->timestamp filemtime($this->filepath);
  135.         }
  136.         return $this->timestamp;
  137.     }
  138. }