]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_resource_extends.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_resource_extends.php
1 <?php
2 /**
3  * Smarty Internal Plugin Resource Extends
4  *
5  * @package    Smarty
6  * @subpackage TemplateResources
7  * @author     Uwe Tews
8  * @author     Rodney Rehm
9  */
10
11 /**
12  * Smarty Internal Plugin Resource Extends
13  * Implements the file system as resource for Smarty which {extend}s a chain of template files templates
14  *
15  * @package    Smarty
16  * @subpackage TemplateResources
17  */
18 class Smarty_Internal_Resource_Extends extends Smarty_Resource
19 {
20     /**
21      * mbstring.overload flag
22      *
23      * @var int
24      */
25     public $mbstring_overload = 0;
26
27     /**
28      * populate Source Object with meta data from Resource
29      *
30      * @param Smarty_Template_Source   $source    source object
31      * @param Smarty_Internal_Template $_template template object
32      *
33      * @throws SmartyException
34      */
35     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
36     {
37         $uid = '';
38         $sources = array();
39         $components = explode('|', $source->name);
40         $smarty = &$source->smarty;
41         $exists = true;
42         foreach ($components as $component) {
43             /* @var \Smarty_Template_Source $_s */
44             $_s = Smarty_Template_Source::load(null, $smarty, $component);
45             if ($_s->type == 'php') {
46                 throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
47             }
48             $sources[ $_s->uid ] = $_s;
49             $uid .= $_s->filepath;
50             if ($_template) {
51                 $exists = $exists && $_s->exists;
52             }
53         }
54         $source->components = $sources;
55         $source->filepath = $_s->filepath;
56         $source->uid = sha1($uid . $source->smarty->_joined_template_dir);
57         $source->exists = $exists;
58         if ($_template) {
59             $source->timestamp = $_s->timestamp;
60         }
61     }
62
63     /**
64      * populate Source Object with timestamp and exists from Resource
65      *
66      * @param Smarty_Template_Source $source source object
67      */
68     public function populateTimestamp(Smarty_Template_Source $source)
69     {
70         $source->exists = true;
71         /* @var \Smarty_Template_Source $_s */
72         foreach ($source->components as $_s) {
73             $source->exists = $source->exists && $_s->exists;
74         }
75         $source->timestamp = $source->exists ? $_s->getTimeStamp() : false;
76     }
77
78     /**
79      * Load template's source from files into current template object
80      *
81      * @param Smarty_Template_Source $source source object
82      *
83      * @return string template source
84      * @throws SmartyException if source cannot be loaded
85      */
86     public function getContent(Smarty_Template_Source $source)
87     {
88         if (!$source->exists) {
89             throw new SmartyException("Unable to load template '{$source->type}:{$source->name}'");
90         }
91
92         $_components = array_reverse($source->components);
93
94         $_content = '';
95         /* @var \Smarty_Template_Source $_s */
96         foreach ($_components as $_s) {
97             // read content
98             $_content .= $_s->getContent();
99         }
100         return $_content;
101     }
102
103     /**
104      * Determine basename for compiled filename
105      *
106      * @param Smarty_Template_Source $source source object
107      *
108      * @return string resource's basename
109      */
110     public function getBasename(Smarty_Template_Source $source)
111     {
112         return str_replace(':', '.', basename($source->filepath));
113     }
114
115     /*
116       * Disable timestamp checks for extends resource.
117       * The individual source components will be checked.
118       *
119       * @return bool
120       */
121     public function checkTimestamps()
122     {
123         return false;
124     }
125 }