view flag.php @ 68:4dfa3f6a2dc1

Modify CacheTimeCheck to have a common parent, and two different implementations for script caches and file caches. Support for linkedcaches.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Thu, 11 Oct 2012 23:16:53 +0200
parents 0f1e08cdfff2
children dd4ddedca4c5
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';

$cache = CacheTimeCheck::instance(__FILE__);
$cache->includeOnce('Language.inc');
$cache->includeOnce('common-functions.inc');

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

$name = "../img/flag-${lang}";
if ($active)
  $name .= "-active";
$name .= ".png";

$cache->cache_time($name);
$cache->CheckHttpModified();

$flag = loadFile($name);

if (floatval($flag) < 0) {
  errorPage('Resource not found', 404);
}
else {
  header("Content-Type: image/png");
  print $flag;
}