Mercurial > SimpleWebPresenter
comparison Flag.inc @ 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 | |
| children | 9d766788f0bc 7c68015b211a |
comparison
equal
deleted
inserted
replaced
| 75:5e76b6feb2ad | 76:fae4322d6c29 |
|---|---|
| 1 <?php | |
| 2 /** | |
| 3 * @file | |
| 4 * Displays a flag, in an active or disabled state, depending on parameters | |
| 5 */ | |
| 6 define(DEBUG,0); | |
| 7 | |
| 8 include_once 'CacheTimeCheck.inc'; | |
| 9 | |
| 10 $scriptCache = ScriptIncludeCache::instance(__FILE__); | |
| 11 $scriptCache->includeOnce('Language.inc'); | |
| 12 $scriptCache->includeOnce('common-functions.inc'); | |
| 13 | |
| 14 class Flag { | |
| 15 private $active; | |
| 16 private $lang; | |
| 17 private $cache; | |
| 18 | |
| 19 function __construct($masterCache) | |
| 20 { | |
| 21 $this->active = $_GET['active']; | |
| 22 $lang = $_GET['lang']; | |
| 23 | |
| 24 if(!$lang) { | |
| 25 $lang = "no"; | |
| 26 $langs = Language::accepted(); | |
| 27 foreach ($langs as $l => $val) { | |
| 28 if (file_exists($l)) { | |
| 29 $lang = $l; | |
| 30 break; | |
| 31 } | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 | |
| 36 $this->lang = $lang; | |
| 37 $this->name = "../img/flag-${lang}"; | |
| 38 if ($this->active) | |
| 39 $this->name .= "-active"; | |
| 40 $this->name .= ".png"; | |
| 41 | |
| 42 $this->cache = new CacheTimeCheck($this->name); | |
| 43 $this->cache->addParent($masterCache); | |
| 44 $this->cache->cache_time($this->name); | |
| 45 } | |
| 46 | |
| 47 function getPage() | |
| 48 { | |
| 49 $this->cache->CheckHttpModified(); | |
| 50 | |
| 51 $flag = loadFile($this->name); | |
| 52 | |
| 53 if (floatval($flag) < 0) { | |
| 54 errorPage('Resource not found', 404); | |
| 55 } | |
| 56 else { | |
| 57 header("Content-Type: image/png"); | |
| 58 return $flag; | |
| 59 } | |
| 60 } | |
| 61 } |
