* outputhtml : add a timestamp after the internal resources when creating the page. Like this, when updating a script, image or css file, it is updated by the client automatically (the browser don't use its cache)
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2771 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -83,7 +83,6 @@ class outputhtml extends output
|
|||||||
EOT;
|
EOT;
|
||||||
$resView = str_replace ("{content}", $resView, $layoutPage);
|
$resView = str_replace ("{content}", $resView, $layoutPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the title replacement in the replacement structure
|
// Do the title replacement in the replacement structure
|
||||||
if (! isset ($replacement["{title}"]))
|
if (! isset ($replacement["{title}"]))
|
||||||
$replacement["{title}"] = $title;
|
$replacement["{title}"] = $title;
|
||||||
@@ -93,6 +92,40 @@ EOT;
|
|||||||
foreach ($replacement as $key=>$val)
|
foreach ($replacement as $key=>$val)
|
||||||
$resView = str_replace ($key, $val, $resView);
|
$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;
|
echo $resView;
|
||||||
if (!defined ("PHPUNIT"))
|
if (!defined ("PHPUNIT"))
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in New Issue
Block a user