view Page.inc @ 78:7c68015b211a

Common source for all page generators. Support for compressed output.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Fri, 12 Oct 2012 16:43:26 +0200
parents
children 88904282b888
line wrap: on
line source

<?
include_once 'ScriptIncludeCache.inc';

/// @cond
$baseDir = dirname(__FILE__);
$cache = ScriptIncludeCache::instance(__FILE__);
$cache->includeOnce('Options.inc', dirname(__FILE__));
/// @endcond

/**
 * Functionality for generating a page
 */
class Page
{
  private $cache;

  function __construct($cache)
  {
    $this->setCache($cache);
  }

  protected function setCache($cache)
  {
    $this->cache = $cache;
  }

  protected function getCache()
  {
    return $this->cache;
  }

  function mayCompress()
  {
    return (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'));
  }

  function startCompression()
  {
    ob_start("ob_gzhandler");
  }

  function genPage()
  {
    if ($this->cacheCheck()) {
      $this->cache->CheckHttpModified();
    }
    $res = $this->generateContent();
    if ($this->mayCompress()) {
      $this->startCompression();
    }
    print $res;
  }


}
?>