view Flag.inc @ 77:9d766788f0bc

Fix remaining documentation errors.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Fri, 12 Oct 2012 01:59:21 +0200
parents fae4322d6c29
children 9b490aa11124
line wrap: on
line source

<?php
/**
 * @file
 * Displays a flag, in an active or disabled state, depending on parameters
 */
define(DEBUG,0);

include_once 'CacheTimeCheck.inc';

/// @cond
$scriptCache = ScriptIncludeCache::instance(__FILE__);
$scriptCache->includeOnce('Language.inc');
$scriptCache->includeOnce('common-functions.inc');
/// @endcond

/**
 * Functionality for generating a flag based on state options
 */
class Flag {
  private $active;
  private $lang;
  private $cache;

  /**
   * 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;
    $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);
  }

  /**
   * Produce an apropriate response, eg cached or the actual content
   */
  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;
    }
  }
}