packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/smarty/sysplugins/smarty_resource_custom.php
changeset 0 3906ca745819
equal deleted inserted replaced
-1:000000000000 0:3906ca745819
       
     1 <?php
       
     2 /**
       
     3  * Smarty Resource Plugin
       
     4  *
       
     5  * @package Smarty
       
     6  * @subpackage TemplateResources
       
     7  * @author Rodney Rehm
       
     8  */
       
     9 
       
    10 /**
       
    11  * Smarty Resource Plugin
       
    12  *
       
    13  * Wrapper Implementation for custom resource plugins
       
    14  *
       
    15  * @package Smarty
       
    16  * @subpackage TemplateResources
       
    17  */
       
    18 abstract class Smarty_Resource_Custom extends Smarty_Resource {
       
    19 
       
    20     /**
       
    21      * fetch template and its modification time from data source
       
    22      *
       
    23      * @param string  $name    template name
       
    24      * @param string  &$source template source
       
    25      * @param integer &$mtime  template modification timestamp (epoch)
       
    26      */
       
    27     protected abstract function fetch($name, &$source, &$mtime);
       
    28 
       
    29     /**
       
    30      * Fetch template's modification timestamp from data source
       
    31      *
       
    32      * {@internal implementing this method is optional.
       
    33      *  Only implement it if modification times can be accessed faster than loading the complete template source.}}
       
    34      *
       
    35      * @param string $name template name
       
    36      * @return integer|boolean timestamp (epoch) the template was modified, or false if not found
       
    37      */
       
    38     protected function fetchTimestamp($name)
       
    39     {
       
    40         return null;
       
    41     }
       
    42 
       
    43     /**
       
    44      * populate Source Object with meta data from Resource
       
    45      *
       
    46      * @param Smarty_Template_Source   $source    source object
       
    47      * @param Smarty_Internal_Template $_template template object
       
    48      */
       
    49     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
       
    50     {
       
    51         $source->filepath = strtolower($source->type . ':' . $source->name);
       
    52         $source->uid = sha1($source->type . ':' . $source->name);
       
    53 
       
    54         $mtime = $this->fetchTimestamp($source->name);
       
    55         if ($mtime !== null) {
       
    56             $source->timestamp = $mtime;
       
    57         } else {
       
    58             $this->fetch($source->name, $content, $timestamp);
       
    59             $source->timestamp = isset($timestamp) ? $timestamp : false;
       
    60             if( isset($content) )
       
    61                 $source->content = $content;
       
    62         }
       
    63         $source->exists = !!$source->timestamp;
       
    64     }
       
    65 
       
    66     /**
       
    67      * Load template's source into current template object
       
    68      *
       
    69      * @param Smarty_Template_Source $source source object
       
    70      * @return string template source
       
    71      * @throws SmartyException if source cannot be loaded
       
    72      */
       
    73     public function getContent(Smarty_Template_Source $source)
       
    74     {
       
    75         $this->fetch($source->name, $content, $timestamp);
       
    76         if (isset($content)) {
       
    77             return $content;
       
    78         }
       
    79 
       
    80         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
       
    81     }
       
    82 
       
    83     /**
       
    84      * Determine basename for compiled filename
       
    85      *
       
    86      * @param Smarty_Template_Source $source source object
       
    87      * @return string resource's basename
       
    88      */
       
    89     protected function getBasename(Smarty_Template_Source $source)
       
    90     {
       
    91         return basename($source->name);
       
    92     }
       
    93 
       
    94 }
       
    95 
       
    96 ?>