comparison index.php @ 20:ac24b41a12ad

Something strange got committed in last comit, correct commit.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Wed, 19 Sep 2012 15:51:33 +0200
parents ee2c31392ea3
children 5dc5cc27471d
comparison
equal deleted inserted replaced
19:ee2c31392ea3 20:ac24b41a12ad
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); 4 define(CACHING,1);
5 5
6 /* 6 /*
7 var_dump($_SERVER); 7 var_dump($_SERVER);
8 exit; 8 exit;
9 */ 9 */
10 10
11 function include_with_mtime($file) {
12 global $newest;
13 $mtime = filemtime($file);
14 if ($mtime > $newest) {
15 $newest = $mtime;
16 }
17 include $file;
18 }
19
20 if (DEBUG) { 11 if (DEBUG) {
21 error_reporting(E_ALL); 12 error_reporting(E_ALL);
22 ini_set("display_errors", 1); 13 ini_set("display_errors", 1);
23 } 14 }
24 15
25 $SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME']; 16 $SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME'];
26 $newest = filemtime($SCRIPT_FILENAME); 17 $newest = filemtime($SCRIPT_FILENAME);
27 $cachable = true; 18 $cacheable = true;
28 19
29 <<<<<<< local 20 include 'php/cache_check.inc';
30 include_with_mtime('php/cache_check.inc');
31 include_with_mtime('php/accept-language.inc'); 21 include_with_mtime('php/accept-language.inc');
32 include_with_mtime('php/filters.inc'); 22 include_with_mtime('php/filters.inc');
33 include_with_mtime('php/common-functions.inc'); 23 include_with_mtime('php/common-functions.inc');
34 ======= 24
35 if(CACHING) { 25 $URL_PARAMS=array('name','lang');
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
42
43 $URL_PARAMS=array('name', 'lang');
44 26
45 #Globals 27 #Globals
46 $name = $_GET['name']; 28 $name = $_GET['name'];
47 $lang = $_GET['lang']; 29 $lang = $_GET['lang'];
48 30
61 } 43 }
62 } 44 }
63 } 45 }
64 } 46 }
65 47
66 <<<<<<< local
67 $title="Dummy title";
68
69 $config=loadFile("${lang}/${name}.xml");
70
71 $confFile="${lang}/${name}.xml";
72 if (!file_exists($confFile)) {
73 errorPage("Resource not available");
74 }
75 $doc = new DOMDocument();
76 $doc->load($confFile);
77
78 $includes=$doc->getElementsByTagName("include");
79 $recurse=0;
80
81 while($includes->length > 0) {
82 if(++$recurse > MAX_RECURSE) {
83 errorPage('Recursion limit exceeded', 500);
84 }
85 foreach ($includes as $include) {
86 $src=$include->getAttribute("src");
87 $subdoc = new DOMDocument();
88 $fname = "${lang}/${src}";
89 $subdoc->load($fname);
90 $mtime = filemtime($fname);
91 if ($mtime > $newest) {
92 $newest = $mtime;
93 }
94 $parent=$include->parentNode;
95 $xml=getElementByTagName($subdoc,"xml");
96 foreach($xml->childNodes as $child) {
97 $text=$subdoc->saveXml($child);
98 $clonedChild=$doc->importNode($child,true);
99 $parent->insertBefore($clonedChild,$include);
100 }
101 $parent->removeChild($include);
102 }
103 $includes=$doc->getElementsByTagName("include");
104 }
105
106 $head=getElementByTagName($doc,"head");
107 $title=$head->getAttribute("title");
108
109 $css=getElementByTagName($head,"css");
110 $css=$doc->saveXML($css);
111 $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css);
112
113 $body=getElementByTagName($doc,"body");
114 $files=$body->getElementsByTagName("file");
115
116
117 $out= '<?xml version="1.0" encoding="UTF-8"?>';
118
119 $out.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
120 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
121 <html xmlns="http://www.w3.org/1999/xhtml">
122 <head>
123 <title>';
124
125 $out.= "$title";
126 $out.= '
127 </title>
128 ';
129 $out.= "$css";
130 $out.= '
131 </head>
132 <body>
133 <div id="container">
134 ';
135
136 =======
137 >>>>>>> other
138 function getParam($param) { 48 function getParam($param) {
139 $param_type=$param->getAttribute("type"); 49 $param_type=$param->getAttribute("type");
140 $param_value; 50 $param_value;
141 if (!$param_type) 51 if (!$param_type)
142 $param_type="scalar"; 52 $param_type="scalar";
171 $name=$param->getAttribute("id"); 81 $name=$param->getAttribute("id");
172 $conf=$_GET[$name]; 82 $conf=$_GET[$name];
173 $GLOBALS[$name]=$conf; 83 $GLOBALS[$name]=$conf;
174 if (!$conf) 84 if (!$conf)
175 $conf=$param->getAttribute("default"); 85 $conf=$param->getAttribute("default");
176 $config=loadFile("${lang}/${conf}.xml"); 86
87 $fname = "${lang}/${conf}.xml";
88 cache_time($fname);
89 $config = loadFile($fname);
177 90
178 $confFile="${lang}/${conf}.xml"; 91 $confFile="${lang}/${conf}.xml";
179 if (!file_exists($confFile)) { 92 if (!file_exists($confFile)) {
180 errorPage("Resource not available"); 93 errorPage("Resource not available");
181 } 94 }
247 160
248 161
249 $body=getElementByTagName($doc,"body"); 162 $body=getElementByTagName($doc,"body");
250 $files=$body->getElementsByTagName("file"); 163 $files=$body->getElementsByTagName("file");
251 164
252 foreach ($files as $file) { 165 foreach ($files as $file) {
253 if ($file->getAttribute("script")) { 166 $script=$file->getAttribute("script");
254 $cachable = false; 167 if ($script) {
255 break; 168 $cacheable = false;
256 } 169 $src="";
257 else { 170 $cwd=getcwd();
258 $src = $file->getAttribute("src"); 171
259 $fname = "${lang}/${src}"; 172 $matches=array();
260 if (!file_exists($fname)) { 173 preg_match('/(.*\/)/', $script, $matches);
261 errorPage("Resource not found '${fname}'"); 174 $dirname=$matches[0];
262 } 175 preg_match('/([^\/]*)$/', $script, $matches);
263 cache_time($fname); 176 $filename=$matches[0];
264 } 177 chdir("${lang}/${dirname}");
265 } 178 $pipe=popen("php ${filename}","r");
266 179 $file_content = stream_get_contents($pipe);
267 if ($cachable) 180 chdir("${cwd}");
268 cache_check($newest); 181 }
269 182 else {
270 foreach ($files as $file) { 183 $src = $file->getAttribute("src");
271 $script = $file->getAttribute("script"); 184 $fname = "${lang}/${src}";
272 if ($script) { 185 cache_time($fname);
273 $src = ""; 186 $file_content = loadFile($fname);
274 $cwd = getcwd(); 187 }
275 188 if(floatval($file_content)<0) {
276 $matches=array(); 189 errorPage("Resource not found '${lang}/${src}'");
277 preg_match('/(.*\/)/', $script, $matches); 190 }
278 $dirname=$matches[0]; 191
279 preg_match('/([^\/]*)$/', $script, $matches); 192 $filters=$file->getElementsByTagName("filter");
280 $filename=$matches[0]; 193 foreach($filters as $filter) {
281 chdir("${lang}/${dirname}"); 194 $func=$filter->getAttribute("function");
282 $pipe=popen("php ${filename}","r"); 195 $params=$filter->getElementsByTagName("param");
283 $file_content = stream_get_contents($pipe); 196 $callString="\$file_content=${func}(\$file_content";
284 chdir("${cwd}"); 197 $param_values=array();
285 } 198 $i=0;
286 else { 199 foreach ($filter->childNodes as $param) {
287 $src = $file->getAttribute("src"); 200 if ($param->nodeType == XML_ELEMENT_NODE)
288 $fname = "${lang}/${src}"; 201 {
289 $file_content = loadFile($fname); 202 $param_value[$i]=getParam($param);
290 } 203 $callString.=",\$param_value[$i]";
291 if(floatval($file_content) < 0) { 204 $i++;
292 errorPage("Resource not found '${lang}/${src}'");
293 }
294
295 $filters=$file->getElementsByTagName("filter");
296 foreach($filters as $filter) {
297 $func=$filter->getAttribute("function");
298 $params=$filter->getElementsByTagName("param");
299 $callString="\$file_content=${func}(\$file_content";
300 $param_values=array();
301 $i=0;
302 foreach ($filter->childNodes as $param) {
303 if ($param->nodeType == XML_ELEMENT_NODE)
304 {
305 $param_value[$i]=getParam($param);
306 $callString.=",\$param_value[$i]";
307 $i++;
308 }
309 } 205 }
310 $callString.=");"; 206 }
311 eval($callString); 207 $callString.=");";
312 } 208 eval($callString);
313 $out.= $file_content; 209 }
314 } 210 $out.= $file_content;
315 211 }
316 <<<<<<< local 212
317
318
319 $out.='
320 </div>
321 </body>
322 </html>
323 ';
324 =======
325 $doc = new DOMDocument(); 213 $doc = new DOMDocument();
326 $doc->loadXml("<xml>${out}</xml>"); 214 $doc->loadXml("<xml>${out}</xml>");
327 >>>>>>> other 215
328
329 return $doc; 216 return $doc;
330 } 217 }
331 218
332 $master = new DOMDocument(); 219 $master = new DOMDocument();
333 $master->load("master.xml"); 220 $master->load("master.xml");
345 $parent->removeChild($param); 232 $parent->removeChild($param);
346 233
347 } 234 }
348 } 235 }
349 236
237 if (CACHING && $cacheable)
238 print cache_check($newest);
239
350 print $master->saveXml($master); 240 print $master->saveXml($master);
351 241
352 ?> 242 ?>