comparison 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
comparison
equal deleted inserted replaced
38:42533600214b 39:bd82b719a0de
1 <?php 1 <?php
2 define(DEBUG, 0); 2 define(VERBOSITY_NONE, 0);
3 define(VERBOSITY_ERROR, 1);
4 define(VERBOSITY_WARNING, 10);
5 define(VERBOSITY_DEBUG, 100);
6
7 define(DEBUG_LEVEL, VERBOSITY_WARNING);
8
9 define(DUMP, 0);
3 define(MAX_RECURSE, 50); 10 define(MAX_RECURSE, 50);
4 define(CACHING, 1); 11 define(CACHING, 1);
5 12
6 /*
7 var_dump($_SERVER);
8 exit;
9 */
10 13
11 if (DEBUG) { 14 if (DEBUG_LEVEL >= VERBOSITY_DEBUG) {
15 var_dump($_SERVER);
16 }
17
18 if (DEBUG_LEVEL >= VERBOSITY_WARNING) {
12 error_reporting(E_ALL); 19 error_reporting(E_ALL);
13 ini_set("display_errors", 1); 20 ini_set("display_errors", 1);
14 } 21 }
15 22
16 $cacheable = true; 23 $cacheable = true;
17 24
18 include_once 'php/CacheTimeCheck.inc'; 25 include_once 'CacheTimeCheck.inc';
19 26
20 $cache = new CacheTimeCheck(filemtime(__FILE__)); 27 $cache = CacheTimeCheck::instance(__FILE__);
21 $cache->includeOnce('php/Options.inc'); 28 $cache->includeOnce('Options.inc');
22 $cache->includeOnce('php/accept-language.inc'); 29 $cache->includeOnce('accept-language.inc');
23 $cache->includeOnce('php/common-functions.inc'); 30 $cache->includeOnce('common-functions.inc');
24 $cache->includeOnce('php/filters.inc'); 31 $cache->includeOnce('filters.inc');
25 $cache->includeOnce('php/inputParser.inc'); 32 $cache->includeOnce('inputParser.inc');
26 33
27 $master = new DOMDocument(); 34 $master = new DOMDocument();
28 $master->load("master.xml"); 35 $masterName = basePath() . "/master.xml";
36 $master->load($masterName);
29 37
30 $options = new Options($master); 38 $options = new Options($master);
31 $options->setCache($cache); 39 $options->setCache($cache);
40 $options->setBasePath(basePath());
32 41
33 $options->setUrlParams(array('name', 'lang')); 42 $options->setUrlParams(array('name', 'lang'));
34 //$URL_PARAMS = array('name', 'lang');
35 43
36 $lang = $_GET['lang']; 44 if(array_key_exists('lang', $_GET)) {
37 if($lang) { 45 $options->setLang($_GET['lang']);
38 $options->setLang($lang);
39 } 46 }
40 else { 47 else {
41 $options->setLang($options->getDefaultLang()); 48 $options->setLang($options->getDefaultLang());
42 } 49 }
43 50
44 $name = $_GET['name']; 51 if( array_key_exists('name', $_GET)) {
45 if($name) { 52 $options->setName($_GET['name']);
46 $options->setName($name);
47 } 53 }
48 54
49 $params = $master->getElementsByTagName("param"); 55 $params = $master->getElementsByTagName("param");
50 56
51 foreach ($params as $param) { 57 foreach ($params as $param) {
60 $parent->removeChild($param); 66 $parent->removeChild($param);
61 } 67 }
62 } 68 }
63 69
64 if (CACHING && $cacheable) 70 if (CACHING && $cacheable)
65 $options->getCache()->CheckHttpModified($newest); 71 $options->getCache()->CheckHttpModified();
66 72
67 print $master->saveXml($master); 73 print $master->saveXml($master);
68 74
69 ?> 75 ?>