Mercurial > SimpleWebPresenter
annotate index.php @ 4:74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
main script.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 19 May 2011 18:04:33 +0200 |
| parents | 238c5127b78c |
| children | 18aafb1a8986 |
| 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 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
7 $name = $_GET['name']; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
8 $lang = $_GET['lang']; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
9 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
10 if(!$name) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
11 $name="home"; |
|
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(!$lang) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
14 $lang="no"; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
15 $langs=acceptedLanguages(); |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
16 foreach ($langs as $l => $val) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
17 if (file_exists($l)) { |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
18 $lang=$l; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
19 break; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
20 } |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
21 } |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
22 } |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
23 |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
24 $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
|
25 |
|
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
|
26 $config=loadFile("${lang}/${name}.xml"); |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
27 |
|
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
|
28 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
|
29 $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
|
30 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
|
31 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
|
32 } |
|
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 $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
|
34 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
|
35 } |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
36 |
|
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
|
37 $doc = new DOMDocument(); |
|
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 $doc->load("${lang}/${name}.xml"); |
|
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 |
|
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
|
40 $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
|
41 $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
|
42 |
|
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
|
43 $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
|
44 $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
|
45 $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
|
46 |
|
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 $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
|
48 $files=$body->getElementsByTagName("file"); |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
49 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
50 print '<?xml version="1.0" encoding="UTF-8"?>'; |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
51 ?> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
52 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
53 "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
|
54 <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
|
55 <head> |
|
1
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
56 <title> |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
57 <?php |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
58 print "$title"; |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
59 ?> |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
60 </title> |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
61 <?php |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
62 print "$css"; |
|
d91abe5f6214
Support for evaluated configuration files.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
0
diff
changeset
|
63 ?> |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
64 </head> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
65 <body> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
66 <div id="container"> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
67 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
68 <?php |
|
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
|
69 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
|
70 $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
|
71 $file_content=loadFile("${lang}/${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
|
72 // print $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
|
73 $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
|
74 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
|
75 $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
|
76 $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
|
77 $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
|
78 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
|
79 $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
|
80 $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
|
81 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
|
82 $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
|
83 $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
|
84 } |
|
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 $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
|
86 } |
|
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 $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
|
88 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
|
89 } |
|
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 print $file_content; |
|
3
238c5127b78c
Generating language-bar.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
1
diff
changeset
|
91 } |
|
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
|
92 |
|
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 /* |
|
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 $body_content=loadFile("${lang}/${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
|
95 if(floatval($body_content)<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
|
96 header('HTTP/1.0 404 Not Found'); |
|
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 $body_content='<div id="page"><h1>Resource not found</h1></div>'; |
|
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 if (!file_exists($lang)) { |
|
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 $lang=no; |
|
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 header('HTTP/1.0 404 Not Found'); |
|
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
|
102 $body_content='<div id="page"><h1>Language is not available</h1></div>'; |
|
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 } |
|
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
|
104 */ |
|
0
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
105 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
106 ?> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
107 |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
108 </div> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
109 </body> |
|
d2da64705bce
Refactored everything in the CMS into this repos.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
110 </html> |
