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,16 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
namespace Plumrocket\GlobalPrivacyControl\Api;
interface GeoTargetingInterface
{
/**
* @return bool
*/
public function isApplicable(): bool;
}
@@ -0,0 +1,15 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
namespace Plumrocket\GlobalPrivacyControl\Api;
interface IsGpcSignalHandledInterface
{
public const COOKIE_NAME = 'pr-gpc-signal-handled';
public function execute(): bool;
}
@@ -0,0 +1,88 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Block\Adminhtml\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Plumrocket\GeoIPLookup\Helper\Config;
class GeoTargetingMultiSelect extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @var \Plumrocket\GeoIPLookup\Helper\Config
*/
private $config;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Plumrocket\GeoIPLookup\Helper\Config $config
* @param array $data
*/
public function __construct(
Context $context,
Config $config,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
}
/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->getGeoIpRestrictionsNotice() . parent::_getElementHtml($element);
}
/**
* @param $withContainer
* @return \Magento\Framework\Phrase|string
*/
public function getGeoIpRestrictionsNotice($withContainer = true)
{
$message = '';
switch (true) {
case ! $this->config->isModuleEnabled():
$message = __(
'Geo Targeting is disabled. ' .
'For more accurate geolocation detection, please enable and configure the IP Geolocation Lookup extension following the <a target="_blank" href="%1">guide</a>.',
'https://plumrocket.com/docs/magento-ip-geolocation-lookup/v2/configuration'
);
break;
case ! $this->config->getEnableMethodsNumber():
$message = __(
'Please enable at least one IP Geolocation Lookup database to use Geo Targeting. ' .
'Click <a target="_blank" href="%1">here</a> for configuration guide.',
'https://plumrocket.com/docs/magento-ip-geolocation-lookup/v2/configuration'
);
break;
}
return (bool) $withContainer && ! empty($message)
? $this->getPreparedNoticeHtml($message)
: $message;
}
/**
* @param $message
* @return string
*/
public function getPreparedNoticeHtml($message): string
{
$style = 'style="margin: 25px 5px;color: #eb5202;background: none;font-size:14px"';
return "<div $style><div><i>$message</i></div></div>";
}
}
@@ -0,0 +1,108 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Block\Adminhtml\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Helper\SecureHtmlRenderer;
use Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager;
use Psr\Log\LoggerInterface;
class WellKnownPreview extends Field
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager
*/
private $wellKnownFileManager;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager $wellKnownFileManager
* @param \Psr\Log\LoggerInterface $logger
* @param array $data
*/
public function __construct(
Context $context,
ObjectManagerInterface $objectManager,
ProductMetadataInterface $productMetadata,
WellKnownFileManager $wellKnownFileManager,
LoggerInterface $logger,
array $data = []
) {
/**
* @TODO Refactor when leave support of Magento 2.3.7 and less
*/
if (version_compare($productMetadata->getVersion(), '2.4.0', '<')) {
parent::__construct($context, $data);
} else {
parent::__construct($context, $data, $objectManager->get(SecureHtmlRenderer::class));
}
$this->wellKnownFileManager = $wellKnownFileManager;
$this->logger = $logger;
}
/**
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element): string
{
try {
return $this->renderPre(
$this->wellKnownFileManager->getContent()
);
} catch (\Exception $e) {
$this->logger->error('[Plumrocket_GlobalPrivacyControl] Unable to read the .well-known file content: ' . $e->getMessage(), ['exception' => $e]);
return $this->renderNotice(
__('Unable to load file content. Please check the logs for more details.')
);
}
}
/**
* Render formatted <pre> block with code.
*
* @param string $content
* @return string
*/
private function renderPre(string $content): string
{
return '<pre class="code-box">' . $content . '</pre>';
}
/**
* Render styled error notice.
*
* @param \Magento\Framework\Phrase|string $message
* @return string
*/
private function renderNotice($message): string
{
return <<<HTML
<div class="pr_notice pr_notice--error">
<div class="pr-notice__content-wrapper">
<div class="pr-notice__content">{$message}</div>
</div>
</div>
HTML;
}
}
@@ -0,0 +1,163 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Block;
use Magento\Framework\Code\Minifier\Adapter\Js\JShrink;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Helper\SecureHtmlRenderer;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
use Plumrocket\GlobalPrivacyControl\ViewModel\Geotargeting as GeotargetingViewModel;
class ComponentInit extends Template
{
public const SCRIPT_TAG_REPLACEMENT = 'pr-global-privacy-control-head-script';
/**
* @var \Magento\Framework\Code\Minifier\Adapter\Js\JShrink
*/
private $jsMinifier;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
*/
private $config;
/**
* @var \Plumrocket\GlobalPrivacyControl\ViewModel\Geotargeting
*/
private $geotargetingViewModel;
/**
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer|mixed|null
*/
private $secureHtmlRenderer;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Code\Minifier\Adapter\Js\JShrink $jsMinifier
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config $config
* @param \Plumrocket\GlobalPrivacyControl\ViewModel\Geotargeting $geotargetingViewModel
* @param array $data
*/
public function __construct(
Context $context,
JShrink $jsMinifier,
SerializerInterface $serializer,
ObjectManagerInterface $objectManager,
Config $config,
GeotargetingViewModel $geotargetingViewModel,
array $data = []
) {
parent::__construct($context, $data);
$this->jsMinifier = $jsMinifier;
$this->serializer = $serializer;
$this->config = $config;
$this->geotargetingViewModel = $geotargetingViewModel;
/**
* @TODO Refactor when leave support of Magento 2.3.7 and less
*/
$this->secureHtmlRenderer = class_exists(SecureHtmlRenderer::class)
? $objectManager->get(SecureHtmlRenderer::class)
: null;
}
/**
* @return array
*/
public function getConfig(): array
{
return [
'canProcessSignal' => $this->config->isModuleEnabled(),
'isGeotargetingEnabled' => $this->geotargetingViewModel->isEnabled(),
'geotargetingApiEndpoint' => $this->geotargetingViewModel->getApplicabilityUrl()
];
}
/**
* @return string
*/
public function getSerializedConfig(): string
{
return $this->serializer->serialize($this->getConfig());
}
/**
* @return array|string|string[]
*/
protected function _toHtml()
{
$html = parent::_toHtml();
preg_match_all('/<script[\s\S]*?\/script>/', $html, $scriptTags);
$scriptTags = array_shift($scriptTags);
foreach ($scriptTags as $scriptTag) {
try {
$modifiedScriptTag = $this->modifyScriptTag($scriptTag);
} catch (\Exception $e) {
continue;
}
$html = str_replace($scriptTag, $modifiedScriptTag, $html);
}
return $html;
}
/**
* Modify script tag to prevent from being moved to footer
*
* @param string $scriptTag
* @return string
* @throws \Exception
*/
private function modifyScriptTag(string $scriptTag): string
{
/**
* @TODO Refactor when leave support of Magento 2.3.7 and less
*/
if (! $this->secureHtmlRenderer) {
preg_match('#<script[\s\S]*?>([^`]*?)<\/script>#', $scriptTag, $matches);
if(isset($matches[1])) {
$originalTagContent = $matches[1];
$minifiedContent = $this->jsMinifier->minify($originalTagContent);
$scriptTag = str_replace($originalTagContent, $minifiedContent, $scriptTag);
}
return str_replace(
['<script', '/script>'],
['<' . self::SCRIPT_TAG_REPLACEMENT, '/'.self::SCRIPT_TAG_REPLACEMENT.'>'],
$scriptTag
);
}
$doc = new \DOMDocument();
$doc->loadHTML($scriptTag);
$scriptNode = $doc->getElementsByTagName('script')->item(0);
$tagAttributes = array_column(iterator_to_array($scriptNode->attributes), 'nodeValue', 'name');
$tagContent = $this->jsMinifier->minify($scriptNode->textContent);
return $this->secureHtmlRenderer->renderTag(self::SCRIPT_TAG_REPLACEMENT, $tagAttributes, $tagContent, false);
}
}
@@ -0,0 +1,58 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Helper;
use Magento\Framework\App\Helper\Context;
use Plumrocket\Base\Api\ConfigUtilsInterface;
use Plumrocket\Base\Helper\ConfigUtils;
class Config extends ConfigUtils
{
public const XML_PATH_IS_MODULE_ENABLED = 'pr_gpc/general/enabled';
public const XML_PATH_WELL_KNOWN_LAST_UPDATE_DATE = 'pr_gpc/well_known/last_update';
/**
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
*/
private $configUtils;
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
*/
public function __construct(
Context $context,
ConfigUtilsInterface $configUtils
) {
parent::__construct($context);
$this->configUtils = $configUtils;
}
/**
* @param $store
* @param $scope
* @return bool
*/
public function isModuleEnabled($store = null, $scope = null): bool
{
return $this->configUtils->isSetFlag(self::XML_PATH_IS_MODULE_ENABLED, $store, $scope);
}
/**
* @param null $store
* @param null $scope
* @return string|null
*/
public function getWellKnownLastUpdateDate($store = null, $scope = null): ?string
{
return $this->getConfig(self::XML_PATH_WELL_KNOWN_LAST_UPDATE_DATE, $store, $scope);
}
}
@@ -0,0 +1,82 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Helper\Config;
use Magento\Framework\App\Helper\Context;
use Plumrocket\Base\Api\ConfigUtilsInterface;
use Plumrocket\Base\Helper\ConfigUtils;
use Plumrocket\GeoIPLookup\Api\LocationsListInterface;
class Geotargeting extends ConfigUtils
{
public const XML_PATH_TARGET_COUNTRIES = 'pr_gpc/general/geo_targeting';
public const XML_PATH_TARGET_US_STATES = 'pr_gpc/general/states_geo_targeting';
/**
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
*/
private $configUtils;
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
*/
public function __construct(
Context $context,
ConfigUtilsInterface $configUtils
) {
parent::__construct($context);
$this->configUtils = $configUtils;
}
/**
* @param $store
* @param $scope
* @return bool
*/
public function isEnabled($store = null, $scope = null): bool
{
return ! in_array(LocationsListInterface::ALL, $this->getTargetCountries($store, $scope), true);
}
/**
* @param $store
* @param $scope
* @return array
*/
public function getTargetCountries($store = null, $scope = null): array
{
$targetingConfig = (string) $this->configUtils->getConfig(self::XML_PATH_TARGET_COUNTRIES, $store, $scope);
return $this->configUtils->prepareMultiselectValue($targetingConfig);
}
/**
* @param $store
* @param $scope
* @return array
*/
public function getTargetUsStates($store = null, $scope = null): array
{
if (! in_array(LocationsListInterface::COUNTRY_CODE_USA, $this->getTargetCountries($store, $scope), true)) {
return [];
}
$targetingConfig = $this->configUtils->prepareMultiselectValue(
(string) $this->configUtils->getConfig(self::XML_PATH_TARGET_US_STATES, $store, $scope)
);
if (in_array(LocationsListInterface::ALL, $targetingConfig, true)) {
return [];
}
return $targetingConfig;
}
}
@@ -0,0 +1,80 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Helper\Config;
use Magento\Cms\Model\Template\FilterProvider;
use Magento\Framework\App\Helper\Context;
use Plumrocket\Base\Api\ConfigUtilsInterface;
use Plumrocket\Base\Helper\ConfigUtils;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
class OptOutNotification extends ConfigUtils
{
private const XML_PATH_OPT_OUT_NOTIFICATION_ENABLED = 'pr_gpc/opt_out_notification/enabled';
private const XML_PATH_OPT_OUT_NOTIFICATION_CONTENT = 'pr_gpc/opt_out_notification/text';
/**
* @var \Magento\Cms\Model\Template\FilterProvider
*/
private $filterProvider;
/**
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
*/
private $configUtils;
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
*/
private $config;
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config $config
*/
public function __construct(
Context $context,
FilterProvider $filterProvider,
ConfigUtilsInterface $configUtils,
Config $config
) {
parent::__construct($context);
$this->filterProvider = $filterProvider;
$this->configUtils = $configUtils;
$this->config = $config;
}
/**
* @param $store
* @param $scope
* @return bool
*/
public function isEnabled($store = null, $scope = null): bool
{
if (! $this->config->isModuleEnabled()) {
return false;
}
return $this->configUtils->isSetFlag(self::XML_PATH_OPT_OUT_NOTIFICATION_ENABLED, $store, $scope);
}
/**
* @return string
*/
public function getNotificationText($store = null, $scope = null): string
{
$text = $this->getConfig(self::XML_PATH_OPT_OUT_NOTIFICATION_CONTENT, $store, $scope);
return $this->filterProvider->getBlockFilter()
->filter($text);
}
}
@@ -0,0 +1,82 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Model;
use Magento\Framework\Exception\LocalizedException;
use Plumrocket\GeoIPLookup\Api\GeoLocationValidatorInterface;
use Plumrocket\GlobalPrivacyControl\Api\GeoTargetingInterface;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
use Plumrocket\GlobalPrivacyControl\Helper\Config\Geotargeting as GeotargetingConfig;
use Psr\Log\LoggerInterface;
class Geotargeting implements GeoTargetingInterface
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
*/
private $config;
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config\Geotargeting
*/
private $geotargetingConfig;
/**
* @var \Plumrocket\GeoIPLookup\Api\GeoLocationValidatorInterface
*/
private $geoLocationValidator;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config $config
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config\Geotargeting $geotargetingConfig
* @param \Plumrocket\GeoIPLookup\Api\GeoLocationValidatorInterface $geoLocationValidator
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
Config $config,
GeotargetingConfig $geotargetingConfig,
GeoLocationValidatorInterface $geoLocationValidator,
LoggerInterface $logger
) {
$this->config = $config;
$this->geotargetingConfig = $geotargetingConfig;
$this->geoLocationValidator = $geoLocationValidator;
$this->logger = $logger;
}
/**
* @return bool
*/
public function isApplicable(): bool
{
if (! $this->config->isModuleEnabled()) {
return false;
}
if (! $this->geotargetingConfig->isEnabled()) {
return true;
}
try {
return $this->geoLocationValidator->validateByMergedOptions(
$this->geotargetingConfig->getTargetCountries(),
$this->geotargetingConfig->getTargetUsStates()
);
} catch (LocalizedException $e) {
$this->logger->critical($e->getMessage());
return true;
}
}
}
@@ -0,0 +1,48 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Model;
use Magento\Framework\Stdlib\BooleanUtils;
use Magento\Framework\Stdlib\Cookie\CookieReaderInterface;
use Plumrocket\GlobalPrivacyControl\Api\IsGpcSignalHandledInterface;
class IsGpcSignalHandled implements IsGpcSignalHandledInterface
{
/**
* @var \Magento\Framework\Stdlib\BooleanUtils
*/
private $booleanUtils;
/**
* @var \Magento\Framework\Stdlib\Cookie\CookieReaderInterface
*/
private $cookieReader;
/**
* @param \Magento\Framework\Stdlib\BooleanUtils $booleanUtils
* @param \Magento\Framework\Stdlib\Cookie\CookieReaderInterface $cookieReader
*/
public function __construct(
BooleanUtils $booleanUtils,
CookieReaderInterface $cookieReader
) {
$this->booleanUtils = $booleanUtils;
$this->cookieReader = $cookieReader;
}
/**
* @return bool
*/
public function execute(): bool
{
$status = $this->cookieReader->getCookie(self::COOKIE_NAME);
return $status && $this->booleanUtils->toBoolean($status);
}
}
@@ -0,0 +1,76 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
use Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager;
use Psr\Log\LoggerInterface;
use Magento\Framework\Message\ManagerInterface;
class GenerateWellKnownFile implements ObserverInterface
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager
*/
private $wellKnownFileManager;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @var \Magento\Framework\Message\ManagerInterface
*/
private $messageManager;
/**
* @param \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager $wellKnownFileManager
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Message\ManagerInterface $messageManager
*/
public function __construct(
WellKnownFileManager $wellKnownFileManager,
LoggerInterface $logger,
ManagerInterface $messageManager
) {
$this->wellKnownFileManager = $wellKnownFileManager;
$this->logger = $logger;
$this->messageManager = $messageManager;
}
/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(Observer $observer): void
{
$changedPaths = $observer->getData('changed_paths');
$triggerPaths = [
Config::XML_PATH_WELL_KNOWN_LAST_UPDATE_DATE,
Config::XML_PATH_IS_MODULE_ENABLED,
];
if (! array_intersect($triggerPaths, $changedPaths)) {
return;
}
try {
$this->wellKnownFileManager->create();
} catch (\Throwable $e) {
$this->logger->error('[Plumrocket_GlobalPrivacyControl] Failed to update .well-known file: ' . $e->getMessage(), ['exception' => $e]);
$this->messageManager->addErrorMessage(
__('Something went wrong while updating the .well-known file: %1', $e->getMessage())
);
}
}
}
@@ -0,0 +1,47 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Plugin\Html;
use Magento\Framework\App\Response\Http;
use Plumrocket\GlobalPrivacyControl\Block\ComponentInit as ComponentInitBlock;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
class ReplaceComponentInitScriptPlaceholderPlugin
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
*/
private $config;
/**
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config $config
*/
public function __construct(
Config $config
) {
$this->config = $config;
}
/**
* @param \Magento\Framework\App\Response\Http $subject
* @return void
*/
public function beforeSendResponse(Http $subject): void
{
$content = $subject->getContent();
if(! is_string($content) || strpos($content, ComponentInitBlock::SCRIPT_TAG_REPLACEMENT) === false) {
return;
}
$subject->setContent(
str_replace(ComponentInitBlock::SCRIPT_TAG_REPLACEMENT, 'script', $content)
);
}
}
@@ -0,0 +1 @@
Plumrocket GlobalPrivacyControl Extension for M2
@@ -0,0 +1,118 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Service;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\Filesystem\DirectoryList as DirectoryListApi;
use Magento\Framework\Config\ConfigOptionsListConstants;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Driver\File as FileDriver;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
class WellKnownFileManager
{
private const FILE_NAME = 'gpc.json';
/**
* @var \Magento\Framework\App\DeploymentConfig
*/
private $deploymentConfig;
/**
* @var \Magento\Framework\Filesystem\DirectoryList
*/
private $directoryList;
/**
* @var \Magento\Framework\Filesystem\Driver\File
*/
private $fileDriver;
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
*/
private $config;
/**
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
* @param \Magento\Framework\Filesystem\DirectoryList $directoryList
* @param \Magento\Framework\Filesystem\Driver\File $fileDriver
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config $config
*/
public function __construct(
DeploymentConfig $deploymentConfig,
DirectoryList $directoryList,
FileDriver $fileDriver,
Config $config
) {
$this->deploymentConfig = $deploymentConfig;
$this->directoryList = $directoryList;
$this->fileDriver = $fileDriver;
$this->config = $config;
}
/**
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\RuntimeException
*/
public function create(): void
{
$filePath = $this->getFilePath();
$directoryPath = dirname($filePath);
if (! $this->fileDriver->isExists($directoryPath)) {
$this->fileDriver->createDirectory($directoryPath);
}
$jsonData = json_encode(
[
'gpc' => $this->config->isModuleEnabled(),
'version' => '1.0',
'created' => $this->config->getWellKnownLastUpdateDate()
],
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
$this->fileDriver->filePutContents($filePath, $jsonData);
}
/**
* @return string
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\RuntimeException
*/
public function getContent(): string
{
$filePath = $this->getFilePath();
if (! $this->fileDriver->isExists($filePath)) {
throw new LocalizedException(
__("The .well-known file was not found.")
);
}
return $this->fileDriver->fileGetContents($filePath);
}
/**
* @return string
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\RuntimeException
*/
private function getFilePath(): string
{
$rootPath = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB)
? $this->directoryList->getPath(DirectoryListApi::PUB)
: $this->directoryList->getRoot();
return $rootPath . DIRECTORY_SEPARATOR . '.well-known' . DIRECTORY_SEPARATOR . self::FILE_NAME;
}
}
@@ -0,0 +1,101 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Setup\Patch\Data;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Cache\Manager as CacheManager;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
use Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager;
use Psr\Log\LoggerInterface;
class CreateWellKnownFIle implements DataPatchInterface
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager
*/
private $wellKnownFileManager;
/**
* @var \Magento\Framework\App\Config\Storage\WriterInterface
*/
private $configWriter;
/**
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
private $dateTime;
/**
* @var \Magento\Framework\App\Cache\Manager
*/
private $cacheManager;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @param \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager $wellKnownFileManager
* @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
* @param \Magento\Framework\App\Cache\Manager $cacheManager
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
WellKnownFileManager $wellKnownFileManager,
WriterInterface $configWriter,
DateTime $dateTime,
CacheManager $cacheManager,
LoggerInterface $logger
) {
$this->wellKnownFileManager = $wellKnownFileManager;
$this->configWriter = $configWriter;
$this->dateTime = $dateTime;
$this->cacheManager = $cacheManager;
$this->logger = $logger;
}
/**
* @inheirtDoc
*/
public function apply(): CreateWellKnownFIle
{
$date = $this->dateTime->gmtDate('Y-m-d');
$this->configWriter->save(Config::XML_PATH_WELL_KNOWN_LAST_UPDATE_DATE, $date);
$this->cacheManager->clean(['config']);
try {
$this->wellKnownFileManager->create();
} catch (\Throwable $e) {
$this->logger->error('[Plumrocket_GlobalPrivacyControl] Failed to update .well-known file: ' . $e->getMessage(), ['exception' => $e]);
}
return $this;
}
/**
* @inheirtDoc
*/
public static function getDependencies(): array
{
return [];
}
/**
* @inheirtDoc
*/
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,55 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\ViewModel;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Plumrocket\GlobalPrivacyControl\Helper\Config\Geotargeting as GeotargetingConfig;
class Geotargeting implements ArgumentInterface
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config\Geotargeting
*/
private $geotargetingConfig;
/**
* @var \Magento\Framework\UrlInterface
*/
private $urlBuilder;
/**
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config\Geotargeting $geotargetingConfig
* @param \Magento\Framework\UrlInterface $urlBuilder
*/
public function __construct(
GeotargetingConfig $geotargetingConfig,
UrlInterface $urlBuilder
) {
$this->geotargetingConfig = $geotargetingConfig;
$this->urlBuilder = $urlBuilder;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->geotargetingConfig->isEnabled();
}
/**
* @return string
*/
public function getApplicabilityUrl(): string
{
return rtrim($this->urlBuilder->getBaseUrl(), '/') . '/rest/V1/pr-global-privacy-control/geo-targeting/is-applicable';
}
}
@@ -0,0 +1,63 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\ViewModel;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Plumrocket\GlobalPrivacyControl\Helper\Config\OptOutNotification as OptOutNotificationConfig;
class OptOutNotification implements ArgumentInterface
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config\OptOutNotification
*/
private $optOutNotificationConfig;
/**
* @var \Magento\Framework\Escaper
*/
private $escaper;
/**
* @param \Plumrocket\GlobalPrivacyControl\Helper\Config\OptOutNotification $optOutNotificationConfig
* @param \Magento\Framework\Escaper $escaper
*/
public function __construct(
OptOutNotificationConfig $optOutNotificationConfig,
Escaper $escaper
) {
$this->optOutNotificationConfig = $optOutNotificationConfig;
$this->escaper = $escaper;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->optOutNotificationConfig->isEnabled();
}
/**
* @param bool $escapeForJs
* @return string
*/
public function getNotificationHtml(bool $escapeForJs = false): string
{
$html = <<<HTML
<div class="pr-gpc-notification-wrap">
{$this->optOutNotificationConfig->getNotificationText()}
</div>
HTML;
return $escapeForJs
? $this->escaper->escapeJs($html)
: $html;
}
}
@@ -0,0 +1,20 @@
{
"name": "plumrocket/module-global-privacy-control",
"description": "Plumrocket Global Privacy Control Extension for Magento 2",
"require": {
"php": ">=7.1",
"plumrocket/module-plumbase": ">=2.11.5",
"plumrocket/module-geo-ip-lookup": ">=2.0.4",
"plumrocket/module-extended-admin-ui": ">=1.0.7"
},
"type": "magento2-module",
"version": "1.0.3",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Plumrocket\\GlobalPrivacyControl\\": ""
}
}
}
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Plumrocket_GlobalPrivacyControl::configuration" title="Global Privacy Control (GPC) Section" />
</resource>
</resource>
</resource>
</resource>
</resources>
</acl>
</config>
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="admin_system_config_changed_section_pr_gpc">
<observer name="pr_gpc_generate_well_known_file" instance="Plumrocket\GlobalPrivacyControl\Observer\GenerateWellKnownFile"/>
</event>
</config>
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Menu/etc/menu.xsd">
<menu>
<add module="Plumrocket_GlobalPrivacyControl" parent="Plumrocket_Base::elements" id="Plumrocket_GlobalPrivacyControl::pr_menu" resource="Plumrocket_GlobalPrivacyControl::pr_menu" title="Global Privacy Control (GPC)" translate="title" sortOrder="3940412"/>
<add module="Plumrocket_GlobalPrivacyControl" parent="Plumrocket_GlobalPrivacyControl::pr_menu" id="Plumrocket_GlobalPrivacyControl::configuration" resource="Plumrocket_GlobalPrivacyControl::configuration" action="adminhtml/system_config/edit/section/pr_gpc" title="Configuration" translate="title" sortOrder="10"/>
</menu>
</config>
@@ -0,0 +1,107 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="pr_gpc" translate="label" type="text" sortOrder="3940412" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Global Privacy Control (GPC)</label>
<tab>plumrocket</tab>
<resource>Plumrocket_GlobalPrivacyControl::configuration</resource>
<group id="toolbox" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Plumrocket\Base\Block\Adminhtml\System\Config\Form\ToolbarFieldset</frontend_model>
<field id="version" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Plumrocket\Base\Block\Adminhtml\System\Config\Form\Version</frontend_model>
<attribute type="pr_extension_name">GlobalPrivacyControl</attribute>
</field>
</group>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<attribute type="expanded">1</attribute>
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable Extension</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Enable automatic GPC detection.</comment>
</field>
<field id="serial" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<frontend_model>Plumrocket\Base\Block\Adminhtml\System\Config\Form\Serial</frontend_model>
<label>Serial Key</label>
<attribute type="pr_extension_name">GlobalPrivacyControl</attribute>
</field>
<field id="geo_targeting" translate="label comment" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Geo Targeting</label>
<source_model>Plumrocket\GeoIPLookup\Model\System\Config\Source\GeoTargeting</source_model>
<frontend_model>Plumrocket\GlobalPrivacyControl\Block\Adminhtml\System\Config\GeoTargetingMultiSelect</frontend_model>
<frontend_class>geoip-select-with-chosen prgdpr-coutry</frontend_class>
<comment>Limit GPC functionality to visitors from specified regions.</comment>
</field>
<field id="states_geo_targeting" translate="label comment" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>U.S. States</label>
<source_model>Plumrocket\GeoIPLookup\Model\System\Config\Source\GeoTargetingStates</source_model>
<frontend_class>geoip-select-with-chosen prgdpr-ccpa</frontend_class>
</field>
</group>
<group id="cookie_consent_management" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Cookie Consent Management</label>
<attribute type="expanded">1</attribute>
<field id="addon_required_notice" type="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Plumrocket\ExtendedAdminUi\Block\Adminhtml\System\Config\Form\Notice</frontend_model>
<attribute type="pr_notice__level">note addon-required-notice</attribute>
<attribute type="pr_notice__text">
<![CDATA[<b>Cookie Consent Pro Extension Required.</b><br>Please make sure the Cookie Consent Pro extension is installed correctly.]]>
</attribute>
</field>
</group>
<group id="do_not_sell" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Do Not Sell or Share Request Management</label>
<attribute type="expanded">1</attribute>
<field id="addon_required_notice" type="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Plumrocket\ExtendedAdminUi\Block\Adminhtml\System\Config\Form\Notice</frontend_model>
<attribute type="pr_notice__level">note addon-required-notice</attribute>
<attribute type="pr_notice__text">
<![CDATA[<div class="pr-gpc-notice-intro"><p><strong>US Privacy Laws Pro Extension Required.</strong> To recognize GPC signals for "Do Not Sell or Share My Personal Information" requests, the US Privacy Laws Pro extension by Plumrocket must be installed. Upgrade today for full compliance – <strong>pay only the difference</strong> with coupon code.</p></div><div class="pr-gpc-coupon-wrapper"><div class="pr-gpc-coupon">USPrivacyUpgrade</div></div><a href="https://plumrocket.com/magento-us-privacy-laws" target="_blank">Get US Privacy Laws Extension →</a>]]>
</attribute>
</field>
</group>
<group id="opt_out_notification" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>GPC Opt-Out Notification</label>
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>When enabled, a notification will appear to users on their initial visit, confirming that the opt-out preference signal has been honored. This aligns with privacy laws like CPRA and similar regulations in other regions, which recommend honoring user privacy preferences.</comment>
</field>
<field id="text" translate="label comment" type="editor" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Notification</label>
<frontend_model>Plumrocket\ExtendedAdminUi\Block\Adminhtml\System\Config\Form\Editor</frontend_model>
<comment>Enter the notification text to display to your visitors.</comment>
</field>
</group>
<group id="well_known" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0">
<label>GPC .well-known Settings</label>
<attribute type="expanded">1</attribute>
<field id="last_update" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Last Update Date</label>
<comment>Enter the date of the last update to the GPC settings. Please use the format YYYY-MM-DD. By default, this field is set to the date when the extension was installed.</comment>
<validate>required-entry validate-date</validate>
</field>
<field id="preview" translate="label comment" type="label" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Preview of .well-known/gpc.json File</label>
<comment>This is the content of the .well-known/gpc.json file, which informs browsers and other tools that your site supports Global Privacy Control (GPC). The file includes the GPC status and the last update date.</comment>
<frontend_model>Plumrocket\GlobalPrivacyControl\Block\Adminhtml\System\Config\WellKnownPreview</frontend_model>
</field>
</group>
</section>
</system>
</config>
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<pr_gpc>
<general>
<enabled>0</enabled>
<geo_targeting>eu,AU,CA,JP,NZ,GB,US</geo_targeting>
<states_geo_targeting>California,Colorado,Connecticut,Utah,Virginia</states_geo_targeting>
</general>
<opt_out_notification>
<enabled>1</enabled>
<text><![CDATA[<h2>Your Opt-Out Preferences Honored</h2>
<p>Your browser's privacy preference (GPC) has been detected.</p>
<p class="pr-gpc-text-with-icon"><img src="{{view url='Plumrocket_GlobalPrivacyControl::images/check_circle.png'}}" width="18" height="18" alt="GPC Icon" /> Non-essential cookies have been disabled on our website.</p>]]></text>
</opt_out_notification>
</pr_gpc>
</default>
</config>
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Plumrocket\GlobalPrivacyControl\Api\GeoTargetingInterface" type="Plumrocket\GlobalPrivacyControl\Model\Geotargeting" />
<preference for="Plumrocket\GlobalPrivacyControl\Api\IsGpcSignalHandledInterface" type="Plumrocket\GlobalPrivacyControl\Model\IsGpcSignalHandled" />
</config>
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!--
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license End-user License Agreement
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\Response\Http">
<plugin name="pr-gpc-replace-component-init-script-placeholder" type="Plumrocket\GlobalPrivacyControl\Plugin\Html\ReplaceComponentInitScriptPlaceholderPlugin"/>
</type>
</config>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Plumrocket_GlobalPrivacyControl"/>
</config>
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<cookies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Plumrocket_CookieConsent:etc/pr-cookies.xsd">
<cookie name="pr-gpc-notification-shown" category="necessary">
<duration xsi:type="const">Plumrocket\CookieConsent\Model\Cookie\Duration::SESSION</duration>
<description>Stores whether the GPC opt-out notification was shown to and closed by the user.</description>
</cookie>
<cookie name="pr-gpc-signal-handled" category="necessary">
<duration xsi:type="const">Plumrocket\CookieConsent\Model\Cookie\Duration::SESSION</duration>
<description>Stores whether the Global Privacy Control (GPC) signal has been detected on the front end and the associated handling logic has been executed for the current user.</description>
</cookie>
</cookies>
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<extensions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Plumrocket_Base:etc/pr_extensions.xsd">
<extension name="GlobalPrivacyControl"
title="Global Privacy Control (GPC)"
config_section="pr_gpc"
is_enabled_path="pr_gpc/general/enabled"
documentation="https://plumrocket.com/docs/magento-global-privacy-control/v1"
>
<customer key="18771d78aa85ca47851fca7fdf3dd545bad4a02358"/>
</extension>
</extensions>
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route method="POST" url="/V1/pr-global-privacy-control/geo-targeting/is-applicable">
<service class="Plumrocket\GlobalPrivacyControl\Api\GeoTargetingInterface" method="isApplicable"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
@@ -0,0 +1,10 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Plumrocket_GlobalPrivacyControl', __DIR__);
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="pr_system_config_element_notice"/>
<head>
<script src="Plumrocket_GlobalPrivacyControl::js/system_config_edit.js" />
<css src="Plumrocket_ExtendedAdminUi::css/lib/chosen.css" />
<css src="Plumrocket_GlobalPrivacyControl::css/system_config_edit.css" />
<css src="Plumrocket_ExtendedAdminUi::css/lib/chosen.css" />
</head>
</page>
@@ -0,0 +1,68 @@
#config-edit-form .section-config:has(.addon-required-notice) .entry-edit-head a{
color: #727272;
}
#pr_gpc_well_known .code-box {
border: 1px solid #ccc;
margin: 0;
padding: 10px;
border-radius: 4px;
background-color: #f9f9f9;
font-family: monospace;
}
#pr_gpc_well_known .pr-notice__content-wrapper {
padding: 0;
}
/* Notice */
#row_pr_gpc_do_not_sell_addon_required_notice{
}
#row_pr_gpc_do_not_sell_addon_required_notice .pr-notice__content:before{
content: none;
}
.pr-gpc-notice-intro{
position: relative;
margin-left: -5.5rem;
margin-bottom: 20px;
padding-left: 5.5rem;
line-height: 1.5;
}
.pr-gpc-notice-intro:before{
color: #007bdb;
content: '\e61a';
background: none;
border: 0;
font-family: 'Admin Icons';
font-size: 1.9rem;
font-style: normal;
font-weight: 400;
height: auto;
left: 1.9rem;
line-height: inherit;
position: absolute;
speak: none;
text-shadow: none;
top: 50%;
margin-top: -1.25rem;
width: auto;
}
.pr-gpc-coupon-wrapper{
margin-bottom: 20px;
}
.pr-gpc-coupon{
display: inline-flex;
align-items: center;
justify-content: center;
color: #ff5607;
padding: 10px 20px;
border: 1px dashed #ff5607;
background: #e9f0f5;
border-radius: 2px;
}
@@ -0,0 +1,17 @@
/**
* 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_Extension
* @copyright Copyright (c) 2026 Plumrocket Inc. (http://www.plumrocket.com)
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
*/
var __prinitparam = 'MzM5Njkw';
@@ -0,0 +1,175 @@
require([
'jquery',
'mage/translate',
'Plumrocket_ExtendedAdminUi/js/lib/chosen.jquery.min',
'domReady!'
], function ($, __) {
'use strict';
/* enable chosen */
setTimeout(function () {
/* Scope. */$('#row_pr_gpc_general_geo_targeting_inherit:checked').click().click();
initializeGeoIPSelects();
}, 2000);
/* fix for chosen in not expanded section */
$('#pr_gpc_general-head').on('click', function () {
reinitializeGeoIPSelect(document.getElementById('pr_gpc_general_geo_targeting'));
});
$('#row_pr_gpc_general_geo_targeting_inherit').on('click', function () {
reinitializeGeoIPSelect(document.getElementById('pr_gpc_general_geo_targeting'));
});
/* Registry for all selects with class geoip-select-with-chosen */
window.initializedSelects = [];
function initializeGeoIPSelects()
{
var selects = getGeoIPSelects();
selects.forEach(function (select) {
if (! isInitializedGeoIPSelect(select)) {
initializeGeoIPSelect(select);
initializeGeoIPOptionDepends(select);
if (!$(select).hasClass('prgdpr-coutry')) {
geoIpFieldsDepend($(select));
var id = $(select).attr('id');
$(select).parent().prepend('<div style="font-weight: 600; margin-bottom: 10px;" id="ccpa-html-wrap"></div>');
$('#ccpa-html-wrap').append($('[for="' + id + '"]'));
}
}
});
}
function geoIpFieldsDepend(select)
{
var geoTargeting = $('.prgdpr-coutry'), values, toggle = function () {
values = $(geoTargeting).val();
if (values) {
values.forEach(function (element) {
if (element === 'US') {
select.parent().parent().show();
} else {
select.parent().parent().hide();
}
});
} else {
select.parent().parent().hide();
}
};
toggle(); /* Auto states toggle when page loaded */
/* If we change Geo Targeting field */
geoTargeting.change(function () {
toggle();
});
}
function getGeoIPSelects()
{
var result = $('select.geoip-select-with-chosen');
return result.length ? result.toArray() : [];
}
function initializeGeoIPSelect(select)
{
if (! select instanceof HTMLElement) {
return false;
}
if (isInitializedGeoIPSelect(select)) {
return getIndexOfRegisteredGeoIPSelect(select);
}
var enableSearch = true;
if ("readonly" === select.getAttribute('readonly')) {
enableSearch = false;
}
$(select).chosen({
"display_selected_options" : true,
"display_disabled_options": true,
"hide_results_on_select": true,
"group_search": enableSearch
});
return registerGeoIPSelect(select);
}
function registerGeoIPSelect(select)
{
return initializedSelects.push(select.name);
}
function getIndexOfRegisteredGeoIPSelect(select)
{
return initializedSelects.indexOf(select.name);
}
function isInitializedGeoIPSelect(select)
{
return -1 !== getIndexOfRegisteredGeoIPSelect(select);
}
function reinitializeGeoIPSelect(select)
{
if (isInitializedGeoIPSelect(select)) {
$(select).chosen("destroy");
initializedSelects.splice(getIndexOfRegisteredGeoIPSelect(select), 1);
initializeGeoIPSelect(select);
}
}
function updateGeoIpSelect(select)
{
if (! isInitializedGeoIPSelect(select)) {
initializeGeoIPSelect(select);
}
$(select).trigger("chosen:updated");
}
function initializeGeoIPOptionDepends(select)
{
initializeGeoIPSelect(select);
var geoipEl = $(select),
allOptionId = 'all';
var initialValues = ! geoipEl.val() ? [] : geoipEl.val();
var initialShowToAllIndex = initialValues.indexOf(allOptionId);
geoipEl.on('change', function () {
var values = ! $(this).val() ? [] : $(this).val();
var showToAllIndex = values.indexOf(allOptionId);
if (-1 !== initialShowToAllIndex) {
if (-1 !== showToAllIndex && values.length > 1) {
for (var i = 0; i < values.length; i++) {
values.splice(showToAllIndex, 1);
}
geoipEl.val(values);
}
} else {
if (-1 !== showToAllIndex && values.length > 1) {
geoipEl.val([allOptionId]);
}
}
if (! $(this).val()) {
$(this).val([allOptionId]);
}
initialValues = $(this).val();
initialShowToAllIndex = initialValues.indexOf(allOptionId);
updateGeoIpSelect(select);
});
}
});
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://www.plumrocket.com)
* @license https://www.plumrocket.com/license/ End-user License Agreement
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Plumrocket_GlobalPrivacyControl::css/gpc.css"/>
</head>
<body>
<referenceBlock name="head.additional">
<block class="Plumrocket\GlobalPrivacyControl\Block\ComponentInit" name="pr.gpc.init" after="pr.cookie.cookie_service">
<arguments>
<argument name="template" xsi:type="string">Plumrocket_GlobalPrivacyControl::init.phtml</argument>
<argument name="cspNonceViewModel" xsi:type="object">Plumrocket\Base\ViewModel\CspNonce</argument>
</arguments>
</block>
</referenceBlock>
<referenceContainer name="before.body.end">
<block class="Magento\Framework\View\Element\Template" name="pr.gpc.opt_out_notification" ifconfig="pr_gpc/general/enabled">
<arguments>
<argument name="template" xsi:type="string">Plumrocket_GlobalPrivacyControl::opt_out_notification.phtml</argument>
<argument name="cspNonceViewModel" xsi:type="object">Plumrocket\Base\ViewModel\CspNonce</argument>
<argument name="optOutNotificationViewModel" xsi:type="object">Plumrocket\GlobalPrivacyControl\ViewModel\OptOutNotification</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,13 @@
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license End-user License Agreement
*/
var config = {
map: {
'*': {
'prGlobalPrivacyControlApi': 'Plumrocket_GlobalPrivacyControl/js/gpc-api-wrapper'
}
}
};
@@ -0,0 +1,127 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
?>
<?php
/** @var \Magento\Framework\View\Element\Template $block */
/** @var \Plumrocket\Base\ViewModel\CspNonce $cspNonceViewModel */
$cspNonceViewModel = $block->getData('cspNonceViewModel');
?>
<script <?= /* @noEscape */ $cspNonceViewModel->getNonce() ?>>
var prGlobalPrivacyControlApi = {
config: <?= /* @noEscape */ $block->getSerializedConfig() ?>,
isApplicableForUser: false,
isConfigured: false,
configure: function () {
const setConfigurationResult = (isApplicable) => {
this.isApplicableForUser = isApplicable;
this.isConfigured = true;
if (isApplicable) {
this.signalHandlers.processPendingHandlers();
}
document.dispatchEvent(new Event('pr-global-privacy-control-api:configured'));
};
if (! this.config.canProcessSignal) {
setConfigurationResult(false);
return;
}
if (this.cache.get('isApplicableForUser')) {
setConfigurationResult(this.cache.get('isApplicableForUser'));
return;
}
if (! navigator.globalPrivacyControl) {
setConfigurationResult(false);
return;
}
if (! this.config.isGeotargetingEnabled) {
this.cache.set('isApplicableForUser', true);
setConfigurationResult(true);
return;
}
this.geotargeting.isApplicable()
.then(result => {
this.cache.set('isApplicableForUser', result);
setConfigurationResult(result);
})
.catch(() => setConfigurationResult(true));
},
shouldApply: function () {
if (! this.isConfigured) {
return false;
}
return this.isApplicableForUser;
},
};
prGlobalPrivacyControlApi.geotargeting = {
isApplicable: async function () {
return fetch(prGlobalPrivacyControlApi.config.geotargetingApiEndpoint, {
method: 'POST',
credentials: 'include'
}).then(r => r.json());
}
};
prGlobalPrivacyControlApi.signalHandlers = {
handlers: [],
addHandler: function (callback) {
let handler = {callback: callback, executed: false}
this.handlers.push(handler);
if (prGlobalPrivacyControlApi.isConfigured && prGlobalPrivacyControlApi.shouldApply()) {
handler.callback();
handler.executed = true;
}
},
processPendingHandlers: function () {
if (! prGlobalPrivacyControlApi.shouldApply()) {
return;
}
// Set cookie to indicate signal was handled
if (! prCookieService.get('pr-gpc-signal-handled')) {
prCookieService.set('pr-gpc-signal-handled', true, {expires: null});
}
this.handlers.forEach(function (handler) {
if (false === handler.executed) {
handler.callback();
handler.executed = true;
}
}.bind(this));
}
};
prGlobalPrivacyControlApi.cache = {
storageKey: 'pr_global_privacy_control_api_cache',
get: function (key) {
try {
let raw = sessionStorage.getItem(this.storageKey);
let cacheData = JSON.parse(raw);
return cacheData.hasOwnProperty(key) ? cacheData[key] : null;
} catch (e) {
return null;
}
},
set: function (key, value) {
try {
let cacheData = JSON.parse(sessionStorage.getItem(this.storageKey) || '{}');
cacheData[key] = value;
sessionStorage.setItem(this.storageKey, JSON.stringify(cacheData));
} catch (e) {}
},
};
prGlobalPrivacyControlApi.configure();
</script>
@@ -0,0 +1,30 @@
<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
?>
<?php
/** @var \Magento\Framework\View\Element\Template $block */
/** @var \Plumrocket\Base\ViewModel\CspNonce $cspNonceViewModel */
$cspNonceViewModel = $block->getData('cspNonceViewModel');
/** @var \Plumrocket\GlobalPrivacyControl\ViewModel\OptOutNotification $optOutNotificationViewModel */
$optOutNotificationViewModel = $block->getData('optOutNotificationViewModel');
?>
<?php if ($optOutNotificationViewModel->isEnabled()): ?>
<div id="pr-gpc-notification-modal" style="display: none;">
<?= $optOutNotificationViewModel->getNotificationHtml() ?>
</div>
<script type="text/x-magento-init" <?= /* @noEscape */ $cspNonceViewModel->getNonce() ?>>
{
"#pr-gpc-notification-modal": {
"Plumrocket_GlobalPrivacyControl/js/opt-out-notification": {}
}
}
</script>
<?php endif; ?>
@@ -0,0 +1,111 @@
.pr-gpc-notification-wrap{
padding: 20px 30px;
border-radius: 6px;
background: #F0F6FC;
margin: 20px 0;
}
#pr-gpc-notification-modal .pr-gpc-notification-wrap {
padding: 0;
border-radius: 0;
background: transparent;
margin: 0;
}
.pr-gpc-notification,
.pr-gpc-notification-wrap p,
.pr-gpc-notification-wrap span{
color: #3E3E3E;
font-size: 14px;
font-weight: 400;
line-height: 1.4;
}
.pr-gpc-notification-wrap h2{
margin: 0 0 18px 0;
color: #1F1F1F;
font-size: 16px;
font-weight: 700;
line-height: 1.4;
}
.pr-gpc-text-with-icon{
vertical-align: middle;
}
.pr-gpc-text-with-icon img{
vertical-align: middle;
display: inline-block;
margin-right: 5px;
}
.pr-gpc-notification-wrap p{
margin-bottom: 9px;
}
/* Popup styles */
.pr-gpc-notification-modal._has-modal{
overflow: initial;
}
.pr-gpc-notification-popup.modal-popup .modal-header{
padding-top: 20px;
}
.pr-gpc-notification-popup .pr-gpc-notification-wrap > h2{
margin: 0 0 14px 0;
padding-bottom: 14px;
border-bottom: 1px solid #EDEDED;
color: #1F1F1F;
font-size: 16px;
font-weight: 500;
line-height: 1.4;
}
.pr-gpc-notification-popup .pr-gpc-notification-wrap,
.pr-gpc-notification-popup .pr-gpc-notification-wrap p,
.pr-gpc-notification-popup .pr-gpc-notification-wrap span{
color: #3E3E3E;
font-size: 13px;
line-height: 1.2;
}
.pr-gpc-notification-popup .modal-inner-wrap{
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
bottom: 0;
right: 0;
left: 0;
max-width: 100%;
width: auto;
border-radius: 8px;
border: 1px solid #E7E7E7;
box-shadow: 0px 5px 24.9px 0px rgba(0, 0, 0, 0.10);
}
.pr-gpc-notification-popup .modal-footer{
padding-top: 20px;
padding-bottom: 20px;
}
.pr-gpc-notification-popup .modal-footer .action.primary{
padding: 8px 20px;
min-width: 70px;
}
.pr-gpc-notification-backdrop.modals-overlay{
background-color: transparent;
display: none;
}
@media (min-width: 768px){
.pr-gpc-notification-popup .modal-inner-wrap{
right: auto;
left: 33px;
margin-bottom: 33px;
width: 460px;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

@@ -0,0 +1,11 @@
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license End-user License Agreement
*/
define([], function() {
'use strict';
return window.prGlobalPrivacyControlApi;
});
@@ -0,0 +1,64 @@
define([
'jquery',
'Magento_Ui/js/modal/modal',
'prCookieService',
'prGlobalPrivacyControlApi'
], function ($, modal, prCookieService, prGlobalPrivacyControlApi) {
'use strict';
$.widget('plumrocket.gpcOptOutNotification', {
options: {
cookieName: 'pr-gpc-notification-shown'
},
/**
* Widget initialization
* @private
*/
_create: function () {
var self = this;
// Initialize modal options
var modalOptions = {
type: 'popup',
innerScroll: true,
modalClass: 'pr-gpc-notification-popup',
overlayClass: 'pr-gpc-notification-backdrop modals-overlay',
parentModalClass: 'pr-gpc-notification-modal _has-modal',
buttons: [{
text: $.mage.__('OK'),
class: 'action primary',
click: function () {
this.closeModal();
}
}],
closed: function () {
self._setCookie();
}
};
modal(modalOptions, $(this.element));
prGlobalPrivacyControlApi.signalHandlers.addHandler(this._showModal.bind(this));
},
_showModal: function () {
if (prCookieService.get(this.options.cookieName)) {
return;
}
setTimeout($.proxy(function () {
$(this.element).modal('openModal');
}, this), 1000);
},
/**
* Set cookie to remember that notification was shown
* @private
*/
_setCookie: function () {
prCookieService.set(this.options.cookieName, '1', {expires: null});
}
});
return $.plumrocket.gpcOptOutNotification;
});