Mercurial > SimpleWebPresenter
changeset 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 | fae4322d6c29 |
| children | 9b490aa11124 |
| files | Flag.inc InputParser.inc Page.inc Sitemap.inc flag.php |
| diffstat | 5 files changed, 100 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Flag.inc Fri Oct 12 01:54:51 2012 +0200 +++ b/Flag.inc Fri Oct 12 16:43:26 2012 +0200 @@ -10,11 +10,12 @@ $scriptCache = ScriptIncludeCache::instance(__FILE__); $scriptCache->includeOnce('Language.inc'); $scriptCache->includeOnce('common-functions.inc'); +$scriptCache->includeOnce('Page.inc'); -class Flag { +class Flag extends Page +{ private $active; private $lang; - private $cache; function __construct($masterCache) { @@ -39,14 +40,24 @@ $this->name .= "-active"; $this->name .= ".png"; - $this->cache = new CacheTimeCheck($this->name); - $this->cache->addParent($masterCache); - $this->cache->cache_time($this->name); + $cache = new CacheTimeCheck($this->name); + $cache->addParent($masterCache); + $this->setCache($cache); } - function getPage() + function cacheCheck() { - $this->cache->CheckHttpModified(); + $this->getCache()->cache_time($this->name); + return $true; + } + + function mayCompress() + { + return false; + } + + function generateContent() + { $flag = loadFile($this->name);
--- a/InputParser.inc Fri Oct 12 01:54:51 2012 +0200 +++ b/InputParser.inc Fri Oct 12 16:43:26 2012 +0200 @@ -1,8 +1,15 @@ <?php +/// @cond +$baseDir = dirname(__FILE__); +$cache = ScriptIncludeCache::instance(__FILE__); +$cache->includeOnce('Page.inc', dirname(__FILE__)); +/// @endcond + /** * Functionality for translating an XML configuration document into a webpage */ -class InputParser { +class InputParser extends Page +{ private $options; private $master; @@ -18,6 +25,7 @@ $this->master = new DOMDocument(); $cache = new CacheTimeCheck($name); $cache->addParent($masterCache); + parent::setCache($cache); $this->master->load($name); $this->options = new Options($this->master); @@ -56,17 +64,20 @@ } + function cacheCheck() + { + return $this->options->getCacheable(); + } + /** * Generate an appropriate response for this page, eg. 302 NOT * MODIFIED or the actual page */ - function genPage() + function generateContent() { //print_r($this->options->getCache()->cacheSet(1)); //exit; - if (CACHING && $this->options->getCacheable()) - $this->options->getCache()->CheckHttpModified(); - print $this->master->saveXml($this->master); + return $this->master->saveXml($this->master); } /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Page.inc Fri Oct 12 16:43:26 2012 +0200 @@ -0,0 +1,56 @@ +<? +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; + } + + +} +?>
--- a/Sitemap.inc Fri Oct 12 01:54:51 2012 +0200 +++ b/Sitemap.inc Fri Oct 12 16:43:26 2012 +0200 @@ -5,13 +5,13 @@ $baseDir = dirname(__FILE__); $cache = ScriptIncludeCache::instance(__FILE__); $cache->includeOnce('common-functions.inc', $baseDir); -$cache->includeOnce('Options.inc', dirname(__FILE__)); +$cache->includeOnce('Page.inc', dirname(__FILE__)); /// @endcond /** * Functionality for generating a sitemap */ -class Sitemap +class Sitemap extends Page { private $master; private $options; @@ -28,7 +28,12 @@ $this->options = new Options($this->master); } - function genPage() { + function cacheCheck() + { + return false; + } + + function generateContent() { /// The final output variable $out = '<?xml version="1.0" encoding="UTF-8"?>'; $out .= "\n"; @@ -99,7 +104,7 @@ $out .= '</urlset>'; header('Content-type: application/xml'); - print $out; + return $out; } } ?>
