changeset 12:a20bb1b51aad

Merge.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Tue, 29 May 2012 21:08:23 +0200
parents ba6f0818018b (diff) 60e73809887a (current diff)
children ee2c31392ea3
files index.php
diffstat 2 files changed, 126 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/flag.php	Mon May 28 23:13:17 2012 +0200
+++ b/flag.php	Tue May 29 21:08:23 2012 +0200
@@ -1,4 +1,6 @@
 <?php
+define(DEBUG,0);
+
 include 'cache_check.inc';
 include 'accept-language.inc';
 
--- a/index.php	Mon May 28 23:13:17 2012 +0200
+++ b/index.php	Tue May 29 21:08:23 2012 +0200
@@ -1,6 +1,12 @@
 <?php
 define(DEBUG,0);
 define(MAX_RECURSE,50);
+define(CACHING,0);
+
+/*
+var_dump($_SERVER);
+exit;
+*/
 
 if (DEBUG) {
   error_reporting(E_ALL);
@@ -8,7 +14,9 @@
 }
 
 
+if(CACHING) {
 include 'php/cache_check.inc';
+}
 include 'php/accept-language.inc';
 include 'php/filters.inc';
 include 'php/common-functions.inc';
@@ -26,78 +34,16 @@
 if(!$lang) {
   $lang="no";
   $langs=acceptedLanguages();
-  foreach ($langs as $l => $val) {
-    if (file_exists($l)) {
-      $lang=$l;
-      break;
+  if ($langs) {
+    foreach ($langs as $l => $val) {
+      if (file_exists($l)) {
+        $lang=$l;
+        break;
+      }
     }
   }
 }
 
-$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();
-	$subdoc->load("${lang}/${src}");
-	$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">
-';
-
 function getParam($param) {
   $param_type=$param->getAttribute("type");
   $param_value;
@@ -127,6 +73,91 @@
   return $param_value;
 }
 
+function getInput($master, $param) {
+  $out='';
+
+  $lang=$GLOBALS['lang'];
+  $name=$param->getAttribute("id");
+  $conf=$_GET[$name];
+  $GLOBALS[$name]=$conf;
+  if (!$conf)
+    $conf=$param->getAttribute("default");
+  $config=loadFile("${lang}/${conf}.xml");
+
+  $confFile="${lang}/${conf}.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();
+	$subdoc->load("${lang}/${src}");
+	$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");
+
+  if($title) {
+    $values=$master->getElementsByTagName("param");
+    foreach ($values as $value) {
+      if ($value->getAttribute("type")=="input_config") {
+        if ($value->getAttribute("id")=="title") {
+          $tmp = new DOMDocument();
+          $tmp->loadXml("<xml>${title}</xml>");
+	  $parent=$value->parentNode;
+	  $parent->removeChild($value);
+	  $parent->appendChild(new DOMText($tmp->textContent));
+        }
+      }
+    }
+  }
+
+  $css=getElementByTagName($head,"css");
+  $css=$doc->saveXML($css);
+  $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css);
+
+  if($css) {
+    $values=$master->getElementsByTagName("param");
+    foreach ($values as $value) {
+      if ($value->getAttribute("type")=="input_config") {
+        if ($value->getAttribute("id")=="css") {
+          $tmp = new DOMDocument();
+          $tmp->loadXml("<xml>${css}</xml>");
+	  $parent=$value->parentNode;
+	  foreach($tmp->firstChild->childNodes as $node) {
+		$clonedChild=$master->importNode($node,true);
+		$parent->insertBefore($clonedChild,$value);
+          }
+	  $parent->removeChild($value);
+        }
+      }
+    }
+  }
+
+
+  $body=getElementByTagName($doc,"body");
+  $files=$body->getElementsByTagName("file");
+
 foreach ($files as $file) {
 	$script=$file->getAttribute("script");
 	if ($script) {
@@ -172,11 +203,30 @@
         $out.= $file_content;
 }
 
-$out.='
-      </div>
-    </body>
-</html>
-';
+  $doc = new DOMDocument();
+  $doc->loadXml("<xml>${out}</xml>");
+
+  return $doc;
+}
+
+$master = new DOMDocument();
+$master->load("master.xml");
+
+$params=$master->getElementsByTagName("param");
+foreach ($params as $param) {
+  if ($param->getAttribute("type") == "input") {
+    $doc=getInput($master,$param);
 
-print $out;
+    $parent=$param->parentNode;
+    foreach ($doc->firstChild->childNodes as $child) {
+      $clonedChild=$master->importNode($child,true);
+      $parent->insertBefore($clonedChild,$param);
+    }
+    $parent->removeChild($param);	
+
+  }
+}
+
+print $master->saveXml($master);
+
 ?>