# HG changeset patch # User Tom Fredrik "BFG" Klaussen # Date 1350053245 -7200 # Node ID 9b490aa11124a1510b2f565526d7e71ae9aa5a39 # Parent 7c68015b211acae555ac44539f378a727e83b78a# Parent 9d766788f0bc4a9b4cd39c935a28f58b5dc3b93d Branch merge. diff -r 9d766788f0bc -r 9b490aa11124 Flag.inc --- a/Flag.inc Fri Oct 12 01:59:21 2012 +0200 +++ b/Flag.inc Fri Oct 12 16:47:25 2012 +0200 @@ -11,15 +11,16 @@ $scriptCache = ScriptIncludeCache::instance(__FILE__); $scriptCache->includeOnce('Language.inc'); $scriptCache->includeOnce('common-functions.inc'); +$scriptCache->includeOnce('Page.inc'); /// @endcond /** * Functionality for generating a flag based on state options */ -class Flag { +class Flag extends Page +{ private $active; private $lang; - private $cache; /** * Constructs a flag object @@ -49,17 +50,27 @@ $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 cacheCheck() + { + $this->getCache()->cache_time($this->name); + return $true; + } + + function mayCompress() + { + return false; } /** - * Produce an apropriate response, eg cached or the actual content + * Produce the actual content */ - function getPage() + function generateContent() { - $this->cache->CheckHttpModified(); $flag = loadFile($this->name); diff -r 9d766788f0bc -r 9b490aa11124 InputParser.inc --- a/InputParser.inc Fri Oct 12 01:59:21 2012 +0200 +++ b/InputParser.inc Fri Oct 12 16:47:25 2012 +0200 @@ -1,8 +1,15 @@ 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); } /** diff -r 9d766788f0bc -r 9b490aa11124 Page.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Page.inc Fri Oct 12 16:47:25 2012 +0200 @@ -0,0 +1,56 @@ +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; + } + + +} +?> diff -r 9d766788f0bc -r 9b490aa11124 Sitemap.inc --- a/Sitemap.inc Fri Oct 12 01:59:21 2012 +0200 +++ b/Sitemap.inc Fri Oct 12 16:47:25 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 = ''; $out .= "\n"; @@ -99,7 +104,7 @@ $out .= ''; header('Content-type: application/xml'); - print $out; + return $out; } } ?> diff -r 9d766788f0bc -r 9b490aa11124 flag.php --- a/flag.php Fri Oct 12 01:59:21 2012 +0200 +++ b/flag.php Fri Oct 12 16:47:25 2012 +0200 @@ -12,5 +12,5 @@ $scriptCache->includeOnce('Flag.inc'); $flag = new Flag($scriptCache); -print $flag->getPage(); -/// @endcond \ No newline at end of file +$flag->genPage(); +/// @endcond