Skip to content

Commit

Permalink
Merge branch '1.3' into 1.3-misc
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 10, 2009
2 parents 26e19ca + adaa2b6 commit f5cfab7
Show file tree
Hide file tree
Showing 26 changed files with 436 additions and 96 deletions.
2 changes: 2 additions & 0 deletions cake/console/libs/bake.php
Expand Up @@ -230,6 +230,8 @@ function help() {
$this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info"); $this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info");
$this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info"); $this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info");
$this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info"); $this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info");
$this->out("\n\tbake fixture\n\t\tbakes fixtures. run 'bake fixture help' for more info.");
$this->out("\n\tbake test\n\t\tbakes unit tests. run 'bake test help' for more info.");
$this->out(); $this->out();


} }
Expand Down
1 change: 1 addition & 0 deletions cake/console/libs/tasks/db_config.php
Expand Up @@ -258,6 +258,7 @@ function bake($configs) {
$oldConfigs = array(); $oldConfigs = array();


if (file_exists($filename)) { if (file_exists($filename)) {
config('database');
$db = new $this->databaseClassName; $db = new $this->databaseClassName;
$temp = get_class_vars(get_class($db)); $temp = get_class_vars(get_class($db));


Expand Down
4 changes: 3 additions & 1 deletion cake/console/libs/tasks/fixture.php
Expand Up @@ -277,9 +277,11 @@ function _generateRecords($tableInfo, $recordCount = 1) {
} }
switch ($fieldInfo['type']) { switch ($fieldInfo['type']) {
case 'integer': case 'integer':
case 'float':
$insert = $i + 1; $insert = $i + 1;
break; break;
case 'string'; case 'string':
case 'binary':
$isPrimaryUuid = ( $isPrimaryUuid = (
isset($fieldInfo['key']) && strtolower($fieldInfo['key']) == 'primary' && isset($fieldInfo['key']) && strtolower($fieldInfo['key']) == 'primary' &&
isset($fieldInfo['length']) && $fieldInfo['length'] == 36 isset($fieldInfo['length']) && $fieldInfo['length'] == 36
Expand Down
5 changes: 3 additions & 2 deletions cake/console/libs/tasks/project.php
Expand Up @@ -224,7 +224,8 @@ function corePath($path) {
$File =& new File($path . 'webroot' . DS . 'index.php'); $File =& new File($path . 'webroot' . DS . 'index.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents); $root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'";
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', " . $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "');", $contents);
if (!$File->write($result)) { if (!$File->write($result)) {
return false; return false;
} }
Expand All @@ -235,7 +236,7 @@ function corePath($path) {
$File =& new File($path . 'webroot' . DS . 'test.php'); $File =& new File($path . 'webroot' . DS . 'test.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
$result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents); $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', ". (strpos(CAKE_CORE_INCLUDE_PATH, '/')===0? " DS . '":"'") . str_replace('/', '\' . DS . \'', trim(CAKE_CORE_INCLUDE_PATH, '/')) . "');", $contents);
if (!$File->write($result)) { if (!$File->write($result)) {
return false; return false;
} }
Expand Down
14 changes: 9 additions & 5 deletions cake/dispatcher.php
Expand Up @@ -614,15 +614,19 @@ function cached($url) {
$this->_stop(); $this->_stop();
} }
$isAsset = false; $isAsset = false;
$assets = array('js' => 'text/javascript', 'css' => 'text/css', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png'); $assets = array(
'js' => 'text/javascript', 'css' => 'text/css',
'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png'
);
$ext = array_pop(explode('.', $url)); $ext = array_pop(explode('.', $url));


foreach ($assets as $type => $contentType) { foreach ($assets as $type => $contentType) {
if ($type === $ext) { if ($type === $ext) {
if ($type === 'css' || $type === 'js') { $parts = explode('/', $url);
$pos = strpos($url, $type . '/'); if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') {
$pos = 0;
} else { } else {
$pos = strpos($url, 'img/'); $pos = strlen($parts[0]);
} }
$isAsset = true; $isAsset = true;
break; break;
Expand All @@ -640,7 +644,7 @@ function cached($url) {
$paths = array(); $paths = array();


if ($pos > 0) { if ($pos > 0) {
$plugin = substr($url, 0, $pos - 1); $plugin = substr($url, 0, $pos);
$url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url); $url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url);
$paths[] = App::pluginPath($plugin) . 'vendors' . DS; $paths[] = App::pluginPath($plugin) . 'vendors' . DS;
} }
Expand Down
9 changes: 5 additions & 4 deletions cake/libs/configure.php
Expand Up @@ -367,10 +367,6 @@ function __loadBootstrap($boot) {
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); 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);
} }


if (!include(CONFIGS . 'bootstrap.php')) {
trigger_error(sprintf(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
}

if (Configure::read('Cache.disable') !== true) { if (Configure::read('Cache.disable') !== true) {
$cache = Cache::config('default'); $cache = Cache::config('default');


Expand Down Expand Up @@ -407,6 +403,11 @@ function __loadBootstrap($boot) {
} }
Cache::config('default'); Cache::config('default');
} }

if (!include(CONFIGS . 'bootstrap.php')) {
trigger_error(sprintf(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
}

if (App::path('controllers') == array()) { if (App::path('controllers') == array()) {
App::build(array( App::build(array(
'models' => $modelPaths, 'views' => $viewPaths, 'controllers' => $controllerPaths, 'models' => $modelPaths, 'views' => $viewPaths, 'controllers' => $controllerPaths,
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/components/security.php
Expand Up @@ -576,7 +576,7 @@ function _validatePost(&$controller) {
} }
$data = $controller->data; $data = $controller->data;


if (!isset($data['_Token']) || !isset($data['_Token']['fields'])) { if (!isset($data['_Token']) || !isset($data['_Token']['fields']) || !isset($data['_Token']['key'])) {
return false; return false;
} }
$token = $data['_Token']['key']; $token = $data['_Token']['key'];
Expand Down
5 changes: 3 additions & 2 deletions cake/libs/controller/controller.php
Expand Up @@ -1112,8 +1112,9 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
$type = $defaults[0]; $type = $defaults[0];
unset($defaults[0]); unset($defaults[0]);
} }

$options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options);
extract($options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options)); $options['limit'] = (empty($options['limit']) || !is_numeric($options['limit'])) ? 1 : $options['limit'];
extract($options);


if (is_array($scope) && !empty($scope)) { if (is_array($scope) && !empty($scope)) {
$conditions = array_merge($conditions, $scope); $conditions = array_merge($conditions, $scope);
Expand Down
7 changes: 5 additions & 2 deletions cake/libs/error.php
Expand Up @@ -107,10 +107,13 @@ function __construct($method, $messages) {
if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) { if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
$method = 'error'; $method = 'error';
} }

if ($method !== 'error') { if ($method !== 'error') {
if (Configure::read('debug') == 0) { if (Configure::read('debug') == 0) {
$parentMethods = get_class_methods(get_parent_class($this)); $parentClass = get_parent_class($this);
if (strtolower($parentClass) != 'errorhandler') {
$method = 'error404';
}
$parentMethods = get_class_methods($parentClass);
if (in_array($method, $parentMethods)) { if (in_array($method, $parentMethods)) {
$method = 'error404'; $method = 'error404';
} }
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/behaviors/containable.php
Expand Up @@ -155,7 +155,7 @@ function beforeFind(&$Model, $query) {
if (!$reset && empty($instance->__backOriginalAssociation)) { if (!$reset && empty($instance->__backOriginalAssociation)) {
$instance->__backOriginalAssociation = $backupBindings; $instance->__backOriginalAssociation = $backupBindings;
} else if ($reset) { } else if ($reset) {
$instance->__backAssociation[$type] = $instance->{$type}; $instance->__backAssociation[$type] = $backupBindings[$type];
} }
$instance->{$type}[$assoc] = array_merge($instance->{$type}[$assoc], $model['keep'][$assoc]); $instance->{$type}[$assoc] = array_merge($instance->{$type}[$assoc], $model['keep'][$assoc]);
} }
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/model/model.php
Expand Up @@ -2453,7 +2453,7 @@ function invalidFields($options = array()) {
) || ) ||
$this->beforeValidate($options) === false $this->beforeValidate($options) === false
) { ) {
return $this->validationErrors; return false;
} }


if (!isset($this->validate) || empty($this->validate)) { if (!isset($this->validate) || empty($this->validate)) {
Expand Down Expand Up @@ -2925,7 +2925,7 @@ function afterDelete() {
} }


/** /**
* Called during save operations, before validation. Please note that custom * Called during validation operations, before validation. Please note that custom
* validation rules can be defined in $validate. * validation rules can be defined in $validate.
* *
* @return boolean True if validate operation should continue, false to abort * @return boolean True if validate operation should continue, false to abort
Expand Down
16 changes: 12 additions & 4 deletions cake/libs/view/helpers/cache.php
Expand Up @@ -68,24 +68,32 @@ function cache($file, $out, $cache = false) {
$useCallbacks = false; $useCallbacks = false;
if (is_array($this->cacheAction)) { if (is_array($this->cacheAction)) {
$controller = Inflector::underscore($this->controllerName); $controller = Inflector::underscore($this->controllerName);
$controllerAlternate = Inflector::variable($this->controllerName);

$check = str_replace('/', '_', $this->here); $check = str_replace('/', '_', $this->here);
$replace = str_replace('/', '_', $this->base); $basePath = str_replace('/', '_', $this->base);

$match = str_replace($this->base, '', $this->here); $match = str_replace($this->base, '', $this->here);
$match = str_replace('//', '/', $match); $match = str_replace('//', '/', $match);
$match = str_replace('/' . $controller . '/', '', $match); $match = str_replace('/' . $controller . '/', '', $match);
$match = str_replace('/' . $controllerAlternate . '/', '', $match);
$match = str_replace('/' . $this->controllerName . '/', '', $match); $match = str_replace('/' . $this->controllerName . '/', '', $match);
$check = str_replace($replace, '', $check);
$check = str_replace($basePath, '', $check);
$check = str_replace('_' . $controller . '_', '', $check); $check = str_replace('_' . $controller . '_', '', $check);
$check = str_replace('_' . $this->controllerName . '_', '', $check); $check = str_replace('_' . $this->controllerName . '_', '', $check);
$check = str_replace('_' . $controllerAlternate . '_', '', $match);

$check = Inflector::slug($check); $check = Inflector::slug($check);
$check = preg_replace('/^_+/', '', $check); $check = trim($check, '_');

$keys = str_replace('/', '_', array_keys($this->cacheAction)); $keys = str_replace('/', '_', array_keys($this->cacheAction));
$found = array_keys($this->cacheAction); $found = array_keys($this->cacheAction);
$index = null; $index = null;
$count = 0; $count = 0;


foreach ($keys as $key => $value) { foreach ($keys as $key => $value) {
if (strpos($check, $value) === 0) { if (strpos($check, rtrim($value, '_')) === 0) {
$index = $found[$count]; $index = $found[$count];
break; break;
} }
Expand Down
24 changes: 10 additions & 14 deletions cake/libs/view/helpers/html.php
Expand Up @@ -355,7 +355,7 @@ function link($title, $url = null, $options = array(), $confirmMessage = false)
* *
* #### Options * #### Options
* *
* - `inline` If set to false, the generated tag appears in the head tag of the layout. * - `inline` If set to false, the generated tag appears in the head tag of the layout. Defaults to true
* *
* @param mixed $path The name of a CSS style sheet or an array containing names of * @param mixed $path The name of a CSS style sheet or an array containing names of
* CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot * CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
Expand All @@ -366,13 +366,13 @@ function link($title, $url = null, $options = array(), $confirmMessage = false)
* @access public * @access public
*/ */
function css($path, $rel = null, $options = array()) { function css($path, $rel = null, $options = array()) {
$inline = isset($options['inline']) ? $options['inline'] : true; $options += array('inline' => true);
if (is_array($path)) { if (is_array($path)) {
$out = ''; $out = '';
foreach ($path as $i) { foreach ($path as $i) {
$out .= "\n\t" . $this->css($i, $rel, $options, $inline); $out .= "\n\t" . $this->css($i, $rel, $options);
} }
if ($inline) { if ($options['inline']) {
return $out . "\n"; return $out . "\n";
} }
return; return;
Expand Down Expand Up @@ -401,7 +401,7 @@ function css($path, $rel = null, $options = array()) {
} }


if ($rel == 'import') { if ($rel == 'import') {
$out = sprintf($this->tags['style'], $this->_parseAttributes($options, null, '', ' '), '@import url(' . $url . ');'); $out = sprintf($this->tags['style'], $this->_parseAttributes($options, array('inline'), '', ' '), '@import url(' . $url . ');');
} else { } else {
if ($rel == null) { if ($rel == null) {
$rel = 'stylesheet'; $rel = 'stylesheet';
Expand All @@ -410,7 +410,7 @@ function css($path, $rel = null, $options = array()) {
} }
$out = $this->output($out); $out = $this->output($out);


if ($inline) { if ($options['inline']) {
return $out; return $out;
} else { } else {
$view =& ClassRegistry::getObject('view'); $view =& ClassRegistry::getObject('view');
Expand Down Expand Up @@ -471,12 +471,10 @@ function script($url, $options = array()) {
$url = str_replace(JS_URL, 'cjs/', $url); $url = str_replace(JS_URL, 'cjs/', $url);
} }
} }
$inline = $options['inline']; $attributes = $this->_parseAttributes($options, array('inline', 'once'), ' ');
unset($options['inline'], $options['once']);
$attributes = $this->_parseAttributes($options, ' ', ' ');
$out = $this->output(sprintf($this->tags['javascriptlink'], $url, $attributes)); $out = $this->output(sprintf($this->tags['javascriptlink'], $url, $attributes));


if ($inline) { if ($options['inline']) {
return $out; return $out;
} else { } else {
$view =& ClassRegistry::getObject('view'); $view =& ClassRegistry::getObject('view');
Expand All @@ -496,8 +494,7 @@ function script($url, $options = array()) {
* @return mixed string or null depending on the value of `$options['inline']` * @return mixed string or null depending on the value of `$options['inline']`
**/ **/
function scriptBlock($script, $options = array()) { function scriptBlock($script, $options = array()) {
$defaultOptions = array('safe' => true, 'inline' => true); $options += array('safe' => true, 'inline' => true);
$options = array_merge($defaultOptions, $options);
if ($options['safe']) { if ($options['safe']) {
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n"; $script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
} }
Expand Down Expand Up @@ -526,8 +523,7 @@ function scriptBlock($script, $options = array()) {
* @return void * @return void
**/ **/
function scriptStart($options = array()) { function scriptStart($options = array()) {
$defaultOptions = array('safe' => true, 'inline' => true); $options += array('safe' => true, 'inline' => true);
$options = array_merge($defaultOptions, $options);
$this->_scriptBlockOptions = $options; $this->_scriptBlockOptions = $options;
ob_start(); ob_start();
return null; return null;
Expand Down

0 comments on commit f5cfab7

Please sign in to comment.