comparison index.php @ 19:ee2c31392ea3

Merge Regression, fast cache-checking has been removed.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Wed, 19 Sep 2012 15:50:18 +0200
parents a64e8f968e7e a20bb1b51aad
children ac24b41a12ad
comparison
equal deleted inserted replaced
18:d5068ced2ad1 19:ee2c31392ea3
1 <?php 1 <?php
2 define(DEBUG,0); 2 define(DEBUG,0);
3 define(MAX_RECURSE,50); 3 define(MAX_RECURSE,50);
4 define(CACHING,0);
5
6 /*
7 var_dump($_SERVER);
8 exit;
9 */
4 10
5 function include_with_mtime($file) { 11 function include_with_mtime($file) {
6 global $newest; 12 global $newest;
7 $mtime = filemtime($file); 13 $mtime = filemtime($file);
8 if ($mtime > $newest) { 14 if ($mtime > $newest) {
18 24
19 $SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME']; 25 $SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME'];
20 $newest = filemtime($SCRIPT_FILENAME); 26 $newest = filemtime($SCRIPT_FILENAME);
21 $cachable = true; 27 $cachable = true;
22 28
29 <<<<<<< local
23 include_with_mtime('php/cache_check.inc'); 30 include_with_mtime('php/cache_check.inc');
24 include_with_mtime('php/accept-language.inc'); 31 include_with_mtime('php/accept-language.inc');
25 include_with_mtime('php/filters.inc'); 32 include_with_mtime('php/filters.inc');
26 include_with_mtime('php/common-functions.inc'); 33 include_with_mtime('php/common-functions.inc');
34 =======
35 if(CACHING) {
36 include 'php/cache_check.inc';
37 }
38 include 'php/accept-language.inc';
39 include 'php/filters.inc';
40 include 'php/common-functions.inc';
41 >>>>>>> other
27 42
28 $URL_PARAMS=array('name', 'lang'); 43 $URL_PARAMS=array('name', 'lang');
29 44
30 #Globals 45 #Globals
31 $name = $_GET['name']; 46 $name = $_GET['name'];
36 } 51 }
37 52
38 if(!$lang) { 53 if(!$lang) {
39 $lang="no"; 54 $lang="no";
40 $langs=acceptedLanguages(); 55 $langs=acceptedLanguages();
41 foreach ($langs as $l => $val) { 56 if ($langs) {
42 if (file_exists($l)) { 57 foreach ($langs as $l => $val) {
43 $lang=$l; 58 if (file_exists($l)) {
44 break; 59 $lang=$l;
45 } 60 break;
46 } 61 }
47 } 62 }
48 63 }
64 }
65
66 <<<<<<< local
49 $title="Dummy title"; 67 $title="Dummy title";
50 68
51 $config=loadFile("${lang}/${name}.xml"); 69 $config=loadFile("${lang}/${name}.xml");
52 70
53 $confFile="${lang}/${name}.xml"; 71 $confFile="${lang}/${name}.xml";
113 </head> 131 </head>
114 <body> 132 <body>
115 <div id="container"> 133 <div id="container">
116 '; 134 ';
117 135
136 =======
137 >>>>>>> other
118 function getParam($param) { 138 function getParam($param) {
119 $param_type=$param->getAttribute("type"); 139 $param_type=$param->getAttribute("type");
120 $param_value; 140 $param_value;
121 if (!$param_type) 141 if (!$param_type)
122 $param_type="scalar"; 142 $param_type="scalar";
141 } 161 }
142 } 162 }
143 } 163 }
144 return $param_value; 164 return $param_value;
145 } 165 }
166
167 function getInput($master, $param) {
168 $out='';
169
170 $lang=$GLOBALS['lang'];
171 $name=$param->getAttribute("id");
172 $conf=$_GET[$name];
173 $GLOBALS[$name]=$conf;
174 if (!$conf)
175 $conf=$param->getAttribute("default");
176 $config=loadFile("${lang}/${conf}.xml");
177
178 $confFile="${lang}/${conf}.xml";
179 if (!file_exists($confFile)) {
180 errorPage("Resource not available");
181 }
182 $doc = new DOMDocument();
183 $doc->load($confFile);
184
185 $includes=$doc->getElementsByTagName("include");
186 $recurse=0;
187
188 while($includes->length>0) {
189 if(++$recurse>MAX_RECURSE) {
190 errorPage('Recursion limit exceeded', 500);
191 }
192 foreach ($includes as $include) {
193 $src=$include->getAttribute("src");
194 $subdoc = new DOMDocument();
195 $subdoc->load("${lang}/${src}");
196 $parent=$include->parentNode;
197 $xml=getElementByTagName($subdoc,"xml");
198 foreach($xml->childNodes as $child) {
199 $text=$subdoc->saveXml($child);
200 $clonedChild=$doc->importNode($child,true);
201 $parent->insertBefore($clonedChild,$include);
202 }
203 $parent->removeChild($include);
204 }
205 $includes=$doc->getElementsByTagName("include");
206 }
207
208 $head=getElementByTagName($doc,"head");
209 $title=$head->getAttribute("title");
210
211 if($title) {
212 $values=$master->getElementsByTagName("param");
213 foreach ($values as $value) {
214 if ($value->getAttribute("type")=="input_config") {
215 if ($value->getAttribute("id")=="title") {
216 $tmp = new DOMDocument();
217 $tmp->loadXml("<xml>${title}</xml>");
218 $parent=$value->parentNode;
219 $parent->removeChild($value);
220 $parent->appendChild(new DOMText($tmp->textContent));
221 }
222 }
223 }
224 }
225
226 $css=getElementByTagName($head,"css");
227 $css=$doc->saveXML($css);
228 $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css);
229
230 if($css) {
231 $values=$master->getElementsByTagName("param");
232 foreach ($values as $value) {
233 if ($value->getAttribute("type")=="input_config") {
234 if ($value->getAttribute("id")=="css") {
235 $tmp = new DOMDocument();
236 $tmp->loadXml("<xml>${css}</xml>");
237 $parent=$value->parentNode;
238 foreach($tmp->firstChild->childNodes as $node) {
239 $clonedChild=$master->importNode($node,true);
240 $parent->insertBefore($clonedChild,$value);
241 }
242 $parent->removeChild($value);
243 }
244 }
245 }
246 }
247
248
249 $body=getElementByTagName($doc,"body");
250 $files=$body->getElementsByTagName("file");
146 251
147 foreach ($files as $file) { 252 foreach ($files as $file) {
148 if ($file->getAttribute("script")) { 253 if ($file->getAttribute("script")) {
149 $cachable = false; 254 $cachable = false;
150 break; 255 break;
206 eval($callString); 311 eval($callString);
207 } 312 }
208 $out.= $file_content; 313 $out.= $file_content;
209 } 314 }
210 315
316 <<<<<<< local
211 317
212 318
213 $out.=' 319 $out.='
214 </div> 320 </div>
215 </body> 321 </body>
216 </html> 322 </html>
217 '; 323 ';
218 324 =======
219 print $out; 325 $doc = new DOMDocument();
326 $doc->loadXml("<xml>${out}</xml>");
327 >>>>>>> other
328
329 return $doc;
330 }
331
332 $master = new DOMDocument();
333 $master->load("master.xml");
334
335 $params=$master->getElementsByTagName("param");
336 foreach ($params as $param) {
337 if ($param->getAttribute("type") == "input") {
338 $doc=getInput($master,$param);
339
340 $parent=$param->parentNode;
341 foreach ($doc->firstChild->childNodes as $child) {
342 $clonedChild=$master->importNode($child,true);
343 $parent->insertBefore($clonedChild,$param);
344 }
345 $parent->removeChild($param);
346
347 }
348 }
349
350 print $master->saveXml($master);
351
220 ?> 352 ?>