Mercurial > SimpleWebPresenter
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Flag.inc.php Sun Jan 22 19:22:00 2023 +0100 @@ -0,0 +1,93 @@ +<?php +/** + * @file + * Displays a flag, in an active or disabled state, depending on parameters + */ + +include_once 'CacheTimeCheck.inc.php'; + +/// @cond +$scriptCache = ScriptIncludeCache::instance(__FILE__); +$scriptCache->includeOnce('Language.inc.php'); +$scriptCache->includeOnce('common-functions.inc.php'); +$scriptCache->includeOnce('Page.inc.php'); +/// @endcond + +/** + * Functionality for generating a flag based on state options + */ +class Flag extends Page +{ + private $active; + private $lang; + + /** + * Constructs a flag object + * + * @param $masterCache link this objects cache to this masterCache + */ + 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; + foreach ( [ 'img', '../img' ] as $dir) { + $this->name = "${dir}/flag-${lang}"; + if ($this->active) + $this->name .= "-active"; + $this->name .= ".png"; + if (file_exists($this->name)) + break; + } + + $cache = new CacheTimeCheck($this->name); + $cache->setMaxAge(30*86400); + $cache->addParent($masterCache); + $this->setCache($cache); + } + + function cacheCheck() + { + return Cacheable::YES; + } + + function mayCompress() + { + return false; + } + + function mayValidate() + { + return false; + } + + /** + * Produce the actual content + */ + function generateContent() + { + $flag = loadFile($this->name); + + if (floatval($flag) < 0) { + errorPage('Resource not found', 404); + } + else { + $flag = new PageContent($flag); + $flag->setHeader('Content-Type', 'image/png'); + return $flag; + } + } +}
