Mercurial > SimpleWebPresenter
changeset 76:fae4322d6c29
Refactored Flag into a separate class.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 12 Oct 2012 01:54:51 +0200 |
| parents | 5e76b6feb2ad |
| children | 9d766788f0bc 7c68015b211a |
| files | Flag.inc flag.php |
| diffstat | 2 files changed, 64 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Flag.inc Fri Oct 12 01:54:51 2012 +0200 @@ -0,0 +1,61 @@ +<?php +/** + * @file + * Displays a flag, in an active or disabled state, depending on parameters + */ +define(DEBUG,0); + +include_once 'CacheTimeCheck.inc'; + +$scriptCache = ScriptIncludeCache::instance(__FILE__); +$scriptCache->includeOnce('Language.inc'); +$scriptCache->includeOnce('common-functions.inc'); + +class Flag { + private $active; + private $lang; + private $cache; + + function __construct($masterCache) + { + $this->active = $_GET['active']; + $lang = $_GET['lang']; + + if(!$lang) { + $lang = "no"; + $langs = Language::accepted(); + foreach ($langs as $l => $val) { + if (file_exists($l)) { + $lang = $l; + break; + } + } + } + + + $this->lang = $lang; + $this->name = "../img/flag-${lang}"; + if ($this->active) + $this->name .= "-active"; + $this->name .= ".png"; + + $this->cache = new CacheTimeCheck($this->name); + $this->cache->addParent($masterCache); + $this->cache->cache_time($this->name); + } + + function getPage() + { + $this->cache->CheckHttpModified(); + + $flag = loadFile($this->name); + + if (floatval($flag) < 0) { + errorPage('Resource not found', 404); + } + else { + header("Content-Type: image/png"); + return $flag; + } + } +} \ No newline at end of file
--- a/flag.php Fri Oct 12 01:19:23 2012 +0200 +++ b/flag.php Fri Oct 12 01:54:51 2012 +0200 @@ -8,39 +8,7 @@ include_once 'CacheTimeCheck.inc'; $scriptCache = ScriptIncludeCache::instance(__FILE__); -$scriptCache->includeOnce('Language.inc'); -$scriptCache->includeOnce('common-functions.inc'); - -$active = $_GET['active']; -$lang = $_GET['lang']; - -if(!$lang) { - $lang = "no"; - $langs = Language::accepted(); - foreach ($langs as $l => $val) { - if (file_exists($l)) { - $lang = $l; - break; - } - } -} +$scriptCache->includeOnce('Flag.inc'); -$name = "../img/flag-${lang}"; -if ($active) - $name .= "-active"; -$name .= ".png"; - -$cache = new CacheTimeCheck($name); -$cache->addParent($scriptCache); -$cache->cache_time($name); -$cache->CheckHttpModified(); - -$flag = loadFile($name); - -if (floatval($flag) < 0) { - errorPage('Resource not found', 404); -} -else { - header("Content-Type: image/png"); - print $flag; -} \ No newline at end of file +$flag = new Flag($scriptCache); +print $flag->getPage(); \ No newline at end of file
