Merging fixes and enhancements into trunk.

Revision: [2193]
Adding fix for Ticket #471

Revision: [2192]
Adding fix from Ticket #464.

Revision: [2191]
Adding fix for Ticket #461

Revision: [2190]
Adding fix for array_merge_recursive() error when unbindModelis used

Revision: [2189]
merging changes made in model_php5.php

Revision: [2188]
Fixing controller so $viewPath can be set as a var

Revision: [2186]
Adding Security component

Revision: [2185]
Adding additional RequestHandler detection, form security authentication, and automagic view variable $data

Revision: [2183]
Fixing Ticket #473

Revision: [2182]
Adding fix for Ticket #261

Revision: [2181]
Changing MySQL column defs from 12 hour times to 24 (#465)

Revision: [2180]
Fixing Tickets #463 and #462, and an error in Controller::setAction()

Revision: [2179]
Fixing a bug I found in AjaxHelper::link(), and changing the stopwatch time to 4 decimals

Revision: [2177]
Added patch from Ticket #459

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2195 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-03-08 03:13:32 +00:00
parent f6cf220c40
commit 03ba042f41
15 changed files with 163 additions and 39 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.8.2176
0.10.8.2195

View file

@ -110,6 +110,6 @@ else
if (DEBUG)
{
echo "<!-- ". round(getMicrotime() - $TIME_START, 2) ."s -->";
echo "<!-- ". round(getMicrotime() - $TIME_START, 4) ."s -->";
}
?>

View file

@ -135,6 +135,10 @@ class Dispatcher extends Object
{
$params['controller'] = Inflector::underscore($ctrlName);
$ctrlClass = $ctrlName.'Controller';
if (!is_null($params['action']))
{
array_unshift($params['pass'], $params['action']);
}
$params['action'] = $oldAction;
}
}

View file

@ -102,6 +102,36 @@ class RequestHandlerComponent extends Object
}
}
/**
* Returns true if the current call a POST request
*
* @return bool True if call is a POST
*/
function isPost()
{
return (low(env('REQUEST_METHOD')) == 'post');
}
/**
* Returns true if the current call a PUT request
*
* @return bool True if call is a PUT
*/
function isPut()
{
return (low(env('REQUEST_METHOD')) == 'put');
}
/**
* Returns true if the current call a GET request
*
* @return bool True if call is a GET
*/
function isGet()
{
return (low(env('REQUEST_METHOD')) == 'get');
}
/**
* Gets Prototype version if call is Ajax, otherwise empty string.

View file

@ -90,7 +90,7 @@ class Controller extends Object
*
* @var unknown_type
*/
var $viewPath;
var $viewPath = null;
/**
* Variables for the view
@ -208,7 +208,12 @@ class Controller extends Object
}
$this->name = $r[1];
}
$this->viewPath = Inflector::underscore($this->name);
if ($this->viewPath == null)
{
$this->viewPath = Inflector::underscore($this->name);
}
$this->modelClass = Inflector::singularize($this->name);
$this->modelKey = Inflector::underscore($this->modelClass);
@ -395,6 +400,8 @@ class Controller extends Object
$this->action = $action;
$args = func_get_args();
unset($args[0]);
call_user_func_array(array(&$this, $action), $args);
}
@ -461,6 +468,18 @@ class Controller extends Object
$this->beforeRender();
if (!isset($this->_viewVars['data']))
{
if (isset($this->params['data']))
{
$this->set('data', $this->params['data']);
}
else
{
$this->set('data', array());
}
}
$this->_viewClass =& new $viewClass($this);
if(!empty($this->modelNames))
{

View file

@ -445,12 +445,12 @@ class DataSource extends Object
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
foreach($keys as $key)
{
$val = null;
if (strpos($query, $key) !== false)
{
switch($key)
{
case '{$__cakeID__$}':
$val = null;
if (isset($data[$index][$model->name]))
{
if(isset($data[$index][$model->name][$model->primaryKey]))
@ -463,8 +463,9 @@ class DataSource extends Object
}
}
break;
case '{$__cake_foreignKey__$}':
case '{$__cakeForeignKey__$}':
$foreignKey = Inflector::underscore($linkModel->name).'_id';
$val = $data[$index][$model->name][$foreignKey];
break;
}
$query = r($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query);

View file

@ -383,6 +383,7 @@ class DboSource extends DataSource
$linkedModels = array();
$this->__bypass = false;
$this->__assocJoins = null;
if(!is_null($recursive))
{
$_recursive = $model->recursive;
@ -429,16 +430,15 @@ class DboSource extends DataSource
{
foreach($model->{$type} as $assoc => $assocData)
{
$linkModel =& $model->{$assocData['className']};
if (!in_array($type.'/'.$assoc, $linkedModels))
{
$linkModel =& $model->{$assocData['className']};
$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive);
} else {
// Fetch recursively on belongsTo and hasOne
if ($model->recursive > 1)
{
//$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1);
}
}
elseif($model->recursive > 1 && ($type == 'belongsTo' || $type == 'hasOne'))
{
// Do recursive joins on belongsTo and hasOne relationships
$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1);
}
}
}
@ -656,10 +656,11 @@ class DboSource extends DataSource
$assocData['fields'] = '';
}
$sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$alias;
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$alias.' ';
$conditions = $queryData['conditions'];
$condition = $model->escapeField($assocData['foreignKey']);
$condition .= '={$__cakeForeignKey__$}';
if (is_array($conditions))
{
$conditions[] = $condition;
@ -722,7 +723,7 @@ class DboSource extends DataSource
$conditions = $assocData['conditions'];
$condition = $linkModel->escapeField($linkModel->primaryKey);
$condition .= '={$__cakeID__$}';
$condition .= '={$__cakeForeignKey__$}';
if (is_array($conditions))
{
@ -1026,7 +1027,7 @@ class DboSource extends DataSource
{
if (!preg_match('/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i', $conditions, $match))
{
$clause = 'WHERE ';
$clause = ' WHERE ';
}
}
if (is_string($conditions))
@ -1066,7 +1067,7 @@ class DboSource extends DataSource
}
else
{
$clause = 'WHERE ';
$clause = ' WHERE ';
$out = $this->conditionKeysToString($conditions);
return $clause . ' ('.join(') AND (', $out).')';
}

View file

@ -88,9 +88,9 @@ class DboMysql extends DboSource
'text' => array('name' => 'text'),
'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
'float' => array('name' => 'float', 'formatter' => 'floatval'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
'time' => array('name' => 'time', 'format' => 'h:i:s', 'formatter' => 'date'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
'binary' => array('name' => 'blob'),
'boolean' => array('name' => 'tinyint', 'limit' => '1'));

View file

@ -389,6 +389,54 @@ class DboPostgres extends DboSource
return null;
}
/**
* Converts database-layer column types to basic types
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return string Abstract column type (i.e. "string")
*/
function column($real)
{
$col = r(')', '', $real);
$limit = null;
@list($col, $limit) = explode('(', $col);
if (in_array($col, array('date', 'time', 'timestamp')))
{
return $col;
}
if ($col == 'boolean')
{
return 'boolean';
}
if (strpos($col, 'integer') !== false)
{
return 'integer';
}
if (strpos($col, 'char') !== false)
{
return 'string';
}
if (strpos($col, 'text') !== false)
{
return 'text';
}
if (strpos($col, 'bytea') !== false)
{
return 'binary';
}
if (in_array($col, array('float', 'double', 'decimal')))
{
return 'float';
}
return 'text';
}
/**
* Enter description here...
*
* @param unknown_type $results
*/
function resultSet(&$results)
{
$this->results =& $results;

View file

@ -417,7 +417,7 @@ class Model extends Object
$this->__backAssociation[$assoc] = $this->{$assoc};
foreach($models as $model)
{
$this->__backAssociation = array_merge_recursive($this->__backAssociation, $this->{$assoc});
$this->__backAssociation = array_merge($this->__backAssociation, $this->{$assoc});
unset($this->{$assoc}[$model]);
}
}
@ -555,7 +555,7 @@ class Model extends Object
{
if($this->db->isInterfaceSupported('listSources'))
{
if (!in_array(strtolower($tableName), $this->db->listSources()))
if (!in_array(low($tableName), $this->db->listSources()) && !in_array($tableName, $this->db->listSources()))
{
return $this->cakeError('missingTable',array(array('className' => $this->name,
'table' => $tableName)));
@ -847,6 +847,7 @@ class Model extends Object
$weHaveMulti = false;
}
$newID = null;
foreach ($this->data as $n => $v)
{
if(isset($weHaveMulti) && $count > 0 && count($this->hasAndBelongsToMany) > 0)
@ -917,13 +918,16 @@ class Model extends Object
if($this->db->create($this, $fields, $values))
{
$this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
$this->id = $this->__insertID;
if(!$this->id > 0 && isset($newID))
if (!$this->__insertID && $newID != null)
{
$this->__insertID = $newID;
$this->id = $newID;
}
else
{
$this->id = $this->__insertID;
}
if(!empty($joined))
{
@ -1311,7 +1315,7 @@ class Model extends Object
$sizeOf = sizeof($data);
for ($ii=0; $ii < $sizeOf; $ii++)
{
if ($data[$ii][$this->name]['parent_id'] == $root)
if (($data[$ii][$this->name]['parent_id'] == $root) || (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0')))
{
$tmp = $data[$ii];
if (isset($data[$ii][$this->name][$this->primaryKey]))

View file

@ -413,7 +413,7 @@ class Model extends Object
$this->__backAssociation[$assoc] = $this->{$assoc};
foreach($models as $model)
{
$this->__backAssociation = array_merge_recursive($this->__backAssociation, $this->{$assoc});
$this->__backAssociation = array_merge($this->__backAssociation, $this->{$assoc});
unset($this->{$assoc}[$model]);
}
}
@ -551,7 +551,7 @@ class Model extends Object
{
if($this->db->isInterfaceSupported('listSources'))
{
if (!in_array(strtolower($tableName), $this->db->listSources()))
if (!in_array(low($tableName), $this->db->listSources()) && !in_array($tableName, $this->db->listSources()))
{
return $this->cakeError('missingTable',array(array('className' => $this->name,
'table' => $tableName)));
@ -843,6 +843,7 @@ class Model extends Object
$weHaveMulti = false;
}
$newID = null;
foreach ($this->data as $n => $v)
{
if(isset($weHaveMulti) && $count > 0 && count($this->hasAndBelongsToMany) > 0)
@ -913,13 +914,16 @@ class Model extends Object
if($this->db->create($this, $fields, $values))
{
$this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
$this->id = $this->__insertID;
if(!$this->id > 0 && isset($newID))
if (!$this->__insertID && $newID != null)
{
$this->__insertID = $newID;
$this->id = $newID;
}
else
{
$this->id = $this->__insertID;
}
if(!empty($joined))
{
@ -1307,7 +1311,7 @@ class Model extends Object
$sizeOf = sizeof($data);
for ($ii=0; $ii < $sizeOf; $ii++)
{
if ($data[$ii][$this->name]['parent_id'] == $root)
if (($data[$ii][$this->name]['parent_id'] == $root) || (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0')))
{
$tmp = $data[$ii];
if (isset($data[$ii][$this->name][$this->primaryKey]))

View file

@ -53,7 +53,7 @@ class Security extends Object
function inactiveMins()
{
$security =& Security::getInstance();
//$security =& Security::getInstance();
switch (CAKE_SECURITY)
{
case 'high':
@ -71,8 +71,7 @@ class Security extends Object
function generateAuthKey()
{
return $authKey;
return Security::hash(uniqid(rand(), true));
}
function validateAuthKey($authKey)

View file

@ -189,7 +189,7 @@ class AjaxHelper extends Helper
if (isset($options['id']))
{
$htmlOptions['onclick'] = ' return false;';
return $this->Html->link($title, $href, $htmlOptions) . $this->Javascript->event("$('{$options['id']}')", "click", $this->remoteFunction($options));
return $this->Html->link($title, $href, $htmlOptions, null, $escapeTitle) . $this->Javascript->event("$('{$options['id']}')", "click", $this->remoteFunction($options));
}
else
{
@ -648,11 +648,17 @@ class AjaxHelper extends Helper
{
foreach($this->ajaxOptions as $key)
{
unset($options[$key]);
if (isset($options[$key]))
{
unset($options[$key]);
}
}
foreach($extra as $key)
{
unset($options[$key]);
if (isset($extra[$key]))
{
unset($options[$key]);
}
}
return $options;
}

View file

@ -208,7 +208,7 @@ class HtmlHelper extends Helper
$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
}
if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0)))
if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0)))
{
$output = sprintf($this->tags['link'], $url,
$this->_parseAttributes($htmlAttributes), $title);
@ -1126,7 +1126,13 @@ class HtmlHelper extends Helper
$htmlAttributes['method'] = $type=='get'? 'get': 'post';
$type == 'file'? $htmlAttributes['enctype'] = 'multipart/form-data': null;
return sprintf($this->tags['form'], $this->parseHtmlOptions($htmlAttributes, null, ''));
$token = '';
if (isset($this->params['_Token']) && !empty($this->params['_Token']))
{
$token = $this->hidden('_Token/key', array('value' => $this->params['_Token']['key']), true);
}
return sprintf($this->tags['form'], $this->parseHtmlOptions($htmlAttributes, null, '')) . $token;
}
/**

View file

@ -41,6 +41,7 @@ define ('DS', DIRECTORY_SEPARATOR);
define ('ROOT', dirname(dirname(dirname(__FILE__))).DS);
define ('APP_DIR', 'app');
define('CAKE_CORE_INCLUDE_PATH', ROOT);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH);
define ('DEBUG', 1);
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS);
@ -53,6 +54,7 @@ uses ('neat_array');
uses ('object');
uses ('session');
uses ('security');
uses ('inflector');
uses ('model'.DS.'connection_manager');
uses ('model'.DS.'datasources'.DS.'dbo_source');
uses ('model'.DS.'model');