From b22b39f15886dcb8ccdeea6e827ef2d53a33abbb Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 31 Jul 2013 12:57:15 +0530 Subject: [PATCH] Deprecate constants IMAGES_URL, CSS_URL, JS_URL and add corresponding config values instead. --- app/Config/core.php | 18 ++++++++++++ .../Console/Templates/skel/Config/core.php | 18 ++++++++++++ .../Test/Case/View/Helper/HtmlHelperTest.php | 2 +- lib/Cake/Test/Case/View/HelperTest.php | 28 +++++++++---------- lib/Cake/View/Helper/FormHelper.php | 2 +- lib/Cake/View/Helper/HtmlHelper.php | 14 +++++----- lib/Cake/bootstrap.php | 4 +++ 7 files changed, 63 insertions(+), 23 deletions(-) diff --git a/app/Config/core.php b/app/Config/core.php index 28c4655c5..72be1c7f6 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -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. * diff --git a/lib/Cake/Console/Templates/skel/Config/core.php b/lib/Cake/Console/Templates/skel/Config/core.php index bda4331dc..c0afda24d 100644 --- a/lib/Cake/Console/Templates/skel/Config/core.php +++ b/lib/Cake/Console/Templates/skel/Config/core.php @@ -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. * diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index d8be24ab1..2e37f3c7f 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -1877,7 +1877,7 @@ class HtmlHelperTest extends CakeTestCase { 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.', diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index a35dcac3d..39fb4aaa7 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -600,8 +600,8 @@ class HelperTest extends CakeTestCase { 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); @@ -609,25 +609,25 @@ class HelperTest extends CakeTestCase { $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); } /** @@ -708,8 +708,8 @@ class HelperTest extends CakeTestCase { $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); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d65346147..9c48cc99b 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1880,7 +1880,7 @@ class FormHelper extends AppHelper { } 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, '/')); } diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 6249f7978..06ac1ab29 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -444,13 +444,13 @@ class HtmlHelper extends AppHelper { 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'))); } } } @@ -545,11 +545,11 @@ class HtmlHelper extends AppHelper { $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'), ' '); @@ -803,7 +803,7 @@ class HtmlHelper extends AppHelper { * @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'])) { @@ -1106,7 +1106,7 @@ class HtmlHelper extends AppHelper { } 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']; diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index c9fd04d80..9f79be841 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -168,6 +168,10 @@ if (!defined('FULL_BASE_URL')) { 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);