]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/demo/plugins/resource.extendsall.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / demo / plugins / resource.extendsall.php
1 <?php
2
3 /**
4  * Extends All Resource
5  * Resource Implementation modifying the extends-Resource to walk
6  * through the template_dirs and inherit all templates of the same name
7  *
8  * @package Resource-examples
9  * @author  Rodney Rehm
10  */
11 class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
12 {
13     /**
14      * populate Source Object with meta data from Resource
15      *
16      * @param  Smarty_Template_Source   $source    source object
17      * @param  Smarty_Internal_Template $_template template object
18      *
19      * @return void
20      */
21     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
22     {
23         $uid = '';
24         $sources = array();
25         $timestamp = 0;
26         foreach ($source->smarty->getTemplateDir() as $key => $directory) {
27             try {
28                 $s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name);
29                 if (!$s->exists) {
30                     continue;
31                 }
32                 $sources[ $s->uid ] = $s;
33                 $uid .= $s->filepath;
34                 $timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
35             }
36             catch (SmartyException $e) {
37             }
38         }
39         if (!$sources) {
40             $source->exists = false;
41             return;
42         }
43
44         $sources = array_reverse($sources, true);
45         reset($sources);
46         $s = current($sources);
47         $source->components = $sources;
48         $source->filepath = $s->filepath;
49         $source->uid = sha1($uid . $source->smarty->_joined_template_dir);
50         $source->exists = true;
51         $source->timestamp = $timestamp;
52     }
53
54     /*
55      * Disable timestamp checks for extendsall resource.
56      * The individual source components will be checked.
57      *
58      * @return bool
59      */
60     public function checkTimestamps()
61     {
62         return false;
63     }
64
65 }