library/smarty/demo/plugins/resource.extendsall.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     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      * populate Source Object with meta data from Resource
       
    14      *
       
    15      * @param  Smarty_Template_Source $source source object
       
    16      * @param  Smarty_Internal_Template $_template template object
       
    17      *
       
    18      * @return void
       
    19      */
       
    20     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
       
    21         $uid = '';
       
    22         $sources = array();
       
    23         $exists = true;
       
    24         foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
       
    25             try {
       
    26                 $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name);
       
    27                 if (!$s->exists) {
       
    28                     continue;
       
    29                 }
       
    30                 $sources[$s->uid] = $s;
       
    31                 $uid .= $s->filepath;
       
    32             } catch (SmartyException $e) {
       
    33             }
       
    34         }
       
    35 
       
    36         if (!$sources) {
       
    37             $source->exists = false;
       
    38             $source->template = $_template;
       
    39 
       
    40             return;
       
    41         }
       
    42 
       
    43         $sources = array_reverse($sources, true);
       
    44         reset($sources);
       
    45         $s = current($sources);
       
    46 
       
    47         $source->components = $sources;
       
    48         $source->filepath = $s->filepath;
       
    49         $source->uid = sha1($uid);
       
    50         $source->exists = $exists;
       
    51         if ($_template && $_template->smarty->compile_check) {
       
    52             $source->timestamp = $s->timestamp;
       
    53         }
       
    54         // need the template at getContent()
       
    55         $source->template = $_template;
       
    56     }
       
    57 }