Skip to content

Commit

Permalink
* Restoring the cache buster output filter which was lost at some point
Browse files Browse the repository at this point in the history
Refs #4019
  • Loading branch information
mattab committed Jul 1, 2013
1 parent e572dd6 commit 7bae344
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion core/View.php
Expand Up @@ -131,7 +131,36 @@ public function render()
// always sending this header, sometimes empty, to ensure that Dashboard embed loads (which could call this header() multiple times, the last one will prevail)
@header('X-Frame-Options: ' . (string)$this->xFrameOptions);

return $this->twig->render($this->template, $this->templateVars);
return $this->renderTwigTemplate();
}

protected function renderTwigTemplate()
{
$output = $this->twig->render($this->template, $this->templateVars);
$output = $this->applyFilter_cacheBuster($output);
return $output;
}

protected function applyFilter_cacheBuster($output)
{
$cacheBuster = md5(Piwik_Common::getSalt() . PHP_VERSION . Piwik_Version::VERSION);
$tag = 'cb=' . $cacheBuster;

$pattern = array(
'~<script type=[\'"]text/javascript[\'"] src=[\'"]([^\'"]+)[\'"]>~',
'~<script src=[\'"]([^\'"]+)[\'"] type=[\'"]text/javascript[\'"]>~',
'~<link rel=[\'"]stylesheet[\'"] type=[\'"]text/css[\'"] href=[\'"]([^\'"]+)[\'"] ?/?>~',
'~(src|href)=\"index.php\?module=([A-Za-z0-9_]+)&action=([A-Za-z0-9_]+)\?cb=~',
);

$replace = array(
'<script type="text/javascript" src="$1?' . $tag . '">',
'<script type="text/javascript" src="$1?' . $tag . '">',
'<link rel="stylesheet" type="text/css" href="$1?' . $tag . '" />',
'$1="index.php?module=$2&amp;action=$3&amp;cb=',
);

return preg_replace($pattern, $replace, $output);
}

/**
Expand Down

0 comments on commit 7bae344

Please sign in to comment.