Skip to content

Commit

Permalink
Version 1.3.4.2
Browse files Browse the repository at this point in the history
Merged from Athlete2 version 1.8
  • Loading branch information
olegnax committed Jul 23, 2024
1 parent 3641d78 commit 7bbe0c3
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 247 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/InfoTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function rightCustomBlocks($data = [])
$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>';
$notice[] = '<div class="ox-info-block__support support-' . ($supportExpired ? 'expired' : 'active') . '"><div class="ox-wrapper 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 {
Expand Down
124 changes: 57 additions & 67 deletions Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Exception;
use Magento\AdminNotification\Model\InboxFactory;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Component\ComponentRegistrarInterface;
Expand All @@ -24,7 +23,7 @@
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Notification\MessageInterface;
use Magento\Store\Model\StoreManagerInterface;
use Olegnax\Core\Helper\Helper;
use Olegnax\Core\Helper\Helper as CoreHelper;
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\ExistsFactory;
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\ExpiredFactory;
use Olegnax\Core\Model\ResourceModel\Inbox\Collection\OxContent;
Expand All @@ -49,18 +48,53 @@ class Feed extends AbstractModel
*/
const REMOVE_FREQUENCY = 6;

/**
*
* @var ObjectManager
*/
public $_objectManager;
/**
* Feed url
*
* @var string
*/
protected $expiredFactory;
protected $productMetadata;
protected $storeManagerInterface;
protected $moduleListInterface;
protected $componentRegistrarInterface;
protected $readFactory;
protected $oxFactory;
protected $existsFactory;
protected $deploymentConfig;
protected $inboxFactory;
protected $coreHelper;
protected $curlFactory;
protected $_feedUrl;

public function __construct(
ExpiredFactory $expiredFactory,
ProductMetadataInterface $productMetadata,
StoreManagerInterface $storeManagerInterface,
ModuleListInterface $moduleListInterface,
ComponentRegistrarInterface $componentRegistrarInterface,
ReadFactory $readFactory,
OXFactory $oxFactory,
ExistsFactory $existsFactory,
DeploymentConfig $deploymentConfig,
InboxFactory $inboxFactory,
coreHelper $coreHelper,
CurlFactory $curlFactory
) {
$this->expiredFactory = $expiredFactory;
$this->productMetadata = $productMetadata;
$this->storeManagerInterface = $storeManagerInterface;
$this->moduleListInterface = $moduleListInterface;
$this->componentRegistrarInterface = $componentRegistrarInterface;
$this->readFactory = $readFactory;
$this->oxFactory = $oxFactory;
$this->existsFactory = $existsFactory;
$this->deploymentConfig = $deploymentConfig;
$this->inboxFactory = $inboxFactory;
$this->coreHelper = $coreHelper;
$this->curlFactory = $curlFactory;
}

/**
* @return $this
*/
Expand All @@ -74,7 +108,7 @@ public function checkUpdate()

$feedXml = $this->getFeedXml();

$installDate = strtotime($this->_loadObject(DeploymentConfig::class)->get(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE));
$installDate = strtotime($this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE));
$types = [];

if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
Expand Down Expand Up @@ -152,7 +186,7 @@ public function checkUpdate()
if (!empty($types)) {
$this->removeOXType($types);
}
$this->_loadObject(InboxFactory::class)->create()->parse(array_reverse($feedData));
$this->inboxFactory->create()->parse(array_reverse($feedData));
}
}
$this->setLastUpdate();
Expand All @@ -168,19 +202,12 @@ public function getFrequency()
return self::FREQUENCY * 3600;
}

/**
* @return Helper
*/
protected function helper(){
return $this->_loadObject( Helper::class);
}

/**
* @return int
*/
public function getLastUpdate()
{
return (int)$this->helper()->getModuleConfig('admin_notifications/lastcheck');
return (int)$this->coreHelper->getModuleConfig('admin_notifications/lastcheck');
}

/**
Expand All @@ -203,7 +230,7 @@ public function getFeedXml()
*/
public function getFeedData()
{
$curl = $this->_loadObject(CurlFactory::class)->create();
$curl = $this->curlFactory->create();
$curl->setConfig(
[
'timeout' => 2,
Expand All @@ -225,51 +252,21 @@ public function getFeedData()

return $data;
}

/**
* @param string $object
* @return mixed
*/
protected function _loadObject($object)
{
return $this->_getObjectManager()->get($object);
}

/**
* @return ObjectManager
*/
protected function _getObjectManager()
{
if (!$this->_objectManager) {
$this->_objectManager = ObjectManager::getInstance();
}

return $this->_objectManager;
}

/**
* @return string
*/
protected function getUserAgent()
{
return sprintf("Olegnax: %s/%s (%s)", $this->getProductMetadata()->getName(),
$this->getProductMetadata()->getVersion(), $this->getProductMetadata()->getEdition());
}

/**
* @return ProductMetadataInterface
*/
protected function getProductMetadata()
{
return $this->_loadObject(ProductMetadataInterface::class);
return sprintf("Olegnax: %s/%s (%s)", $this->productMetadata->getName(),
$this->productMetadata->getVersion(), $this->productMetadata->getEdition());
}

/**
* @return StoreManagerInterface
*/
public function getCurrentUrl()
{
return $this->_loadObject(StoreManagerInterface::class)->getStore()->getBaseUrl();
return $this->storeManagerInterface->getStore()->getBaseUrl();
}

/**
Expand All @@ -290,13 +287,6 @@ public function getFeedUrl()
private function getScheme()
{
return 'https://';
// $url = $this->_loadObject(StoreManagerInterface::class)->getStore()->getBaseUrl();
// $scheme = parse_url($url, PHP_URL_SCHEME);
// if (empty($scheme)) {
// $scheme = 'http';
// }
//
// return $scheme . '://';
}

/**
Expand Down Expand Up @@ -391,7 +381,7 @@ protected function prepareExtValue($extension)
*/
protected function getInstalledExt($vendor = '')
{
$modules = $this->_loadObject(ModuleListInterface::class)->getNames();
$modules = $this->moduleListInterface->getNames();

$dispatchResult = new DataObject($modules);
$modules = $dispatchResult->toArray();
Expand Down Expand Up @@ -435,10 +425,10 @@ protected function validateVersion($moduleName, $version)
*/
protected function getComposerVersion($moduleName, $type = ComponentRegistrar::MODULE)
{
$path = $this->_loadObject(ComponentRegistrarInterface::class)->getPath($type, $moduleName);
$path = $this->componentRegistrarInterface->getPath($type, $moduleName);

if ($path) {
$dirReader = $this->_loadObject(ReadFactory::class)->create($path);
$dirReader = $this->readFactory->create($path);

if ($dirReader->isExist('composer.json')) {
$data = $dirReader->readFile('composer.json');
Expand Down Expand Up @@ -491,7 +481,7 @@ public function removeOXType($types = [])

$types = array_unique($types);
/** @var OXFactory $collection */
$collection = $this->_loadObject(OXFactory::class)->create()->addFieldToFilter('ox_type',
$collection = $this->oxFactory->create()->addFieldToFilter('ox_type',
array('in' => $types));
foreach ($collection as $model) {
$model->setIsRemove(1)->save()->delete();
Expand All @@ -505,7 +495,7 @@ public function removeOXType($types = [])
*/
public function setLastUpdate()
{
$this->helper()->setModuleConfig('admin_notifications/lastcheck', time());
$this->coreHelper->setModuleConfig('admin_notifications/lastcheck', time());
return $this;
}

Expand All @@ -519,7 +509,7 @@ public function removeExpiredItems()
}

/** @var ExpiredFactory $collection */
$collection = $this->_loadObject(ExpiredFactory::class)->create();
$collection = $this->expiredFactory->create();
foreach ($collection as $model) {
$model->setIsRemove(1)->save()->delete();
}
Expand All @@ -534,15 +524,15 @@ public function removeExpiredItems()
*/
public function getLastRemove()
{
return (int)$this->helper()->getModuleConfig('admin_notifications/lastremove');
return (int)$this->coreHelper->getModuleConfig('admin_notifications/lastremove');
}

/**
* @return $this
*/
public function setLastRemove()
{
$this->helper()->setModuleConfig('admin_notifications/lastremove', time());
$this->coreHelper->setModuleConfig('admin_notifications/lastremove', time());
return $this;
}

Expand All @@ -552,7 +542,7 @@ public function setLastRemove()
*/
private function isItemExists($link)
{
return $this->_loadObject(ExistsFactory::class)->create()->execute($this->escapeString($link));
return $this->existsFactory->create()->execute($this->escapeString($link));
}

}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "olegnax/module-core",
"description": "Olegnax Core. Required by all Olegnax extensions and themes.",
"version": "1.3.4",
"version": "1.3.4.2",
"type": "magento2-module",
"license": [
"OSL-3.0"
Expand Down
12 changes: 9 additions & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="olegnax" translate="label" sortOrder="10">
<label>Olegnax</label>
</tab>
<tab id="olegnax" translate="label" sortOrder="10">
<label>Olegnax</label>
</tab>
<section id="olegnax_core_settings" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
<label>Core</label>
<tab>olegnax</tab>
Expand All @@ -26,6 +26,12 @@
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="defer_assets" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="14" translate="label"
type="select">
<label>Defer CSS Assest Enabled</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
Expand Down
5 changes: 3 additions & 2 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<olegnax_core_settings>
<general>
<lazyload>1</lazyload>
<owlcarousel>1</owlcarousel>
<owlcarousel>1</owlcarousel>
<defer_assets>1</defer_assets>
</general>
</olegnax_core_settings>
</olegnax_core_settings>
</default>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Olegnax_Core" setup_version="1.3.4">
<module name="Olegnax_Core" setup_version="1.3.4.2">
<sequence>
<module name="Magento_AdminNotification"/>
<module name="Magento_Catalog"/>
Expand Down
6 changes: 6 additions & 0 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="ox_core_assets" remove="true"/>
</body>
</page>
7 changes: 4 additions & 3 deletions view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="head.additional">
<block name="ox_core_assets" class="Olegnax\Core\Block\SimpleTemplate" template="Olegnax_Core::assets.phtml"/>
</referenceContainer>
<body>
<referenceContainer name="head.additional">
<block name="ox_core_assets" class="Olegnax\Core\Block\SimpleTemplate" template="Olegnax_Core::assets.phtml"/>
</referenceContainer>
<referenceContainer name="before.body.end">
<block ifconfig="olegnax_core_settings/general/defer_assets" class="Magento\Framework\View\Element\Template" name="ox_core_onloadcss" template="Olegnax_Core::onloadcss.phtml"/>
<block ifconfig="olegnax_core_settings/general/lazyload" class="Olegnax\Core\Block\SimpleTemplate" name="ox_core_lazy" template="Olegnax_Core::lazy_min.phtml"/>
</referenceContainer>
</body>
Expand Down
9 changes: 4 additions & 5 deletions view/frontend/templates/assets.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
if ($this->getConfig('olegnax_core_settings/general/owlcarousel')) { ?>
<link href="<?= $block->getViewFileUrl('Olegnax_Core::owl.carousel/assets/owl.carousel.css'); ?>" rel="stylesheet" media="print" onload="this.media='all'" crossorigin="anonymous">
<?php } ?>

<?php if ($this->getConfig('olegnax_core_settings/general/owlcarousel')) : ?>
<?php $defer = (bool)$this->getConfig('olegnax_core_settings/general/defer_assets'); ?>
<link href="<?= $block->getViewFileUrl('Olegnax_Core::owl.carousel/assets/owl.carousel.css'); ?>" <?php echo ($defer ? 'data-onloadcss' : ''); ?> rel="stylesheet" type="text/css" media="<?php echo ($defer ? 'print' : 'all'); ?>" >
<?php endif; ?>
Loading

0 comments on commit 7bbe0c3

Please sign in to comment.