Mercurial > SimpleWebPresenter
comparison Flag.inc.php @ 134:b6b4a58c7625
Using .inc.php rather than just .inc for include files.
| author | Tom Fredrik Blenning <bfg@bfgconsult.no> |
|---|---|
| date | Sun, 22 Jan 2023 19:22:00 +0100 |
| parents | Flag.inc@16c3ee204330 |
| children |
comparison
equal
deleted
inserted
replaced
| 133:00255ca89459 | 134:b6b4a58c7625 |
|---|---|
| 1 <?php | |
| 2 /** | |
| 3 * @file | |
| 4 * Displays a flag, in an active or disabled state, depending on parameters | |
| 5 */ | |
| 6 | |
| 7 include_once 'CacheTimeCheck.inc.php'; | |
| 8 | |
| 9 /// @cond | |
| 10 $scriptCache = ScriptIncludeCache::instance(__FILE__); | |
| 11 $scriptCache->includeOnce('Language.inc.php'); | |
| 12 $scriptCache->includeOnce('common-functions.inc.php'); | |
| 13 $scriptCache->includeOnce('Page.inc.php'); | |
| 14 /// @endcond | |
| 15 | |
| 16 /** | |
| 17 * Functionality for generating a flag based on state options | |
| 18 */ | |
| 19 class Flag extends Page | |
| 20 { | |
| 21 private $active; | |
| 22 private $lang; | |
| 23 | |
| 24 /** | |
| 25 * Constructs a flag object | |
| 26 * | |
| 27 * @param $masterCache link this objects cache to this masterCache | |
| 28 */ | |
| 29 function __construct($masterCache) | |
| 30 { | |
| 31 $this->active = $_GET['active']; | |
| 32 $lang = $_GET['lang']; | |
| 33 | |
| 34 if(!$lang) { | |
| 35 $lang = "no"; | |
| 36 $langs = Language::accepted(); | |
| 37 foreach ($langs as $l => $val) { | |
| 38 if (file_exists($l)) { | |
| 39 $lang = $l; | |
| 40 break; | |
| 41 } | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 | |
| 46 $this->lang = $lang; | |
| 47 foreach ( [ 'img', '../img' ] as $dir) { | |
| 48 $this->name = "${dir}/flag-${lang}"; | |
| 49 if ($this->active) | |
| 50 $this->name .= "-active"; | |
| 51 $this->name .= ".png"; | |
| 52 if (file_exists($this->name)) | |
| 53 break; | |
| 54 } | |
| 55 | |
| 56 $cache = new CacheTimeCheck($this->name); | |
| 57 $cache->setMaxAge(30*86400); | |
| 58 $cache->addParent($masterCache); | |
| 59 $this->setCache($cache); | |
| 60 } | |
| 61 | |
| 62 function cacheCheck() | |
| 63 { | |
| 64 return Cacheable::YES; | |
| 65 } | |
| 66 | |
| 67 function mayCompress() | |
| 68 { | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 function mayValidate() | |
| 73 { | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 /** | |
| 78 * Produce the actual content | |
| 79 */ | |
| 80 function generateContent() | |
| 81 { | |
| 82 $flag = loadFile($this->name); | |
| 83 | |
| 84 if (floatval($flag) < 0) { | |
| 85 errorPage('Resource not found', 404); | |
| 86 } | |
| 87 else { | |
| 88 $flag = new PageContent($flag); | |
| 89 $flag->setHeader('Content-Type', 'image/png'); | |
| 90 return $flag; | |
| 91 } | |
| 92 } | |
| 93 } |
