[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/summary/view/ -> summarycachedview.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/view/view.class.php" );
   4  
   5      /**
   6       * This class should extended SmartyView but SmartyView was designed to work with BlogInfo
   7       * objects while the summary does not so we had to reimplement part of the functionality... This is
   8       * ideal or optimal but it works so we will let it be for a while.
   9       */
  10      class SummaryCachedView extends View
  11      {
  12  
  13          var $_templateName;
  14          var $_data;
  15          var $_template;
  16          var $_viewId;
  17  
  18          function SummaryCachedView( $templateName, $data )
  19          {
  20              $this->View();
  21              $this->_templateName = $templateName;
  22              $this->_data = $data;
  23              $this->_viewId = $this->generateCacheId();
  24  
  25              $this->generateTemplate();
  26          }
  27  
  28          function generateTemplate()
  29          {
  30              lt_include( PLOG_CLASS_PATH."class/template/templateservice.class.php" );
  31  
  32              $templateService = new TemplateService();
  33              $this->_template = $templateService->customTemplate( $this->_templateName, "summary", true );
  34  
  35              // set the summary custom time
  36              lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
  37              $config =& Config::getConfig();
  38              // set the summary cache lifetime, or zero if none
  39              $summaryTemplateLifetime = $config->getValue( "summary_template_cache_lifetime", 0 );
  40              if( $summaryTemplateLifetime > 0 ) {
  41                  $this->_template->cache_lifetime = $summaryTemplateLifetime;
  42              }
  43          }
  44  
  45          /**
  46           * generates a unique identifier for this view
  47           *
  48           * @private
  49           */
  50  		function generateCacheId()
  51          {
  52              $cacheId = "";
  53              foreach( $this->_data as $key => $value )
  54                  $cacheId .= "$key=$value";
  55              $cacheId = md5($cacheId);
  56  
  57              return $cacheId;
  58          }
  59  
  60  		function getBlogViewId()
  61          {
  62              return $this->_viewId;
  63          }
  64  
  65  		function isCached()
  66          {
  67              $isCached = $this->_template->isCached( $this->_viewId );
  68  
  69              return $isCached;
  70          }
  71  
  72          /**
  73           * @private
  74           */
  75  		function _getLocale()
  76          {
  77              // load the Locale object from the view context or initialize it now
  78              if( $this->_params->keyExists( "locale" )) {
  79                  $this->_locale = $this->_params->getValue( "locale" );
  80              }
  81              else {
  82                  $config =& Config::getConfig();
  83                  $this->_locale =& Locales::getLocale( $config->getValue("default_locale" ));
  84              }
  85          }
  86  
  87  		function sendUncachedOutput()
  88          {
  89              lt_include( PLOG_CLASS_PATH."class/xml/rssparser/rssparser.class.php" );
  90  
  91              $config =& Config::getConfig();
  92              $baseurl = $config->getValue( "base_url" );
  93  
  94              $this->_getLocale();
  95              $this->_params->setValue( "version", new Version());
  96              $this->_params->setValue( "locale", $this->_locale);
  97              $this->_params->setValue( "rss", new RssParser());
  98              $this->_params->setValue( "baseurl", $baseurl);
  99              $this->_params->setValue( "serviceName", $config->getValue( "summary_service_name" ));
 100  
 101              lt_include( PLOG_CLASS_PATH."class/summary/net/summaryrequestgenerator.class.php" );
 102              $this->_params->setValue( "url", new SummaryRequestGenerator());
 103  
 104              $this->_template->assign( $this->_params->getAsArray());
 105              print $this->_template->fetch( $this->_viewId );
 106          }
 107  
 108  		function getCacheTimeSeconds()
 109          {
 110              $config =& Config::getConfig();
 111  
 112              $cacheTime = $config->getValue( "http_cache_lifetime", 1800 );
 113  
 114              if( $cacheTime == "" || !is_numeric($cacheTime))
 115                  $cacheTime = 1; // [almost] no value, just one second of caching
 116              if( $cacheTime == -1 )
 117                  $cacheTime = 788400000; // a veeery long time!
 118              if( $cacheTime > 788400000)
 119                  $cacheTime = 788400000;
 120  
 121              return( $cacheTime );
 122          }
 123  
 124          function render()
 125          {
 126             lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
 127             lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
 128  
 129              // set the view character set based on the default locale
 130              $this->_getLocale();
 131              $this->setCharset( $this->_locale->getCharset());
 132  
 133              $sendOutput = true;
 134  
 135              // check if support for conditional HTTP requests is enabled
 136              $config =& Config::getConfig();
 137              if( $config->getValue( "template_http_cache_enabled" )) {
 138                  lt_include( PLOG_CLASS_PATH."class/net/http/httpcache.class.php" );
 139                  // some debug information
 140                  $timestamp = $this->_template->getCreationTimestamp();
 141                  // and now send the correct headers
 142                  if( HttpCache::httpConditional( $timestamp, $this->getCacheTimeSeconds()))
 143                      $sendOutput = false;
 144  
 145                  header( "Last-Modified: ".gmdate('D, d M Y H:i:s', $timestamp).' GMT');
 146              }
 147              else {
 148                  $sendOutput = true;
 149              }
 150  
 151              if( $sendOutput ) {
 152                   View::render();
 153                   $this->sendUncachedOutput();
 154              }
 155          }
 156      }
 157  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics