Mercurial > SimpleWebPresenter
diff 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 |
line wrap: on
line diff
--- a/index.php Thu May 19 18:04:33 2011 +0200 +++ b/index.php Fri May 20 13:25:53 2011 +0200 @@ -4,12 +4,16 @@ include 'php/filters.inc'; include 'php/common-functions.inc'; +$URL_PARAMS=array('name','lang'); + +#Globals $name = $_GET['name']; $lang = $_GET['lang']; if(!$name) { $name="home"; } + if(!$lang) { $lang="no"; $langs=acceptedLanguages(); @@ -34,8 +38,12 @@ return $elem; } +$confFile="${lang}/${name}.xml"; +if (!file_exists($confFile)) { + errorPage("Resource not available"); +} $doc = new DOMDocument(); -$doc->load("${lang}/${name}.xml"); +$doc->load($confFile); $head=getElementByTagName($doc,"head"); $title=$head->getAttribute("title"); @@ -47,29 +55,33 @@ $body=getElementByTagName($doc,"body"); $files=$body->getElementsByTagName("file"); -print '<?xml version="1.0" encoding="UTF-8"?>'; -?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + +$out= '<?xml version="1.0" encoding="UTF-8"?>'; + +$out.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> - <title> -<?php -print "$title"; -?> + <title>'; + +$out.= "$title"; +$out.= ' </title> -<?php -print "$css"; -?> +'; +$out.= "$css"; +$out.= ' </head> <body> <div id="container"> +'; -<?php foreach ( $files as $file) { $src=$file->getAttribute("src"); $file_content=loadFile("${lang}/${src}"); -// print $file_content; + if(floatval($file_content)<0) { + errorPage("Resource not found '${lang}/${src}'"); + } + $filters=$file->getElementsByTagName("filter"); foreach($filters as $filter) { $func=$filter->getAttribute("function"); @@ -87,24 +99,14 @@ $callString.=");"; eval($callString); } - print $file_content; -} - -/* -$body_content=loadFile("${lang}/${body}"); -if(floatval($body_content)<0) { - header('HTTP/1.0 404 Not Found'); - $body_content='<div id="page"><h1>Resource not found</h1></div>'; + $out.= $file_content; } -if (!file_exists($lang)) { - $lang=no; - header('HTTP/1.0 404 Not Found'); - $body_content='<div id="page"><h1>Language is not available</h1></div>'; -} -*/ -?> - +$out.=' </div> </body> </html> +'; + +print $out; +?>
