Mercurial > SimpleWebPresenter
view index.php @ 1:d91abe5f6214
Support for evaluated configuration files.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Tue, 10 May 2011 14:45:45 +0200 |
| parents | d2da64705bce |
| children | 238c5127b78c |
line wrap: on
line source
<?php include 'php/cache_check.inc'; include 'php/accept-language.inc'; function loadFile($sFilename, $sCharset = 'UTF-8') { if (floatval(phpversion()) >= 4.3) { if (!file_exists($sFilename)) return -3; $sData = file_get_contents($sFilename); } else { if (!file_exists($sFilename)) return -3; $rHandle = fopen($sFilename, 'r'); if (!$rHandle) return -2; $sData = ''; while(!feof($rHandle)) $sData .= fread($rHandle, filesize($sFilename)); fclose($rHandle); } if ($sEncoding = mb_detect_encoding($sData, 'auto', true) != $sCharset) { if ($sEncoding != 1) { $sData = mb_convert_encoding($sData, $sCharset, $sEncoding); } } return $sData; } $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"; $header="header.html"; $footer="footer.html"; $body="body.html"; $config=loadFile("${lang}/${name}.cfg"); eval($config); $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>'; } 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 $header_content=loadFile("${lang}/${header}"); $footer_content=loadFile("${lang}/${footer}"); $pattern = "/<li id=\"${name}\"\s?([^>]*)>/is"; $replacement = "<li id=\"${name}\" class=\"active\" $1>"; $header_content= preg_replace($pattern, $replacement, $header_content); $pattern = '/<li id="([^"]+)"\s?([^>]*)>(.*?)<\/li>/is'; $replacement = "<li id=\"\$1\" \$2><a href=\"?name=$1&lang=${lang}\">\$3</a></li>"; $header_content=preg_replace($pattern, $replacement, $header_content); print $header_content; print $body_content; print $footer_content; ?> </div> </body> </html>
