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