changeset 121:e3f97bbf12f3

Better checking for uncommon conditions.
author Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no>
date Thu, 28 Dec 2017 18:44:28 +0100
parents 111770d32c2e
children 74c22a8dd38f
files Sitemap.inc
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Sitemap.inc	Thu Dec 28 18:40:56 2017 +0100
+++ b/Sitemap.inc	Thu Dec 28 18:44:28 2017 +0100
@@ -1,4 +1,4 @@
-<?
+<?php
 include_once 'ScriptIncludeCache.inc';
 
 /// @cond
@@ -151,20 +151,27 @@
 
       $location = htmlentities($location);
 
-      $lastmod = $headers["Last-Modified"];
+      if (array_key_exists('Last-Modified', $headers)) {
+	$lastmod = $headers["Last-Modified"];
+      }
 
       $n = StatusCodes::codeFromHeader($headers['']);
 
       if ($n == StatusCodes::HTTP_OK) {
-	$lastmod = strtotime($lastmod);
-	if ($lastmod > $this->lastmod) {
-	  $this->lastmod = $lastmod;
+	if (isset($lastmod)) {
+
+	  $lastmod = strtotime($lastmod);
+	  if ($lastmod > $this->lastmod) {
+	    $this->lastmod = $lastmod;
+	  }
+	  $lastmod = date(DateTime::W3C, $lastmod);
 	}
-	$lastmod = date(DateTime::W3C, $lastmod);
 
 	$out .= "<url>\n";
 	$out .= "<loc>${location}</loc>\n";
-	$out .= "<lastmod>${lastmod}</lastmod>\n";
+	if (isset($lastmod)) {
+	  $out .= "<lastmod>${lastmod}</lastmod>\n";
+	}
 	$out .= "</url>\n";
       }
     }