ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,134 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie\Attribute;
use Magento\Framework\Data\OptionSourceInterface;
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
class DurationDecorator implements OptionSourceInterface
{
public const PERIOD_DAYS = 'days';
public const PERIOD_HOURS = 'hours';
public const PERIOD_MINUTES = 'minutes';
public const PERIOD_SECONDS = 'seconds';
public const DURATION_PERIOD = 'duration-period';
public const PERIODS = [
self::PERIOD_DAYS => 86400,
self::PERIOD_HOURS => 3600,
self::PERIOD_MINUTES => 60,
];
/**
* Serialize two duration fields into one
*
* @param array $data
* @return array
*/
public function serializeParams(array $data): array
{
if ($data[CookieInterface::DURATION]) {
$duration = $data[CookieInterface::DURATION];
$period = $data[self::DURATION_PERIOD];
switch ($period) {
case self::PERIOD_DAYS:
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_DAYS] * $duration;
break;
case self::PERIOD_HOURS:
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_HOURS] * $duration;
break;
case self::PERIOD_MINUTES:
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_MINUTES] * $duration;
break;
case self::PERIOD_SECONDS:
$data[CookieInterface::DURATION] = $duration;
break;
}
}
unset($data[self::DURATION_PERIOD]);
return $data;
}
/**
* @param array $data
* @return array
*/
public function unserializeParams(array $data): array
{
return array_merge($data, $this->getValues(
(int) ($data[CookieInterface::DURATION] ?? 0)
));
}
/**
* Calculate values for 'duration' and 'duration-select'
*
* @param int $durationInSeconds
* @return array
*/
private function getValues(int $durationInSeconds): array
{
if ($durationInSeconds) {
foreach (self::PERIODS as $optionName => $periodInSeconds) {
if (! ($durationInSeconds % $periodInSeconds)) {
return [
CookieInterface::DURATION => $durationInSeconds / $periodInSeconds,
self::DURATION_PERIOD => $optionName,
];
}
}
return [
CookieInterface::DURATION => $durationInSeconds,
self::DURATION_PERIOD => self::PERIOD_SECONDS,
];
}
return [
CookieInterface::DURATION => 0,
self::DURATION_PERIOD => self::PERIOD_DAYS,
];
}
public function toOptionArray(): array
{
return [
[
'value' => self::PERIOD_SECONDS,
'label' => __('seconds')
],
[
'value' => self::PERIOD_MINUTES,
'label' => __('minutes')
],
[
'value' => self::PERIOD_HOURS,
'label' => __('hours')
],
[
'value' => self::PERIOD_DAYS,
'label' => __('days')
],
];
}
}
@@ -0,0 +1,96 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie\Attribute\Source;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
/**
* @since 1.0.0
*/
class CategoryKey extends EavAbstractSource
{
/**
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
*/
private $categoryRepository;
/**
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
/**
* @var array|null
*/
private $optionHash;
/**
* CategoryKey constructor.
*
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
*/
public function __construct(
CategoryRepositoryInterface $categoryRepository,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->categoryRepository = $categoryRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}
/**
* @return array
*/
public function getAllOptions(): array
{
$result = [];
foreach ($this->toOptionHash() as $key => $value) {
$result[] = [
'value' => $key,
'label' => $value,
];
}
return $result;
}
/**
* Return array of options
*
* @return array Format: array(array('<value>' => '<label>'), ...)
*/
public function toOptionHash(): array
{
if (null === $this->optionHash) {
$categories = $this->categoryRepository
->getList($this->searchCriteriaBuilder->create())
->getItems();
$this->optionHash = ['' => __('--Please Select--')];
foreach ($categories as $category) {
$this->optionHash[$category->getKey()] = $category->getName();
}
}
return $this->optionHash;
}
}
@@ -0,0 +1,48 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie\Attribute\Source;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
/**
* @since 1.0.0
*/
class Type extends EavAbstractSource
{
public const TYPE_FIRST = 'first';
public const TYPE_THIRD = 'third';
/**
* @return array
*/
public function getAllOptions(): array
{
return [
[
'value' => self::TYPE_FIRST,
'label' => __('1st Party')
],
[
'value' => self::TYPE_THIRD,
'label' => __('3rd Party')
],
];
}
}
@@ -0,0 +1,94 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie;
use Magento\Framework\Session\Config\ConfigInterface;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
use Magento\Framework\Stdlib\CookieManagerInterface;
/**
* @since 1.0.0
*/
class ClearRejected
{
/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/
private $cookieManager;
/**
* @var \Plumrocket\CookieConsent\Model\Cookie\IsAllowed
*/
private $isAllowed;
/**
* @var \Plumrocket\CookieConsent\Model\Cookie\GetSetCookiesNames
*/
private $getSetCookiesNames;
/**
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
*/
private $cookieMetadataFactory;
/**
* @var \Magento\Framework\Session\Config\ConfigInterface
*/
private $sessionConfig;
/**
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
* @param \Plumrocket\CookieConsent\Model\Cookie\IsAllowed $isAllowed
* @param \Plumrocket\CookieConsent\Model\Cookie\GetSetCookiesNames $getSetCookiesNames
* @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
*/
public function __construct(
CookieManagerInterface $cookieManager,
IsAllowed $isAllowed,
GetSetCookiesNames $getSetCookiesNames,
CookieMetadataFactory $cookieMetadataFactory,
ConfigInterface $sessionConfig
) {
$this->cookieManager = $cookieManager;
$this->isAllowed = $isAllowed;
$this->getSetCookiesNames = $getSetCookiesNames;
$this->cookieMetadataFactory = $cookieMetadataFactory;
$this->sessionConfig = $sessionConfig;
}
/**
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException
*/
public function execute()
{
$metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
$metadata->setPath('/');
$metadata->setSecure($this->sessionConfig->getCookieSecure());
$metadata->setHttpOnly($this->sessionConfig->getCookieHttpOnly());
foreach ($this->getSetCookiesNames->execute() as $cookieName) {
if (! $this->isAllowed->execute($cookieName)) {
$this->cookieManager->deleteCookie($cookieName, $metadata);
}
}
}
}
@@ -0,0 +1,86 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie\Config;
use Magento\Framework\Config\ConverterInterface;
use Magento\Framework\Data\Argument\Interpreter\Constant;
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type;
class Converter implements ConverterInterface
{
/**
* @var \Magento\Framework\Data\Argument\Interpreter\Constant
*/
private $constInterpreter;
public function __construct(Constant $constInterpreter)
{
$this->constInterpreter = $constInterpreter;
}
/**
* Convert dom node tree to array
*
* @param \DOMDocument $source
* @return array
*/
public function convert($source)
{
$output = [];
/** @var \DOMNodeList $cookies */
$cookies = $source->getElementsByTagName('cookie');
/** @var \DOMNode $cookie */
foreach ($cookies as $cookie) {
$cookieConfig = [];
foreach ($cookie->attributes as $attribute) {
$cookieConfig[$attribute->nodeName] = $attribute->nodeValue;
}
/** @var \DOMNode $childNode */
foreach ($cookie->childNodes as $childNode) {
if ($childNode->nodeType == XML_ELEMENT_NODE ||
($childNode->nodeType == XML_CDATA_SECTION_NODE ||
$childNode->nodeType == XML_TEXT_NODE && trim(
$childNode->nodeValue
) != '')
) {
if ($childNode->attributes->getNamedItem('type')
&& 'const' === $childNode->attributes->getNamedItem('type')->nodeValue
) {
$value = $this->constInterpreter->evaluate(['value' => $childNode->nodeValue]);
} else {
$value = $childNode->nodeValue;
}
$cookieConfig[$childNode->nodeName] = $value;
}
}
$output[$cookie->attributes->getNamedItem('name')->nodeValue] = $cookieConfig;
}
$output = array_map(static function ($cookie) {
$cookie['type'] = $cookie['type'] ?? Type::TYPE_FIRST;
$cookie['category_key'] = $cookie['category'];
unset($cookie['category']);
return $cookie;
}, $output);
return ['cookies' => $output];
}
}
@@ -0,0 +1,53 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
namespace Plumrocket\CookieConsent\Model\Cookie;
use Magento\Framework\Session\Config\ConfigInterface;
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
/**
* @since 1.0.0
*/
class Domain
{
/**
* @var \Magento\Framework\Session\Config\ConfigInterface
*/
private $sessionConfig;
/**
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
*/
public function __construct(ConfigInterface $sessionConfig)
{
$this->sessionConfig = $sessionConfig;
}
/**
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
* @return string
*/
public function getLabel(CookieInterface $cookie): string
{
if ($cookie->isFirstParty() && ! $cookie->getDomain()) {
return $this->sessionConfig->getCookieDomain();
}
return $cookie->getDomain();
}
}
@@ -0,0 +1,73 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
namespace Plumrocket\CookieConsent\Model\Cookie;
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
/**
* @since 1.0.0
*/
class Duration
{
public const ONE_YEAR = 31536000;
public const TWO_YEARS = 63072000;
public const SESSION = 0;
public const ONE_DAY = 86400;
public const FOR_LOCAL_STORAGE_COOKIE = 86400;
public const ONE_HOUR = 3600;
/**
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
* @return string
*/
public function getLabel(CookieInterface $cookie): string
{
return $this->durationToLabel($cookie->getDuration());
}
/**
* @param int $seconds
* @return string
*/
public function durationToLabel(int $seconds): string
{
if (self::SESSION === $seconds) {
return (string) __('Session');
}
if ($seconds >= self::ONE_DAY) {
$days = round($seconds / self::ONE_DAY);
if ($days > 1) {
return (string) __('%1 days', $days);
}
return (string) __('1 day');
}
if ($seconds >= self::ONE_HOUR) {
$hours = round($seconds / self::ONE_HOUR);
if ($hours > 1) {
return (string) __('%1 hours', $hours);
}
return (string) __('1 hour');
}
return (string) __('less than an hour');
}
}
@@ -0,0 +1,34 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie;
/**
* @since 1.0.0
*/
class GetSetCookiesNames
{
/**
* @return string[]
*/
public function execute(): array
{
return array_keys($_COOKIE); //phpcs:ignore -- magento cookie reader has not method for reading all cookies
}
}
@@ -0,0 +1,143 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie;
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
use Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface;
use Plumrocket\CookieConsent\Api\IsAllowedCookieInterface;
use Plumrocket\CookieConsent\Api\IsUserOptInInterface;
use Plumrocket\CookieConsent\Helper\Config;
use Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName;
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey;
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown;
/**
* @since 1.0.0
*/
class IsAllowed implements IsAllowedCookieInterface
{
/**
* System cookie always allowed
*
* @var array
*/
private $systemCookies;
/**
* @var \Plumrocket\CookieConsent\Api\CanManageCookieInterface
*/
private $canManageCookie;
/**
* @var \Plumrocket\CookieConsent\Helper\Config
*/
private $config;
/**
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey
*/
private $getCategoryKey;
/**
* @var \Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface
*/
private $isAllowedCategory;
/**
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown
*/
private $isKnownCookie;
/**
* @var \Plumrocket\CookieConsent\Api\IsUserOptInInterface
*/
private $isUserOptIn;
/**
* @var \Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName
*/
private $getTrueName;
/**
* @param \Plumrocket\CookieConsent\Api\CanManageCookieInterface $canManageCookie
* @param \Plumrocket\CookieConsent\Helper\Config $config
* @param \Plumrocket\CookieConsent\Api\IsUserOptInInterface $isUserOptIn
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey $getCategoryKey
* @param \Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface $isAllowedCategory
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown $isKnownCookie
* @param \Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName $getTrueName
* @param array $systemCookies
*/
public function __construct(
CanManageCookieInterface $canManageCookie,
Config $config,
IsUserOptInInterface $isUserOptIn,
GetCategoryKey $getCategoryKey,
IsAllowedCategoryInterface $isAllowedCategory,
IsKnown $isKnownCookie,
GetTrueName $getTrueName,
array $systemCookies = []
) {
$this->canManageCookie = $canManageCookie;
$this->config = $config;
$this->isUserOptIn = $isUserOptIn;
$this->getCategoryKey = $getCategoryKey;
$this->isAllowedCategory = $isAllowedCategory;
$this->isKnownCookie = $isKnownCookie;
$this->systemCookies = $systemCookies;
$this->getTrueName = $getTrueName;
}
/**
* This logic has js alternative in CookieRestriction.isAllowed
*
* @inheritDoc
*/
public function execute(string $name): bool
{
if (in_array($name, $this->systemCookies, true)) {
return true;
}
if (! $this->canManageCookie->execute()) {
return true;
}
$name = $this->getTrueName->execute($name);
if (! $this->isUserOptIn->execute()) {
if ($this->config->canUseCookieBeforeOptIn()) {
return true;
}
if ($this->isKnownCookie->execute($name)) {
return $this->isAllowedCategory->execute($this->getCategoryKey->execute($name));
}
return false;
}
if (! $this->isKnownCookie->execute($name)) {
return ! $this->config->canBlockUnknownCookie();
}
return $this->isAllowedCategory->execute($this->getCategoryKey->execute($name));
}
}
@@ -0,0 +1,165 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie;
use Magento\Framework\Config\DataInterface;
use Magento\Framework\Session\Config\ConfigInterface;
use Magento\Persistent\Helper\Data as PersistentHelper;
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
use Plumrocket\CookieConsent\Api\KnownCookieRegistryInterface;
use Plumrocket\CookieConsent\Helper\Config;
use Plumrocket\CookieConsent\Model\Category\Attribute\Source\CategoryKey;
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type;
use Plumrocket\CookieConsent\Model\User\SetCookieConsentId;
/**
* @since 1.0.0
*/
class KnownCookieRegistry implements KnownCookieRegistryInterface
{
/**
* @var array
*/
private $list;
/**
* @var \Magento\Framework\Session\Config\ConfigInterface
*/
private $sessionConfig;
/**
* @var \Plumrocket\CookieConsent\Helper\Config
*/
private $config;
/**
* @var \Magento\Persistent\Helper\Data
*/
private $persistentHelper;
/**
* @var \Magento\Framework\Config\DataInterface
*/
private $cookieConfig;
/**
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
* @param \Plumrocket\CookieConsent\Helper\Config $config
* @param \Magento\Persistent\Helper\Data $persistentHelper
* @param \Magento\Framework\Config\DataInterface $cookieConfig
* @param array $list
*/
public function __construct(
ConfigInterface $sessionConfig,
Config $config,
PersistentHelper $persistentHelper,
DataInterface $cookieConfig,
array $list = []
) {
$this->list = $list;
$this->sessionConfig = $sessionConfig;
$this->config = $config;
$this->persistentHelper = $persistentHelper;
$this->cookieConfig = $cookieConfig;
}
/**
* @inheritDoc
*/
public function getList(): array
{
$magentoCookieLifeTime = $this->sessionConfig->getCookieLifetime();
$persistentLifeTime = $this->persistentHelper->getLifeTime();
$dynamicCookie = [
GetUserConsentInterface::COOKIE_CONSENT_NAME => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => $this->config->getConsentExpiry(),
'description' => 'Keeps your cookie consent.'
],
SetCookieConsentId::COOKIE_CONSENT_ID => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => $this->config->getConsentExpiry(),
'description' => 'Keeps your cookie consent id.'
],
'form_key' => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => $magentoCookieLifeTime,
'description' => 'A security measure that appends a random ' .
'string to all form submissions to protect the data from ' .
'Cross-Site Request Forgery (CSRF).'
],
'X-Magento-Vary' => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => $magentoCookieLifeTime,
'description' => 'Configuration setting that improves performance ' .
'when using Varnish static content caching.'
],
'private_content_version' => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => $persistentLifeTime,
'description' => 'Appends a random, unique number and time to pages with customer content to prevent ' .
'them from being cached on the server.'
],
'persistent_shopping_cart' => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => $persistentLifeTime,
'description' => 'Stores the key (ID) of persistent cart to make it possible to restore the cart ' .
'for an anonymous shopper.'
],
// Magento Commerce only
'add_to_cart' => [
'category_key' => CategoryKey::KEY_STATISTICS,
'type' => Type::TYPE_FIRST,
'duration' => Duration::ONE_HOUR,
'description' => 'Used by Google Tag Manager. Captures the product SKU, name, price and quantity ' .
'removed from the cart, and makes the information available for future integration by third-party '.
'scripts.'
],
'mage-banners-cache-storage' => [
'category_key' => CategoryKey::KEY_NECESSARY,
'type' => Type::TYPE_FIRST,
'duration' => Duration::ONE_HOUR,
'description' => 'Stores banner content locally to improve performance.'
],
'remove_from_cart' => [
'category_key' => CategoryKey::KEY_STATISTICS,
'type' => Type::TYPE_FIRST,
'duration' => Duration::ONE_HOUR,
'description' => 'Used by Google Tag Manager. Captures the product SKU, name, price and quantity ' .
'added to the cart, and makes the information available for future integration by third-party ' .
'scripts.'
],
];
return array_merge($this->cookieConfig->get('cookies'), $this->list, $dynamicCookie);
}
}
@@ -0,0 +1,65 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie\Name;
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames;
/**
* If cookie name match some pattern if would be replaced to name in data base
*
* @since 1.1.1
*/
class GetTrueName
{
/**
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames
*/
private $getDynamicNames;
/**
* @var \Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex
*/
private $toRegex;
/**
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames $getDynamicNames
* @param \Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex $toRegex
*/
public function __construct(
GetDynamicNames $getDynamicNames,
ToRegex $toRegex
) {
$this->getDynamicNames = $getDynamicNames;
$this->toRegex = $toRegex;
}
public function execute(string $name): string
{
$patterns = $this->toRegex->execute($this->getDynamicNames->execute());
foreach ($patterns as $dynamicName => $pattern) {
if (preg_match("#$pattern#", $name)) {
return $dynamicName;
}
}
return $name;
}
}
@@ -0,0 +1,42 @@
<?php
/**
* Plumrocket Inc.
*
* NOTICE OF LICENSE
*
* This source file is subject to the End-user License Agreement
* that is available through the world-wide-web at this URL:
* http://wiki.plumrocket.net/wiki/EULA
* If you are unable to obtain it through the world-wide-web, please
* send an email to support@plumrocket.com so we can send you a copy immediately.
*
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie\Name;
/**
* Convert dynamic names to regex without borders /../
*
* @since 1.1.1
*/
class ToRegex
{
/**
* @param string[] $names
* @return string[]
*/
public function execute(array $names): array
{
$result = [];
foreach ($names as $name) {
$result[$name] = str_replace('*', '.*', $name);
}
return $result;
}
}
@@ -0,0 +1,37 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Cookie;
/**
* @since 1.8.2
*/
class ParentDomain
{
/**
* Get parent domain from subdomain.
*
* @param string $domain
* @return string
*/
public function resolve(string $domain): string
{
$countDots = substr_count($domain, '.');
if (1 === $countDots) {
return '';
}
if (2 === $countDots && preg_match('/\.\w\w\.\w\w/', $domain)) {
return '';
}
return preg_replace('/[^.]+/', '', $domain, 1);
}
}