Permalink
Browse files

Adding ability for plugins to have there own webroot.

plugins/<PLUGINNAME>/webroot/*

Themes can also be self contained with a webroot directory.
app/views/themed/<THEMENAME>/webroot/*

vendors directory for assets is deprecated and no longer supported
  • Loading branch information...
1 parent 97239f0 commit 2254bfe5c91fa710138b87cf79b3b8628e83fed1 @phpnut phpnut committed Nov 25, 2009
View
45 cake/dispatcher.php
@@ -605,7 +605,7 @@ function getUrl($uri = null, $base = null) {
* @access public
*/
function cached($url) {
- if (strpos($url, 'css/') !== false || strpos($url, 'js/') !== false || strpos($url, 'img/') !== false) {
+ if (strpos($url, '.ico') !== false || strpos($url, 'css/') !== false || strpos($url, 'js/') !== false || strpos($url, 'img/') !== false) {
if (strpos($url, 'ccss/') === 0) {
include WWW_ROOT . DS . Configure::read('Asset.filter.css');
$this->_stop();
@@ -615,8 +615,12 @@ function cached($url) {
}
$isAsset = false;
$assets = array(
- 'js' => 'text/javascript', 'css' => 'text/css',
- 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png'
+ 'js' => 'text/javascript',
+ 'css' => 'text/css',
+ 'gif' => 'image/gif',
+ 'jpg' => 'image/jpeg',
+ 'png' => 'image/png',
+ 'ico' => 'image/vnd.microsoft.icon'
);
$ext = array_pop(explode('.', $url));
@@ -625,7 +629,9 @@ function cached($url) {
$parts = explode('/', $url);
if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') {
$pos = 0;
- } else {
+ } elseif ($parts[0] === 'theme') {
+ $pos = strlen($parts[0] . $parts[1]) + 1;
+ } elseif (count($parts) > 2) {
$pos = strlen($parts[0]);
}
$isAsset = true;
@@ -642,18 +648,37 @@ function cached($url) {
}
$assetFile = null;
$paths = array();
+ $matched = false;
if ($pos > 0) {
$plugin = substr($url, 0, $pos);
$url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url);
- $paths[] = App::pluginPath($plugin) . 'vendors' . DS;
+
+ if (strpos($plugin, '/') !== false) {
+ list($plugin, $theme) = explode('/', $plugin);
+ $path = VIEWS . 'themed' . DS . $theme . DS . 'webroot' . DS;
+ if ($plugin === 'theme' && (is_file($path . $url) && file_exists($path . $url))) {
+ $assetFile = $path . $url;
+ $matched = true;
+ }
+ }
+
+ if ($matched === false) {
+ $pluginPaths = App::path('plugins');
+ $count = count($pluginPaths);
+
+ for ($i = 0; $i < $count; $i++) {
+ $paths[] = $pluginPaths[$i] . $plugin . DS . 'webroot' . DS;
+ }
+ }
}
- $paths = array_merge($paths, App::path('vendors'));
- foreach ($paths as $path) {
- if (is_file($path . $url) && file_exists($path . $url)) {
- $assetFile = $path . $url;
- break;
+ if ($matched === false) {
+ foreach ($paths as $path) {
+ if (is_file($path . $url) && file_exists($path . $url)) {
+ $assetFile = $path . $url;
+ break;
+ }
}
}
View
27 cake/libs/view/helper.php
@@ -198,24 +198,27 @@ function url($url = null, $full = false) {
* @return string $webPath web path to file.
*/
function webroot($file) {
- $webPath = "{$this->webroot}" . $file;
- if (!empty($this->themeWeb)) {
- $os = env('OS');
- if (!empty($os) && strpos($os, 'Windows') !== false) {
- if (strpos(WWW_ROOT . $this->themeWeb . $file, '\\') !== false) {
- $path = str_replace('/', '\\', WWW_ROOT . $this->themeWeb . $file);
+ $asset = explode('?', $file);
+ $asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
+ $webPath = "{$this->webroot}" . $asset[0];
+
+ if (!empty($this->theme)) {
+ $viewPaths = App::path('views');
+
+ foreach ($viewPaths as $viewPath) {
+ $path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $asset[0];
+ $theme = $this->theme . '/';
+
+ if (file_exists($path)) {
+ $webPath = "{$this->webroot}theme/" . $theme . $asset[0];
+ break;
}
- } else {
- $path = WWW_ROOT . $this->themeWeb . $file;
- }
- if (file_exists($path)) {
- $webPath = "{$this->webroot}" . $this->themeWeb . $file;
}
}
if (strpos($webPath, '//') !== false) {
return str_replace('//', '/', $webPath);
}
- return $webPath;
+ return $webPath . $asset[1];
}
/**
View
2 cake/libs/view/helpers/cache.php
@@ -268,7 +268,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\'));
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
$controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\'));
- $controller->themeWeb = $this->themeWeb = \'' . $this->themeWeb . '\';
+ $controller->theme = $this->theme = \'' . $this->theme . '\';
Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));';
if ($useCallbacks == true) {
View
6 cake/libs/view/theme.php
@@ -40,12 +40,6 @@ class ThemeView extends View {
function __construct(&$controller) {
parent::__construct($controller);
$this->theme =& $controller->theme;
-
- if (!empty($this->theme)) {
- if (is_dir(WWW_ROOT . 'themed' . DS . $this->theme)) {
- $this->themeWeb = 'themed/'. $this->theme .'/';
- }
- }
}
/**
View
9 cake/libs/view/view.php
@@ -161,13 +161,13 @@ class View extends Object {
* @var string
*/
var $subDir = null;
-
+
/**
* Theme name.
*
* @var string
*/
- var $themeWeb = null;
+ var $theme = null;
/**
* Used to define methods a controller that will be cached.
@@ -779,9 +779,7 @@ function &_loadHelpers(&$loaded, $helpers, $parent = null) {
}
}
$loaded[$helper] =& new $helperCn($options);
- $vars = array(
- 'base', 'webroot', 'here', 'params', 'action', 'data', 'themeWeb', 'plugin'
- );
+ $vars = array('base', 'webroot', 'here', 'params', 'action', 'data', 'theme', 'plugin');
$c = count($vars);
for ($j = 0; $j < $c; $j++) {
@@ -837,7 +835,6 @@ function _getViewFileName($name = null) {
$name = $this->viewPath . DS . $subDir . $name;
}
}
-
$paths = $this->_paths(Inflector::underscore($this->plugin));
$exts = array($this->ext);
View
37 cake/tests/cases/dispatcher.test.php
@@ -1784,23 +1784,24 @@ function testStaticAssets() {
));
$Dispatcher =& new TestDispatcher();
-
- Configure::write('debug', 0);
- ob_start();
- $Dispatcher->dispatch('img/test.jpg');
- $result = ob_get_clean();
- $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
- $this->assertEqual($file, $result);
-
-
- Configure::write('debug', 0);
- $Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
-
- ob_start();
- $Dispatcher->cached('css/test_asset.css');
- $result = ob_get_clean();
- $this->assertEqual('this is the test asset css file', $result);
-
+/**
+ * Removing assets in vendors so these 2 tests need to be removed
+ * Configure::write('debug', 0);
+ * ob_start();
+ * $Dispatcher->dispatch('img/test.jpg');
+ * $result = ob_get_clean();
+ * $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
+ * $this->assertEqual($file, $result);
+ *
+ *
+ * Configure::write('debug', 0);
+ * $Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
+ *
+ * ob_start();
+ * $Dispatcher->cached('css/test_asset.css');
+ * $result = ob_get_clean();
+ * $this->assertEqual('this is the test asset css file', $result);
+ */
ob_start();
$Dispatcher->cached('test_plugin/js/test_plugin/test.js');
@@ -1829,7 +1830,7 @@ function testStaticAssets() {
ob_start();
$Dispatcher->cached('test_plugin/img/cake.icon.gif');
$result = ob_get_clean();
- $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .DS . 'vendors' . DS . 'img' . DS . 'cake.icon.gif');
+ $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);
View
3 cake/tests/cases/libs/debugger.test.php
@@ -240,7 +240,7 @@ function testExportVar() {
View::$autoLayout = true
View::$ext = ".ctp"
View::$subDir = NULL
- View::$themeWeb = NULL
+ View::$theme = NULL
View::$cacheAction = false
View::$validationErrors = array
View::$hasRendered = false
@@ -256,7 +256,6 @@ function testExportVar() {
View::$__passedVars = array
View::$__scripts = array
View::$__paths = array
- View::$_log = NULL
View::$webroot = NULL';
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
View
16 cake/tests/cases/libs/view/helpers/html.test.php
@@ -333,27 +333,27 @@ function testImageTagWithTimestampping() {
* @link https://trac.cakephp.org/ticket/6490
*/
function testImageTagWithTheme() {
- $file = WWW_ROOT . 'themed' . DS . 'default' . DS . 'img' . DS . 'cake.power.gif';
- $message = "File '{$file}' not present. %s";
- $this->skipUnless(file_exists($file), $message);
-
+ App::build(array(
+ 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
+ ));
Configure::write('Asset.timestamp', true);
Configure::write('debug', 1);
- $this->Html->themeWeb = 'themed/default/';
-
+
+ $this->Html->theme = 'test_theme';
$result = $this->Html->image('cake.power.gif');
$this->assertTags($result, array(
'img' => array(
- 'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/',
+ 'src' => 'preg:/theme\/test_theme\/img\/cake\.power\.gif\?\d+/',
'alt' => ''
)));
$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/';
$result = $this->Html->image('cake.power.gif');
+
$this->assertTags($result, array(
'img' => array(
- 'src' => 'preg:/\/testing\/themed\/default\/img\/cake\.power\.gif\?\d+/',
+ 'src' => 'preg:/\/testing\/theme\/test_theme\/img\/cake\.power\.gif\?\d+/',
'alt' => ''
)));
$this->Html->webroot = $webroot;
View
2 cake/tests/cases/libs/view/theme.test.php
@@ -179,6 +179,8 @@ function startTest() {
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
+ $Configure = App::getInstance();
+ array_shift($Configure->views);
}
/**
View
0 ...plugins/plugin_js/vendors/js/plugin_js.js → ...plugins/plugin_js/webroot/js/plugin_js.js
File renamed without changes.
View
0 ..._plugin/vendors/css/test_plugin_asset.css → ..._plugin/webroot/css/test_plugin_asset.css
File renamed without changes.
View
0 ...ins/test_plugin/vendors/img/cake.icon.gif → ...ins/test_plugin/webroot/img/cake.icon.gif
File renamed without changes
View
0 ...est_plugin/vendors/js/test_plugin/test.js → ...est_plugin/webroot/js/test_plugin/test.js
File renamed without changes.
View
BIN cake/tests/test_app/views/themed/test_theme/webroot/img/cake.power.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2254bfe

Please sign in to comment.