changeset 116:374e3eff07fd

Branch merge
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Thu, 17 Mar 2016 22:34:49 +0100
parents b9668126e52e (current diff) f498ea087d67 (diff)
children e01ce5722f2b
files InputParser.inc
diffstat 6 files changed, 64 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/CacheTimeCheck.inc	Thu Mar 17 22:32:33 2016 +0100
+++ b/CacheTimeCheck.inc	Thu Mar 17 22:34:49 2016 +0100
@@ -26,15 +26,15 @@
     //print_r($gmdate_mod);
   }
 
+  foreach($cache->cacheControl() as $header => $value) {
+    header ("${header}: ${value}");
+  }
   if(array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
     $HTTP_IF_MODIFIED_SINCE = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
     $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
 
     if (strtotime($if_modified_since) >= $cache->getNewest()) {
       header("HTTP/1.0 304 Not Modified");
-      foreach($cache->cacheControl() as $header => $value) {
-	header ("${header}: ${value}");
-      }
       return false;
     }
   }
--- a/FileCacheSet.inc	Thu Mar 17 22:32:33 2016 +0100
+++ b/FileCacheSet.inc	Thu Mar 17 22:34:49 2016 +0100
@@ -13,7 +13,12 @@
   }
 
   function cacheControl() {
-    return array("expires" => toGMTime(time()+$this->max_age), "cache-control" => "public, max-age=$this->max_age");
+    if ($this->max_age > 0) {
+      return array("expires" => toGMTime(time()+$this->max_age), "cache-control" => "public, max-age=$this->max_age");
+    }
+    else {
+      return array("expires" => 0, "cache-control" => "public, max-age=0, no-cache");
+    }
   }
 
 };
--- a/InputParser.inc	Thu Mar 17 22:32:33 2016 +0100
+++ b/InputParser.inc	Thu Mar 17 22:34:49 2016 +0100
@@ -64,7 +64,7 @@
     }
     $this->master = self::getFiles($this->master, $this->options);
     self::removeCommentsFromDOM($this->master);
-    $cache->setMaxAge(20);
+    $cache->setMaxAge(0);
   }
 
   /**
--- a/Page.inc	Thu Mar 17 22:32:33 2016 +0100
+++ b/Page.inc	Thu Mar 17 22:34:49 2016 +0100
@@ -110,6 +110,8 @@
    */
   function mayCompress()
   {
+    if (COMPRESSION_DISABLED)
+      return false;
     //We want to add the variant even if we don't serve with compression.
     $this->addVariant('Accept-Encoding');
     if (!array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER))
--- a/Sitemap.inc	Thu Mar 17 22:32:33 2016 +0100
+++ b/Sitemap.inc	Thu Mar 17 22:34:49 2016 +0100
@@ -69,7 +69,49 @@
     return false;
   }
 
+  private function processDir($dir, $lang, $acceptedLanguages, $base) {
+    $urls = array();
+
+    if ($handle = opendir(basePath() . "/${dir}")) {
+      while (false !== ($entry = readdir($handle))) {
+	if (endsWith($entry, '.xml')) {
+	  $fentry = basepath() . "/${dir}/${entry}";
+
+	  $doc = new DOMDocument();
+
+	  if (file_exists($fentry)) {
+	    $doc->load($fentry);
+
+	    $opts = array();
+	    if (count($acceptedLanguages) > 1) {
+	      $opts['lang'] = $lang;
+	    }
+
+	    $toplevel = $doc->getElementsByTagName("toplevel");
+
+	    if($toplevel->length) {
+	      $name = substr($entry, 0, -4);
+
+	      if ($name != $this->options->getInputDefault('name')) {
+		$opts['name'] = $name;
+	      }
+
+	      $optstring = genUrl($opts, array(), array('lang', 'name'));
+
+	      $location = "${base}${optstring}/";
+
+	      array_push($urls, $location);
+	    }
+	  }
+	}
+      }
+      closedir($handle);
+    }
+    return $urls;
+  }
+
   function generateContent() {
+
     /// The final output variable
     $out = '<?xml version="1.0" encoding="UTF-8"?>';
     $out .= "\n";
@@ -92,40 +134,14 @@
     $urls = array();
 
     foreach($this->options->getAcceptedLanguages() as $lang) {
-      if ($handle = opendir(basePath() . "/${lang}")) {
-	while (false !== ($entry = readdir($handle))) {
-	  if (endsWith($entry, '.xml')) {
-	    $fentry = basepath() . "/${lang}/${entry}";
-	    $doc = new DOMDocument();
-
-	    if (file_exists($fentry)) {
-	      $doc->load($fentry);
-
-	      $opts = array();
-	      if (count($acceptedLanguages) > 1) {
-		$opts['lang'] = $lang;
-	      }
-
-	      $toplevel = $doc->getElementsByTagName("toplevel");
-
-	      if($toplevel->length) {
-		$name = substr($entry, 0, -4);
-
-		if ($name != $this->options->getInputDefault('name')) {
-		  $opts['name'] = $name;
-		}
-
-		$optstring = genUrl($opts, array(), array('lang', 'name'));
-
-		$location = "${base}${optstring}/";
-
-		array_push($urls, $location);
-	      }
-	    }
-	  }
-	}
-	closedir($handle);
-      }
+      $urls=array_merge($urls,
+			$this->processDir($lang, $lang,
+					  $acceptedLanguages, $base)
+			);
+      $urls=array_merge($urls,
+			$this->processDir("common", $lang,
+					  $acceptedLanguages, $base)
+			);
     }
 
     usort($urls, "cmp_length_lex");
@@ -153,7 +169,7 @@
       }
     }
 
-    $out .= '</urlset>';
+    $out .= "</urlset>";
 
     $res = new PageContent($out);
     $cache=new SimpleCache($this->lastmod);
--- a/constants.inc	Thu Mar 17 22:32:33 2016 +0100
+++ b/constants.inc	Thu Mar 17 22:34:49 2016 +0100
@@ -9,6 +9,7 @@
 define(VERBOSITY_DEBUG, 100);
 
 define(DEBUG_LEVEL, VERBOSITY_NONE);
+define(COMPRESSION_DISABLED, 0);
 
 define(DUMP, 0);
 define(MAX_RECURSE, 50);