[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/template/template.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 5 6 /** 7 * \ingroup Template 8 * 9 * Extends the Template class to provide support for cached templated. This class adds 10 * two additional methods that are not available in Template: 11 * 12 * - CachedTemplate::isCached() to know whether the current CachedTemplate is working on cached contents 13 * - CachedTemplate::clearCache() to clear the current cached contents of this template 14 * - CachedTemplate::getCreationTimestamp() to determine when the current cached version was created 15 * 16 * @see TemplateService 17 * @see Template 18 */ 19 class CachedTemplate extends Template 20 { 21 22 /** 23 * Constructor. 24 * 25 * @param cacheLifeTime How many seconds we would like to cache the template 26 */ 27 function CachedTemplate( $templateFile, $cacheLifetime = 300 ) 28 { 29 // create the Smarty object and set the security values 30 $this->Template( $templateFile ); 31 $config =& Config::getConfig(); 32 $this->caching = $config->getValue( "template_cache_enabled"); 33 $this->cache_lifetime = $config->getValue( "template_cache_lifetime" ); 34 } 35 36 /** 37 * Renders the template and returns the contents as an string 38 * 39 * @return The result as an string 40 */ 41 function fetch( $cacheId ) 42 { 43 return Smarty::fetch( $this->getTemplateFile(), $cacheId ); 44 } 45 46 /** 47 * returns wether this template is cached or not 48 * 49 * @param cacheId The cache identifier 50 * @return true if the template is cached or false otherwise 51 */ 52 function isCached( $cacheId ) 53 { 54 $isCached = $this->is_cached( $this->getTemplateFile(), $cacheId ); 55 56 return $isCached; 57 } 58 59 /** 60 * clears the cache whose id is $cacheId 61 * 62 * @param cacheId The id of the cache that we'd like to clear 63 * @return nothing 64 */ 65 function clearCache( $cacheId ) 66 { 67 return $this->clear_cache( $this->_templateFile, $cacheId ); 68 } 69 70 /** 71 * Displays the result of rendering the template 72 * 73 * @return Always true 74 */ 75 function display( $cacheId ) 76 { 77 Smarty::display( $this->_templateFile, $cacheId ); 78 79 return true; 80 } 81 82 /** 83 * returns the date when this template was created 84 * 85 * @param the UNIX timestamp when this template was created 86 */ 87 function getCreationTimestamp() 88 { 89 // if the page was just generated, smarty doesn't have this information 90 91 if(isset($this->_cache_info['timestamp'])) 92 $timestamp = $this->_cache_info['timestamp']; 93 else 94 $timestamp = time(); 95 96 return $timestamp; 97 } 98 } 99 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |