diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 5dd2a2c3c..cb3d20287 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -123,13 +123,11 @@ class Dispatcher extends Object { $url = $this->getUrl(); $this->params = array_merge($this->parseParams($url), $additionalParams); } - $this->here = $this->base . '/' . $url; if ($this->cached($url)) { $this->_stop(); } - $controller =& $this->__getController(); if (!is_object($controller)) { @@ -141,7 +139,6 @@ class Dispatcher extends Object { 'base' => $this->base ))); } - $privateAction = $this->params['action'][0] === '_'; $prefixes = Router::prefixes(); @@ -167,7 +164,6 @@ class Dispatcher extends Object { 'base' => $this->base ))); } - $controller->base = $this->base; $controller->here = $this->here; $controller->webroot = $this->webroot; @@ -377,21 +373,21 @@ class Dispatcher extends Object { $this->webroot = $base .'/'; return $base; } - $file = '/' . basename($baseUrl); - $base = dirname($baseUrl); + $file = '/' . basename($baseUrl); + $base = dirname($baseUrl); + + if ($base === DS || $base === '.') { + $base = ''; + } + $this->webroot = $base .'/'; - if ($base === DS || $base === '.') { - $base = ''; - } - $this->webroot = $base .'/'; - - if (strpos($this->webroot, $dir) === false) { - $this->webroot .= $dir . '/' ; - } - if (strpos($this->webroot, $webroot) === false) { - $this->webroot .= $webroot . '/'; - } - return $base . $file; + if (strpos($this->webroot, $dir) === false) { + $this->webroot .= $dir . '/' ; + } + if (strpos($this->webroot, $webroot) === false) { + $this->webroot .= $webroot . '/'; + } + return $base . $file; } /** @@ -615,9 +611,8 @@ class Dispatcher extends Object { if (isset($Media->mimeType[$ext])) { $pos = 0; $parts = explode('/', $url); - if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') { - $pos = 0; - } elseif ($parts[0] === 'theme') { + + if ($parts[0] === 'theme') { $pos = strlen($parts[0] . $parts[1]) + 1; } elseif (count($parts) > 2) { $pos = strlen($parts[0]); diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index 848ea667e..0a1f78f71 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -56,8 +56,7 @@ class ThemeView extends View { $count = count($paths); for ($i = 0; $i < $count; $i++) { if (strpos($paths[$i], DS . 'plugins' . DS) === false - && strpos($paths[$i], DS . 'libs' . DS . 'view') === false - && strpos($paths[$i], DS . $plugin . DS) === false) { + && strpos($paths[$i], DS . 'libs' . DS . 'view') === false) { if ($plugin) { $themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . 'plugins' . DS . $plugin . DS; } diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index 1029ab543..ab75ae772 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -1811,13 +1811,24 @@ class DispatcherTest extends CakeTestCase { $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg'); $this->assertEqual($file, $result); - $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css'); ob_start(); $Dispatcher->cached('theme/test_theme/css/test_asset.css'); $result = ob_get_clean(); $this->assertEqual('this is the test asset css file', $result); + $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/theme.js'); + ob_start(); + $Dispatcher->cached('theme/test_theme/js/theme.js'); + $result = ob_get_clean(); + $this->assertEqual('root theme js file', $result); + + $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/one/theme_one.js'); + ob_start(); + $Dispatcher->cached('theme/test_theme/js/one/theme_one.js'); + $result = ob_get_clean(); + $this->assertEqual('nested theme js file', $result); + ob_start(); $Dispatcher->dispatch('test_plugin/flash/plugin_test.swf'); $result = ob_get_clean(); @@ -1856,16 +1867,22 @@ class DispatcherTest extends CakeTestCase { $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .DS . 'webroot' . DS . 'img' . DS . 'cake.icon.gif'); $this->assertEqual($file, $result); - - Configure::write('debug', $debug); $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js'); ob_start(); $Dispatcher->cached('plugin_js/js/plugin_js.js'); $result = ob_get_clean(); $expected = "alert('win sauce');"; $this->assertEqual($result, $expected); - - header('Content-type: text/html');//reset the header content-type without page can render as plain text. + + $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/one/plugin_one.js'); + ob_start(); + $Dispatcher->cached('plugin_js/js/one/plugin_one.js'); + $result = ob_get_clean(); + $expected = "alert('plugin one nested js file');"; + $this->assertEqual($result, $expected); + Configure::write('debug', $debug); + //reset the header content-type without page can render as plain text. + header('Content-type: text/html'); } /** diff --git a/cake/tests/test_app/plugins/plugin_js/webroot/js/one/plugin_one.js b/cake/tests/test_app/plugins/plugin_js/webroot/js/one/plugin_one.js new file mode 100644 index 000000000..03e21bb19 --- /dev/null +++ b/cake/tests/test_app/plugins/plugin_js/webroot/js/one/plugin_one.js @@ -0,0 +1 @@ +alert('plugin one nested js file'); \ No newline at end of file diff --git a/cake/tests/test_app/views/themed/test_theme/webroot/js/one/theme_one.js b/cake/tests/test_app/views/themed/test_theme/webroot/js/one/theme_one.js new file mode 100644 index 000000000..d29bcbc94 --- /dev/null +++ b/cake/tests/test_app/views/themed/test_theme/webroot/js/one/theme_one.js @@ -0,0 +1 @@ +nested theme js file \ No newline at end of file diff --git a/cake/tests/test_app/views/themed/test_theme/webroot/js/theme.js b/cake/tests/test_app/views/themed/test_theme/webroot/js/theme.js new file mode 100644 index 000000000..ec17940de --- /dev/null +++ b/cake/tests/test_app/views/themed/test_theme/webroot/js/theme.js @@ -0,0 +1 @@ +root theme js file \ No newline at end of file