Mercurial > SimpleWebPresenter
changeset 20:ac24b41a12ad
Something strange got committed in last comit, correct commit.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 19 Sep 2012 15:51:33 +0200 |
| parents | ee2c31392ea3 |
| children | 5dc5cc27471d |
| files | index.php |
| diffstat | 1 files changed, 57 insertions(+), 167 deletions(-) [+] |
line wrap: on
line diff
--- a/index.php Wed Sep 19 15:50:18 2012 +0200 +++ b/index.php Wed Sep 19 15:51:33 2012 +0200 @@ -1,22 +1,13 @@ <?php define(DEBUG,0); define(MAX_RECURSE,50); -define(CACHING,0); +define(CACHING,1); /* var_dump($_SERVER); exit; */ -function include_with_mtime($file) { - global $newest; - $mtime = filemtime($file); - if ($mtime > $newest) { - $newest = $mtime; - } - include $file; -} - if (DEBUG) { error_reporting(E_ALL); ini_set("display_errors", 1); @@ -24,23 +15,14 @@ $SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME']; $newest = filemtime($SCRIPT_FILENAME); -$cachable = true; +$cacheable = true; -<<<<<<< local -include_with_mtime('php/cache_check.inc'); +include 'php/cache_check.inc'; include_with_mtime('php/accept-language.inc'); include_with_mtime('php/filters.inc'); include_with_mtime('php/common-functions.inc'); -======= -if(CACHING) { -include 'php/cache_check.inc'; -} -include 'php/accept-language.inc'; -include 'php/filters.inc'; -include 'php/common-functions.inc'; ->>>>>>> other -$URL_PARAMS=array('name', 'lang'); +$URL_PARAMS=array('name','lang'); #Globals $name = $_GET['name']; @@ -63,78 +45,6 @@ } } -<<<<<<< local -$title="Dummy title"; - -$config=loadFile("${lang}/${name}.xml"); - -$confFile="${lang}/${name}.xml"; -if (!file_exists($confFile)) { - errorPage("Resource not available"); -} -$doc = new DOMDocument(); -$doc->load($confFile); - -$includes=$doc->getElementsByTagName("include"); -$recurse=0; - -while($includes->length > 0) { - if(++$recurse > MAX_RECURSE) { - errorPage('Recursion limit exceeded', 500); - } - foreach ($includes as $include) { - $src=$include->getAttribute("src"); - $subdoc = new DOMDocument(); - $fname = "${lang}/${src}"; - $subdoc->load($fname); - $mtime = filemtime($fname); - if ($mtime > $newest) { - $newest = $mtime; - } - $parent=$include->parentNode; - $xml=getElementByTagName($subdoc,"xml"); - foreach($xml->childNodes as $child) { - $text=$subdoc->saveXml($child); - $clonedChild=$doc->importNode($child,true); - $parent->insertBefore($clonedChild,$include); - } - $parent->removeChild($include); - } - $includes=$doc->getElementsByTagName("include"); -} - -$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"); - - -$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>'; - -$out.= "$title"; -$out.= ' - </title> -'; -$out.= "$css"; -$out.= ' - </head> - <body> - <div id="container"> -'; - -======= ->>>>>>> other function getParam($param) { $param_type=$param->getAttribute("type"); $param_value; @@ -173,7 +83,10 @@ $GLOBALS[$name]=$conf; if (!$conf) $conf=$param->getAttribute("default"); - $config=loadFile("${lang}/${conf}.xml"); + + $fname = "${lang}/${conf}.xml"; + cache_time($fname); + $config = loadFile($fname); $confFile="${lang}/${conf}.xml"; if (!file_exists($confFile)) { @@ -249,83 +162,57 @@ $body=getElementByTagName($doc,"body"); $files=$body->getElementsByTagName("file"); -foreach ($files as $file) { - if ($file->getAttribute("script")) { - $cachable = false; - break; - } - else { - $src = $file->getAttribute("src"); - $fname = "${lang}/${src}"; - if (!file_exists($fname)) { - errorPage("Resource not found '${fname}'"); + foreach ($files as $file) { + $script=$file->getAttribute("script"); + if ($script) { + $cacheable = false; + $src=""; + $cwd=getcwd(); + + $matches=array(); + preg_match('/(.*\/)/', $script, $matches); + $dirname=$matches[0]; + preg_match('/([^\/]*)$/', $script, $matches); + $filename=$matches[0]; + chdir("${lang}/${dirname}"); + $pipe=popen("php ${filename}","r"); + $file_content = stream_get_contents($pipe); + chdir("${cwd}"); } - cache_time($fname); - } -} - -if ($cachable) - cache_check($newest); - -foreach ($files as $file) { - $script = $file->getAttribute("script"); - if ($script) { - $src = ""; - $cwd = getcwd(); + else { + $src = $file->getAttribute("src"); + $fname = "${lang}/${src}"; + cache_time($fname); + $file_content = loadFile($fname); + } + if(floatval($file_content)<0) { + errorPage("Resource not found '${lang}/${src}'"); + } - $matches=array(); - preg_match('/(.*\/)/', $script, $matches); - $dirname=$matches[0]; - preg_match('/([^\/]*)$/', $script, $matches); - $filename=$matches[0]; - chdir("${lang}/${dirname}"); - $pipe=popen("php ${filename}","r"); - $file_content = stream_get_contents($pipe); - chdir("${cwd}"); - } - else { - $src = $file->getAttribute("src"); - $fname = "${lang}/${src}"; - $file_content = loadFile($fname); - } - if(floatval($file_content) < 0) { - errorPage("Resource not found '${lang}/${src}'"); - } + $filters=$file->getElementsByTagName("filter"); + foreach($filters as $filter) { + $func=$filter->getAttribute("function"); + $params=$filter->getElementsByTagName("param"); + $callString="\$file_content=${func}(\$file_content"; + $param_values=array(); + $i=0; + foreach ($filter->childNodes as $param) { + if ($param->nodeType == XML_ELEMENT_NODE) + { + $param_value[$i]=getParam($param); + $callString.=",\$param_value[$i]"; + $i++; + } + } + $callString.=");"; + eval($callString); + } + $out.= $file_content; + } - $filters=$file->getElementsByTagName("filter"); - foreach($filters as $filter) { - $func=$filter->getAttribute("function"); - $params=$filter->getElementsByTagName("param"); - $callString="\$file_content=${func}(\$file_content"; - $param_values=array(); - $i=0; - foreach ($filter->childNodes as $param) { - if ($param->nodeType == XML_ELEMENT_NODE) - { - $param_value[$i]=getParam($param); - $callString.=",\$param_value[$i]"; - $i++; - } - } - $callString.=");"; - eval($callString); - } - $out.= $file_content; -} - -<<<<<<< local - - -$out.=' - </div> - </body> -</html> -'; -======= $doc = new DOMDocument(); $doc->loadXml("<xml>${out}</xml>"); ->>>>>>> other - + return $doc; } @@ -347,6 +234,9 @@ } } +if (CACHING && $cacheable) + print cache_check($newest); + print $master->saveXml($master); ?>
