![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/core/Helper/ |
<?php /** * Copyright © Extmag. All rights reserved. */ /* File stub */ namespace Extmag\Core\Helper; use Extmag\Core\Model\Config; use Extmag\Core\Model\ConfigFactory; use Extmag\Core\Model\ConfigRepository; use Extmag\Core\Model\ResourceModel\Config\Collection; use Extmag\Core\Model\ResourceModel\Config\CollectionFactory; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; use Magento\Framework\Filesystem; use Magento\Framework\HTTP\ClientFactory; use Magento\Framework\Message\ManagerInterface; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use SplFileInfo; class Checker extends AbstractHelper { /** * @var ClientFactory */ protected $curl; /** * @var ScopeConfigInterface */ protected $scopeConfig; /** * @var ManagerInterface */ protected $messageManager; /** * @var Filesystem */ protected $filesystem; /** * @var CollectionFactory */ protected $collection; /** * @var ConfigFactory */ protected $config; /** * @var ConfigRepository */ protected $configRepository; /** * @param Context $context * @param ClientFactory $curl * @param ScopeConfigInterface $scopeConfig * @param ManagerInterface $messageManager * @param Filesystem $filesystem * @param CollectionFactory $collection * @param ConfigFactory $config * @param ConfigRepository $configRepository */ public function __construct( Context $context, ClientFactory $curl, ScopeConfigInterface $scopeConfig, ManagerInterface $messageManager, Filesystem $filesystem, CollectionFactory $collection, ConfigFactory $config, ConfigRepository $configRepository ) { parent::__construct($context); $this->curl = $curl; $this->scopeConfig = $scopeConfig; $this->messageManager = $messageManager; $this->filesystem = $filesystem; $this->collection = $collection; $this->config = $config; $this->configRepository = $configRepository; } public function setWarning() { $checker = null; if (!empty($checker)) { $this->messageManager->addComplexNoticeMessage( 'extmagNewsMessage', [ 'msg' => $checker['description'], ] ); } } public function check() { if ($this->scopeConfig->getValue('extmag_subscription/general/news') == 1 && 1 == 0) { $curl = $this->curl->create(); $curl->get( 'https://extmag.com/rest/default/V1/check/news/' . urlencode($this->getDomain()) . '/magento2' ); $response = json_decode($curl->getBody(), true); if ($curl->getStatus() == 200 && !empty($response['status']) && $response['status'] == 'ok') { } } /** * @var Collection $collection */ $collection = $this->collection->create(); $collection->addFieldToFilter('path', 'dm/expired/message'); foreach ($collection as $item) { $this->configRepository->delete($item); } $path = $this->filesystem->getDirectoryRead(DirectoryList::APP)->getAbsolutePath('code/Extmag'); if (file_exists($path)) { $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY ); if (!empty($files)) { $foundModules = []; /** * @var SplFileInfo $file */ foreach ($files as $file) { if ($file->isFile()) { $fileContent = ''; $fp = fopen($file->getRealPath(), 'r'); if ($fp !== false) { for ($i = 0; $i < 20; $i++) { if (feof($fp)) { break; } $fileContent .= fgets($fp); } fclose($fp); } if (!empty($fileContent) && strpos($fileContent, 'Extmag. All rights reserved. This is the Demo version.') !== false) { $averageTime = (int)(($file->getFileInfo()->getATime() + $file->getFileInfo()->getMTime() + $file->getFileInfo()->getCTime()) / 3); if ((time() - $averageTime) / 86400 > 14 && !isset($foundModules[$file->getPath()])) { $foundModules[$file->getPath()] = 1; } } } } if (!empty($foundModules)) { foreach ($foundModules as $key => $foundModule) { $pathParts = explode("/", $key); $moduleName = $pathParts[count($pathParts) - 1]; /** * @var Config $configModel */ $configModel = $this->config->create(); $configModel->setModule(strtolower($moduleName)); $configModel->setPath('dm/expired/message'); $configModel->setValue(__('The free trial of the %1 extension has expired. Continued use of the demo version of this module violates the license agreement and will entail legal consequences. Please pay for the real license and install the real version of the extension.', $moduleName)); $this->configRepository->save($configModel); } } } } } }