view index.php @ 41:2a3ff56697db

Don't set values if they are empty in URL.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Fri, 05 Oct 2012 00:48:33 +0200
parents fbbb82ced6de
children 79f708a48a7c
line wrap: on
line source

<?php
define(VERBOSITY_NONE, 0);
define(VERBOSITY_ERROR, 1);
define(VERBOSITY_WARNING, 10);
define(VERBOSITY_DEBUG, 100);

define(DEBUG_LEVEL, VERBOSITY_WARNING);

define(DUMP, 0);
define(MAX_RECURSE, 50);
define(CACHING, 1);


if (DEBUG_LEVEL >= VERBOSITY_DEBUG) {
  var_dump($_SERVER);
}

if (DEBUG_LEVEL >= VERBOSITY_WARNING) {
  error_reporting(E_ALL);
  ini_set("display_errors", 1);
}

$cacheable = true;

include_once 'CacheTimeCheck.inc';

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

$master = new DOMDocument();
$masterName = basePath() . "/master.xml";
$master->load($masterName);

$options = new Options($master);
$options->setCache($cache);
$options->setBasePath(basePath());

$options->setUrlParams(array('name', 'lang'));

if(array_key_exists('lang', $_GET) && $_GET['lang']) {
  $options->setLang($_GET['lang']);
}
else {
  $options->setLang($options->getDefaultLang());
}

if(array_key_exists('name', $_GET) && $_GET['name']) {
  $options->setName($_GET['name']);
}

$params = $master->getElementsByTagName("param");

foreach ($params as $param) {
  if ($param->getAttribute("type") == "input") {
    $doc = getInput($master, $param, $options);

    $parent = $param->parentNode;
    foreach ($doc->firstChild->childNodes as $child) {
      $clonedChild = $master->importNode($child, true);
      $parent->insertBefore($clonedChild, $param);
    }
    $parent->removeChild($param);
  }
}

if (CACHING && $cacheable)
  $options->getCache()->CheckHttpModified();

print $master->saveXml($master);

?>