diff --git a/VERSION.txt b/VERSION.txt index b1d702d25..31fa15fd2 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.8.2195 \ No newline at end of file +1.0.0.2250 \ No newline at end of file diff --git a/app/config/core.php b/app/config/core.php index 74c96f2c9..d5eb191d3 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -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 diff --git a/app/config/database.php.default b/app/config/database.php.default index 5ac8de78e..77288bf1f 100644 --- a/app/config/database.php.default +++ b/app/config/database.php.default @@ -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', diff --git a/cake/basics.php b/cake/basics.php index e3bbd9b34..4a9c729ec 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -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 diff --git a/cake/bootstrap.php b/cake/bootstrap.php index 90e1584c6..85a1e6582 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -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 ""; + } + $out = ob_get_clean(); + if (preg_match('/^/', $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'; diff --git a/cake/libs/class_registry.php b/cake/libs/class_registry.php index de732c11a..8dfa6653f 100644 --- a/cake/libs/class_registry.php +++ b/cake/libs/class_registry.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. * diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 95e481ea0..0faf6deb5 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -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); } /** diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 663f47a2a..399e4a4b8 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -193,6 +193,13 @@ class Controller extends Object */ var $plugin = null; +/** + * Enter description here... + * + * @var unknown_type + */ + var $cacheAction = false; + /** * Constructor. * diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index a39040427..6bf49432b 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -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... * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 083a909fb..be4fc0ab1 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -368,7 +368,7 @@ class DboSource extends DataSource } /** - * Enter description here... + * The "R" in CRUD * * @param Model $model * @param array $queryData diff --git a/cake/libs/model/dbo/dbo_mysql.php b/cake/libs/model/dbo/dbo_mysql.php index 60efc3e28..9d38586d6 100644 --- a/cake/libs/model/dbo/dbo_mysql.php +++ b/cake/libs/model/dbo/dbo_mysql.php @@ -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) . "'"; } /** diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php index 8290a072a..97ac9cb8c 100644 --- a/cake/libs/model/model_php4.php +++ b/cake/libs/model/model_php4.php @@ -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 diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php index 92605f56b..96c1f6aba 100644 --- a/cake/libs/model/model_php5.php +++ b/cake/libs/model/model_php5.php @@ -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; + } } ?> \ No newline at end of file diff --git a/cake/libs/sanitize.php b/cake/libs/sanitize.php index ad7c52270..2bdc7bf7f 100644 --- a/cake/libs/sanitize.php +++ b/cake/libs/sanitize.php @@ -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; + }*/ + } + } + } + } + } } ?> \ No newline at end of file diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 120c6ba51..67e88f76e 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -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 = ''.$view; + $result = preg_replace('/\/\//', '/', $this->here); + $cache = str_replace('/', '_', $result.'.php'); + return cache('views'.DS.$cache, $content, $timestamp); + } } ?> \ No newline at end of file