mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-05 15:43:53 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Cookie Component
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Controller.Component
|
||||
* @since CakePHP(tm) v 1.2.0.4213
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Component', 'Controller');
|
||||
|
@ -28,7 +27,6 @@ App::uses('Hash', 'Utility');
|
|||
*
|
||||
* @package Cake.Controller.Component
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html
|
||||
*
|
||||
*/
|
||||
class CookieComponent extends Component {
|
||||
|
||||
|
@ -61,7 +59,7 @@ class CookieComponent extends Component {
|
|||
* $this->Cookie->path = '/';
|
||||
*
|
||||
* The path on the server in which the cookie will be available on.
|
||||
* If public $cookiePath is set to '/foo/', the cookie will only be available
|
||||
* If public $cookiePath is set to '/foo/', the cookie will only be available
|
||||
* within the /foo/ directory and all sub-directories such as /foo/bar/ of domain.
|
||||
* The default value is the entire domain.
|
||||
*
|
||||
|
@ -93,7 +91,7 @@ class CookieComponent extends Component {
|
|||
* Indicates that the cookie should only be transmitted over a secure HTTPS connection.
|
||||
* When set to true, the cookie will only be set if a secure connection exists.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $secure = false;
|
||||
|
||||
|
@ -110,10 +108,10 @@ class CookieComponent extends Component {
|
|||
/**
|
||||
* HTTP only cookie
|
||||
*
|
||||
* Set to true to make HTTP only cookies. Cookies that are HTTP only
|
||||
* are not accessible in Javascript.
|
||||
* Set to true to make HTTP only cookies. Cookies that are HTTP only
|
||||
* are not accessible in JavaScript.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $httpOnly = false;
|
||||
|
||||
|
@ -131,7 +129,9 @@ class CookieComponent extends Component {
|
|||
* Type of encryption to use.
|
||||
*
|
||||
* Currently two methods are available: cipher and rijndael
|
||||
* Defaults to Security::cipher();
|
||||
* Defaults to Security::cipher(). Cipher is horribly insecure and only
|
||||
* the default because of backwards compatibility. In new applications you should
|
||||
* always change this to 'aes' or 'rijndael'.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
@ -177,14 +177,14 @@ class CookieComponent extends Component {
|
|||
if ($controller && isset($controller->response)) {
|
||||
$this->_response = $controller->response;
|
||||
} else {
|
||||
$this->_response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
|
||||
$this->_response = new CakeResponse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start CookieComponent for use in the controller
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @param Controller $controller Controller instance.
|
||||
* @return void
|
||||
*/
|
||||
public function startup(Controller $controller) {
|
||||
|
@ -207,8 +207,9 @@ class CookieComponent extends Component {
|
|||
*
|
||||
* @param string|array $key Key for the value
|
||||
* @param mixed $value Value
|
||||
* @param boolean $encrypt Set to true to encrypt value, false otherwise
|
||||
* @param integer|string $expires Can be either Unix timestamp, or date string
|
||||
* @param bool $encrypt Set to true to encrypt value, false otherwise
|
||||
* @param int|string $expires Can be either the number of seconds until a cookie
|
||||
* expires, or a strtotime compatible time offset.
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::write
|
||||
*/
|
||||
|
@ -217,7 +218,7 @@ class CookieComponent extends Component {
|
|||
$this->read();
|
||||
}
|
||||
|
||||
if (is_null($encrypt)) {
|
||||
if ($encrypt === null) {
|
||||
$encrypt = true;
|
||||
}
|
||||
$this->_encrypted = $encrypt;
|
||||
|
@ -228,17 +229,27 @@ class CookieComponent extends Component {
|
|||
}
|
||||
|
||||
foreach ($key as $name => $value) {
|
||||
if (strpos($name, '.') === false) {
|
||||
$this->_values[$this->name][$name] = $value;
|
||||
$this->_write("[$name]", $value);
|
||||
} else {
|
||||
$names = array($name);
|
||||
if (strpos($name, '.') !== false) {
|
||||
$names = explode('.', $name, 2);
|
||||
if (!isset($this->_values[$this->name][$names[0]])) {
|
||||
$this->_values[$this->name][$names[0]] = array();
|
||||
}
|
||||
$this->_values[$this->name][$names[0]] = Hash::insert($this->_values[$this->name][$names[0]], $names[1], $value);
|
||||
$this->_write('[' . implode('][', $names) . ']', $value);
|
||||
}
|
||||
$firstName = $names[0];
|
||||
$isMultiValue = (is_array($value) || count($names) > 1);
|
||||
|
||||
if (!isset($this->_values[$this->name][$firstName]) && $isMultiValue) {
|
||||
$this->_values[$this->name][$firstName] = array();
|
||||
}
|
||||
|
||||
if (count($names) > 1) {
|
||||
$this->_values[$this->name][$firstName] = Hash::insert(
|
||||
$this->_values[$this->name][$firstName],
|
||||
$names[1],
|
||||
$value
|
||||
);
|
||||
} else {
|
||||
$this->_values[$this->name][$firstName] = $value;
|
||||
}
|
||||
$this->_write('[' . $firstName . ']', $this->_values[$this->name][$firstName]);
|
||||
}
|
||||
$this->_encrypted = true;
|
||||
}
|
||||
|
@ -250,7 +261,7 @@ class CookieComponent extends Component {
|
|||
* $this->Cookie->read(Name.key);
|
||||
*
|
||||
* @param string $key Key of the value to be obtained. If none specified, obtain map key => values
|
||||
* @return string or null, value for specified key
|
||||
* @return string|null Value for specified key
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::read
|
||||
*/
|
||||
public function read($key = null) {
|
||||
|
@ -260,7 +271,7 @@ class CookieComponent extends Component {
|
|||
if (empty($this->_values[$this->name])) {
|
||||
$this->_values[$this->name] = array();
|
||||
}
|
||||
if (is_null($key)) {
|
||||
if ($key === null) {
|
||||
return $this->_values[$this->name];
|
||||
}
|
||||
|
||||
|
@ -273,20 +284,42 @@ class CookieComponent extends Component {
|
|||
}
|
||||
|
||||
if (!empty($names[1])) {
|
||||
return Hash::get($this->_values[$this->name][$key], $names[1]);
|
||||
if (is_array($this->_values[$this->name][$key])) {
|
||||
return Hash::get($this->_values[$this->name][$key], $names[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return $this->_values[$this->name][$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given variable is set in cookie.
|
||||
*
|
||||
* @param string $key Variable name to check for
|
||||
* @return bool True if variable is there
|
||||
*/
|
||||
public function check($key = null) {
|
||||
if (empty($key)) {
|
||||
return false;
|
||||
}
|
||||
return $this->read($key) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cookie value
|
||||
*
|
||||
* Optional [Name.], required key
|
||||
* $this->Cookie->read('Name.key);
|
||||
* $this->Cookie->delete('Name.key);
|
||||
*
|
||||
* You must use this method before any output is sent to the browser.
|
||||
* Failure to do so will result in header already sent errors.
|
||||
*
|
||||
* This method will delete both the top level and 2nd level cookies set.
|
||||
* For example assuming that $name = App, deleting `User` will delete
|
||||
* both `App[User]` and any other cookie values like `App[User][email]`
|
||||
* This is done to clean up cookie storage from before 2.4.3, where cookies
|
||||
* were stored inconsistently.
|
||||
*
|
||||
* @param string $key Key of the value to be deleted
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::delete
|
||||
|
@ -306,7 +339,7 @@ class CookieComponent extends Component {
|
|||
return;
|
||||
}
|
||||
$names = explode('.', $key, 2);
|
||||
if (isset($this->_values[$this->name][$names[0]])) {
|
||||
if (isset($this->_values[$this->name][$names[0]]) && is_array($this->_values[$this->name][$names[0]])) {
|
||||
$this->_values[$this->name][$names[0]] = Hash::remove($this->_values[$this->name][$names[0]], $names[1]);
|
||||
}
|
||||
$this->_delete('[' . implode('][', $names) . ']');
|
||||
|
@ -349,10 +382,11 @@ class CookieComponent extends Component {
|
|||
public function type($type = 'cipher') {
|
||||
$availableTypes = array(
|
||||
'cipher',
|
||||
'rijndael'
|
||||
'rijndael',
|
||||
'aes'
|
||||
);
|
||||
if (!in_array($type, $availableTypes)) {
|
||||
trigger_error(__d('cake_dev', 'You must use cipher or rijndael for cookie encryption type'), E_USER_WARNING);
|
||||
trigger_error(__d('cake_dev', 'You must use cipher, rijndael or aes for cookie encryption type'), E_USER_WARNING);
|
||||
$type = 'cipher';
|
||||
}
|
||||
$this->_type = $type;
|
||||
|
@ -368,24 +402,24 @@ class CookieComponent extends Component {
|
|||
* CookieComponent::write(string, string, boolean, 8400);
|
||||
* CookieComponent::write(string, string, boolean, '5 Days');
|
||||
*
|
||||
* @param integer|string $expires Can be either Unix timestamp, or date string
|
||||
* @return integer Unix timestamp
|
||||
* @param int|string $expires Can be either Unix timestamp, or date string
|
||||
* @return int Unix timestamp
|
||||
*/
|
||||
protected function _expire($expires = null) {
|
||||
$now = time();
|
||||
if (is_null($expires)) {
|
||||
if ($expires === null) {
|
||||
return $this->_expires;
|
||||
}
|
||||
$this->_reset = $this->_expires;
|
||||
|
||||
if ($expires == 0) {
|
||||
if (!$expires) {
|
||||
return $this->_expires = 0;
|
||||
}
|
||||
$now = new DateTime();
|
||||
|
||||
if (is_integer($expires) || is_numeric($expires)) {
|
||||
return $this->_expires = $now + intval($expires);
|
||||
if (is_int($expires) || is_numeric($expires)) {
|
||||
return $this->_expires = $now->format('U') + (int)$expires;
|
||||
}
|
||||
return $this->_expires = strtotime($expires, $now);
|
||||
$now->modify($expires);
|
||||
return $this->_expires = $now->format('U');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -406,7 +440,7 @@ class CookieComponent extends Component {
|
|||
'httpOnly' => $this->httpOnly
|
||||
));
|
||||
|
||||
if (!is_null($this->_reset)) {
|
||||
if (!empty($this->_reset)) {
|
||||
$this->_expires = $this->_reset;
|
||||
$this->_reset = null;
|
||||
}
|
||||
|
@ -434,19 +468,26 @@ class CookieComponent extends Component {
|
|||
* Encrypts $value using public $type method in Security class
|
||||
*
|
||||
* @param string $value Value to encrypt
|
||||
* @return string encrypted string
|
||||
* @return string Encoded values
|
||||
*/
|
||||
protected function _encrypt($value) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->_implode($value);
|
||||
}
|
||||
|
||||
if ($this->_encrypted === true) {
|
||||
$type = $this->_type;
|
||||
$value = "Q2FrZQ==." . base64_encode(Security::$type($value, $this->key, 'encrypt'));
|
||||
if (!$this->_encrypted) {
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
$prefix = "Q2FrZQ==.";
|
||||
if ($this->_type === 'rijndael') {
|
||||
$cipher = Security::rijndael($value, $this->key, 'encrypt');
|
||||
}
|
||||
if ($this->_type === 'cipher') {
|
||||
$cipher = Security::cipher($value, $this->key);
|
||||
}
|
||||
if ($this->_type === 'aes') {
|
||||
$cipher = Security::encrypt($value, $this->key);
|
||||
}
|
||||
return $prefix . base64_encode($cipher);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -462,27 +503,40 @@ class CookieComponent extends Component {
|
|||
foreach ((array)$values as $name => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $key => $val) {
|
||||
$pos = strpos($val, 'Q2FrZQ==.');
|
||||
$decrypted[$name][$key] = $this->_explode($val);
|
||||
|
||||
if ($pos !== false) {
|
||||
$val = substr($val, 8);
|
||||
$decrypted[$name][$key] = $this->_explode(Security::$type(base64_decode($val), $this->key, 'decrypt'));
|
||||
}
|
||||
$decrypted[$name][$key] = $this->_decode($val);
|
||||
}
|
||||
} else {
|
||||
$pos = strpos($value, 'Q2FrZQ==.');
|
||||
$decrypted[$name] = $this->_explode($value);
|
||||
|
||||
if ($pos !== false) {
|
||||
$value = substr($value, 8);
|
||||
$decrypted[$name] = $this->_explode(Security::$type(base64_decode($value), $this->key, 'decrypt'));
|
||||
}
|
||||
$decrypted[$name] = $this->_decode($value);
|
||||
}
|
||||
}
|
||||
return $decrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes and decrypts a single value.
|
||||
*
|
||||
* @param string $value The value to decode & decrypt.
|
||||
* @return string Decoded value.
|
||||
*/
|
||||
protected function _decode($value) {
|
||||
$prefix = 'Q2FrZQ==.';
|
||||
$pos = strpos($value, $prefix);
|
||||
if ($pos === false) {
|
||||
return $this->_explode($value);
|
||||
}
|
||||
$value = base64_decode(substr($value, strlen($prefix)));
|
||||
if ($this->_type === 'rijndael') {
|
||||
$plain = Security::rijndael($value, $this->key, 'decrypt');
|
||||
}
|
||||
if ($this->_type === 'cipher') {
|
||||
$plain = Security::cipher($value, $this->key);
|
||||
}
|
||||
if ($this->_type === 'aes') {
|
||||
$plain = Security::decrypt($value, $this->key);
|
||||
}
|
||||
return $this->_explode($plain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implode method to keep keys are multidimensional arrays
|
||||
*
|
||||
|
@ -504,7 +558,7 @@ class CookieComponent extends Component {
|
|||
$first = substr($string, 0, 1);
|
||||
if ($first === '{' || $first === '[') {
|
||||
$ret = json_decode($string, true);
|
||||
return ($ret != null) ? $ret : $string;
|
||||
return ($ret !== null) ? $ret : $string;
|
||||
}
|
||||
$array = array();
|
||||
foreach (explode(',', $string) as $pair) {
|
||||
|
@ -517,4 +571,3 @@ class CookieComponent extends Component {
|
|||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue