comparison Sitemap.inc @ 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 f498ea087d67
children 74c22a8dd38f
comparison
equal deleted inserted replaced
120:111770d32c2e 121:e3f97bbf12f3
1 <? 1 <?php
2 include_once 'ScriptIncludeCache.inc'; 2 include_once 'ScriptIncludeCache.inc';
3 3
4 /// @cond 4 /// @cond
5 $baseDir = dirname(__FILE__); 5 $baseDir = dirname(__FILE__);
6 $cache = ScriptIncludeCache::instance(__FILE__); 6 $cache = ScriptIncludeCache::instance(__FILE__);
149 foreach($urls as $location) { 149 foreach($urls as $location) {
150 $headers = Http::getHeaders($location, 5); 150 $headers = Http::getHeaders($location, 5);
151 151
152 $location = htmlentities($location); 152 $location = htmlentities($location);
153 153
154 $lastmod = $headers["Last-Modified"]; 154 if (array_key_exists('Last-Modified', $headers)) {
155 $lastmod = $headers["Last-Modified"];
156 }
155 157
156 $n = StatusCodes::codeFromHeader($headers['']); 158 $n = StatusCodes::codeFromHeader($headers['']);
157 159
158 if ($n == StatusCodes::HTTP_OK) { 160 if ($n == StatusCodes::HTTP_OK) {
159 $lastmod = strtotime($lastmod); 161 if (isset($lastmod)) {
160 if ($lastmod > $this->lastmod) { 162
161 $this->lastmod = $lastmod; 163 $lastmod = strtotime($lastmod);
164 if ($lastmod > $this->lastmod) {
165 $this->lastmod = $lastmod;
166 }
167 $lastmod = date(DateTime::W3C, $lastmod);
162 } 168 }
163 $lastmod = date(DateTime::W3C, $lastmod);
164 169
165 $out .= "<url>\n"; 170 $out .= "<url>\n";
166 $out .= "<loc>${location}</loc>\n"; 171 $out .= "<loc>${location}</loc>\n";
167 $out .= "<lastmod>${lastmod}</lastmod>\n"; 172 if (isset($lastmod)) {
173 $out .= "<lastmod>${lastmod}</lastmod>\n";
174 }
168 $out .= "</url>\n"; 175 $out .= "</url>\n";
169 } 176 }
170 } 177 }
171 178
172 $out .= "</urlset>"; 179 $out .= "</urlset>";