view flag.php @ 39:bd82b719a0de

Make CacheTimeCheck a singleton. Robustify if_modified_since check. Quiet warnings. Set debug levels. Fix basepath references.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Fri, 05 Oct 2012 00:21:27 +0200
parents 42533600214b
children 2cfea6e84694
line wrap: on
line source

<?php
define(DEBUG,0);

include_once 'CacheTimeCheck.inc';

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

$active = $_GET['active'];
$lang = $_GET['lang'];

if(!$lang) {
  $lang = "no";
  $langs = acceptedLanguages();
  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;
}