Skip to content

Commit

Permalink
Deprecate constants IMAGES_URL, CSS_URL, JS_URL and add corresponding…
Browse files Browse the repository at this point in the history
… config values instead.
  • Loading branch information
ADmad committed Jul 31, 2013
1 parent 48df85d commit b22b39f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 23 deletions.
18 changes: 18 additions & 0 deletions app/Config/core.php
Expand Up @@ -117,6 +117,24 @@
*/
//Configure::write('App.fullBaseURL', 'http://example.com');

/**
* Web path to the public images directory under webroot.
* If not set defaults to 'img/'
*/
//Configure::write('App.imagesURL', 'img/');

/**
* Web path to the CSS files directory under webroot.
* If not set defaults to 'css/'
*/
//Configure::write('App.cssURL', 'css/');

/**
* Web path to the js files directory under webroot.
* If not set defaults to 'js/'
*/
//Configure::write('App.jsURL', 'js/');

/**
* Uncomment the define below to use CakePHP prefix routes.
*
Expand Down
18 changes: 18 additions & 0 deletions lib/Cake/Console/Templates/skel/Config/core.php
Expand Up @@ -108,6 +108,24 @@
*/
//Configure::write('App.fullBaseURL', 'http://example.com');

/**
* Web path to the public images directory under webroot.
* If not set defaults to 'img/'
*/
//Configure::write('App.imagesURL', 'img/');

/**
* Web path to the CSS files directory under webroot.
* If not set defaults to 'css/'
*/
//Configure::write('App.cssURL', 'css/');

/**
* Web path to the js files directory under webroot.
* If not set defaults to 'js/'
*/
//Configure::write('App.jsURL', 'js/');

/**
* Uncomment the define below to use CakePHP prefix routes.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -1877,7 +1877,7 @@ public function testMedia() {
array('pathPrefix' => 'videos/', 'poster' => 'poster.jpg', 'text' => 'Your browser does not support the HTML5 Video element.')
);
$expected = array(
'video' => array('poster' => IMAGES_URL . 'poster.jpg'),
'video' => array('poster' => Configure::read('App.imagesURL') . 'poster.jpg'),
array('source' => array('src' => 'videos/video.webm', 'type' => 'video/webm')),
array('source' => array('src' => 'videos/video.ogv', 'type' => 'video/ogg; codecs='theora, vorbis'')),
'Your browser does not support the HTML5 Video element.',
Expand Down
28 changes: 14 additions & 14 deletions lib/Cake/Test/Case/View/HelperTest.php
Expand Up @@ -600,34 +600,34 @@ public function testUrlConversion() {
public function testAssetTimestamp() {
Configure::write('Foo.bar', 'test');
Configure::write('Asset.timestamp', false);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertEquals(CSS_URL . 'cake.generic.css', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssURL') . 'cake.generic.css');
$this->assertEquals(Configure::read('App.cssURL') . 'cake.generic.css', $result);

Configure::write('Asset.timestamp', true);
Configure::write('debug', 0);

$result = $this->Helper->assetTimestamp('/%3Cb%3E/cake.generic.css');
$this->assertEquals('/%3Cb%3E/cake.generic.css', $result);

$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertEquals(CSS_URL . 'cake.generic.css', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssURL') . 'cake.generic.css');
$this->assertEquals(Configure::read('App.cssURL') . 'cake.generic.css', $result);

Configure::write('Asset.timestamp', true);
Configure::write('debug', 2);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssURL') . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssURL') . 'cake.generic.css?', '/') . '[0-9]+/', $result);

Configure::write('Asset.timestamp', 'force');
Configure::write('debug', 0);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssURL') . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssURL') . 'cake.generic.css?', '/') . '[0-9]+/', $result);

$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
$this->assertEquals(CSS_URL . 'cake.generic.css?someparam', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssURL') . 'cake.generic.css?someparam');
$this->assertEquals(Configure::read('App.cssURL') . 'cake.generic.css?someparam', $result);

$this->Helper->request->webroot = '/some/dir/';
$result = $this->Helper->assetTimestamp('/some/dir/' . CSS_URL . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp('/some/dir/' . Configure::read('App.cssURL') . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssURL') . 'cake.generic.css?', '/') . '[0-9]+/', $result);
}

/**
Expand Down Expand Up @@ -708,8 +708,8 @@ public function testAssetUrlTimestampForce() {
$this->Helper->webroot = '';
Configure::write('Asset.timestamp', 'force');

$result = $this->Helper->assetUrl('cake.generic.css', array('pathPrefix' => CSS_URL));
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetUrl('cake.generic.css', array('pathPrefix' => Configure::read('App.cssURL')));
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssURL') . 'cake.generic.css?', '/') . '[0-9]+/', $result);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1880,7 +1880,7 @@ public function submit($caption = null, $options = array()) {
} elseif ($isImage) {
unset($options['type']);
if ($caption{0} !== '/') {
$url = $this->webroot(IMAGES_URL . $caption);
$url = $this->webroot(Configure::read('App.imagesURL') . $caption);
} else {
$url = $this->webroot(trim($caption, '/'));
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -444,13 +444,13 @@ public function css($path, $options = array()) {
if (strpos($path, '//') !== false) {
$url = $path;
} else {
$url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css'));
$url = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.cssURL'), 'ext' => '.css'));
$options = array_diff_key($options, array('fullBase' => null));

if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL);
$pos = strpos($url, Configure::read('App.cssURL'));
if ($pos !== false) {
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(Configure::read('App.cssURL')));
}
}
}
Expand Down Expand Up @@ -545,11 +545,11 @@ public function script($url, $options = array()) {
$this->_includedScripts[$url] = true;

if (strpos($url, '//') === false) {
$url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js'));
$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsURL'), 'ext' => '.js'));
$options = array_diff_key($options, array('fullBase' => null));

if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
$url = str_replace(Configure::read('App.jsURL'), 'cjs/', $url);
}
}
$attributes = $this->_parseAttributes($options, array('block', 'once'), ' ');
Expand Down Expand Up @@ -803,7 +803,7 @@ protected function _prepareCrumbs($startText) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image
*/
public function image($path, $options = array()) {
$path = $this->assetUrl($path, $options + array('pathPrefix' => IMAGES_URL));
$path = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.imagesURL')));
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));

if (!isset($options['alt'])) {
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public function media($path, $options = array()) {
}

if (isset($options['poster'])) {
$options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => IMAGES_URL) + $options);
$options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => Configure::read('App.imagesURL')) + $options);
}
$text = $options['text'];

Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/bootstrap.php
Expand Up @@ -168,6 +168,10 @@
unset($httpHost, $s);
}

Configure::write('App.imagesURL', IMAGES_URL);
Configure::write('App.cssURL', CSS_URL);
Configure::write('App.jsURL', JS_URL);

App::$bootstrapping = true;

Configure::bootstrap(isset($boot) ? $boot : true);
Expand Down

0 comments on commit b22b39f

Please sign in to comment.