view Flag.inc @ 92:f468365813c9

Set language header. Remove cruft.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Thu, 18 Oct 2012 14:04:19 +0200
parents 1d4c980f4255
children d98e315308cd
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');
$scriptCache->includeOnce('Page.inc');
/// @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;
    $this->name = "../img/flag-${lang}";
    if ($this->active)
      $this->name .= "-active";
    $this->name .= ".png";

    $cache = new CacheTimeCheck($this->name);
    $cache->addParent($masterCache);
    $this->setCache($cache);
  }

  function cacheCheck()
  {
    $this->getCache()->cache_time($this->name);
    return $true;
  }

  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;
    }
  }
}