diff --git a/outputhtml.php b/outputhtml.php index 895b280..c0a35db 100644 --- a/outputhtml.php +++ b/outputhtml.php @@ -83,7 +83,6 @@ class outputhtml extends output EOT; $resView = str_replace ("{content}", $resView, $layoutPage); } - // Do the title replacement in the replacement structure if (! isset ($replacement["{title}"])) $replacement["{title}"] = $title; @@ -93,6 +92,40 @@ EOT; foreach ($replacement as $key=>$val) $resView = str_replace ($key, $val, $resView); + // Manage the timestamp/md5sum for the external files managed by this + // server. + $dom = new DOMDocument (); + @$dom->loadHTML ($resView); + foreach (array ("script"=>"src", "link"=>"href", "img"=>"src") + as $key=>$val) + { + $files = $dom->getElementsByTagName ($key); + for ($i = 0 ; $i < $files->length ; $i++) + { + if ($files[$i]->hasAttribute ($val) === false) + continue; + $src = $files[$i]->getAttribute ($val); + if ($src === "") + continue; + if (substr ($src, 0, 7) === "http://" || + substr ($src, 0, 8) === "https://" || + substr ($src, 0, 2) === "//") + continue; + // If there is already a ? with some variables, don't add the timestamp + if (strpos ($src, "?")) + continue; + if (! array_key_exists ("{baseurl}", $replacement)) + continue; + $srcFile = substr ($src, strlen ($replacement["{baseurl}"])); + if (file_exists ($srcFile)) + $srcHash = filemtime ($srcFile); + else + $srcHash = time(); + $dom->getElementsByTagName ($key)[$i]->setAttribute ($val, + "$src?$srcHash"); + } + } + echo $dom->saveHTML();exit; echo $resView; if (!defined ("PHPUNIT")) exit;