diff --git a/app/Config/core.php b/app/Config/core.php index 28c4655c5..6586b2b02 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -115,7 +115,25 @@ * will override the automatic detection of full base URL and can be * useful when generating links from the CLI (e.g. sending emails) */ - //Configure::write('App.fullBaseURL', 'http://example.com'); + //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.imageBaseUrl', 'img/'); + +/** + * Web path to the CSS files directory under webroot. + * If not set defaults to 'css/' + */ + //Configure::write('App.cssBaseUrl', 'css/'); + +/** + * Web path to the js files directory under webroot. + * If not set defaults to 'js/' + */ + //Configure::write('App.jsBaseUrl', 'js/'); /** * Uncomment the define below to use CakePHP prefix routes. diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 0be88001c..2d50cd46d 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -137,9 +137,9 @@ class ShellDispatcher { $this->setErrorHandlers(); if (!defined('FULL_BASE_URL')) { - $url = Configure::read('App.fullBaseURL'); + $url = Configure::read('App.fullBaseUrl'); define('FULL_BASE_URL', $url ? $url : 'http://localhost'); - Configure::write('App.fullBaseURL', FULL_BASE_URL); + Configure::write('App.fullBaseUrl', FULL_BASE_URL); } return true; diff --git a/lib/Cake/Console/Templates/skel/Config/core.php b/lib/Cake/Console/Templates/skel/Config/core.php index bda4331dc..22a80b71f 100644 --- a/lib/Cake/Console/Templates/skel/Config/core.php +++ b/lib/Cake/Console/Templates/skel/Config/core.php @@ -106,7 +106,25 @@ * will override the automatic detection of full base URL and can be * useful when generating links from the CLI (e.g. sending emails) */ - //Configure::write('App.fullBaseURL', 'http://example.com'); + //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.imageBaseUrl', 'img/'); + +/** + * Web path to the CSS files directory under webroot. + * If not set defaults to 'css/' + */ + //Configure::write('App.cssBaseUrl', 'css/'); + +/** + * Web path to the js files directory under webroot. + * If not set defaults to 'js/' + */ + //Configure::write('App.jsBaseUrl', 'js/'); /** * Uncomment the define below to use CakePHP prefix routes. diff --git a/lib/Cake/Core/Object.php b/lib/Cake/Core/Object.php index 5af47e782..053c68f7c 100644 --- a/lib/Cake/Core/Object.php +++ b/lib/Cake/Core/Object.php @@ -88,8 +88,8 @@ class Object { $data = isset($extra['data']) ? $extra['data'] : null; unset($extra['data']); - if (is_string($url) && strpos($url, Router::baseURL()) === 0) { - $url = Router::normalize(str_replace(Router::baseURL(), '', $url)); + if (is_string($url) && strpos($url, Router::fullBaseUrl()) === 0) { + $url = Router::normalize(str_replace(Router::fullBaseUrl(), '', $url)); } if (is_string($url)) { $request = new CakeRequest($url); diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 14c0a1cb1..fb7ccc04d 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -238,7 +238,7 @@ class CakeRequest implements ArrayAccess { if ($qPosition !== false && strpos($_SERVER['REQUEST_URI'], '://') > $qPosition) { $uri = $_SERVER['REQUEST_URI']; } else { - $uri = substr($_SERVER['REQUEST_URI'], strlen(Configure::read('App.fullBaseURL'))); + $uri = substr($_SERVER['REQUEST_URI'], strlen(Configure::read('App.fullBaseUrl'))); } } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) { $uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']); @@ -424,7 +424,7 @@ class CakeRequest implements ArrayAccess { $ref = $forwarded; } - $base = Configure::read('App.fullBaseURL') . $this->webroot; + $base = Configure::read('App.fullBaseUrl') . $this->webroot; if (!empty($ref) && !empty($base)) { if ($local && strpos($ref, $base) === 0) { $ref = substr($ref, strlen($base)); diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index bdba40a45..1dccba4d4 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -62,7 +62,7 @@ class Router { * * @var string */ - protected static $_baseURL; + protected static $_fullBaseUrl; /** * List of action prefixes used in connected routes. @@ -767,7 +767,7 @@ class Router { * cake relative URLs are required when using requestAction. * - `?` - Takes an array of query string parameters * - `#` - Allows you to set URL hash fragments. - * - `full_base` - If true the `Router::baseURL()` value will be prepended to generated URLs. + * - `full_base` - If true the `Router::fullBaseUrl()` value will be prepended to generated URLs. * * @param string|array $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" * or an array specifying any of the following: 'controller', 'action', @@ -805,7 +805,7 @@ class Router { if (empty($url)) { $output = isset($path['here']) ? $path['here'] : '/'; if ($full) { - $output = self::baseURL() . $output; + $output = self::fullBaseUrl() . $output; } return $output; } elseif (is_array($url)) { @@ -893,7 +893,7 @@ class Router { $output = str_replace('//', '/', $base . '/' . $output); if ($full) { - $output = self::baseURL() . $output; + $output = self::fullBaseUrl() . $output; } if (!empty($extension)) { $output = rtrim($output, '/'); @@ -917,15 +917,15 @@ class Router { * For example: ``http://example.com`` * @return string */ - public static function baseURL($base = null) { + public static function fullBaseUrl($base = null) { if ($base !== null) { - self::$_baseURL = $base; - Configure::write('App.fullBaseURL', $base); + self::$_fullBaseUrl = $base; + Configure::write('App.fullBaseUrl', $base); } - if (empty(self::$_baseURL)) { - self::$_baseURL = Configure::read('App.fullBaseURL'); + if (empty(self::$_fullBaseUrl)) { + self::$_fullBaseUrl = Configure::read('App.fullBaseUrl'); } - return self::$_baseURL; + return self::$_fullBaseUrl; } /** diff --git a/lib/Cake/Test/Case/Core/ObjectTest.php b/lib/Cake/Test/Case/Core/ObjectTest.php index e6b63819a..d445f1a8a 100644 --- a/lib/Cake/Test/Case/Core/ObjectTest.php +++ b/lib/Cake/Test/Case/Core/ObjectTest.php @@ -456,7 +456,7 @@ class ObjectTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $this->object->requestAction( - Configure::read('App.fullBaseURL') . '/request_action/test_request_action' + Configure::read('App.fullBaseUrl') . '/request_action/test_request_action' ); $expected = 'This is a test'; $this->assertEquals($expected, $result); diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 27a6f8b6b..06e4f8151 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -157,7 +157,7 @@ class CakeRequestTest extends CakeTestCase { $request = new CakeRequest(); $this->assertEquals('some/path', $request->url); - $_SERVER['REQUEST_URI'] = Configure::read('App.fullBaseURL') . '/other/path?url=http://cakephp.org'; + $_SERVER['REQUEST_URI'] = Configure::read('App.fullBaseUrl') . '/other/path?url=http://cakephp.org'; $request = new CakeRequest(); $this->assertEquals('other/path', $request->url); } @@ -689,19 +689,19 @@ class CakeRequestTest extends CakeTestCase { $result = $request->referer(); $this->assertSame($result, '/'); - $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseURL') . '/some/path'; + $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/some/path'; $result = $request->referer(true); $this->assertSame($result, '/some/path'); - $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseURL') . '/some/path'; + $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/some/path'; $result = $request->referer(false); - $this->assertSame($result, Configure::read('App.fullBaseURL') . '/some/path'); + $this->assertSame($result, Configure::read('App.fullBaseUrl') . '/some/path'); - $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseURL') . '/some/path'; + $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/some/path'; $result = $request->referer(true); $this->assertSame($result, '/some/path'); - $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseURL') . '/recipes/add'; + $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/recipes/add'; $result = $request->referer(true); $this->assertSame($result, '/recipes/add'); diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index d5379e536..56dbb5b59 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -49,8 +49,8 @@ class RouterTest extends CakeTestCase { public function tearDown() { parent::tearDown(); CakePlugin::unload(); - Router::baseURL(''); - Configure::write('App.fullBaseURL', 'http://localhost'); + Router::fullbaseURL(''); + Configure::write('App.fullBaseUrl', 'http://localhost'); } /** @@ -71,13 +71,13 @@ class RouterTest extends CakeTestCase { * @return void */ public function testBaseURL() { - $this->assertEquals(FULL_BASE_URL, Router::baseUrl()); - Router::baseURL('http://example.com'); + $this->assertEquals(FULL_BASE_URL, Router::fullBaseUrl()); + Router::fullbaseURL('http://example.com'); $this->assertEquals('http://example.com/', Router::url('/', true)); - $this->assertEquals('http://example.com', Configure::read('App.fullBaseURL')); - Router::baseURL('https://example.com'); + $this->assertEquals('http://example.com', Configure::read('App.fullBaseUrl')); + Router::fullbaseURL('https://example.com'); $this->assertEquals('https://example.com/', Router::url('/', true)); - $this->assertEquals('https://example.com', Configure::read('App.fullBaseURL')); + $this->assertEquals('https://example.com', Configure::read('App.fullBaseUrl')); } /** diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index d8be24ab1..054b09641 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -210,7 +210,7 @@ class HtmlHelperTest extends CakeTestCase { Router::reload(); $result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true)); - $expected = array('a' => array('href' => Router::baseURL() . '/posts'), 'Posts', '/a'); + $expected = array('a' => array('href' => Router::fullBaseUrl() . '/posts'), 'Posts', '/a'); $this->assertTags($result, $expected); $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?')); @@ -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.imageBaseUrl') . '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..96648e508 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.cssBaseUrl') . 'cake.generic.css'); + $this->assertEquals(Configure::read('App.cssBaseUrl') . '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.cssBaseUrl') . 'cake.generic.css'); + $this->assertEquals(Configure::read('App.cssBaseUrl') . '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.cssBaseUrl') . 'cake.generic.css'); + $this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . '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.cssBaseUrl') . 'cake.generic.css'); + $this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . '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.cssBaseUrl') . 'cake.generic.css?someparam'); + $this->assertEquals(Configure::read('App.cssBaseUrl') . '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.cssBaseUrl') . 'cake.generic.css'); + $this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . 'cake.generic.css?', '/') . '[0-9]+/', $result); } /** @@ -644,13 +644,13 @@ class HelperTest extends CakeTestCase { ), array('fullBase' => true) ); - $this->assertEquals(Router::baseURL() . '/js/post.js', $result); + $this->assertEquals(Router::fullBaseUrl() . '/js/post.js', $result); $result = $this->Helper->assetUrl('foo.jpg', array('pathPrefix' => 'img/')); $this->assertEquals('img/foo.jpg', $result); $result = $this->Helper->assetUrl('foo.jpg', array('fullBase' => true)); - $this->assertEquals(Router::baseURL() . '/foo.jpg', $result); + $this->assertEquals(Router::fullBaseUrl() . '/foo.jpg', $result); $result = $this->Helper->assetUrl('style', array('ext' => '.css')); $this->assertEquals('style.css', $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.cssBaseUrl'))); + $this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . 'cake.generic.css?', '/') . '[0-9]+/', $result); } /** diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 3eaa906f8..925ac40c5 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -328,7 +328,7 @@ class Helper extends Object { $path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path))); if (!empty($options['fullBase'])) { - $path = rtrim(Router::baseURL(), '/') . '/' . ltrim($path, '/'); + $path = rtrim(Router::fullBaseUrl(), '/') . '/' . ltrim($path, '/'); } return $path; } diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d65346147..24e650a4c 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.imageBaseUrl') . $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..247cd6020 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.cssBaseUrl'), '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.cssBaseUrl')); 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.cssBaseUrl'))); } } } @@ -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.jsBaseUrl'), '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.jsBaseUrl'), '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.imageBaseUrl'))); $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.imageBaseUrl')) + $options); } $text = $options['text']; diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index c9fd04d80..a2c058248 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -163,11 +163,15 @@ if (!defined('FULL_BASE_URL')) { if (isset($httpHost)) { define('FULL_BASE_URL', 'http' . $s . '://' . $httpHost); - Configure::write('App.fullBaseURL', FULL_BASE_URL); + Configure::write('App.fullBaseUrl', FULL_BASE_URL); } unset($httpHost, $s); } +Configure::write('App.imageBaseUrl', IMAGES_URL); +Configure::write('App.cssBaseUrl', CSS_URL); +Configure::write('App.jsBaseUrl', JS_URL); + App::$bootstrapping = true; Configure::bootstrap(isset($boot) ? $boot : true);