ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?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\Consent;
|
||||
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface;
|
||||
use Plumrocket\CookieConsent\Model\Category\Source\EnabledCategories;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CreateSettingsFromParam
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Category\Source\EnabledCategories
|
||||
*/
|
||||
private $enabledCategories;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface
|
||||
*/
|
||||
private $getEssentialCategoryKeys;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Model\Category\Source\EnabledCategories $enabledCategories
|
||||
* @param \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
*/
|
||||
public function __construct(
|
||||
EnabledCategories $enabledCategories,
|
||||
GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
) {
|
||||
$this->enabledCategories = $enabledCategories;
|
||||
$this->getEssentialCategoryKeys = $getEssentialCategoryKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $acceptedKeys
|
||||
* @return bool[]
|
||||
*/
|
||||
public function execute(array $acceptedKeys): array
|
||||
{
|
||||
if (empty($acceptedKeys)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (in_array(CategoryInterface::ALL_CATEGORIES, $acceptedKeys, true)) {
|
||||
$settings = [CategoryInterface::ALL_CATEGORIES => true];
|
||||
} else {
|
||||
$enabledCategoriesKeys = array_keys($this->enabledCategories->toOptionHash());
|
||||
$essentialCategoryKeys = $this->getEssentialCategoryKeys->execute();
|
||||
|
||||
$settings = [];
|
||||
foreach ($enabledCategoriesKeys as $enabledCategoriesKey) {
|
||||
if (in_array($enabledCategoriesKey, $essentialCategoryKeys, true)) {
|
||||
$settings[$enabledCategoriesKey] = true;
|
||||
} else {
|
||||
$settings[$enabledCategoriesKey] = in_array($enabledCategoriesKey, $acceptedKeys, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?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\Consent;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog as ConsentLogResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Log extends AbstractModel implements ConsentLogInterface
|
||||
{
|
||||
/**
|
||||
* Initialize resource model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(ConsentLogResource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCustomerId(): int
|
||||
{
|
||||
return (int) $this->_getData(ConsentLogInterface::CUSTOMER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getGuestEmail(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::GUEST_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWebsiteId(): int
|
||||
{
|
||||
return (int) $this->_getData(ConsentLogInterface::WEBSITE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSettings(): array
|
||||
{
|
||||
return (array) $this->_getData(ConsentLogInterface::SETTINGS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIpAddress(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::IP_ADDRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCreatedAt(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::CREATED_AT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUserAgent(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::USER_AGENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCustomerId(int $customerId): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::CUSTOMER_ID, $customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setGuestEmail(string $guestEmail): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::GUEST_EMAIL, $guestEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setWebsiteId(int $websiteId): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::WEBSITE_ID, $websiteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSettings(array $settings): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::SETTINGS, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIpAddress(string $ipAddress): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::IP_ADDRESS, $ipAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCreatedAt(string $gmtDateTime): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::CREATED_AT, $gmtDateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUserAgent(string $userAgent): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::USER_AGENT, $userAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUrl(string $url): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::URL, $url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?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\Consent;
|
||||
|
||||
use Magento\Customer\Helper\Session\CurrentCustomer;
|
||||
use Magento\Framework\App\Response\RedirectInterface;
|
||||
use Magento\Framework\HTTP\Header;
|
||||
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterfaceFactory;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog as ConsentLogResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\ConsentLogInterfaceFactory
|
||||
*/
|
||||
private $consentLogFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Store\Model\StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress
|
||||
*/
|
||||
private $remoteAddress;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\DateTime\DateTime
|
||||
*/
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Helper\Session\CurrentCustomer
|
||||
*/
|
||||
private $currentCustomer;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog
|
||||
*/
|
||||
private $consentLogResource;
|
||||
|
||||
/**
|
||||
* @var Header
|
||||
*/
|
||||
private $httpHeader;
|
||||
|
||||
/**
|
||||
* @var RedirectInterface
|
||||
*/
|
||||
private $redirect;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\ConsentLogInterfaceFactory $consentLogFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
|
||||
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
|
||||
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog $consentLogResource
|
||||
* @param Header $httpHeader
|
||||
* @param RedirectInterface $redirect
|
||||
*/
|
||||
public function __construct(
|
||||
ConsentLogInterfaceFactory $consentLogFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
RemoteAddress $remoteAddress,
|
||||
DateTime $dateTime,
|
||||
CurrentCustomer $currentCustomer,
|
||||
ConsentLogResource $consentLogResource,
|
||||
Header $httpHeader,
|
||||
RedirectInterface $redirect
|
||||
) {
|
||||
$this->consentLogFactory = $consentLogFactory;
|
||||
$this->storeManager = $storeManager;
|
||||
$this->remoteAddress = $remoteAddress;
|
||||
$this->dateTime = $dateTime;
|
||||
$this->currentCustomer = $currentCustomer;
|
||||
$this->consentLogResource = $consentLogResource;
|
||||
$this->httpHeader = $httpHeader;
|
||||
$this->redirect = $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $settings
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\ConsentLogInterface
|
||||
* @throws \Magento\Framework\Exception\AlreadyExistsException
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function log(array $settings): ConsentLogInterface
|
||||
{
|
||||
/** @var ConsentLogInterface|Log $consentLog */
|
||||
$consentLog = $this->consentLogFactory->create();
|
||||
|
||||
$consentLog->setCustomerId((int) $this->currentCustomer->getCustomerId());
|
||||
$consentLog->setSettings($settings);
|
||||
$consentLog->setWebsiteId((int) $this->storeManager->getStore()->getWebsiteId());
|
||||
$consentLog->setIpAddress($this->getAnonymizedIp());
|
||||
$consentLog->setUserAgent($this->httpHeader->getHttpUserAgent());
|
||||
$consentLog->setUrl($this->redirect->getRefererUrl());
|
||||
$consentLog->setCreatedAt($this->getFormattedGmtDateTime());
|
||||
|
||||
$this->consentLogResource->save($consentLog);
|
||||
|
||||
return $consentLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date in the proper format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedGmtDateTime(): string
|
||||
{
|
||||
return (string) date('Y-m-d H:i:s', $this->dateTime->gmtTimestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize customer Ip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getAnonymizedIp(): string
|
||||
{
|
||||
$realIp = $this->remoteAddress->getRemoteAddress();
|
||||
$ipPieces = explode('.', $realIp);
|
||||
end($ipPieces);
|
||||
$ipPieces[key($ipPieces)] = '000';
|
||||
|
||||
return implode('.', $ipPieces);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user