mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging fixes and enhancements into trunk.
Changing version number to 1.x.x.x, 0.10.x.x code base had been changed to the version number 1.x.x.x, and what was planned for 1.x.x.x code has now been moved to 2.x.x.x, and 2.x.x.x moved to 3.x.x.x. This will give us easier to track version numbers from now on. Revision: [2248] Merging changes from model_php5.php Revision: [2247] "Removing test code from view class" Revision: [2246] Removed cache time define from core.php. Modified the __() function in basics.php to echo string like it will in later versions of cake with translations. Refactored the cache checking in bootstrap.php to read the files embedded time stamp and delete or output the cached version. Added View::cacheView() for caching pages. Revision: [2245] Moving column formatting from DBO to Sanitize Revision: [2244] Adding beforeValidate() Model callback, and allowing query data to be modified in beforeFind() Revision: [2243] "Adding caching changes to Controller class " Revision: [2242] "Added check to delete cached version if it has expired" Revision: [2241] Adding app/cache/views directory Revision: [2240] "Fixed missing variable" Revision: [2239] "Adding full page caching to view class." Revision: [2238] "Adding defines for caching" Revision: [2237] "Adding caching check too bootstrap.php" Revision: [2236] Adding ClassRegistry::removeObject from Ticket #477 Revision: [2235] "Correcting setting in DATABASE_CONFIG class" Revision: [2231] Adding convenience function am(), which allows merging an infinite number of arrays merged into one Revision: [2207] Change Model::save() to call beforeSave() before validations Revision: [2199] Removing conditions method call in Model::field() Revision: [2196] Setting proper mime type again git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2250 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0f8f8243d5
commit
89fbf1c8bf
15 changed files with 287 additions and 119 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
0.10.8.2195
|
||||
1.0.0.2250
|
|
@ -53,6 +53,13 @@
|
|||
*
|
||||
*/
|
||||
define('DEBUG', 1);
|
||||
/**
|
||||
* Turn of caching checking wide.
|
||||
* You must still use the controller var cacheAction inside you controller class.
|
||||
* You can either set it controller wide, or in each controller method.
|
||||
* use var $cacheAction = true; or in the controller method $this->cacheAction = true;
|
||||
*/
|
||||
define ('CACHE_CHECK', true);
|
||||
/**
|
||||
* Error constant. Used for differentiating error logging and debugging.
|
||||
* Currently PHP supports LOG_DEBUG
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
class DATABASE_CONFIG
|
||||
{
|
||||
var $default = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_pconnect',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
|
@ -68,7 +68,7 @@ class DATABASE_CONFIG
|
|||
'prefix' => '');
|
||||
|
||||
var $test = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_pconnect',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
|
|
|
@ -691,7 +691,30 @@ function params($p)
|
|||
return $p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merge a group of arrays
|
||||
*
|
||||
* @param array First array
|
||||
* @param array Second array
|
||||
* @param array Third array
|
||||
* @param array Etc...
|
||||
* @return array All array parameters merged into one
|
||||
*/
|
||||
function am ()
|
||||
{
|
||||
$r = array();
|
||||
foreach (func_get_args() as $a)
|
||||
{
|
||||
if (!is_array($a))
|
||||
{
|
||||
$a = array($a);
|
||||
}
|
||||
$r = array_merge($r, $a);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -832,7 +855,7 @@ if (!function_exists('file_put_contents'))
|
|||
*/
|
||||
function cache($path, $data = null, $expires = '+1 day', $target = 'cache')
|
||||
{
|
||||
if (is_string($expires))
|
||||
if (!is_numeric($expires))
|
||||
{
|
||||
$expires = strtotime($expires);
|
||||
}
|
||||
|
@ -890,11 +913,17 @@ function stripslashes_deep($value)
|
|||
* @return unknown
|
||||
* @todo Not implemented in 0.10.x.x
|
||||
*/
|
||||
function __($msg, $return = null)
|
||||
{
|
||||
return $msg;
|
||||
}
|
||||
|
||||
function __($msg, $return = null)
|
||||
{
|
||||
if(is_null($return))
|
||||
{
|
||||
echo ($msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the dimensions of an array
|
||||
|
|
|
@ -107,6 +107,38 @@ else
|
|||
}
|
||||
|
||||
$TIME_START = getMicrotime();
|
||||
if(defined('CACHE_CHECK'))
|
||||
{
|
||||
if (empty($uri))
|
||||
{
|
||||
$uri = setUri();
|
||||
}
|
||||
|
||||
$filename = CACHE.'views'.DS.str_replace('/', '_', $uri.'.php');
|
||||
|
||||
if (file_exists($filename))
|
||||
{
|
||||
ob_start();
|
||||
include($filename);
|
||||
if (DEBUG)
|
||||
{
|
||||
echo "<!-- Cached Render Time: ". round(getMicrotime() - $TIME_START, 4) ."s -->";
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match))
|
||||
{
|
||||
if(time() >= $match['1'])
|
||||
{
|
||||
@unlink($filename);
|
||||
unset($out);
|
||||
}
|
||||
else
|
||||
{
|
||||
die(e($out));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require CAKE.'dispatcher.php';
|
||||
require LIBS.'model'.DS.'connection_manager.php';
|
||||
|
|
|
@ -74,7 +74,7 @@ class ClassRegistry
|
|||
function addObject($key, &$object)
|
||||
{
|
||||
$_this =& ClassRegistry::getInstance();
|
||||
$key = strtolower($key);
|
||||
$key = low($key);
|
||||
|
||||
if (array_key_exists($key, $_this->_objects) === false)
|
||||
{
|
||||
|
@ -82,6 +82,23 @@ class ClassRegistry
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove object which corresponds to given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
function removeObject($key)
|
||||
{
|
||||
$_this =& ClassRegistry::getInstance();
|
||||
$key = low($key);
|
||||
|
||||
if (array_key_exists($key, $_this->_objects) === true)
|
||||
{
|
||||
unset($_this->_objects[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given key is present in the ClassRegistry.
|
||||
*
|
||||
|
|
|
@ -209,7 +209,7 @@ class RequestHandlerComponent extends Object
|
|||
*/
|
||||
function isMobile()
|
||||
{
|
||||
return (preg_match(REQUEST_MOBILE_UA, $_SERVER['HTTP_USER_AGENT']) > 0);
|
||||
return (preg_match('/'.REQUEST_MOBILE_UA.'/i', $_SERVER['HTTP_USER_AGENT']) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -193,6 +193,13 @@ class Controller extends Object
|
|||
*/
|
||||
var $plugin = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $cacheAction = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
|
@ -248,7 +248,7 @@ class DataSource extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
$expires = "+1 day";
|
||||
$expires = "+999 days";
|
||||
}
|
||||
|
||||
if ($data !== null)
|
||||
|
@ -398,36 +398,6 @@ class DataSource extends Object
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats column data from definition in DBO's $columns array
|
||||
*
|
||||
* @param string $data The data to be formatted
|
||||
* @param array $specs The column definition array
|
||||
* @return mixed Data formatted to column specifications
|
||||
* @access protected
|
||||
*/
|
||||
function __formatColumnData($data, $specs = array())
|
||||
{
|
||||
if (isset($specs['formatter']))
|
||||
{
|
||||
switch($specs['formatter'])
|
||||
{
|
||||
case 'date':
|
||||
return date($specs['format'], strtotime($data));
|
||||
case 'sprintf':
|
||||
return sprintf($specs['format'], $data);
|
||||
case 'intval':
|
||||
return intval($data);
|
||||
case 'floatval':
|
||||
return floatval($data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
|
|
|
@ -368,7 +368,7 @@ class DboSource extends DataSource
|
|||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* The "R" in CRUD
|
||||
*
|
||||
* @param Model $model
|
||||
* @param array $queryData
|
||||
|
|
|
@ -278,11 +278,11 @@ class DboMysql extends DboSource
|
|||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @param string $column The column into which this data will be inserted
|
||||
* @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
|
||||
* @return string Quoted and escaped data, formatted for column type
|
||||
* @return string Quoted and escaped data
|
||||
*/
|
||||
function value ($data, $column = null, $safe = false)
|
||||
{
|
||||
$parent = parent::value($data, $column);
|
||||
$parent = parent::value($data, $column, $safe);
|
||||
|
||||
if ($parent != null)
|
||||
{
|
||||
|
@ -304,53 +304,7 @@ class DboMysql extends DboSource
|
|||
$data = stripslashes($data);
|
||||
}
|
||||
|
||||
$data = mysql_real_escape_string($data, $this->connection);
|
||||
|
||||
if ($column == null)
|
||||
{
|
||||
if(!is_numeric($data) || $safe == true)
|
||||
{
|
||||
$return = "'" . $data . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = $data;
|
||||
}
|
||||
return $return;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$colData = $this->columns[$column];
|
||||
if (isset($colData['limit']) && strlen(strval($data)) > $colData['limit'])
|
||||
{
|
||||
$data = substr(strval($data), 0, $colData['limit']);
|
||||
}
|
||||
|
||||
if (isset($colData['format']) || isset($colData['fomatter']))
|
||||
{
|
||||
$data = $this->__formatColumnData($data, $colData);
|
||||
}
|
||||
|
||||
switch($column)
|
||||
{
|
||||
case 'integer':
|
||||
case 'int':
|
||||
return $data;
|
||||
break;
|
||||
case 'string':
|
||||
case 'text':
|
||||
case 'binary':
|
||||
case 'date':
|
||||
case 'time':
|
||||
case 'datetime':
|
||||
case 'timestamp':
|
||||
case 'date':
|
||||
return "'" . $data . "'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
return "'" . mysql_real_escape_string($data, $this->connection) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -764,11 +764,6 @@ class Model extends Object
|
|||
return $this->data[$this->name][$name];
|
||||
}
|
||||
|
||||
if ($conditions)
|
||||
{
|
||||
$conditions = $this->db->conditions($conditions);
|
||||
}
|
||||
|
||||
if ($data = $this->find($conditions, $name, $order, 0))
|
||||
{
|
||||
if (isset($data[$this->name][$name]))
|
||||
|
@ -824,6 +819,11 @@ class Model extends Object
|
|||
|
||||
$whitelist = !(empty($fieldList) || count($fieldList) == 0);
|
||||
|
||||
if(!$this->beforeValidate())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($validate && !$this->validates())
|
||||
{
|
||||
return false;
|
||||
|
@ -1186,11 +1186,6 @@ class Model extends Object
|
|||
*/
|
||||
function findAll ($conditions = null, $fields = null, $order = null, $limit = 50, $page = 1, $recursive = null)
|
||||
{
|
||||
if (!$this->beforeFind($conditions))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->id = $this->getID();
|
||||
$offset = 0;
|
||||
if ($page > 1)
|
||||
|
@ -1210,6 +1205,12 @@ class Model extends Object
|
|||
'limit' => $limit_str,
|
||||
'order' => $order
|
||||
);
|
||||
|
||||
if (!$this->beforeFind($queryData))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$return = $this->afterFind($this->db->read($this, $queryData, $recursive));
|
||||
|
||||
if(isset($this->__backAssociation))
|
||||
|
@ -1606,10 +1607,10 @@ class Model extends Object
|
|||
/**
|
||||
* Before find callback
|
||||
*
|
||||
* @param unknown_type $conditions
|
||||
* @param array $queryData Data used to execute this query, i.e. conditions, order, etc.
|
||||
* @return boolean True if the operation should continue, false if it should abort
|
||||
*/
|
||||
function beforeFind($conditions)
|
||||
function beforeFind(&$queryData)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1656,7 +1657,7 @@ class Model extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* After save callback
|
||||
* After delete callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -1664,6 +1665,16 @@ class Model extends Object
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before validate callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function beforeValidate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// --- PHP4 Only
|
||||
|
|
|
@ -760,11 +760,6 @@ class Model extends Object
|
|||
return $this->data[$this->name][$name];
|
||||
}
|
||||
|
||||
if ($conditions)
|
||||
{
|
||||
$conditions = $this->db->conditions($conditions);
|
||||
}
|
||||
|
||||
if ($data = $this->find($conditions, $name, $order, 0))
|
||||
{
|
||||
if (isset($data[$this->name][$name]))
|
||||
|
@ -820,6 +815,11 @@ class Model extends Object
|
|||
|
||||
$whitelist = !(empty($fieldList) || count($fieldList) == 0);
|
||||
|
||||
if(!$this->beforeValidate())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($validate && !$this->validates())
|
||||
{
|
||||
return false;
|
||||
|
@ -1182,11 +1182,6 @@ class Model extends Object
|
|||
*/
|
||||
function findAll ($conditions = null, $fields = null, $order = null, $limit = 50, $page = 1, $recursive = null)
|
||||
{
|
||||
if (!$this->beforeFind($conditions))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->id = $this->getID();
|
||||
$offset = 0;
|
||||
if ($page > 1)
|
||||
|
@ -1206,6 +1201,12 @@ class Model extends Object
|
|||
'limit' => $limit_str,
|
||||
'order' => $order
|
||||
);
|
||||
|
||||
if (!$this->beforeFind($queryData))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$return = $this->afterFind($this->db->read($this, $queryData, $recursive));
|
||||
|
||||
if(isset($this->__backAssociation))
|
||||
|
@ -1602,10 +1603,10 @@ class Model extends Object
|
|||
/**
|
||||
* Before find callback
|
||||
*
|
||||
* @param unknown_type $conditions
|
||||
* @param array $queryData Data used to execute this query, i.e. conditions, order, etc.
|
||||
* @return boolean True if the operation should continue, false if it should abort
|
||||
*/
|
||||
function beforeFind($conditions)
|
||||
function beforeFind(&$queryData)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1652,7 +1653,7 @@ class Model extends Object
|
|||
}
|
||||
|
||||
/**
|
||||
* After save callback
|
||||
* After delete callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -1660,6 +1661,16 @@ class Model extends Object
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before validate callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function beforeValidate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -214,5 +214,87 @@ class Sanitize
|
|||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats column data from definition in DBO's $columns array
|
||||
*
|
||||
* @param Model $model The model containing the data to be formatted
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function formatColumns(&$model)
|
||||
{
|
||||
foreach ($model->data as $name => $values)
|
||||
{
|
||||
if ($name == $model->name)
|
||||
{
|
||||
$curModel =& $model;
|
||||
}
|
||||
else if (isset($model->{$name}) && is_object($model->{$name}) && is_subclass_of($model->{$name}, 'Model'))
|
||||
{
|
||||
$curModel =& $model->{$name};
|
||||
}
|
||||
else
|
||||
{
|
||||
$curModel = null;
|
||||
}
|
||||
|
||||
if ($curModel != null)
|
||||
{
|
||||
foreach($values as $column => $data)
|
||||
{
|
||||
$colType = $curModel->getColumnType($column);
|
||||
|
||||
if ($colType != null)
|
||||
{
|
||||
$colData = $curModel->db->columns[$colType];
|
||||
if (isset($colData['limit']) && strlen(strval($data)) > $colData['limit'])
|
||||
{
|
||||
$data = substr(strval($data), 0, $colData['limit']);
|
||||
}
|
||||
|
||||
if (isset($colData['formatter']) || isset($colData['format']))
|
||||
{
|
||||
switch(low($colData['formatter']))
|
||||
{
|
||||
case 'date':
|
||||
$data = date($colData['format'], strtotime($data));
|
||||
break;
|
||||
case 'sprintf':
|
||||
$data = sprintf($colData['format'], $data);
|
||||
break;
|
||||
case 'intval':
|
||||
$data = intval($data);
|
||||
break;
|
||||
case 'floatval':
|
||||
$data = floatval($data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$model->data[$name][$column] = $data;
|
||||
|
||||
/*switch($colType)
|
||||
{
|
||||
case 'integer':
|
||||
case 'int':
|
||||
return $data;
|
||||
break;
|
||||
case 'string':
|
||||
case 'text':
|
||||
case 'binary':
|
||||
case 'date':
|
||||
case 'time':
|
||||
case 'datetime':
|
||||
case 'timestamp':
|
||||
case 'date':
|
||||
return "'" . $data . "'";
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -654,7 +654,38 @@ class View extends Object
|
|||
@include($___viewFn);
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
return $out;
|
||||
|
||||
if($this->controller->cacheAction != false && CACHE_CHECK === true)
|
||||
{
|
||||
if(is_array($this->controller->cacheAction))
|
||||
{
|
||||
if(isset($this->controller->cacheAction[$this->action]))
|
||||
{
|
||||
$cacheTime = $this->controller->cacheAction[$this->action];
|
||||
}
|
||||
else
|
||||
{
|
||||
$cacheTime = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$cacheTime = $this->controller->cacheAction;
|
||||
}
|
||||
|
||||
if($cacheTime != '' && $cacheTime > 0)
|
||||
{
|
||||
return $this->cacheView($out, $cacheTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -765,5 +796,22 @@ class View extends Object
|
|||
'file' => $viewFileName)));
|
||||
}
|
||||
}
|
||||
|
||||
function cacheView($view, $timestamp)
|
||||
{
|
||||
$now = time();
|
||||
if (is_numeric($timestamp))
|
||||
{
|
||||
$timestamp = $now + $timestamp;
|
||||
}
|
||||
else
|
||||
{
|
||||
$timestamp = $now + strtotime($timestamp);
|
||||
}
|
||||
$content = '<!--cachetime:' . $timestamp . '-->'.$view;
|
||||
$result = preg_replace('/\/\//', '/', $this->here);
|
||||
$cache = str_replace('/', '_', $result.'.php');
|
||||
return cache('views'.DS.$cache, $content, $timestamp);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue