Mercurial > SimpleWebPresenter
view 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 |
line wrap: on
line source
<?php include 'php/cache_check.inc'; include 'php/accept-language.inc'; include 'php/filters.inc'; include 'php/common-functions.inc'; $name = $_GET['name']; $lang = $_GET['lang']; if(!$name) { $name="home"; } if(!$lang) { $lang="no"; $langs=acceptedLanguages(); foreach ($langs as $l => $val) { if (file_exists($l)) { $lang=$l; break; } } } $title="Dummy title"; $config=loadFile("${lang}/${name}.xml"); function getElementByTagName($obj, $name) { $elems=$obj->getElementsByTagName($name); if ($elems->length != 1) { exit; } $elem=$elems->item(0); return $elem; } $doc = new DOMDocument(); $doc->load("${lang}/${name}.xml"); $head=getElementByTagName($doc,"head"); $title=$head->getAttribute("title"); $css=getElementByTagName($head,"css"); $css=$doc->saveXML($css); $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css); $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" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> <?php print "$title"; ?> </title> <?php print "$css"; ?> </head> <body> <div id="container"> <?php foreach ( $files as $file) { $src=$file->getAttribute("src"); $file_content=loadFile("${lang}/${src}"); // print $file_content; $filters=$file->getElementsByTagName("filter"); foreach($filters as $filter) { $func=$filter->getAttribute("function"); $params=$filter->getElementsByTagName("param"); $callString="\$file_content=${func}(\$file_content"; foreach ($params as $param) { $param_subst=$param->getAttribute("subst"); $param_value=$param->getAttribute("value"); if ($param_subst) { $param_value=preg_replace("/name/", $name, $param_subst); $param_value=preg_replace('/lang/', $lang, $param_value); } $callString.=",\"${param_value}\""; } $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>'; } 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>'; } */ ?> </div> </body> </html>
