diff index.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 fbbb82ced6de
line wrap: on
line diff
--- a/index.php	Thu Oct 04 22:07:19 2012 +0200
+++ b/index.php	Fri Oct 05 00:21:27 2012 +0200
@@ -1,49 +1,55 @@
 <?php
-define(DEBUG, 0);
+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);
 
-/*
-var_dump($_SERVER);
-exit;
-*/
 
-if (DEBUG) {
+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 'php/CacheTimeCheck.inc';
+include_once 'CacheTimeCheck.inc';
 
-$cache = new CacheTimeCheck(filemtime(__FILE__));
-$cache->includeOnce('php/Options.inc');
-$cache->includeOnce('php/accept-language.inc');
-$cache->includeOnce('php/common-functions.inc');
-$cache->includeOnce('php/filters.inc');
-$cache->includeOnce('php/inputParser.inc');
+$cache = CacheTimeCheck::instance(__FILE__);
+$cache->includeOnce('Options.inc');
+$cache->includeOnce('accept-language.inc');
+$cache->includeOnce('common-functions.inc');
+$cache->includeOnce('filters.inc');
+$cache->includeOnce('inputParser.inc');
 
 $master = new DOMDocument();
-$master->load("master.xml");
+$masterName = basePath() . "/master.xml";
+$master->load($masterName);
 
 $options = new Options($master);
 $options->setCache($cache);
+$options->setBasePath(basePath());
 
 $options->setUrlParams(array('name', 'lang'));
-//$URL_PARAMS = array('name', 'lang');
 
-$lang = $_GET['lang'];
-if($lang) {
-  $options->setLang($lang);
+if(array_key_exists('lang', $_GET)) {
+  $options->setLang($_GET['lang']);
 }
 else {
   $options->setLang($options->getDefaultLang());
 }
 
-$name = $_GET['name'];
-if($name) {
-  $options->setName($name);
+if( array_key_exists('name', $_GET)) {
+  $options->setName($_GET['name']);
 }
 
 $params = $master->getElementsByTagName("param");
@@ -62,7 +68,7 @@
 }
 
 if (CACHING && $cacheable)
-  $options->getCache()->CheckHttpModified($newest);
+  $options->getCache()->CheckHttpModified();
 
 print $master->saveXml($master);