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