ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\Integration\AdobeCommerce;
|
||||
|
||||
use Magento\Framework\Module\Manager as ModuleManager;
|
||||
use Plumrocket\Base\Api\ConfigUtilsInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 2.0.4
|
||||
*/
|
||||
class DataCollection
|
||||
{
|
||||
public const XML_PATH_CATEGORY_KEY = 'pr_cookie/integrations/adobe_commerce_data_collection/category';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Module\Manager
|
||||
*/
|
||||
private $moduleManager;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
|
||||
* @param \Magento\Framework\Module\Manager $moduleManager
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
ConfigUtilsInterface $configUtils,
|
||||
ModuleManager $moduleManager
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->configUtils = $configUtils;
|
||||
$this->moduleManager = $moduleManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
if (! $this->config->isModuleEnabled() || ! $this->getAssociatedCategoryKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->moduleManager->isEnabled('Magento_DataServices')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key of associated cookie category.
|
||||
*
|
||||
* @param int|string|null $store
|
||||
* @return string
|
||||
*/
|
||||
public function getAssociatedCategoryKey($store = null): string
|
||||
{
|
||||
return (string) $this->configUtils->getStoreConfig(self::XML_PATH_CATEGORY_KEY, $store);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?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\Integration;
|
||||
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Plumrocket\Base\Api\ConfigUtilsInterface;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 1.9.0
|
||||
*/
|
||||
class NoCookieYoutube
|
||||
{
|
||||
|
||||
public const XML_PATH_CATEGORY_KEY = 'pr_cookie/no_cookie_youtube/category';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $cookieCategoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $cookieCategoryRepository
|
||||
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
CategoryRepositoryInterface $cookieCategoryRepository,
|
||||
ConfigUtilsInterface $configUtils
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->cookieCategoryRepository = $cookieCategoryRepository;
|
||||
$this->configUtils = $configUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the no cookie mode enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
if (! $this->config->isModuleEnabled() || ! $this->getAssociatedCategoryKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$cookieCategory = $this->cookieCategoryRepository->get($this->getAssociatedCategoryKey());
|
||||
return $cookieCategory->isEnabled() && ! $cookieCategory->isEssential();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key of associated cookie category.
|
||||
*
|
||||
* @param int|string|null $store
|
||||
* @return string
|
||||
*/
|
||||
public function getAssociatedCategoryKey($store = null): string
|
||||
{
|
||||
return (string) $this->configUtils->getStoreConfig(self::XML_PATH_CATEGORY_KEY, $store);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace domain in YouTube iframes to no cookie mode.
|
||||
*
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
public function convertHtml(string $html): string
|
||||
{
|
||||
preg_match_all(
|
||||
'/(?:<iframe[^>]*?youtube\.com[^>]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/s',
|
||||
$html,
|
||||
$matches,
|
||||
PREG_PATTERN_ORDER
|
||||
);
|
||||
|
||||
foreach ($matches[0] as $iframe) {
|
||||
$iframeWithNoCookieDomain = str_replace(
|
||||
'youtube.com',
|
||||
'youtube-nocookie.com',
|
||||
$iframe,
|
||||
$domainReplaced
|
||||
);
|
||||
|
||||
if ($domainReplaced) {
|
||||
$html = str_replace($iframe, $iframeWithNoCookieDomain, $html);
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user