diff --git a/Plugin/ImageContentValidatorExtension.php b/Plugin/ImageContentValidatorExtension.php
index a7dd627..0d56b18 100644
--- a/Plugin/ImageContentValidatorExtension.php
+++ b/Plugin/ImageContentValidatorExtension.php
@@ -7,8 +7,10 @@
use Magento\Framework\Api\Data\ImageContentInterface;
use Magento\Framework\Api\ImageContentValidator;
use Magento\Framework\Exception\InputException;
+use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem\Io\File as IoFile;
use Magento\Framework\Phrase;
+use MarkShust\PolyshellPatch\Utility\Configurations;
/**
* Validate that the uploaded filename has a safe image extension.
@@ -26,12 +28,20 @@ class ImageContentValidatorExtension
*/
private IoFile $ioFile;
+ /**
+ * @var Configurations
+ */
+ private Configurations $configurations;
+
/**
* @param IoFile $ioFile
*/
- public function __construct(IoFile $ioFile)
- {
+ public function __construct(
+ IoFile $ioFile,
+ Configurations $configurations
+ ) {
$this->ioFile = $ioFile;
+ $this->configurations = $configurations;
}
/**
@@ -40,8 +50,10 @@ public function __construct(IoFile $ioFile)
* @param ImageContentValidator $subject
* @param bool $result
* @param ImageContentInterface $imageContent
+ *
* @return bool
* @throws InputException
+ * *@throws NoSuchEntityException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
@@ -50,6 +62,10 @@ public function afterIsValid(
bool $result,
ImageContentInterface $imageContent
): bool {
+ if (!$this->configurations->isModuleEnabled()) {
+ return $result;
+ }
+
$fileName = $imageContent->getName();
$pathInfo = $this->ioFile->getPathInfo($fileName);
$extension = strtolower($pathInfo['extension'] ?? '');
diff --git a/Plugin/ImageProcessorRestrictExtensions.php b/Plugin/ImageProcessorRestrictExtensions.php
index 8cd3431..534b587 100644
--- a/Plugin/ImageProcessorRestrictExtensions.php
+++ b/Plugin/ImageProcessorRestrictExtensions.php
@@ -7,6 +7,8 @@
use Magento\Framework\Api\Data\ImageContentInterface;
use Magento\Framework\Api\ImageProcessor;
use Magento\Framework\Api\Uploader;
+use Magento\Framework\Exception\NoSuchEntityException;
+use MarkShust\PolyshellPatch\Utility\Configurations;
/**
* Enforce an allowlist of file extensions before ImageProcessor saves uploaded files.
@@ -23,12 +25,21 @@ class ImageProcessorRestrictExtensions
*/
private Uploader $uploader;
+ /**
+ * @var Configurations
+ */
+ private Configurations $configurations;
+
/**
* @param Uploader $uploader
+ * @param Configurations $configurations
*/
- public function __construct(Uploader $uploader)
- {
+ public function __construct(
+ Uploader $uploader,
+ Configurations $configurations
+ ) {
$this->uploader = $uploader;
+ $this->configurations = $configurations;
}
/**
@@ -37,15 +48,21 @@ public function __construct(Uploader $uploader)
* @param ImageProcessor $subject
* @param string $entityType
* @param ImageContentInterface $imageContent
+ *
* @return null
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ * @throws NoSuchEntityException
*/
public function beforeProcessImageContent(
ImageProcessor $subject,
$entityType,
$imageContent
) {
+ if (!$this->configurations->isModuleEnabled()) {
+ return null;
+ }
+
$this->uploader->setAllowedExtensions(self::ALLOWED_EXTENSIONS);
return null;
}
diff --git a/Utility/Configurations.php b/Utility/Configurations.php
new file mode 100644
index 0000000..c065855
--- /dev/null
+++ b/Utility/Configurations.php
@@ -0,0 +1,56 @@
+scopeConfig->isSetFlag(
+ $path,
+ ScopeInterface::SCOPE_STORE,
+ $this->storeManager->getStore()->getStoreId()
+ );
+ }
+
+ /**
+ * Check if the module is enabled
+ *
+ * @return bool
+ * @throws NoSuchEntityException
+ */
+ public function isModuleEnabled(): bool
+ {
+ return $this->_isSetFlag(Constants::POLYSHELL_ENABLED_PATH);
+ }
+}
diff --git a/Utility/Constants.php b/Utility/Constants.php
new file mode 100644
index 0000000..74846b9
--- /dev/null
+++ b/Utility/Constants.php
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
new file mode 100644
index 0000000..8a1f333
--- /dev/null
+++ b/etc/adminhtml/system.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+ separator-top
+
+ mark_shust
+ MarkShust_PolyshellPatch::polyshellpatch_config
+
+
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ Enable Polyshell Patch
+
+
+
+
+
diff --git a/etc/config.xml b/etc/config.xml
new file mode 100644
index 0000000..a30aa17
--- /dev/null
+++ b/etc/config.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+ 1
+
+
+
+