diff --git a/cake/libs/configure.php b/cake/libs/configure.php index b60ba74a057..450d0a8e047 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -390,7 +390,7 @@ function __loadBootstrap($boot) { $libPaths = $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null; if ($boot) { - Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR)); + Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT)); if (!include(CONFIGS . 'core.php')) { trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR); diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index db2f95faed6..5ff3bb4d109 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -201,17 +201,28 @@ function webroot($file) { $asset = explode('?', $file); $asset[1] = isset($asset[1]) ? '?' . $asset[1] : null; $webPath = "{$this->webroot}" . $asset[0]; + $file = $asset[0]; if (!empty($this->theme)) { - $viewPaths = App::path('views'); + $file = trim($file, '/'); + $theme = $this->theme . '/'; - foreach ($viewPaths as $viewPath) { - $path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $asset[0]; - $theme = $this->theme . '/'; + if (DS === '\\') { + $file = str_replace('/', '\\', $file); + } + + if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->theme . DS . $file)) { + $webPath = "{$this->webroot}theme/" . $theme . $asset[0]; + } else { + $viewPaths = App::path('views'); - if (file_exists($path)) { - $webPath = "{$this->webroot}theme/" . $theme . $asset[0]; - break; + foreach ($viewPaths as $viewPath) { + $path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $file; + + if (file_exists($path)) { + $webPath = "{$this->webroot}theme/" . $theme . $asset[0]; + break; + } } } } diff --git a/cake/libs/view/media.php b/cake/libs/view/media.php index 145ca631d95..d181fd8d9cb 100644 --- a/cake/libs/view/media.php +++ b/cake/libs/view/media.php @@ -35,11 +35,11 @@ class MediaView { 'eps' => 'application/postscript', 'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'bz2' => 'application/x-bzip', '7z' => 'application/x-7z-compressed', 'hdf' => 'application/x-hdf', - 'hqx' => 'application/mac-binhex40', 'ips' => 'application/x-ipscript', 'ipx' => 'application/x-ipix', - 'js' => 'application/x-javascript', 'latex' => 'application/x-latex', 'lha' => 'application/octet-stream', - 'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream', 'man' => 'application/x-troff-man', - 'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif', 'ms' => 'application/x-troff-ms', - 'nc' => 'application/x-netcdf', 'oda' => 'application/oda', 'pdf' => 'application/pdf', + 'hqx' => 'application/mac-binhex40', 'ico' => 'image/vnd.microsoft.icon', 'ips' => 'application/x-ipscript', + 'ipx' => 'application/x-ipix', 'js' => 'application/x-javascript', 'latex' => 'application/x-latex', + 'lha' => 'application/octet-stream', 'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream', + 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif', + 'ms' => 'application/x-troff-ms', 'nc' => 'application/x-netcdf', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'pgn' => 'application/x-chess-pgn', 'pot' => 'application/mspowerpoint', 'pps' => 'application/mspowerpoint', 'ppt' => 'application/mspowerpoint', 'ppz' => 'application/mspowerpoint', 'pre' => 'application/x-freelance', 'prt' => 'application/pro_eng', 'ps' => 'application/postscript', 'roff' => 'application/x-troff', diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index d0745efa67d..848ea667eac 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -60,9 +60,8 @@ function _paths($plugin = null, $cached = true) { && strpos($paths[$i], DS . $plugin . DS) === false) { if ($plugin) { $themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . 'plugins' . DS . $plugin . DS; - } else { - $themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS; } + $themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS; } } $paths = array_merge($themePaths, $paths); diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index fbdabe951f6..466e3933cbd 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -663,6 +663,44 @@ function testMultiDimensionalField() { $result = $this->Helper->value('My.title'); $this->assertEqual($result,'My Title'); } + + function testWebrootPaths() { + $this->Helper->webroot = '/'; + $result = $this->Helper->webroot('/img/cake.power.gif'); + $expected = '/img/cake.power.gif'; + $this->assertEqual($result, $expected); + + $this->Helper->theme = 'test_theme'; + + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + )); + + $result = $this->Helper->webroot('/img/cake.power.gif'); + $expected = '/theme/test_theme/img/cake.power.gif'; + $this->assertEqual($result, $expected); + + $result = $this->Helper->webroot('/img/test.jpg'); + $expected = '/theme/test_theme/img/test.jpg'; + $this->assertEqual($result, $expected); + + $webRoot = Configure::read('App.www_root'); + Configure::write('App.www_root', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'webroot' . DS); + + $result = $this->Helper->webroot('/img/cake.power.gif'); + $expected = '/theme/test_theme/img/cake.power.gif'; + $this->assertEqual($result, $expected); + + $result = $this->Helper->webroot('/img/test.jpg'); + $expected = '/theme/test_theme/img/test.jpg'; + $this->assertEqual($result, $expected); + + $result = $this->Helper->webroot('/img/cake.icon.gif'); + $expected = '/img/cake.icon.gif'; + $this->assertEqual($result, $expected); + + Configure::write('App.www_root', $webRoot); + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/theme.test.php b/cake/tests/cases/libs/view/theme.test.php index 5a9d09a70b2..6aac774f822 100644 --- a/cake/tests/cases/libs/view/theme.test.php +++ b/cake/tests/cases/libs/view/theme.test.php @@ -211,8 +211,12 @@ function testPluginThemedGetTemplate() { $result = $ThemeView->getViewFileName('index'); $this->assertEqual($result, $expected); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'plugins' . DS . 'test_plugin' . DS . 'layouts' . DS .'default.ctp'; - $result = $ThemeView->getLayoutFileName(); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'plugins' . DS . 'test_plugin' . DS . 'layouts' . DS .'plugin_default.ctp'; + $result = $ThemeView->getLayoutFileName('plugin_default'); + $this->assertEqual($result, $expected); + + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'layouts' . DS .'default.ctp'; + $result = $ThemeView->getLayoutFileName('default'); $this->assertEqual($result, $expected); } diff --git a/cake/tests/test_app/views/themed/test_theme/plugins/test_plugin/layouts/default.ctp b/cake/tests/test_app/views/themed/test_theme/plugins/test_plugin/layouts/plugin_default.ctp similarity index 100% rename from cake/tests/test_app/views/themed/test_theme/plugins/test_plugin/layouts/default.ctp rename to cake/tests/test_app/views/themed/test_theme/plugins/test_plugin/layouts/plugin_default.ctp diff --git a/cake/tests/test_app/webroot/theme/test_theme/img/cake.power.gif b/cake/tests/test_app/webroot/theme/test_theme/img/cake.power.gif new file mode 100644 index 00000000000..8f8d570a2e2 Binary files /dev/null and b/cake/tests/test_app/webroot/theme/test_theme/img/cake.power.gif differ diff --git a/cake/tests/test_app/webroot/theme/test_theme/img/test.jpg b/cake/tests/test_app/webroot/theme/test_theme/img/test.jpg new file mode 100644 index 00000000000..ca5197ae899 Binary files /dev/null and b/cake/tests/test_app/webroot/theme/test_theme/img/test.jpg differ