Browse Source

Deprecate constants IMAGES_URL, CSS_URL, JS_URL and add corresponding config values instead.

ADmad 12 years ago
parent
commit
b22b39f158

+ 18 - 0
app/Config/core.php

@@ -118,6 +118,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.
  *
  * The value of the define determines the names of the routes

+ 18 - 0
lib/Cake/Console/Templates/skel/Config/core.php

@@ -109,6 +109,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.
  *
  * The value of the define determines the names of the routes

+ 1 - 1
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.',

+ 14 - 14
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);
 	}
 
 /**

+ 1 - 1
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, '/'));
 			}

+ 7 - 7
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'];
 

+ 4 - 0
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);