Permalink
Browse files

Merge branch '1.2' into 1.3

  • Loading branch information...
2 parents 8f801a9 + 68c4bfd commit bc359259a2eaaf7a5a7b9f14ef3277f9e5a3661c gwoo committed Jul 2, 2009
View
@@ -830,7 +830,7 @@ function array_diff_key() {
function array_intersect_key($arr1, $arr2) {
$res = array();
foreach ($arr1 as $key => $value) {
- if (isset($arr2[$key])) {
+ if (array_key_exists($key, $arr2)) {
$res[$key] = $arr1[$key];
}
}
View
@@ -151,17 +151,17 @@ function help() {
$commands = array(
'path' => "\t<type>\n" .
- "\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
- "\t\tAvailable values:\n\n".
- "\t\tbehavior\tLook for class in CakePHP behavior path\n".
- "\t\tcache\tLook for class in CakePHP cache path\n".
- "\t\tcontroller\tLook for class in CakePHP controller path\n".
- "\t\tcomponent\tLook for class in CakePHP component path\n".
- "\t\thelper\tLook for class in CakePHP helper path\n".
- "\t\tmodel\tLook for class in CakePHP model path\n".
- "\t\tview\tLook for class in CakePHP view path\n",
+ "\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
+ "\t\tAvailable values:\n\n".
+ "\t\tbehavior\tLook for class in CakePHP behavior path\n".
+ "\t\tcache\tLook for class in CakePHP cache path\n".
+ "\t\tcontroller\tLook for class in CakePHP controller path\n".
+ "\t\tcomponent\tLook for class in CakePHP component path\n".
+ "\t\thelper\tLook for class in CakePHP helper path\n".
+ "\t\tmodel\tLook for class in CakePHP model path\n".
+ "\t\tview\tLook for class in CakePHP view path\n",
'className' => "\t<className>\n" .
- "\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
+ "\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
);
$this->out($head);
@@ -196,16 +196,16 @@ function __parseClass($path) {
$contents = $File->read();
- if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.+\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
+ if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
foreach ($result[2] as $key => $method) {
$method = str_replace('function ', '', trim($method));
if (strpos($method, '__') === false && $method[0] != '_') {
$parsed[$method] = array(
- 'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
- 'method' => $method,
- 'parameters' => trim($result[3][$key]),
- );
+ 'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
+ 'method' => $method,
+ 'parameters' => trim($result[3][$key])
+ );
}
}
}
@@ -243,8 +243,11 @@ function __interactive($controllerName = false) {
* @access private
*/
function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
- $currentModelName = $this->_modelName($controllerName);
- if (!App::import('Model', $currentModelName)) {
+ $currentModelName = $modelImport = $this->_modelName($controllerName);
+ if ($this->plugin) {
+ $modelImport = $this->plugin . '.' . $modelImport;
+ }
+ if (!App::import('Model', $modelImport)) {
$this->err(__('You must have a model for this class to build scaffold methods. Please try again.', true));
exit;
}
View
@@ -168,7 +168,6 @@ function read($key) {
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
$this->__File->close();
- $this->__File->delete();
return false;
}
$data = $this->__File->read(true);
@@ -263,6 +263,9 @@ function initialize(&$controller) {
*/
function startup(&$controller) {
$methods = array_flip($controller->methods);
+ $controllerAction = strtolower($controller->params['action']);
+ $lowerAllowedActions = array_map('strtolower', $this->allowedActions);
+
$isErrorOrTests = (
strtolower($controller->name) == 'cakeerror' ||
(strtolower($controller->name) == 'tests' && Configure::read() > 0)
@@ -273,7 +276,7 @@ function startup(&$controller) {
$isMissingAction = (
$controller->scaffold === false &&
- !isset($methods[strtolower($controller->params['action'])])
+ !isset($methods[$controllerAction])
);
if ($isMissingAction) {
@@ -295,7 +298,7 @@ function startup(&$controller) {
$isAllowed = (
$this->allowedActions == array('*') ||
- in_array($controller->params['action'], $this->allowedActions)
+ in_array($controllerAction, $lowerAllowedActions)
);
if ($loginAction != $url && $isAllowed) {
@@ -674,8 +674,8 @@ function __smtp() {
return false;
}
- if (isset($this->smtpOptions['host'])) {
- $host = $this->smtpOptions['host'];
+ if (isset($this->smtpOptions['client'])) {
+ $host = $this->smtpOptions['client'];
} else {
$host = env('HTTP_HOST');
}
@@ -389,7 +389,9 @@ function __mergeVars() {
if ($var === 'components') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
- $this->{$var} = Set::merge($app, $normal);
+ if ($app !== $normal) {
+ $this->{$var} = Set::merge($app, $normal);
+ }
} else {
$this->{$var} = Set::merge(
$this->{$var}, array_diff($appVars[$var], $this->{$var})
@@ -413,7 +415,9 @@ function __mergeVars() {
if ($var === 'components') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
- $this->{$var} = Set::merge($normal, array_diff_assoc($app, $normal));
+ if ($app !== $normal) {
+ $this->{$var} = Set::merge($app, $normal);
+ }
} else {
$this->{$var} = Set::merge(
$this->{$var}, array_diff($appVars[$var], $this->{$var})
View
@@ -366,12 +366,13 @@ function safe($name = null, $ext = null) {
function md5($maxsize = 5) {
if ($maxsize === true) {
return md5_file($this->path);
- } else {
- $size = $this->size();
- if ($size && $size < ($maxsize * 1024) * 1024) {
- return md5_file($this->path);
- }
}
+
+ $size = $this->size();
+ if ($size && $size < ($maxsize * 1024) * 1024) {
+ return md5_file($this->path);
+ }
+
return false;
}
/**
@@ -232,20 +232,6 @@ function value($data, $column = null, $safe = false) {
return $data;
}
-/**
- * Begin a transaction
- *
- * @param unknown_type $model
- * @return boolean True on success, false on fail
- * (i.e. if the database/model does not support transactions).
- */
- function begin(&$model) {
- if (parent::begin($model) && $this->execute('START TRANSACTION')) {
- $this->_transactionStarted = true;
- return true;
- }
- return false;
- }
/**
* Returns a formatted error message from previous database operation.
*
@@ -275,6 +275,9 @@ function value($data, $column = null, $read = true) {
case 'inet':
case 'float':
case 'integer':
+ case 'date':
+ case 'datetime':
+ case 'timestamp':
if ($data === '') {
return $read ? 'NULL' : 'DEFAULT';
}
View
@@ -369,6 +369,10 @@ function __construct($id = false, $table = null, $ds = null) {
} elseif ($table) {
$this->useTable = $table;
}
+
+ if ($ds !== null) {
+ $this->useDbConfig = $ds;
+ }
if (is_subclass_of($this, 'AppModel')) {
$appVars = get_class_vars('AppModel');
@@ -1468,7 +1472,7 @@ function saveAll($data = null, $options = array()) {
if (Set::numeric(array_keys($data))) {
while ($validates) {
foreach ($data as $key => $record) {
- if (!$currentValidates = $this->__save($this, $record, $options)) {
+ if (!$currentValidates = $this->__save($record, $options)) {
$validationErrors[$key] = $this->validationErrors;
}
@@ -1521,7 +1525,7 @@ function saveAll($data = null, $options = array()) {
if (isset($associations[$association])) {
switch ($associations[$association]) {
case 'belongsTo':
- if ($this->__save($this->{$association}, $values, $options)) {
+ if ($this->{$association}->__save($values, $options)) {
$data[$this->alias][$this->belongsTo[$association]['foreignKey']] = $this->{$association}->id;
} else {
$validationErrors[$association] = $this->{$association}->validationErrors;
@@ -1534,7 +1538,7 @@ function saveAll($data = null, $options = array()) {
}
}
}
- if (!$this->__save($this, $data, $options)) {
+ if (!$this->__save($data, $options)) {
$validationErrors[$this->alias] = $this->validationErrors;
$validates = false;
}
@@ -1552,7 +1556,7 @@ function saveAll($data = null, $options = array()) {
switch ($type) {
case 'hasOne':
$values[$this->{$type}[$association]['foreignKey']] = $this->id;
- if (!$this->__save($this->{$association}, $values, $options)) {
+ if (!$this->{$association}->__save($values, $options)) {
$validationErrors[$association] = $this->{$association}->validationErrors;
$validates = false;
}
@@ -1625,12 +1629,12 @@ function saveAll($data = null, $options = array()) {
* @access private
* @see Model::saveAll()
*/
- function __save(&$model, $data, $options) {
+ function __save($data, $options) {
if ($options['validate'] === 'first' || $options['validate'] === 'only') {
- if (!($model->create($data) && $model->validates($options))) {
+ if (!($this->create($data) && $this->validates($options))) {
return false;
}
- } elseif (!($model->create(null) !== null && $model->save($data, $options))) {
+ } elseif (!($this->create(null) !== null && $this->save($data, $options))) {
return false;
}
return true;
View
@@ -918,7 +918,7 @@ function normalize($list, $assoc = true, $sep = ',', $trim = true) {
* to null (useful for Set::merge). You can optionally group the values by what is obtained when
* following the path specified in $groupPath.
*
- * @param array $data Array from where to extract keys and values
+ * @param mixed $data Array or object from where to extract keys and values
* @param mixed $path1 As an array, or as a dot-separated string.
* @param mixed $path2 As an array, or as a dot-separated string.
* @param string $groupPath As an array, or as a dot-separated string.
@@ -264,7 +264,8 @@ 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->themeWeb = $this->themeWeb = \'' . $this->themeWeb . '\';
+ Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));';
if ($useCallbacks == true) {
$file .= '
@@ -275,7 +276,6 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
}
$file .= '
- Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach (array_keys($loadedHelpers) as $helper) {
@@ -319,8 +319,104 @@ function escapeScript($script) {
* @return string Escaped string.
*/
function escapeString($string) {
- $escape = array('\n' => '\\\n', "\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
- return str_replace(array_keys($escape), array_values($escape), $string);
+ App::import('Core', 'Multibyte');
+ $escape = array("\r\n" => "\n", "\r" => "\n");
+ $string = str_replace(array_keys($escape), array_values($escape), $string);
+ return $this->_utf8ToHex($string);
+ }
+/**
+ * Encode a string into JSON. Converts and escapes necessary characters.
+ *
+ * @return void
+ **/
+ function _utf8ToHex($string) {
+ $length = strlen($string);
+ $return = '';
+ for ($i = 0; $i < $length; ++$i) {
+ $ord = ord($string{$i});
+ switch (true) {
+ case $ord == 0x08:
+ $return .= '\b';
+ break;
+ case $ord == 0x09:
+ $return .= '\t';
+ break;
+ case $ord == 0x0A:
+ $return .= '\n';
+ break;
+ case $ord == 0x0C:
+ $return .= '\f';
+ break;
+ case $ord == 0x0D:
+ $return .= '\r';
+ break;
+ case $ord == 0x22:
+ case $ord == 0x2F:
+ case $ord == 0x5C:
+ case $ord == 0x27:
+ $return .= '\\' . $string{$i};
+ break;
+ case (($ord >= 0x20) && ($ord <= 0x7F)):
+ $return .= $string{$i};
+ break;
+ case (($ord & 0xE0) == 0xC0):
+ if ($i + 1 >= $length) {
+ $i += 1;
+ $return .= '?';
+ break;
+ }
+ $charbits = $string{$i} . $string{$i + 1};
+ $char = Multibyte::utf8($charbits);
+ $return .= sprintf('\u%04s', dechex($char[0]));
+ $i += 1;
+ break;
+ case (($ord & 0xF0) == 0xE0):
+ if ($i + 2 >= $length) {
+ $i += 2;
+ $return .= '?';
+ break;
+ }
+ $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2};
+ $char = Multibyte::utf8($charbits);
+ $return .= sprintf('\u%04s', dechex($char[0]));
+ $i += 2;
+ break;
+ case (($ord & 0xF8) == 0xF0):
+ if ($i + 3 >= $length) {
+ $i += 3;
+ $return .= '?';
+ break;
+ }
+ $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3};
+ $char = Multibyte::utf8($charbits);
+ $return .= sprintf('\u%04s', dechex($char[0]));
+ $i += 3;
+ break;
+ case (($ord & 0xFC) == 0xF8):
+ if ($i + 4 >= $length) {
+ $i += 4;
+ $return .= '?';
+ break;
+ }
+ $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4};
+ $char = Multibyte::utf8($charbits);
+ $return .= sprintf('\u%04s', dechex($char[0]));
+ $i += 4;
+ break;
+ case (($ord & 0xFE) == 0xFC):
+ if ($i + 5 >= $length) {
+ $i += 5;
+ $return .= '?';
+ break;
+ }
+ $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4} . $string{$i + 5};
+ $char = Multibyte::utf8($charbits);
+ $return .= sprintf('\u%04s', dechex($char[0]));
+ $i += 5;
+ break;
+ }
+ }
+ return $return;
}
/**
* Attach an event to an element. Used with the Prototype library.
Oops, something went wrong.

0 comments on commit bc35925

Please sign in to comment.