-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b32b398
Showing
27 changed files
with
1,422 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Yireo\NextGenImages\Block\Adminhtml\System\Config; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class Gd extends Field | ||
{ | ||
/** | ||
* Override to set a different PHTML template | ||
* | ||
* @return $this | ||
*/ | ||
protected function _prepareLayout() | ||
{ | ||
parent::_prepareLayout(); | ||
$this->setTemplate('config/gd.phtml'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Override to render the template instead of the regular output | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
return $this->toHtml(); | ||
} | ||
|
||
/** | ||
* Check if GD supports WebP | ||
* | ||
* @return bool | ||
*/ | ||
public function hasGdSupport(): bool | ||
{ | ||
if (!function_exists('gd_info')) { | ||
return false; | ||
} | ||
|
||
if (!function_exists('imagecreatefromwebp')) { | ||
return false; | ||
} | ||
|
||
$gdInfo = gd_info(); | ||
$webpMatch = false; | ||
foreach ($gdInfo as $gdInfoLine => $gdInfoSupport) { | ||
if (stristr($gdInfoLine, 'webp')) { | ||
$webpMatch = true; | ||
break; | ||
} | ||
} | ||
|
||
if ($webpMatch === false) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yireo\NextGenImages\Block\Adminhtml\System\Config; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Component\ComponentRegistrar; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Filesystem\Directory\ReadFactory as DirectoryReadFactory; | ||
use Magento\Framework\Filesystem\File\ReadFactory as FileReadFactory; | ||
use Magento\Framework\Module\ModuleListInterface; | ||
use Magento\Framework\Serialize\SerializerInterface; | ||
use Magento\Backend\Block\Template\Context; | ||
|
||
class ModuleVersion extends Field | ||
{ | ||
/** | ||
* @var ComponentRegistrar | ||
*/ | ||
private $componentRegistrar; | ||
|
||
/** | ||
* @var ModuleListInterface | ||
*/ | ||
private $moduleList; | ||
|
||
/** | ||
* @var FileReadFactory | ||
*/ | ||
private $fileReadFactory; | ||
|
||
/** | ||
* @var SerializerInterface | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @var DirectoryReadFactory | ||
*/ | ||
private $directoryReadFactory; | ||
/** | ||
* @var string | ||
*/ | ||
private $moduleName; | ||
|
||
/** | ||
* ModuleVersion constructor. | ||
* @param ComponentRegistrar $componentRegistrar | ||
* @param ModuleListInterface $moduleList | ||
* @param FileReadFactory $fileReadFactory | ||
* @param SerializerInterface $serializer | ||
* @param DirectoryReadFactory $directoryReadFactory | ||
* @param Context $context | ||
* @param array $data | ||
* @param string $moduleName | ||
*/ | ||
public function __construct( | ||
ComponentRegistrar $componentRegistrar, | ||
ModuleListInterface $moduleList, | ||
FileReadFactory $fileReadFactory, | ||
SerializerInterface $serializer, | ||
DirectoryReadFactory $directoryReadFactory, | ||
Context $context, | ||
array $data = [], | ||
string $moduleName = 'Yireo_NextGenImages' | ||
) { | ||
parent::__construct($context, $data); | ||
$this->componentRegistrar = $componentRegistrar; | ||
$this->moduleList = $moduleList; | ||
$this->fileReadFactory = $fileReadFactory; | ||
$this->serializer = $serializer; | ||
$this->directoryReadFactory = $directoryReadFactory; | ||
$this->moduleName = $moduleName; | ||
} | ||
|
||
/** | ||
* Override to set a different PHTML template | ||
* | ||
* @return $this | ||
*/ | ||
protected function _prepareLayout() | ||
{ | ||
parent::_prepareLayout(); | ||
$this->setTemplate('config/module_version.phtml'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Override to render the template instead of the regular output | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
return $this->toHtml(); | ||
} | ||
|
||
/** | ||
* Check if GD supports WebP | ||
* | ||
* @return string | ||
*/ | ||
public function getModuleVersion(): string | ||
{ | ||
$moduleVersion = $this->getModuleVersionFromComposer(); | ||
if ($moduleVersion) { | ||
return $moduleVersion; | ||
} | ||
|
||
return $this->getModuleVersionFromModuleXml(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function getModuleVersionFromComposer(): string | ||
{ | ||
$modulePath = $this->componentRegistrar->getPath('module', $this->moduleName); | ||
$composerJsonFile = $modulePath . '/composer.json'; | ||
|
||
$directoryRead = $this->directoryReadFactory->create($modulePath); | ||
if (!$directoryRead->isExist($composerJsonFile)) { | ||
return ''; | ||
} | ||
|
||
$fileRead = $this->fileReadFactory->create($composerJsonFile, 'file'); | ||
$jsonContents = (string)$fileRead->readAll(); | ||
$data = $this->serializer->unserialize($jsonContents); | ||
if (isset($data['version'])) { | ||
return (string)$data['version']; | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function getModuleVersionFromModuleXml(): string | ||
{ | ||
$module = $this->moduleList->getOne($this->moduleName); | ||
if (isset($module['setup_version'])) { | ||
return (string)$module['setup_version']; | ||
} | ||
|
||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Yireo\NextGenImages\Block\Adminhtml\System\Config; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class PhpVersion extends Field | ||
{ | ||
/** | ||
* Override to set a different PHTML template | ||
* | ||
* @return $this | ||
*/ | ||
protected function _prepareLayout() | ||
{ | ||
parent::_prepareLayout(); | ||
$this->setTemplate('config/php_version.phtml'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Override to render the template instead of the regular output | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
return $this->toHtml(); | ||
} | ||
|
||
/** | ||
* Check if GD supports WebP | ||
* | ||
* @return string | ||
*/ | ||
public function getPhpVersion(): string | ||
{ | ||
return (string)phpversion(); | ||
} | ||
} |
Oops, something went wrong.