changeset 19:ee2c31392ea3

Merge Regression, fast cache-checking has been removed.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Wed, 19 Sep 2012 15:50:18 +0200
parents d5068ced2ad1 (diff) a20bb1b51aad (current diff)
children ac24b41a12ad
files cache_check.inc index.php
diffstat 5 files changed, 165 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/cache_check.inc	Tue May 29 21:08:23 2012 +0200
+++ b/cache_check.inc	Wed Sep 19 15:50:18 2012 +0200
@@ -1,17 +1,33 @@
 <?php
-if (DEBUG)
-  var_dump($_SERVER);
+function cache_check($mtime)
+{
+  if (DEBUG)
+    var_dump($_SERVER);
 
-$HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE'];
-$if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
+  $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE'];
+  $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
 
-$SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME'];
-$mtime = filemtime($SCRIPT_FILENAME);
-$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
+  $gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
 
-if ($if_modified_since == $gmdate_mod) {
+  if ($if_modified_since == $gmdate_mod) {
     header("HTTP/1.0 304 Not Modified");
     exit;
+  }
+  header("Last-Modified: $gmdate_mod");
 }
-header("Last-Modified: $gmdate_mod");
+
+function cache_time($path) {
+  global $newest;
+  $mtime = filemtime($path);
+  if ($mtime > $newest) {
+    $newest = $mtime;
+  }
+}
+
+function include_with_mtime($path) {
+  cache_time($path);
+  include($path);
+}
+
+cache_time('php/cache_check.inc');
 ?>
\ No newline at end of file
--- a/common-functions.inc	Tue May 29 21:08:23 2012 +0200
+++ b/common-functions.inc	Wed Sep 19 15:50:18 2012 +0200
@@ -43,10 +43,10 @@
 		 $new_params[$param]=$val;
 	 }
 	 foreach($new_params as $param => $val) {
-	         if($first) 
+	         if($first)
 		   $first=0;
-		 else 
-		   $out.="&amp;";	     
+		 else
+		   $out.="&amp;";
 	 	 $out.=urlencode($param).'='.urlencode($val);
 	 }
 	 return $out;
--- a/filters.inc	Tue May 29 21:08:23 2012 +0200
+++ b/filters.inc	Wed Sep 19 15:50:18 2012 +0200
@@ -9,11 +9,11 @@
 
 	$pattern = '/<li id="([^"]+)"\s?([^>]*)>(.*?)<\/li>/is';
 	$replacement = "<li id=\"\$1\" \$2><a href=\"%URL-$1%\">\$3</a></li>";
-	$output=preg_replace_callback($pattern, 
+	$output=preg_replace_callback($pattern,
 	create_function(
-	  '$matches', 
+	  '$matches',
 	'return "<li id=\"$matches[1]\" $matches[2]><a href=\"".genUrl(array("name" => $matches[1]))."\">$matches[3]</a></li>";'
-	), 
+	),
 	$output);
 
 	return $output;
@@ -29,12 +29,12 @@
 	   $active=($l == $lang)?0:1;
 	     $langbar.= "
 	    <li class=\"${l}\">";
-	    if ($active) 
+	    if ($active)
 	    $langbar.='<a href="'.genUrl(array( 'lang' => $l)).'">';
 
 	    $langbar.= "
 	      <img src=\"http://dev.bfginvest.no/php/flag.php?lang=${l}&amp;active=${active}\" width=\"20\" height=\"16\" alt=\"Norsk versjon - inaktiv\" title=\"Norsk\"/>";
-	    if ($active) 
+	    if ($active)
 	    $langbar.="</a>";
 
 	      $langbar.= "
--- a/http-response-status-codes.inc	Tue May 29 21:08:23 2012 +0200
+++ b/http-response-status-codes.inc	Wed Sep 19 15:50:18 2012 +0200
@@ -114,7 +114,7 @@
 
 const HTTP_VERSION_NOT_SUPPORTED = 505;
 
-		
+
 
 private static $messages = array(
 
@@ -212,7 +212,7 @@
 
 );
 
-	
+
 
 public static function httpHeaderFor($code) {
 
@@ -225,14 +225,14 @@
 return self::$messages[$code];
 
 	}
-	
+
 
 public static function isError($code) {
 
 return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST;
 
 	}
-	
+
 
 public static function canHaveBody($code) {
 
@@ -253,4 +253,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
--- a/index.php	Tue May 29 21:08:23 2012 +0200
+++ b/index.php	Wed Sep 19 15:50:18 2012 +0200
@@ -8,20 +8,39 @@
 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);
 }
 
+$SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME'];
+$newest = filemtime($SCRIPT_FILENAME);
+$cachable = true;
 
+<<<<<<< local
+include_with_mtime('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'];
@@ -44,6 +63,78 @@
   }
 }
 
+<<<<<<< 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;
@@ -159,10 +250,28 @@
   $files=$body->getElementsByTagName("file");
 
 foreach ($files as $file) {
-	$script=$file->getAttribute("script");
+  if ($file->getAttribute("script")) {
+    $cachable = false;
+    break;
+  }
+  else {
+    $src = $file->getAttribute("src");
+    $fname = "${lang}/${src}";
+    if (!file_exists($fname)) {
+      errorPage("Resource not found '${fname}'");
+    }
+    cache_time($fname);
+  }
+}
+
+if ($cachable)
+  cache_check($newest);
+
+foreach ($files as $file) {
+	$script = $file->getAttribute("script");
 	if ($script) {
-	  $src="";
-	  $cwd=getcwd();
+	  $src = "";
+	  $cwd = getcwd();
 
 	  $matches=array();
 	  preg_match('/(.*\/)/', $script, $matches);
@@ -175,10 +284,11 @@
 	  chdir("${cwd}");
 	}
 	else {
-		$src=$file->getAttribute("src");
-		$file_content=loadFile("${lang}/${src}");
+	  $src = $file->getAttribute("src");
+	  $fname = "${lang}/${src}";
+	  $file_content = loadFile($fname);
 	}
-	if(floatval($file_content)<0) {
+	if(floatval($file_content) < 0) {
 	  errorPage("Resource not found '${lang}/${src}'");
 	}
 
@@ -203,8 +313,18 @@
         $out.= $file_content;
 }
 
+<<<<<<< local
+
+
+$out.='
+      </div>
+    </body>
+</html>
+';
+=======
   $doc = new DOMDocument();
   $doc->loadXml("<xml>${out}</xml>");
+>>>>>>> other
 
   return $doc;
 }