mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updated Html and Javascript helpers to suffix asset urls with timestamp even when the app is run off a subfolder on the domain
Signed-off-by: Mark Story <mark@mark-story.com>
This commit is contained in:
parent
c330934b93
commit
de4737323f
4 changed files with 27 additions and 24 deletions
|
@ -374,14 +374,8 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $this->webroot($path);
|
$url = $this->webroot($path);
|
||||||
|
if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
|
||||||
$url = $path;
|
|
||||||
$timestampEnabled = (
|
|
||||||
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
|
|
||||||
Configure::read('Asset.timestamp') === 'force'
|
|
||||||
);
|
|
||||||
if (strpos($path, '?') === false && $timestampEnabled) {
|
|
||||||
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
|
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,12 +601,15 @@ class HtmlHelper extends AppHelper {
|
||||||
function image($path, $options = array()) {
|
function image($path, $options = array()) {
|
||||||
if (is_array($path)) {
|
if (is_array($path)) {
|
||||||
$path = $this->url($path);
|
$path = $this->url($path);
|
||||||
} elseif ($path[0] === '/') {
|
|
||||||
$path = $this->webroot($path);
|
|
||||||
} elseif (strpos($path, '://') === false) {
|
} elseif (strpos($path, '://') === false) {
|
||||||
$path = $this->webroot(IMAGES_URL . $path);
|
if ($path[0] !== '/') {
|
||||||
|
$path = IMAGES_URL . $path;
|
||||||
|
}
|
||||||
|
|
||||||
if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
|
if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
|
||||||
$path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . $path));
|
$path = $this->webroot($path) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
|
||||||
|
} else {
|
||||||
|
$path = $this->webroot($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,14 +271,10 @@ class JavascriptHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = $this->webroot($url);
|
if (strpos($url, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) {
|
||||||
$timestampEnabled = (
|
$url = $this->webroot($url) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
|
||||||
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
|
} else {
|
||||||
Configure::read('Asset.timestamp') === 'force'
|
$url = $this->webroot($url);
|
||||||
);
|
|
||||||
|
|
||||||
if (strpos($url, '?') === false && $timestampEnabled) {
|
|
||||||
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Configure::read('Asset.filter.js')) {
|
if (Configure::read('Asset.filter.js')) {
|
||||||
|
|
|
@ -332,6 +332,16 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/',
|
'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/',
|
||||||
'alt' => ''
|
'alt' => ''
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
$webroot = $this->Html->webroot;
|
||||||
|
$this->Html->webroot = '/testing/';
|
||||||
|
$result = $this->Html->image('cake.power.gif');
|
||||||
|
$this->assertTags($result, array(
|
||||||
|
'img' => array(
|
||||||
|
'src' => 'preg:/\/testing\/themed\/default\/img\/cake\.power\.gif\?\d+/',
|
||||||
|
'alt' => ''
|
||||||
|
)));
|
||||||
|
$this->Html->webroot = $webroot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -420,14 +430,14 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
$webroot = $this->Html->webroot;
|
$webroot = $this->Html->webroot;
|
||||||
$this->Html->webroot = '/testing/';
|
$this->Html->webroot = '/testing/';
|
||||||
$result = $this->Html->css('cake.generic');
|
$result = $this->Html->css('cake.generic');
|
||||||
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?/';
|
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
$this->Html->webroot = $webroot;
|
$this->Html->webroot = $webroot;
|
||||||
|
|
||||||
$webroot = $this->Html->webroot;
|
$webroot = $this->Html->webroot;
|
||||||
$this->Html->webroot = '/testing/longer/';
|
$this->Html->webroot = '/testing/longer/';
|
||||||
$result = $this->Html->css('cake.generic');
|
$result = $this->Html->css('cake.generic');
|
||||||
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?/';
|
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
$this->Html->webroot = $webroot;
|
$this->Html->webroot = $webroot;
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,11 +278,11 @@ class JavascriptTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->Javascript->webroot = '/testing/';
|
$this->Javascript->webroot = '/testing/';
|
||||||
$result = $this->Javascript->link('__cake_js_test');
|
$result = $this->Javascript->link('__cake_js_test');
|
||||||
$this->assertPattern('/^<script[^<>]+src="\/testing\/js\/__cake_js_test\.js\?"[^<>]*>/', $result);
|
$this->assertPattern('/^<script[^<>]+src="\/testing\/js\/__cake_js_test\.js\?\d+"[^<>]*>/', $result);
|
||||||
|
|
||||||
$this->Javascript->webroot = '/testing/longer/';
|
$this->Javascript->webroot = '/testing/longer/';
|
||||||
$result = $this->Javascript->link('__cake_js_test');
|
$result = $this->Javascript->link('__cake_js_test');
|
||||||
$this->assertPattern('/^<script[^<>]+src="\/testing\/longer\/js\/__cake_js_test\.js\?"[^<>]*>/', $result);
|
$this->assertPattern('/^<script[^<>]+src="\/testing\/longer\/js\/__cake_js_test\.js\?\d+"[^<>]*>/', $result);
|
||||||
|
|
||||||
$this->Javascript->webroot = $webroot;
|
$this->Javascript->webroot = $webroot;
|
||||||
Configure::write('debug', $debug);
|
Configure::write('debug', $debug);
|
||||||
|
|
Loading…
Reference in a new issue