1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Core Cookie helper
29: *
30: * @category Mage
31: * @package Mage_Core
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Core_Helper_Cookie extends Mage_Core_Helper_Abstract
35: {
36: /**
37: * Cookie name for users who allowed cookie save
38: */
39: const IS_USER_ALLOWED_SAVE_COOKIE = 'user_allowed_save_cookie';
40:
41: /**
42: * Path to configuration, check is enable cookie restriction mode
43: */
44: const XML_PATH_COOKIE_RESTRICTION = 'web/cookie/cookie_restriction';
45:
46: /**
47: * Cookie restriction lifetime configuration path
48: */
49: const XML_PATH_COOKIE_RESTRICTION_LIFETIME = 'web/cookie/cookie_restriction_lifetime';
50:
51: /**
52: * Check if cookie restriction notice should be displayed
53: *
54: * @return bool
55: */
56: public function isUserNotAllowSaveCookie()
57: {
58: $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
59: return Mage::getStoreConfig(self::XML_PATH_COOKIE_RESTRICTION) &&
60: empty($acceptedSaveCookiesWebsites[Mage::app()->getWebsite()->getId()]);
61: }
62:
63: /**
64: * Return serialzed list of accepted save cookie website
65: *
66: * @return string
67: */
68: public function getAcceptedSaveCookiesWebsiteIds()
69: {
70: $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
71: $acceptedSaveCookiesWebsites[Mage::app()->getWebsite()->getId()] = 1;
72: return serialize($acceptedSaveCookiesWebsites);
73: }
74:
75: /**
76: * Get accepted save cookies websites
77: *
78: * @return array
79: */
80: protected function _getAcceptedSaveCookiesWebsites()
81: {
82: $serializedList = Mage::getSingleton('core/cookie')->get(self::IS_USER_ALLOWED_SAVE_COOKIE);
83: $unSerializedList = unserialize($serializedList);
84: return is_array($unSerializedList) ? $unSerializedList : array();
85: }
86:
87: /**
88: * Get cookie restriction lifetime (in seconds)
89: *
90: * @return int
91: */
92: public function getCookieRestrictionLifetime()
93: {
94: return (int)Mage::getStoreConfig(self::XML_PATH_COOKIE_RESTRICTION_LIFETIME);
95: }
96: }
97: