ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml\Modules;
|
||||
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Framework\App\DeploymentConfig;
|
||||
use Olegnax\Core\Helper\ModuleInfo;
|
||||
|
||||
/** @noinspection ClassNameCollisionInspection */
|
||||
|
||||
class Update extends Template
|
||||
{
|
||||
const CACHE_KEY_PREFIX = 'OLEGNAX_';
|
||||
|
||||
const CACHE_TAG = 'extensions';
|
||||
/**
|
||||
* @var ModuleInfo
|
||||
*/
|
||||
protected $helper;
|
||||
/**
|
||||
* @var DeploymentConfig
|
||||
*/
|
||||
protected $deploymentConfig;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
DeploymentConfig $deploymentConfig,
|
||||
ModuleInfo $helper,
|
||||
array $data = []
|
||||
) {
|
||||
$this->deploymentConfig = $deploymentConfig;
|
||||
$this->helper = $helper;
|
||||
parent::__construct($context, $data);
|
||||
$this->addData(['cache_lifetime' => 86400, 'cache_tags' => [self::CACHE_TAG]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forsed update Data
|
||||
*/
|
||||
public function ForsedUpdate()
|
||||
{
|
||||
$this->helper->getData(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getModuleVersions()
|
||||
{
|
||||
$modules = $this->deploymentConfig->get('modules');
|
||||
$modules = array_filter($modules, [$this, 'filter_module'], ARRAY_FILTER_USE_KEY);
|
||||
$_modules = [];
|
||||
foreach ($modules as $moduleName => $enabled) {
|
||||
$module = $this->helper->getModuleInfo($moduleName);
|
||||
if (empty($module)) {
|
||||
continue;
|
||||
}
|
||||
$module['enabled'] = $enabled;
|
||||
$_modules[$moduleName] = $module;
|
||||
}
|
||||
|
||||
return $_modules;
|
||||
}
|
||||
|
||||
public function filter_module($moduleName)
|
||||
{
|
||||
return preg_match('/^olegnax_/i', $moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getThemeVersions()
|
||||
{
|
||||
$themes = [
|
||||
'Athlete2' => 'frontend/Olegnax/athlete2',
|
||||
];
|
||||
$_themes = [];
|
||||
foreach ($themes as $themeName => $path) {
|
||||
$theme = $this->helper->getThemeInfo($path, $themeName, false);
|
||||
if (empty($theme)) {
|
||||
continue;
|
||||
}
|
||||
$_themes[$themeName] = $theme;
|
||||
}
|
||||
|
||||
return $_themes;
|
||||
}
|
||||
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml;
|
||||
|
||||
|
||||
use Olegnax\Core\Block\Template;
|
||||
|
||||
class Notice extends Template
|
||||
{
|
||||
|
||||
protected $collector;
|
||||
|
||||
protected function _toHtml()
|
||||
{
|
||||
$contents = $this->getColection();
|
||||
$content = $this->itemSelection($contents);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getColection()
|
||||
{
|
||||
$contents = [];
|
||||
$colection = $this->loadColection();
|
||||
if ($colection && $colection->getSize()) {
|
||||
foreach ($colection as $notice) {
|
||||
$content = $notice->getOxContent();
|
||||
if (!empty($content)) {
|
||||
$contents[] = $content;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
protected function loadColection()
|
||||
{
|
||||
if ($this->collector) {
|
||||
return $this->collector->create();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $contents
|
||||
* @return string
|
||||
*/
|
||||
protected function itemSelection($contents = [])
|
||||
{
|
||||
if (!empty($contents)) {
|
||||
$key = array_rand($contents);
|
||||
$contents = (string)$contents[$key];
|
||||
} else {
|
||||
$contents = '';
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml;
|
||||
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\OxContentFactory;
|
||||
|
||||
class NoticeContent extends Notice
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
OxContentFactory $collector,
|
||||
array $data = []
|
||||
) {
|
||||
$this->collector = $collector;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OxContentFactory
|
||||
*/
|
||||
protected function loadColection()
|
||||
{
|
||||
if ($this->collector) {
|
||||
$location = $this->getLocation();
|
||||
if (empty($location)) {
|
||||
$location = 'global';
|
||||
}
|
||||
|
||||
return $this->collector->create()->addFieldToFilter('ox_type', $location);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml;
|
||||
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\OxContentPFactory;
|
||||
|
||||
class NoticeContentP extends Notice
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
OxContentPFactory $collector,
|
||||
array $data = []
|
||||
) {
|
||||
$this->collector = $collector;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OxContentPFactory
|
||||
*/
|
||||
protected function loadColection()
|
||||
{
|
||||
if ($this->collector) {
|
||||
$location = $this->getLocation();
|
||||
if (empty($location)) {
|
||||
$location = 'global';
|
||||
}
|
||||
|
||||
return $this->collector->create()->addFieldToFilter('ox_type', $location);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml;
|
||||
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\OxNewsFactory;
|
||||
|
||||
class NoticeNews extends Notice
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
OxNewsFactory $collector,
|
||||
array $data = []
|
||||
) {
|
||||
$this->collector = $collector;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $contents
|
||||
* @return string
|
||||
*/
|
||||
protected function itemSelection($contents = [])
|
||||
{
|
||||
return implode('', $contents);
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
use Magento\Framework\Component\ComponentRegistrarInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Filesystem\Directory\ReadFactory;
|
||||
use Magento\Framework\Module\ModuleListInterface;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\OxUpdateFactory;
|
||||
|
||||
class NoticeUpdate extends Notice
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
OxUpdateFactory $collector,
|
||||
array $data = []
|
||||
) {
|
||||
$this->collector = $collector;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getColection()
|
||||
{
|
||||
$contents = [];
|
||||
$colection = $this->loadColection();
|
||||
if ($colection && $colection->getSize()) {
|
||||
foreach ($colection as $notice) {
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$validate = [];
|
||||
try {
|
||||
$_validate = $notice->getOxValidate();
|
||||
$_validate = json_decode($_validate, true);
|
||||
$validate = $_validate;
|
||||
} catch (Exception $exception) {
|
||||
$validate = [];
|
||||
}
|
||||
|
||||
if (!$this->checkExtNeedUpdate($validate)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = $notice->getOxContent();
|
||||
if (!empty($content)) {
|
||||
$contents [] = $content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
protected function checkExtNeedUpdate($validate)
|
||||
{
|
||||
if (!empty($validate)) {
|
||||
if (is_array($validate) && array_key_exists('extension_update', $validate)) {
|
||||
return $this->validateExtNeedUpdate($validate['extension_update'], 'Olegnax');
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function validateExtNeedUpdate($extensions, $vendor = '')
|
||||
{
|
||||
$extensionsName = $this->validateExt($extensions, $vendor);
|
||||
if (!is_array($extensionsName)) {
|
||||
return false;
|
||||
}
|
||||
$extensionsName = array_filter($extensionsName, function ($value) {
|
||||
return 1 === $value;
|
||||
});
|
||||
$extensionsName = array_keys($extensionsName);
|
||||
|
||||
return $extensionsName;
|
||||
}
|
||||
|
||||
protected function validateExt($extensions, $vendor = '', $diff = false)
|
||||
{
|
||||
$extensions = $this->prepareExtValue($extensions);
|
||||
if (empty($extensions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$extensionsName = array_keys($extensions);
|
||||
$modules = $this->getInstalledExt($vendor);
|
||||
if ($diff) {
|
||||
$extensionsName = array_diff($extensionsName, $modules);
|
||||
} else {
|
||||
$extensionsName = array_intersect($extensionsName, $modules);
|
||||
}
|
||||
|
||||
if (empty($extensionsName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$_extensions = [];
|
||||
foreach ($extensionsName as $extensionName) {
|
||||
$_extensions[$extensionName] = $this->validateVersion($extensionName, $extensions[$extensionName]);
|
||||
}
|
||||
|
||||
return $_extensions;
|
||||
}
|
||||
|
||||
protected function prepareExtValue($extension)
|
||||
{
|
||||
$extensions = [];
|
||||
if (preg_match_all('/([a-z0-9_]+)(\s\(([^\(\)]+)\))*/i', $extension, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $matche) {
|
||||
$name = $matche[1];
|
||||
$version = isset($matche[3]) ? $matche[3] : null;
|
||||
$extensions[$name] = $version;
|
||||
}
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
protected function getInstalledExt($vendor = '')
|
||||
{
|
||||
$modules = $this->_loadObject(ModuleListInterface::class)->getNames();
|
||||
|
||||
$dispatchResult = new DataObject($modules);
|
||||
$modules = $dispatchResult->toArray();
|
||||
|
||||
if (!empty($filter)) {
|
||||
$_modules = [];
|
||||
foreach ($modules as $module) {
|
||||
$_module = explode('_', $module);
|
||||
$_vendor = array_shift($_module);
|
||||
if ($vendor == $_vendor) {
|
||||
$_modules[] = $module;
|
||||
}
|
||||
}
|
||||
$modules = $_modules;
|
||||
}
|
||||
$modules = array_filter($modules);
|
||||
sort($modules, SORT_STRING);
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
protected function validateVersion($moduleName, $version)
|
||||
{
|
||||
$cur_version = $this->getComposerVersion($moduleName);
|
||||
if (is_string($version) && is_string($cur_version)) {
|
||||
return version_compare($version, $cur_version);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function getComposerVersion($moduleName, $type = ComponentRegistrar::MODULE)
|
||||
{
|
||||
$path = $this->_loadObject(ComponentRegistrarInterface::class)->getPath($type, $moduleName);
|
||||
|
||||
if ($path) {
|
||||
$dirReader = $this->_loadObject(ReadFactory::class)->create($path);
|
||||
|
||||
if ($dirReader->isExist('composer.json')) {
|
||||
$data = $dirReader->readFile('composer.json');
|
||||
$data = json_decode($data, true);
|
||||
if (isset($data['version'])) {
|
||||
return $data['version'];
|
||||
}
|
||||
}
|
||||
if ($dirReader->isExist('etc/module.xml')) {
|
||||
$data = $dirReader->readFile('etc/module.xml');
|
||||
if (preg_match('/setup_version="([^\"]+)"/i', $data, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $contents
|
||||
* @return string
|
||||
*/
|
||||
protected function itemSelection($contents = [])
|
||||
{
|
||||
return implode('', $contents);
|
||||
}
|
||||
|
||||
protected function validateExtInstalled($extensions, $vendor = '')
|
||||
{
|
||||
return $this->validateExt($extensions, $vendor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
|
||||
use Magento\Backend\Block\Context;
|
||||
use Magento\Backend\Model\Auth\Session;
|
||||
use Magento\Config\Block\System\Config\Form\Fieldset;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
use Magento\Framework\View\Helper\Js;
|
||||
use Olegnax\Core\Block\Adminhtml\NoticeContent;
|
||||
use Olegnax\Core\Helper\ModuleInfo;
|
||||
|
||||
class Info extends Fieldset
|
||||
{
|
||||
/**
|
||||
* @var ModuleInfo
|
||||
*/
|
||||
protected $moduleInfo;
|
||||
/**
|
||||
* @var NoticeContent
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* Info constructor.
|
||||
* @param Context $context
|
||||
* @param Session $authSession
|
||||
* @param Js $jsHelper
|
||||
* @param NoticeContent $content
|
||||
* @param ModuleInfo $moduleInfo
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Session $authSession,
|
||||
Js $jsHelper,
|
||||
NoticeContent $content,
|
||||
ModuleInfo $moduleInfo,
|
||||
array $data = []
|
||||
) {
|
||||
$this->content = $content;
|
||||
$this->moduleInfo = $moduleInfo;
|
||||
parent::__construct($context, $authSession, $jsHelper, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve HTML markup for given form element
|
||||
*
|
||||
* @param AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
public function render(AbstractElement $element)
|
||||
{
|
||||
$html = $this->_toTPL();
|
||||
$html .= $this->getContent();
|
||||
|
||||
if ($element->getIsNested()) {
|
||||
$html = '<tr class="nested"><td colspan="4">' . $html . '</td></tr>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to string
|
||||
*
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function _toTPL($data = [])
|
||||
{
|
||||
ob_start();
|
||||
$this->toTPL(array_replace($this->getModuleInfo(), $data));
|
||||
return (string)ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Template
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function toTPL($data = [])
|
||||
{
|
||||
$rightUrls = [
|
||||
'docs' => __('User Guide'),
|
||||
];
|
||||
$rightBlock = '';
|
||||
foreach ($rightUrls as $key => $label) {
|
||||
if (isset($data[$key]) && !empty($data[$key])) {
|
||||
$rightBlock .= '<div class="ox-info-block__' . $key . '"><a href="' . $this->escapeUrl($data[$key]) . '" target="_blank">' . $label . '</a></div>';
|
||||
}
|
||||
}
|
||||
$rightBlock .= $this->rightCustomBlocks($data);
|
||||
?>
|
||||
<div class="ox-info-block">
|
||||
<a href="https://olegnax.com/" target="_blank" class="ox-info-block__logo"></a>
|
||||
<div class="ox-info-block__title"><?= $this->escapeHtml($data['title']); ?></div>
|
||||
<?= $this->leftCustomBlocks($data); ?>
|
||||
<?php if ($data['update_status']): ?>
|
||||
<div class="ox-info-block__version expired">
|
||||
<div class="ox-module-version">v<?= $this->escapeHtml($data['setup_version']); ?> <span class="ox-server-version">v<?= $this->escapeHtml($data['server_version']) ?></span><?php if (isset($data['url_changelog']) && !empty($data['url_changelog'])): ?> <a href="<?= $this->escapeUrl($data['url_changelog']) ?>" target="_blank"><?= __("What's New") ?></a></div><?php endif; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="ox-info-block__version">
|
||||
<div class="ox-module-version">v<?= $this->escapeHtml($data['setup_version']); ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (array_key_exists('pro', $data)): ?>
|
||||
<a target="_blank" class="ox-pro-version" href="<?php echo $data['pro'] ?>"><?php echo __('Get Pro'); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($rightBlock)): ?><div class="ox-info-block__right"><?= $rightBlock; ?></div><?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Right Custom Blocks
|
||||
*
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
protected function rightCustomBlocks($data = [])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Left Custom Blocks
|
||||
*
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
protected function leftCustomBlocks($data = [])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Module info
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getModuleInfo()
|
||||
{
|
||||
return $this->moduleInfo->getModuleInfo($this->getModuleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show notice
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getContent()
|
||||
{
|
||||
$this->content->setData('location', $this->getModuleName());
|
||||
return $this->content->toHtml();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Olegnax\Core\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
|
||||
use Magento\Backend\Block\Context;
|
||||
use Magento\Backend\Model\Auth\Session;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\View\Helper\Js;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
use Olegnax\Core\Block\Adminhtml\NoticeContent;
|
||||
use Olegnax\Core\Helper\ModuleInfo;
|
||||
|
||||
class InfoTheme extends Info
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_helper;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Session $authSession,
|
||||
Js $jsHelper,
|
||||
NoticeContent $content,
|
||||
ModuleInfo $moduleInfo,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $authSession, $jsHelper, $content, $moduleInfo, $data);
|
||||
}
|
||||
|
||||
protected function rightCustomBlocks($data = [])
|
||||
{
|
||||
if (!$this->moduleInfo->isActive('Olegnax_Athlete2')) {
|
||||
return '';
|
||||
}
|
||||
$this->_helper = ObjectManager::getInstance()->get(Helper::class);
|
||||
$code = $this->_helper->getSystemDefaultValue('athlete2_license/general/code');
|
||||
$license = $this->_helper->get();
|
||||
$status = !empty($license)
|
||||
&& isset($license->data->the_key)
|
||||
&& $license->data->the_key == $code
|
||||
&& $license->data->status == "active";
|
||||
$supportExpired = isset($license->notices->support);
|
||||
$notice = [];
|
||||
if ($status) {
|
||||
$notice[] = '<div class="ox-info-block__support support-' . ($supportExpired ? 'expired' : 'active') . '"><div class="wrapper"><span class="label">' . __('Support') . '</span>';
|
||||
if ($supportExpired) {
|
||||
$notice[] = '<a href="https://themeforest.net/item/athlete2-strong-magento-2-theme/23693737" target="_blank">' . __('Renew') . '</a>';
|
||||
} else {
|
||||
$notice[] = '<a href="https://olegnax.com/help" target="_blank">' . __('Active') . '</a>';
|
||||
}
|
||||
$notice[] = '</div></div>';
|
||||
}
|
||||
|
||||
return implode($notice);
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block;
|
||||
|
||||
use Magento\Framework\View\Element\AbstractBlock;
|
||||
|
||||
class ChildTemplate extends Template
|
||||
{
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
if ($parent) {
|
||||
return call_user_func_array([$parent, $method], $args);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
if ($parent) {
|
||||
return isset($parent->{$name});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
if ($parent) {
|
||||
return $parent->{$name};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve child block by name
|
||||
*
|
||||
* @param string $alias
|
||||
* @return AbstractBlock|bool
|
||||
*/
|
||||
public function getChildBlock($alias)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
$layout = $parent->getLayout();
|
||||
if (!$layout) {
|
||||
return false;
|
||||
}
|
||||
$name = $layout->getChildName($parent->getNameInLayout(), $alias);
|
||||
if ($name) {
|
||||
return $layout->getBlock($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve child block HTML
|
||||
*
|
||||
* @param string $alias
|
||||
* @param boolean $useCache
|
||||
* @return string
|
||||
*/
|
||||
public function getChildHtml($alias = '', $useCache = true)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
$layout = $parent->getLayout();
|
||||
if (!$layout) {
|
||||
return '';
|
||||
}
|
||||
$name = $parent->getNameInLayout();
|
||||
$out = '';
|
||||
if ($alias) {
|
||||
$childName = $layout->getChildName($name, $alias);
|
||||
if ($childName) {
|
||||
$out = $layout->renderElement($childName, $useCache);
|
||||
}
|
||||
} else {
|
||||
foreach ($layout->getChildNames($name) as $child) {
|
||||
$out .= $layout->renderElement($child, $useCache);
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render output of child child element
|
||||
*
|
||||
* @param string $alias
|
||||
* @param string $childChildAlias
|
||||
* @param bool $useCache
|
||||
* @return string
|
||||
*/
|
||||
public function getChildChildHtml($alias, $childChildAlias = '', $useCache = true)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
$layout = $parent->getLayout();
|
||||
if (!$layout) {
|
||||
return '';
|
||||
}
|
||||
$childName = $layout->getChildName($parent->getNameInLayout(), $alias);
|
||||
if (!$childName) {
|
||||
return '';
|
||||
}
|
||||
$out = '';
|
||||
if ($childChildAlias) {
|
||||
$childChildName = $layout->getChildName($childName, $childChildAlias);
|
||||
$out = $layout->renderElement($childChildName, $useCache);
|
||||
} else {
|
||||
foreach ($layout->getChildNames($childName) as $childChild) {
|
||||
$out .= $layout->renderElement($childChild, $useCache);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves sorted list of child names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChildNames()
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
$layout = $parent->getLayout();
|
||||
if (!$layout) {
|
||||
return [];
|
||||
}
|
||||
return $layout->getChildNames($parent->getNameInLayout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a group of child blocks
|
||||
*
|
||||
* Returns an array of <alias> => <block>
|
||||
* or an array of <alias> => <callback_result>
|
||||
* The callback currently supports only $this methods and passes the alias as parameter
|
||||
*
|
||||
* @param string $groupName
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupChildNames($groupName)
|
||||
{
|
||||
$parent = $this->getParentBlock();
|
||||
return $parent->getLayout()->getGroupChildNames($parent->getNameInLayout(),
|
||||
$groupName);
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
|
||||
class SimpleTemplate extends \Magento\Framework\View\Element\Template
|
||||
{
|
||||
|
||||
public function isLoggedIn()
|
||||
{
|
||||
return $this->getSession()->isLoggedIn();
|
||||
}
|
||||
|
||||
public function getSession()
|
||||
{
|
||||
return ObjectManager::getInstance()->create(Session::class);
|
||||
}
|
||||
|
||||
public function getConfig($path, $storeCode = null)
|
||||
{
|
||||
return $this->getSystemValue($path, $storeCode);
|
||||
}
|
||||
|
||||
public function getSystemValue($path, $storeCode = null)
|
||||
{
|
||||
$value = $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeCode);
|
||||
if (is_null($value)) {
|
||||
$value = '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
protected function _loadObject($object)
|
||||
{
|
||||
return $this->_getObjectManager()->get($object);
|
||||
}
|
||||
|
||||
protected function _getObjectManager()
|
||||
{
|
||||
return ObjectManager::getInstance();
|
||||
}
|
||||
}
|
||||
Executable
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Core
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Core\Block;
|
||||
|
||||
use Magento\Customer\Model\Form;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Olegnax\Core\Helper\Helper as HelperHelper;
|
||||
use Olegnax\Core\Helper\ProductImage as HelperProductImage;
|
||||
|
||||
abstract class Template extends SimpleTemplate
|
||||
{
|
||||
const CHILD_TEMPLATE = ChildTemplate::class;
|
||||
|
||||
|
||||
// Helper Product Image //
|
||||
|
||||
public function getImage(
|
||||
$product,
|
||||
$imageId,
|
||||
$template = HelperProductImage::TEMPLATE,
|
||||
array $attributes = [],
|
||||
$properties = []
|
||||
) {
|
||||
return $this->getHelperProductImage()->getImage($product, $imageId, $template, $attributes, $properties);
|
||||
}
|
||||
|
||||
public function getHelperProductImage()
|
||||
{
|
||||
return $this->_loadObject(HelperProductImage::class);
|
||||
}
|
||||
|
||||
public function getImageHover(
|
||||
$product,
|
||||
$imageId,
|
||||
$imageId_hover,
|
||||
$template = HelperProductImage::HOVER_TEMPLATE,
|
||||
array $attributes = [],
|
||||
$properties = []
|
||||
) {
|
||||
return $this->getHelperProductImage()->getImageHover($product, $imageId, $imageId_hover, $template, $attributes,
|
||||
$properties);
|
||||
}
|
||||
|
||||
public function getResizedImage(
|
||||
$product,
|
||||
$imageId,
|
||||
$size,
|
||||
$template = HelperProductImage::TEMPLATE,
|
||||
array $attributes = [],
|
||||
$properties = []
|
||||
) {
|
||||
return $this->getHelperProductImage()->getResizedImage($product, $imageId, $size, $template, $attributes,
|
||||
$properties);
|
||||
}
|
||||
|
||||
public function getResizedImageHover(
|
||||
$product,
|
||||
$imageId,
|
||||
$imageId_hover,
|
||||
$size,
|
||||
$template = HelperProductImage::HOVER_TEMPLATE,
|
||||
array $attributes = [],
|
||||
$properties = []
|
||||
) {
|
||||
return $this->getHelperProductImage()->getResizedImageHover($product, $imageId, $imageId_hover, $size,
|
||||
$template, $attributes, $properties);
|
||||
}
|
||||
|
||||
public function hasHoverImage($product, $imageId, $imageId_hover)
|
||||
{
|
||||
return $this->getHelperProductImage()->hasHoverImage($product, $imageId, $imageId_hover);
|
||||
}
|
||||
|
||||
public function getUrlResizedImage($product, $image, $size, $properties = [])
|
||||
{
|
||||
return $this->getHelperProductImage()->getUrlResizedImage($product, $image, $size, $properties);
|
||||
}
|
||||
|
||||
public function isLoggedIn()
|
||||
{
|
||||
return $this->getHelper()->isLoggedIn();
|
||||
}
|
||||
|
||||
// Helper Helper //
|
||||
|
||||
public function getHelper()
|
||||
{
|
||||
return $this->_loadObject(HelperHelper::class);
|
||||
}
|
||||
|
||||
public function getWishlistCount()
|
||||
{
|
||||
return $this->getHelper()->getWishlistCount();
|
||||
}
|
||||
|
||||
public function getCompareListUrl()
|
||||
{
|
||||
return $this->getHelper()->getCompareListUrl();
|
||||
}
|
||||
|
||||
function getCompareListCount()
|
||||
{
|
||||
return $this->getHelper()->getCompareListCount();
|
||||
}
|
||||
|
||||
public function isAutocompleteDisabled()
|
||||
{
|
||||
return (bool)!$this->getSystemValue(Form::XML_PATH_ENABLE_AUTOCOMPLETE);
|
||||
}
|
||||
|
||||
public function getBlockTemplateProcessor($content = '')
|
||||
{
|
||||
if (empty($content) || !is_string($content)) {
|
||||
$content = '';
|
||||
}
|
||||
return $this->getHelper()->getBlockTemplateProcessor($content);
|
||||
}
|
||||
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return $this->getHelper()->getBaseUrl();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user