Created
April 27, 2018 20:30
-
-
Save meminuygur/bb078a52e43525d13d1bd2dcf7722518 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace Fietsuniek\BaseConfig\Override\Cms\Model\Wysiwyg\Images; | |
use Magento\Cms\Model\Wysiwyg\Images\Storage as WysiwygImagesStorage; | |
/** | |
* Override thumbs directory name .thumbs folder not accessible in youwe hosting environment | |
* | |
* @SuppressWarnings(PHPMD.LongVariable) | |
* @SuppressWarnings(PHPMD.TooManyFields) | |
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | |
* | |
* @api | |
* @since 100.0.2 | |
*/ | |
class Storage extends WysiwygImagesStorage | |
{ | |
const THUMBS_DIRECTORY_NAME = 'thumbs'; | |
/** | |
* Construct | |
* | |
* @param \Magento\Backend\Model\Session $session | |
* @param \Magento\Backend\Model\UrlInterface $backendUrl | |
* @param \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages | |
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb | |
* @param \Magento\Framework\Filesystem $filesystem | |
* @param \Magento\Framework\Image\AdapterFactory $imageFactory | |
* @param \Magento\Framework\View\Asset\Repository $assetRepo | |
* @param \Magento\Cms\Model\Wysiwyg\Images\Storage\CollectionFactory $storageCollectionFactory | |
* @param \Magento\MediaStorage\Model\File\Storage\FileFactory $storageFileFactory | |
* @param \Magento\MediaStorage\Model\File\Storage\DatabaseFactory $storageDatabaseFactory | |
* @param \Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory $directoryDatabaseFactory | |
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory | |
* @param array $resizeParameters | |
* @param array $extensions | |
* @param array $dirs | |
* @param array $data | |
* | |
* @throws \Magento\Framework\Exception\FileSystemException | |
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | |
*/ | |
public function __construct( | |
\Magento\Backend\Model\Session $session, | |
\Magento\Backend\Model\UrlInterface $backendUrl, | |
\Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages, | |
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb, | |
\Magento\Framework\Filesystem $filesystem, | |
\Magento\Framework\Image\AdapterFactory $imageFactory, | |
\Magento\Framework\View\Asset\Repository $assetRepo, | |
\Magento\Cms\Model\Wysiwyg\Images\Storage\CollectionFactory $storageCollectionFactory, | |
\Magento\MediaStorage\Model\File\Storage\FileFactory $storageFileFactory, | |
\Magento\MediaStorage\Model\File\Storage\DatabaseFactory $storageDatabaseFactory, | |
\Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory $directoryDatabaseFactory, | |
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, | |
array $resizeParameters = [], | |
array $extensions = [], | |
array $dirs = [], | |
array $data = [] | |
) { | |
parent::__construct( | |
$session, | |
$backendUrl, | |
$cmsWysiwygImages, | |
$coreFileStorageDb, | |
$filesystem, | |
$imageFactory, | |
$assetRepo, | |
$storageCollectionFactory, | |
$storageFileFactory, | |
$storageDatabaseFactory, | |
$directoryDatabaseFactory, | |
$uploaderFactory, | |
$resizeParameters, | |
$extensions, | |
$dirs, | |
$data | |
); | |
} | |
public function getThumbnailUrl($filePath, $checkFile = false) | |
{ | |
$mediaRootDir = $this->_cmsWysiwygImages->getStorageRoot(); | |
if (strpos($filePath, $mediaRootDir) === 0) { | |
$thumbSuffix = self::THUMBS_DIRECTORY_NAME . substr($filePath, strlen($mediaRootDir)); | |
if (!$checkFile || $this->_directory->isExist( | |
$this->_directory->getRelativePath($mediaRootDir . '/' . $thumbSuffix) | |
) | |
) { | |
$thumbSuffix = substr( | |
$mediaRootDir, | |
strlen($this->_directory->getAbsolutePath()) | |
) . '/' . $thumbSuffix; | |
$randomIndex = '?rand=' . time(); | |
return str_replace('\\', '/', $this->_cmsWysiwygImages->getBaseUrl() . $thumbSuffix) . $randomIndex; | |
} | |
} | |
return false; | |
} | |
public function getThumbnailRoot() | |
{ | |
return $this->_cmsWysiwygImages->getStorageRoot() . '/' . self::THUMBS_DIRECTORY_NAME; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment