comparison index.php @ 14:91ee5f49907e

Correct caching. We could probably push caching earlier, but more important that it is correct.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Wed, 19 Sep 2012 13:55:58 +0200
parents 19dfa6f3e2be
children a64e8f968e7e
comparison
equal deleted inserted replaced
13:9dab5b96b789 14:91ee5f49907e
1 <?php 1 <?php
2 define(DEBUG,0); 2 define(DEBUG,0);
3 define(MAX_RECURSE,50); 3 define(MAX_RECURSE,50);
4 4
5 function include_with_mtime($file) {
6 global $newest;
7 $mtime = filemtime($file);
8 if ($mtime > $newest) {
9 $newest = $mtime;
10 }
11 include $file;
12 }
13
5 if (DEBUG) { 14 if (DEBUG) {
6 error_reporting(E_ALL); 15 error_reporting(E_ALL);
7 ini_set("display_errors", 1); 16 ini_set("display_errors", 1);
8 } 17 }
9 18
10 19 $SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME'];
11 include 'php/cache_check.inc'; 20 $newest = filemtime($SCRIPT_FILENAME);
12 include 'php/accept-language.inc'; 21 $cachable = true;
13 include 'php/filters.inc'; 22
14 include 'php/common-functions.inc'; 23 include_with_mtime('php/cache_check.inc');
15 24 include_with_mtime('php/accept-language.inc');
16 $URL_PARAMS=array('name','lang'); 25 include_with_mtime('php/filters.inc');
26 include_with_mtime('php/common-functions.inc');
27
28 $URL_PARAMS=array('name', 'lang');
17 29
18 #Globals 30 #Globals
19 $name = $_GET['name']; 31 $name = $_GET['name'];
20 $lang = $_GET['lang']; 32 $lang = $_GET['lang'];
21 33
46 $doc->load($confFile); 58 $doc->load($confFile);
47 59
48 $includes=$doc->getElementsByTagName("include"); 60 $includes=$doc->getElementsByTagName("include");
49 $recurse=0; 61 $recurse=0;
50 62
51 while($includes->length>0) { 63 while($includes->length > 0) {
52 if(++$recurse>MAX_RECURSE) { 64 if(++$recurse > MAX_RECURSE) {
53 errorPage('Recursion limit exceeded', 500); 65 errorPage('Recursion limit exceeded', 500);
54 } 66 }
55 foreach ($includes as $include) { 67 foreach ($includes as $include) {
56 $src=$include->getAttribute("src"); 68 $src=$include->getAttribute("src");
57 $subdoc = new DOMDocument(); 69 $subdoc = new DOMDocument();
58 $subdoc->load("${lang}/${src}"); 70 $fname = "${lang}/${src}";
71 $subdoc->load($fname);
72 $mtime = filemtime($fname);
73 if ($mtime > $newest) {
74 $newest = $mtime;
75 }
59 $parent=$include->parentNode; 76 $parent=$include->parentNode;
60 $xml=getElementByTagName($subdoc,"xml"); 77 $xml=getElementByTagName($subdoc,"xml");
61 foreach($xml->childNodes as $child) { 78 foreach($xml->childNodes as $child) {
62 $text=$subdoc->saveXml($child); 79 $text=$subdoc->saveXml($child);
63 $clonedChild=$doc->importNode($child,true); 80 $clonedChild=$doc->importNode($child,true);
128 } 145 }
129 146
130 foreach ($files as $file) { 147 foreach ($files as $file) {
131 $script=$file->getAttribute("script"); 148 $script=$file->getAttribute("script");
132 if ($script) { 149 if ($script) {
150 $cachable = false;
133 $src=""; 151 $src="";
134 $cwd=getcwd(); 152 $cwd=getcwd();
135 153
136 $matches=array(); 154 $matches=array();
137 preg_match('/(.*\/)/', $script, $matches); 155 preg_match('/(.*\/)/', $script, $matches);
143 $file_content = stream_get_contents($pipe); 161 $file_content = stream_get_contents($pipe);
144 chdir("${cwd}"); 162 chdir("${cwd}");
145 } 163 }
146 else { 164 else {
147 $src=$file->getAttribute("src"); 165 $src=$file->getAttribute("src");
148 $file_content=loadFile("${lang}/${src}"); 166 $fname = "${lang}/${src}";
167 $mtime = filemtime($fname);
168 if ($mtime > $newest) {
169 $newest = $mtime;
170 }
171 $file_content=loadFile($fname);
149 } 172 }
150 if(floatval($file_content)<0) { 173 if(floatval($file_content)<0) {
151 errorPage("Resource not found '${lang}/${src}'"); 174 errorPage("Resource not found '${lang}/${src}'");
152 } 175 }
153 176
169 $callString.=");"; 192 $callString.=");";
170 eval($callString); 193 eval($callString);
171 } 194 }
172 $out.= $file_content; 195 $out.= $file_content;
173 } 196 }
197 if ($cachable)
198 cache_check($newest);
199
174 200
175 $out.=' 201 $out.='
176 </div> 202 </div>
177 </body> 203 </body>
178 </html> 204 </html>