diff 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
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