Mercurial > SimpleWebPresenter
annotate 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 |
| rev | line source |
|---|---|
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
1 <?php |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
2 include 'php/cache_check.inc'; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
3 include 'php/accept-language.inc'; |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
4 include 'php/filters.inc'; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
5 include 'php/common-functions.inc'; |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
6 |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
7 $URL_PARAMS=array('name','lang'); |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
8 |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
9 #Globals |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
10 $name = $_GET['name']; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
11 $lang = $_GET['lang']; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
12 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
13 if(!$name) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
14 $name="home"; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
15 } |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
16 |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
17 if(!$lang) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
18 $lang="no"; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
19 $langs=acceptedLanguages(); |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
20 foreach ($langs as $l => $val) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
21 if (file_exists($l)) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
22 $lang=$l; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
23 break; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
24 } |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
25 } |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
26 } |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
27 |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
28 $title="Dummy title"; |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
29 |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
30 $config=loadFile("${lang}/${name}.xml"); |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
31 |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
32 function getElementByTagName($obj, $name) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
33 $elems=$obj->getElementsByTagName($name); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
34 if ($elems->length != 1) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
35 exit; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
36 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
37 $elem=$elems->item(0); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
38 return $elem; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
39 } |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
40 |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
41 $confFile="${lang}/${name}.xml"; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
42 if (!file_exists($confFile)) { |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
43 errorPage("Resource not available"); |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
44 } |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
45 $doc = new DOMDocument(); |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
46 $doc->load($confFile); |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
47 |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
48 $head=getElementByTagName($doc,"head"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
49 $title=$head->getAttribute("title"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
50 |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
51 $css=getElementByTagName($head,"css"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
52 $css=$doc->saveXML($css); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
53 $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
54 |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
55 $body=getElementByTagName($doc,"body"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
56 $files=$body->getElementsByTagName("file"); |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
57 |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
58 |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
59 $out= '<?xml version="1.0" encoding="UTF-8"?>'; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
60 |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
61 $out.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
62 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
63 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
64 <head> |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
65 <title>'; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
66 |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
67 $out.= "$title"; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
68 $out.= ' |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
69 </title> |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
70 '; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
71 $out.= "$css"; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
72 $out.= ' |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
73 </head> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
74 <body> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
75 <div id="container"> |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
76 '; |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
77 |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
78 foreach ( $files as $file) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
79 $src=$file->getAttribute("src"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
80 $file_content=loadFile("${lang}/${src}"); |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
81 if(floatval($file_content)<0) { |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
82 errorPage("Resource not found '${lang}/${src}'"); |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
83 } |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
84 |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
85 $filters=$file->getElementsByTagName("filter"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
86 foreach($filters as $filter) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
87 $func=$filter->getAttribute("function"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
88 $params=$filter->getElementsByTagName("param"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
89 $callString="\$file_content=${func}(\$file_content"; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
90 foreach ($params as $param) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
91 $param_subst=$param->getAttribute("subst"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
92 $param_value=$param->getAttribute("value"); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
93 if ($param_subst) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
94 $param_value=preg_replace("/name/", $name, $param_subst); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
95 $param_value=preg_replace('/lang/', $lang, $param_value); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
96 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
97 $callString.=",\"${param_value}\""; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
98 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
99 $callString.=");"; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
100 eval($callString); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
101 } |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
102 $out.= $file_content; |
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
3
diff
changeset
|
103 } |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
104 |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
105 $out.=' |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
106 </div> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
107 </body> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
108 </html> |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
109 '; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
110 |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
111 print $out; |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
4
diff
changeset
|
112 ?> |
