cakephp2-php8/lib/Cake/Controller/Component/CookieComponent.php

502 lines
13 KiB
PHP
Raw Normal View History

<?php
/**
* Cookie Component
*
2010-10-03 16:38:58 +00:00
* PHP 5
*
2009-11-06 06:46:59 +00:00
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
2011-05-29 21:31:39 +00:00
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
2011-05-29 21:31:39 +00:00
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
2009-11-06 06:00:11 +00:00
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller.Component
* @since CakePHP(tm) v 1.2.0.4213
2009-11-06 06:51:51 +00:00
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
2011-01-28 06:36:30 +00:00
App::uses('Component', 'Controller');
App::uses('Security', 'Utility');
/**
* Cookie Component.
*
* Cookie handling for the controller.
*
* @package Cake.Controller.Component
2011-10-15 16:08:49 +00:00
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html
*
*/
class CookieComponent extends Component {
/**
* The name of the cookie.
*
* Overridden with the controller beforeFilter();
* $this->Cookie->name = 'CookieName';
*
* @var string
*/
public $name = 'CakeCookie';
/**
* The time a cookie will remain valid.
*
* Can be either integer Unix timestamp or a date string.
*
* Overridden with the controller beforeFilter();
* $this->Cookie->time = '5 Days';
*
* @var mixed
*/
public $time = null;
/**
* Cookie path.
*
* Overridden with the controller beforeFilter();
* $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
* within the /foo/ directory and all sub-directories such as /foo/bar/ of domain.
* The default value is the entire domain.
*
* @var string
*/
public $path = '/';
/**
* Domain path.
*
* The domain that the cookie is available.
*
* Overridden with the controller beforeFilter();
* $this->Cookie->domain = '.example.com';
*
* To make the cookie available on all subdomains of example.com.
* Set $this->Cookie->domain = '.example.com'; in your controller beforeFilter
*
* @var string
*/
public $domain = '';
/**
* Secure HTTPS only cookie.
*
* Overridden with the controller beforeFilter();
* $this->Cookie->secure = true;
*
* 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
*/
public $secure = false;
/**
* Encryption key.
*
* Overridden with the controller beforeFilter();
* $this->Cookie->key = 'SomeRandomString';
*
* @var string
*/
public $key = null;
/**
* HTTP only cookie
*
2011-08-16 03:55:08 +00:00
* Set to true to make HTTP only cookies. Cookies that are HTTP only
* are not accessible in Javascript.
*
* @var boolean
*/
public $httpOnly = false;
/**
* Values stored in the cookie.
*
* Accessed in the controller using $this->Cookie->read('Name.key');
*
* @see CookieComponent::read();
* @var string
*/
protected $_values = array();
/**
* Type of encryption to use.
*
* Currently only one method is available
* Defaults to Security::cipher();
*
* @var string
* @todo add additional encryption methods
*/
protected $_type = 'cipher';
/**
* Used to reset cookie time if $expire is passed to CookieComponent::write()
*
* @var string
*/
protected $_reset = null;
/**
* Expire time of the cookie
*
* This is controlled by CookieComponent::time;
*
* @var string
*/
protected $_expires = 0;
/**
* Constructor
*
* @param ComponentCollection $collection A ComponentCollection for this component
* @param array $settings Array of settings.
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
$this->key = Configure::read('Security.salt');
parent::__construct($collection, $settings);
if (isset($this->time)) {
$this->_expire($this->time);
}
}
/**
* Start CookieComponent for use in the controller
*
2011-07-29 04:06:43 +00:00
* @param Controller $controller
* @return void
*/
public function startup($controller) {
$this->_expire($this->time);
if (isset($_COOKIE[$this->name])) {
$this->_values = $this->_decrypt($_COOKIE[$this->name]);
}
}
/**
* Write a value to the $_COOKIE[$key];
*
* Optional [Name.], required key, optional $value, optional $encrypt, optional $expires
* $this->Cookie->write('[Name.]key, $value);
*
* By default all values are encrypted.
* You must pass $encrypt false to store values in clear test
*
* You must use this method before any output is sent to the browser.
* Failure to do so will result in header already sent errors.
*
* @param mixed $key Key for the value
* @param mixed $value Value
* @param boolean $encrypt Set to true to encrypt value, false otherwise
* @param string $expires Can be either Unix timestamp, or date string
2011-07-29 04:06:43 +00:00
* @return void
2011-11-23 06:32:13 +00:00
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::write
*/
public function write($key, $value = null, $encrypt = true, $expires = null) {
if (is_null($encrypt)) {
$encrypt = true;
}
$this->_encrypted = $encrypt;
$this->_expire($expires);
2011-08-16 03:55:08 +00:00
if (!is_array($key)) {
$key = array($key => $value);
}
foreach ($key as $name => $value) {
if (strpos($name, '.') === false) {
$this->_values[$name] = $value;
$this->_write("[$name]", $value);
} else {
$names = explode('.', $name, 2);
if (!isset($this->_values[$names[0]])) {
$this->_values[$names[0]] = array();
}
$this->_values[$names[0]] = Set::insert($this->_values[$names[0]], $names[1], $value);
$this->_write('[' . implode('][', $names) . ']', $value);
}
}
$this->_encrypted = true;
}
/**
* Read the value of the $_COOKIE[$key];
*
* Optional [Name.], required key
* $this->Cookie->read(Name.key);
*
* @param mixed $key Key of the value to be obtained. If none specified, obtain map key => values
* @return string or null, value for specified key
2011-11-23 06:32:13 +00:00
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::read
*/
public function read($key = null) {
if (empty($this->_values) && isset($_COOKIE[$this->name])) {
$this->_values = $this->_decrypt($_COOKIE[$this->name]);
}
if (is_null($key)) {
return $this->_values;
}
if (strpos($key, '.') !== false) {
$names = explode('.', $key, 2);
$key = $names[0];
}
if (!isset($this->_values[$key])) {
return null;
}
if (!empty($names[1])) {
return Set::extract($this->_values[$key], $names[1]);
}
return $this->_values[$key];
}
/**
* Delete a cookie value
*
* Optional [Name.], required key
* $this->Cookie->read('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.
*
* @param string $key Key of the value to be deleted
* @return void
2011-11-23 06:32:13 +00:00
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::delete
*/
public function delete($key) {
if (empty($this->_values)) {
$this->read();
}
if (strpos($key, '.') === false) {
if (isset($this->_values[$key]) && is_array($this->_values[$key])) {
foreach ($this->_values[$key] as $idx => $val) {
$this->_delete("[$key][$idx]");
}
}
Merge branch '1.3' into merger Conflicts: app/Config/acl.ini.php app/config/database.php.default app/webroot/css.php app/webroot/css/cake.generic.css cake/basics.php cake/bootstrap.php cake/config/paths.php cake/console/cake.php cake/console/error.php cake/console/libs/acl.php cake/console/libs/bake.php cake/console/libs/i18n.php cake/console/libs/shell.php cake/console/libs/tasks/extract.php cake/console/libs/tasks/plugin.php cake/console/libs/tasks/project.php cake/console/libs/testsuite.php cake/console/templates/default/classes/test.ctp cake/console/templates/default/views/home.ctp cake/console/templates/default/views/view.ctp cake/console/templates/skel/config/database.php.default cake/console/templates/skel/views/elements/email/text/default.ctp cake/console/templates/skel/webroot/css.php cake/dispatcher.php cake/libs/cache.php cake/libs/cake_session.php cake/libs/configure.php cake/libs/controller/component.php cake/libs/controller/components/auth.php cake/libs/controller/components/email.php cake/libs/controller/components/request_handler.php cake/libs/controller/components/security.php cake/libs/controller/controller.php cake/libs/controller/scaffold.php cake/libs/error.php cake/libs/magic_db.php cake/libs/model/behaviors/acl.php cake/libs/model/connection_manager.php cake/libs/model/datasources/dbo/dbo_mysqli.php cake/libs/model/model_behavior.php cake/libs/overloadable.php cake/libs/overloadable_php4.php cake/libs/overloadable_php5.php cake/libs/router.php cake/libs/view/errors/missing_action.ctp cake/libs/view/errors/missing_behavior_class.ctp cake/libs/view/errors/missing_behavior_file.ctp cake/libs/view/errors/missing_component_class.ctp cake/libs/view/errors/missing_component_file.ctp cake/libs/view/errors/missing_connection.ctp cake/libs/view/errors/missing_controller.ctp cake/libs/view/errors/missing_helper_class.ctp cake/libs/view/errors/missing_helper_file.ctp cake/libs/view/errors/missing_layout.ctp cake/libs/view/errors/missing_model.ctp cake/libs/view/errors/missing_scaffolddb.ctp cake/libs/view/errors/missing_table.ctp cake/libs/view/errors/missing_view.ctp cake/libs/view/errors/private_action.ctp cake/libs/view/errors/scaffold_error.ctp cake/libs/view/helpers/ajax.php cake/libs/view/helpers/javascript.php cake/libs/view/helpers/js.php cake/libs/view/helpers/session.php cake/libs/view/helpers/xml.php cake/libs/view/media.php cake/libs/view/pages/home.ctp cake/libs/view/scaffolds/edit.ctp cake/libs/view/scaffolds/index.ctp cake/libs/view/scaffolds/view.ctp cake/libs/view/view.php cake/libs/xml.php cake/tests/cases/console/cake.test.php cake/tests/cases/console/libs/acl.test.php cake/tests/cases/console/libs/api.test.php cake/tests/cases/console/libs/bake.test.php cake/tests/cases/console/libs/shell.test.php cake/tests/cases/console/libs/tasks/controller.test.php cake/tests/cases/console/libs/tasks/db_config.test.php cake/tests/cases/console/libs/tasks/fixture.test.php cake/tests/cases/console/libs/tasks/model.test.php cake/tests/cases/console/libs/tasks/plugin.test.php cake/tests/cases/console/libs/tasks/project.test.php cake/tests/cases/console/libs/tasks/test.test.php cake/tests/cases/console/libs/tasks/view.test.php cake/tests/cases/dispatcher.test.php cake/tests/cases/libs/cache/apc.test.php cake/tests/cases/libs/cake_session.test.php cake/tests/cases/libs/cake_test_case.test.php cake/tests/cases/libs/code_coverage_manager.test.php cake/tests/cases/libs/configure.test.php cake/tests/cases/libs/controller/component.test.php cake/tests/cases/libs/controller/components/auth.test.php cake/tests/cases/libs/controller/components/cookie.test.php cake/tests/cases/libs/controller/components/request_handler.test.php cake/tests/cases/libs/controller/components/session.test.php cake/tests/cases/libs/controller/controller.test.php cake/tests/cases/libs/controller/pages_controller.test.php cake/tests/cases/libs/error.test.php cake/tests/cases/libs/http_socket.test.php cake/tests/cases/libs/magic_db.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php cake/tests/cases/libs/model/datasources/dbo_source.test.php cake/tests/cases/libs/model/models.php cake/tests/cases/libs/overloadable.test.php cake/tests/cases/libs/test_manager.test.php cake/tests/cases/libs/view/helpers/ajax.test.php cake/tests/cases/libs/view/helpers/javascript.test.php cake/tests/cases/libs/view/helpers/session.test.php cake/tests/cases/libs/view/helpers/xml.test.php cake/tests/cases/libs/view/media.test.php cake/tests/cases/libs/view/theme.test.php cake/tests/cases/libs/xml.test.php cake/tests/fixtures/aco_fixture.php cake/tests/fixtures/translate_fixture.php cake/tests/groups/acl.group.php cake/tests/groups/bake.group.php cake/tests/groups/behaviors.group.php cake/tests/groups/cache.group.php cake/tests/groups/components.group.php cake/tests/groups/configure.group.php cake/tests/groups/console.group.php cake/tests/groups/controller.group.php cake/tests/groups/database.group.php cake/tests/groups/helpers.group.php cake/tests/groups/i18n.group.php cake/tests/groups/javascript.group.php cake/tests/groups/lib.group.php cake/tests/groups/model.group.php cake/tests/groups/no_cross_contamination.group.php cake/tests/groups/routing_system.group.php cake/tests/groups/socket.group.php cake/tests/groups/test_suite.group.php cake/tests/groups/view.group.php cake/tests/groups/xml.group.php cake/tests/lib/cake_test_case.php cake/tests/lib/cake_test_model.php cake/tests/lib/cake_test_suite_dispatcher.php cake/tests/lib/cake_web_test_case.php cake/tests/lib/code_coverage_manager.php cake/tests/lib/reporter/cake_base_reporter.php cake/tests/lib/reporter/cake_cli_reporter.php cake/tests/lib/reporter/cake_text_reporter.php cake/tests/lib/templates/menu.php cake/tests/lib/templates/simpletest.php cake/tests/lib/test_manager.php cake/tests/test_app/controllers/tests_apps_controller.php cake/tests/test_app/libs/cache/test_app_cache.php cake/tests/test_app/libs/library.php cake/tests/test_app/libs/log/test_app_log.php cake/tests/test_app/plugins/test_plugin/config/load.php cake/tests/test_app/plugins/test_plugin/config/more.load.php cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php cake/tests/test_app/plugins/test_plugin/vendors/welcome.php cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php cake/tests/test_app/vendors/Test/MyTest.php cake/tests/test_app/vendors/Test/hello.php cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php cake/tests/test_app/vendors/shells/sample.php cake/tests/test_app/vendors/somename/some.name.php cake/tests/test_app/vendors/welcome.php cake/tests/test_app/views/elements/email/text/default.ctp cake/tests/test_app/views/layouts/default.ctp cake/tests/test_app/views/posts/test_nocache_tags.ctp lib/Cake/Cache/Engine/MemcacheEngine.php lib/Cake/Config/config.php lib/Cake/Console/Command/Task/ModelTask.php lib/Cake/Console/Templates/skel/webroot/css/cake.generic.css lib/Cake/Console/Templates/skel/webroot/test.php lib/Cake/Console/cake.bat lib/Cake/Controller/Component/CookieComponent.php lib/Cake/Log/CakeLog.php lib/Cake/Model/CakeSchema.php lib/Cake/Test/Case/Log/Engine/FileLog.php lib/Cake/Test/Case/View/Helper/FormHelperTest.php lib/Cake/Test/test_app/View/Emails/html/custom.ctp lib/Cake/Test/test_app/View/Emails/text/custom.ctp lib/Cake/TestSuite/templates/header.php lib/Cake/Utility/Sanitize.php lib/Cake/Utility/Validation.php lib/Cake/VERSION.txt lib/Cake/View/Helper/FormHelper.php
2011-06-23 19:48:06 +00:00
$this->_delete("[$key]");
unset($this->_values[$key]);
return;
}
$names = explode('.', $key, 2);
Merge branch '1.3' into merger Conflicts: app/Config/acl.ini.php app/config/database.php.default app/webroot/css.php app/webroot/css/cake.generic.css cake/basics.php cake/bootstrap.php cake/config/paths.php cake/console/cake.php cake/console/error.php cake/console/libs/acl.php cake/console/libs/bake.php cake/console/libs/i18n.php cake/console/libs/shell.php cake/console/libs/tasks/extract.php cake/console/libs/tasks/plugin.php cake/console/libs/tasks/project.php cake/console/libs/testsuite.php cake/console/templates/default/classes/test.ctp cake/console/templates/default/views/home.ctp cake/console/templates/default/views/view.ctp cake/console/templates/skel/config/database.php.default cake/console/templates/skel/views/elements/email/text/default.ctp cake/console/templates/skel/webroot/css.php cake/dispatcher.php cake/libs/cache.php cake/libs/cake_session.php cake/libs/configure.php cake/libs/controller/component.php cake/libs/controller/components/auth.php cake/libs/controller/components/email.php cake/libs/controller/components/request_handler.php cake/libs/controller/components/security.php cake/libs/controller/controller.php cake/libs/controller/scaffold.php cake/libs/error.php cake/libs/magic_db.php cake/libs/model/behaviors/acl.php cake/libs/model/connection_manager.php cake/libs/model/datasources/dbo/dbo_mysqli.php cake/libs/model/model_behavior.php cake/libs/overloadable.php cake/libs/overloadable_php4.php cake/libs/overloadable_php5.php cake/libs/router.php cake/libs/view/errors/missing_action.ctp cake/libs/view/errors/missing_behavior_class.ctp cake/libs/view/errors/missing_behavior_file.ctp cake/libs/view/errors/missing_component_class.ctp cake/libs/view/errors/missing_component_file.ctp cake/libs/view/errors/missing_connection.ctp cake/libs/view/errors/missing_controller.ctp cake/libs/view/errors/missing_helper_class.ctp cake/libs/view/errors/missing_helper_file.ctp cake/libs/view/errors/missing_layout.ctp cake/libs/view/errors/missing_model.ctp cake/libs/view/errors/missing_scaffolddb.ctp cake/libs/view/errors/missing_table.ctp cake/libs/view/errors/missing_view.ctp cake/libs/view/errors/private_action.ctp cake/libs/view/errors/scaffold_error.ctp cake/libs/view/helpers/ajax.php cake/libs/view/helpers/javascript.php cake/libs/view/helpers/js.php cake/libs/view/helpers/session.php cake/libs/view/helpers/xml.php cake/libs/view/media.php cake/libs/view/pages/home.ctp cake/libs/view/scaffolds/edit.ctp cake/libs/view/scaffolds/index.ctp cake/libs/view/scaffolds/view.ctp cake/libs/view/view.php cake/libs/xml.php cake/tests/cases/console/cake.test.php cake/tests/cases/console/libs/acl.test.php cake/tests/cases/console/libs/api.test.php cake/tests/cases/console/libs/bake.test.php cake/tests/cases/console/libs/shell.test.php cake/tests/cases/console/libs/tasks/controller.test.php cake/tests/cases/console/libs/tasks/db_config.test.php cake/tests/cases/console/libs/tasks/fixture.test.php cake/tests/cases/console/libs/tasks/model.test.php cake/tests/cases/console/libs/tasks/plugin.test.php cake/tests/cases/console/libs/tasks/project.test.php cake/tests/cases/console/libs/tasks/test.test.php cake/tests/cases/console/libs/tasks/view.test.php cake/tests/cases/dispatcher.test.php cake/tests/cases/libs/cache/apc.test.php cake/tests/cases/libs/cake_session.test.php cake/tests/cases/libs/cake_test_case.test.php cake/tests/cases/libs/code_coverage_manager.test.php cake/tests/cases/libs/configure.test.php cake/tests/cases/libs/controller/component.test.php cake/tests/cases/libs/controller/components/auth.test.php cake/tests/cases/libs/controller/components/cookie.test.php cake/tests/cases/libs/controller/components/request_handler.test.php cake/tests/cases/libs/controller/components/session.test.php cake/tests/cases/libs/controller/controller.test.php cake/tests/cases/libs/controller/pages_controller.test.php cake/tests/cases/libs/error.test.php cake/tests/cases/libs/http_socket.test.php cake/tests/cases/libs/magic_db.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php cake/tests/cases/libs/model/datasources/dbo_source.test.php cake/tests/cases/libs/model/models.php cake/tests/cases/libs/overloadable.test.php cake/tests/cases/libs/test_manager.test.php cake/tests/cases/libs/view/helpers/ajax.test.php cake/tests/cases/libs/view/helpers/javascript.test.php cake/tests/cases/libs/view/helpers/session.test.php cake/tests/cases/libs/view/helpers/xml.test.php cake/tests/cases/libs/view/media.test.php cake/tests/cases/libs/view/theme.test.php cake/tests/cases/libs/xml.test.php cake/tests/fixtures/aco_fixture.php cake/tests/fixtures/translate_fixture.php cake/tests/groups/acl.group.php cake/tests/groups/bake.group.php cake/tests/groups/behaviors.group.php cake/tests/groups/cache.group.php cake/tests/groups/components.group.php cake/tests/groups/configure.group.php cake/tests/groups/console.group.php cake/tests/groups/controller.group.php cake/tests/groups/database.group.php cake/tests/groups/helpers.group.php cake/tests/groups/i18n.group.php cake/tests/groups/javascript.group.php cake/tests/groups/lib.group.php cake/tests/groups/model.group.php cake/tests/groups/no_cross_contamination.group.php cake/tests/groups/routing_system.group.php cake/tests/groups/socket.group.php cake/tests/groups/test_suite.group.php cake/tests/groups/view.group.php cake/tests/groups/xml.group.php cake/tests/lib/cake_test_case.php cake/tests/lib/cake_test_model.php cake/tests/lib/cake_test_suite_dispatcher.php cake/tests/lib/cake_web_test_case.php cake/tests/lib/code_coverage_manager.php cake/tests/lib/reporter/cake_base_reporter.php cake/tests/lib/reporter/cake_cli_reporter.php cake/tests/lib/reporter/cake_text_reporter.php cake/tests/lib/templates/menu.php cake/tests/lib/templates/simpletest.php cake/tests/lib/test_manager.php cake/tests/test_app/controllers/tests_apps_controller.php cake/tests/test_app/libs/cache/test_app_cache.php cake/tests/test_app/libs/library.php cake/tests/test_app/libs/log/test_app_log.php cake/tests/test_app/plugins/test_plugin/config/load.php cake/tests/test_app/plugins/test_plugin/config/more.load.php cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php cake/tests/test_app/plugins/test_plugin/vendors/welcome.php cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php cake/tests/test_app/vendors/Test/MyTest.php cake/tests/test_app/vendors/Test/hello.php cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php cake/tests/test_app/vendors/shells/sample.php cake/tests/test_app/vendors/somename/some.name.php cake/tests/test_app/vendors/welcome.php cake/tests/test_app/views/elements/email/text/default.ctp cake/tests/test_app/views/layouts/default.ctp cake/tests/test_app/views/posts/test_nocache_tags.ctp lib/Cake/Cache/Engine/MemcacheEngine.php lib/Cake/Config/config.php lib/Cake/Console/Command/Task/ModelTask.php lib/Cake/Console/Templates/skel/webroot/css/cake.generic.css lib/Cake/Console/Templates/skel/webroot/test.php lib/Cake/Console/cake.bat lib/Cake/Controller/Component/CookieComponent.php lib/Cake/Log/CakeLog.php lib/Cake/Model/CakeSchema.php lib/Cake/Test/Case/Log/Engine/FileLog.php lib/Cake/Test/Case/View/Helper/FormHelperTest.php lib/Cake/Test/test_app/View/Emails/html/custom.ctp lib/Cake/Test/test_app/View/Emails/text/custom.ctp lib/Cake/TestSuite/templates/header.php lib/Cake/Utility/Sanitize.php lib/Cake/Utility/Validation.php lib/Cake/VERSION.txt lib/Cake/View/Helper/FormHelper.php
2011-06-23 19:48:06 +00:00
if (isset($this->_values[$names[0]])) {
$this->_values[$names[0]] = Set::remove($this->_values[$names[0]], $names[1]);
}
$this->_delete('[' . implode('][', $names) . ']');
}
/**
* Destroy current cookie
*
* You must use this method before any output is sent to the browser.
* Failure to do so will result in header already sent errors.
*
* @return void
2011-11-23 06:32:13 +00:00
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::destroy
*/
public function destroy() {
if (isset($_COOKIE[$this->name])) {
$this->_values = $this->_decrypt($_COOKIE[$this->name]);
}
foreach ($this->_values as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
unset($this->_values[$name][$key]);
$this->_delete("[$name][$key]");
}
}
unset($this->_values[$name]);
$this->_delete("[$name]");
}
}
/**
* Will allow overriding default encryption method.
*
* @param string $type Encryption method
2011-07-29 04:06:43 +00:00
* @return void
* @todo NOT IMPLEMENTED
*/
public function type($type = 'cipher') {
$this->_type = 'cipher';
}
/**
* Set the expire time for a session variable.
*
* Creates a new expire time for a session variable.
* $expire can be either integer Unix timestamp or a date string.
*
* Used by write()
* CookieComponent::write(string, string, boolean, 8400);
* CookieComponent::write(string, string, boolean, '5 Days');
*
* @param mixed $expires Can be either Unix timestamp, or date string
* @return integer Unix timestamp
*/
protected function _expire($expires = null) {
$now = time();
if (is_null($expires)) {
return $this->_expires;
}
$this->_reset = $this->_expires;
if ($expires == 0) {
return $this->_expires = 0;
}
if (is_integer($expires) || is_numeric($expires)) {
return $this->_expires = $now + intval($expires);
}
return $this->_expires = strtotime($expires, $now);
}
/**
* Set cookie
*
* @param string $name Name for cookie
* @param string $value Value for cookie
2011-07-29 04:06:43 +00:00
* @return void
*/
protected function _write($name, $value) {
$this->_setcookie(
2011-08-16 03:55:08 +00:00
$this->name . $name, $this->_encrypt($value),
$this->_expires, $this->path, $this->domain, $this->secure, $this->httpOnly
);
if (!is_null($this->_reset)) {
$this->_expires = $this->_reset;
$this->_reset = null;
}
}
/**
* Sets a cookie expire time to remove cookie value
*
* @param string $name Name of cookie
* @return void
*/
protected function _delete($name) {
$this->_setcookie(
2011-08-16 03:55:08 +00:00
$this->name . $name, '',
time() - 42000, $this->path, $this->domain, $this->secure, $this->httpOnly
);
}
/**
* Object wrapper for setcookie() so it can be mocked in unit tests.
*
* @todo Re-factor setting cookies into CakeResponse. Cookies are part
* of the HTTP response, and should be handled there.
*
* @param string $name Name of the cookie
2011-07-29 04:06:43 +00:00
* @param string $value Value of the cookie
* @param integer $expire Time the cookie expires in
* @param string $path Path the cookie applies to
* @param string $domain Domain the cookie is for.
* @param boolean $secure Is the cookie https?
* @param boolean $httpOnly Is the cookie available in the client?
* @return void
*/
protected function _setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly = false) {
setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
}
2011-11-23 06:32:13 +00:00
/**
* 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));
}
return $value;
}
/**
* Decrypts $value using public $type method in Security class
*
* @param array $values Values to decrypt
* @return string decrypted string
*/
protected function _decrypt($values) {
$decrypted = array();
$type = $this->_type;
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));
}
}
} 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));
}
}
}
return $decrypted;
}
/**
* Implode method to keep keys are multidimensional arrays
*
* @param array $array Map of key and values
* @return string A json encoded string.
*/
protected function _implode(array $array) {
return json_encode($array);
}
/**
* Explode method to return array from string set in CookieComponent::_implode()
* Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
*
* @param string $string A string containing JSON encoded data, or a bare string.
* @return array Map of key and values
*/
protected function _explode($string) {
$first = substr($string, 0, 1);
if ($first !== false && $first === '{' || $first === '[') {
$ret = json_decode($string, true);
return ($ret != null) ? $ret : $string;
}
$array = array();
foreach (explode(',', $string) as $pair) {
$key = explode('|', $pair);
if (!isset($key[1])) {
return $key[0];
}
$array[$key[0]] = $key[1];
}
return $array;
}
}