20 private $imageDirectorySubpath;
78 \
Magento\Backend\Helper\Data $backendData,
83 parent::__construct($context);
84 $this->_backendData = $backendData;
131 return $this->_storeManager->getStore()->getBaseUrl(\
Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
165 if (
$id === \
Magento\Theme\Helper\Storage::NODE_ROOT) {
169 if (preg_match(
'/\.\.(\\\|\/)/',
$path)) {
170 throw new \InvalidArgumentException(
'Path is invalid');
184 $checkResult = (object) [];
185 $checkResult->isAllowed =
false;
186 $this->_eventManager->dispatch(
187 'cms_wysiwyg_images_static_urls_allowed',
188 [
'result' => $checkResult,
'store_id' => $this->_storeId]
190 return $checkResult->isAllowed;
203 $mediaUrl = $this->_storeManager->getStore()->getBaseUrl(\
Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
204 $mediaPath = str_replace($mediaUrl,
'', $fileUrl);
205 $directive = sprintf(
'{{media url="%s"}}',
$mediaPath);
208 $html = sprintf(
'<img src="%s" alt="" />', $src);
213 $directive = $this->urlEncoder->encode($directive);
214 $html = $this->_backendData->getUrl(
215 'cms/wysiwyg/directive',
217 '___directive' => $directive,
218 '_escape_params' =>
false,
235 if (!$this->_currentPath) {
240 if ($this->_directory->isDirectory($this->_directory->getRelativePath(
$path))) {
241 $currentPath =
$path;
245 $currentDir = $this->_directory->getRelativePath($currentPath);
246 if (!$this->_directory->isExist($currentDir)) {
247 $this->_directory->create($currentDir);
249 }
catch (\
Magento\Framework\Exception\FileSystemException $e) {
250 $message =
__(
'The directory %1 is not writable by server.', $currentPath);
251 throw new \Magento\Framework\Exception\LocalizedException(
$message);
253 $this->_currentPath = $currentPath;
265 if (!$this->_currentUrl) {
267 $mediaUrl = $this->_storeManager->getStore(
270 \
Magento\Framework\UrlInterface::URL_TYPE_MEDIA
272 $this->_currentUrl = rtrim($mediaUrl . $this->_directory->getRelativePath(
$path),
'/') .
'/';
285 return strtr(base64_encode($string),
'+/=',
':_-');
296 $string = strtr($string,
':_-',
'+/=');
297 return base64_decode($string);
309 if (strlen($filename) <= $maxLength) {
312 return substr($filename, 0, $maxLength) .
'...';
323 $this->imageDirectorySubpath = $subpath;
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Backend\Helper\Data $backendData, \Magento\Framework\Filesystem $filesystem, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Escaper $escaper)
isUsingStaticUrlsAllowed()
getImageHtmlDeclaration($filename, $renderAsTag=false)
getShortFilename($filename, $maxLength=20)
setImageDirectorySubpath($subpath)