comparison index.php @ 5:18aafb1a8986

Better handling of errors and globals.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Fri, 20 May 2011 13:25:53 +0200
parents 74196528fc64
children 6c0162497d56
comparison
equal deleted inserted replaced
4:74196528fc64 5:18aafb1a8986
2 include 'php/cache_check.inc'; 2 include 'php/cache_check.inc';
3 include 'php/accept-language.inc'; 3 include 'php/accept-language.inc';
4 include 'php/filters.inc'; 4 include 'php/filters.inc';
5 include 'php/common-functions.inc'; 5 include 'php/common-functions.inc';
6 6
7 $URL_PARAMS=array('name','lang');
8
9 #Globals
7 $name = $_GET['name']; 10 $name = $_GET['name'];
8 $lang = $_GET['lang']; 11 $lang = $_GET['lang'];
9 12
10 if(!$name) { 13 if(!$name) {
11 $name="home"; 14 $name="home";
12 } 15 }
16
13 if(!$lang) { 17 if(!$lang) {
14 $lang="no"; 18 $lang="no";
15 $langs=acceptedLanguages(); 19 $langs=acceptedLanguages();
16 foreach ($langs as $l => $val) { 20 foreach ($langs as $l => $val) {
17 if (file_exists($l)) { 21 if (file_exists($l)) {
32 } 36 }
33 $elem=$elems->item(0); 37 $elem=$elems->item(0);
34 return $elem; 38 return $elem;
35 } 39 }
36 40
41 $confFile="${lang}/${name}.xml";
42 if (!file_exists($confFile)) {
43 errorPage("Resource not available");
44 }
37 $doc = new DOMDocument(); 45 $doc = new DOMDocument();
38 $doc->load("${lang}/${name}.xml"); 46 $doc->load($confFile);
39 47
40 $head=getElementByTagName($doc,"head"); 48 $head=getElementByTagName($doc,"head");
41 $title=$head->getAttribute("title"); 49 $title=$head->getAttribute("title");
42 50
43 $css=getElementByTagName($head,"css"); 51 $css=getElementByTagName($head,"css");
45 $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css); 53 $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css);
46 54
47 $body=getElementByTagName($doc,"body"); 55 $body=getElementByTagName($doc,"body");
48 $files=$body->getElementsByTagName("file"); 56 $files=$body->getElementsByTagName("file");
49 57
50 print '<?xml version="1.0" encoding="UTF-8"?>'; 58
51 ?> 59 $out= '<?xml version="1.0" encoding="UTF-8"?>';
52 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 60
61 $out.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
53 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 62 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
54 <html xmlns="http://www.w3.org/1999/xhtml"> 63 <html xmlns="http://www.w3.org/1999/xhtml">
55 <head> 64 <head>
56 <title> 65 <title>';
57 <?php 66
58 print "$title"; 67 $out.= "$title";
59 ?> 68 $out.= '
60 </title> 69 </title>
61 <?php 70 ';
62 print "$css"; 71 $out.= "$css";
63 ?> 72 $out.= '
64 </head> 73 </head>
65 <body> 74 <body>
66 <div id="container"> 75 <div id="container">
76 ';
67 77
68 <?php
69 foreach ( $files as $file) { 78 foreach ( $files as $file) {
70 $src=$file->getAttribute("src"); 79 $src=$file->getAttribute("src");
71 $file_content=loadFile("${lang}/${src}"); 80 $file_content=loadFile("${lang}/${src}");
72 // print $file_content; 81 if(floatval($file_content)<0) {
82 errorPage("Resource not found '${lang}/${src}'");
83 }
84
73 $filters=$file->getElementsByTagName("filter"); 85 $filters=$file->getElementsByTagName("filter");
74 foreach($filters as $filter) { 86 foreach($filters as $filter) {
75 $func=$filter->getAttribute("function"); 87 $func=$filter->getAttribute("function");
76 $params=$filter->getElementsByTagName("param"); 88 $params=$filter->getElementsByTagName("param");
77 $callString="\$file_content=${func}(\$file_content"; 89 $callString="\$file_content=${func}(\$file_content";
85 $callString.=",\"${param_value}\""; 97 $callString.=",\"${param_value}\"";
86 } 98 }
87 $callString.=");"; 99 $callString.=");";
88 eval($callString); 100 eval($callString);
89 } 101 }
90 print $file_content; 102 $out.= $file_content;
91 } 103 }
92
93 /*
94 $body_content=loadFile("${lang}/${body}");
95 if(floatval($body_content)<0) {
96 header('HTTP/1.0 404 Not Found');
97 $body_content='<div id="page"><h1>Resource not found</h1></div>';
98 }
99 if (!file_exists($lang)) {
100 $lang=no;
101 header('HTTP/1.0 404 Not Found');
102 $body_content='<div id="page"><h1>Language is not available</h1></div>';
103 }
104 */
105 104
106 ?> 105 $out.='
107
108 </div> 106 </div>
109 </body> 107 </body>
110 </html> 108 </html>
109 ';
110
111 print $out;
112 ?>