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,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);
}
}