-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/v1.19.7'
- Loading branch information
Showing
9 changed files
with
232 additions
and
5 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,130 @@ | ||
<?php | ||
namespace Cloudinary\Cloudinary\Controller\Adminhtml\Ajax; | ||
|
||
use Cloudinary\Api\BaseApiClient; | ||
use Cloudinary\Cloudinary\Core\ConfigurationInterface; | ||
use Cloudinary\Cloudinary\Core\ConfigurationBuilder; | ||
use Cloudinary\Cloudinary\Core\Image\ImageFactory; | ||
use Cloudinary\Cloudinary\Core\UrlGenerator; | ||
use Cloudinary\Configuration\Configuration; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Backend\App\Action; | ||
use Magento\Framework\Controller\Result\RawFactory as ResultRawFactory; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent; | ||
use Magento\Framework\Filesystem as FileSysten; | ||
use Magento\Catalog\Helper\Image as CatalogImageHelper; | ||
use Cloudinary\Cloudinary\Core\Image; | ||
use Cloudinary\Asset\Media; | ||
use Cloudinary\Cloudinary\Core\Image\Transformation; | ||
|
||
class UpdateAdminImage extends Action | ||
{ | ||
/** | ||
* @var ConfigurationInterface | ||
*/ | ||
protected $configuration; | ||
/** | ||
* @var UrlGenerator | ||
*/ | ||
protected $urlGenerator; | ||
/** | ||
* @var ImageFactory | ||
*/ | ||
protected $imageFactory; | ||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
protected $storeManager; | ||
|
||
/** | ||
* @var UrlInterface | ||
*/ | ||
protected $urlInterface; | ||
|
||
protected $resultFactory; | ||
|
||
protected $imageContent; | ||
|
||
protected $filesystem; | ||
|
||
private $_authorised; | ||
|
||
protected $configurationBuilder; | ||
|
||
protected $transformation; | ||
|
||
/** | ||
* @param ImageFactory $imageFactory | ||
* @param UrlGenerator $urlGenerator | ||
* @param ConfigurationInterface $configuration | ||
* @param StoreManagerInterface $storeManager | ||
* @param UrlInterface $urlInterface | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
ImageFactory $imageFactory, | ||
UrlGenerator $urlGenerator, | ||
ConfigurationInterface $configuration, | ||
StoreManagerInterface $storeManager, | ||
UrlInterface $urlInterface, | ||
ResultRawFactory $resultFactory, | ||
FileSysten $filesystem, | ||
ConfigurationBuilder $configurationBuilder, | ||
Transformation $transformation | ||
) { | ||
parent::__construct($context); | ||
$this->imageFactory = $imageFactory; | ||
$this->urlGenerator = $urlGenerator; | ||
$this->configuration = $configuration; | ||
$this->storeManager = $storeManager; | ||
$this->urlInterface = $urlInterface; | ||
$this->resultFactory = $resultFactory; | ||
$this->filesystem = $filesystem; | ||
$this->configurationBuilder = $configurationBuilder; | ||
$this->transformation = $transformation; | ||
} | ||
|
||
private function authorise() | ||
{ | ||
if (!$this->_authorised && $this->configuration->isEnabled()) { | ||
Configuration::instance($this->configurationBuilder->build()); | ||
BaseApiClient::$userPlatform = $this->configuration->getUserPlatform(); | ||
$this->_authorised = true; | ||
} | ||
} | ||
|
||
public function execute() | ||
{ | ||
$this->authorise(); | ||
if ($this->configuration->isEnabled()) { | ||
try{ | ||
$remoteImageUrl = $this->getRequest()->getParam('remote_image'); | ||
$filedId = str_replace($this->storeManager->getStore()->getBaseUrl(), '', $remoteImageUrl); | ||
|
||
$result = Media::fromParams( | ||
$filedId, | ||
[ 'transformation' => $this->transformation->build(), | ||
'secure' => true, | ||
'sign_url' => $this->configuration->getUseSignedUrls(), | ||
'version' => 1 | ||
] | ||
) . '?_i=AB'; | ||
|
||
|
||
|
||
|
||
} catch (\Exception $e) { | ||
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; | ||
} | ||
} | ||
|
||
|
||
$response = $this->resultFactory->create(); | ||
$response->setHeader('Content-type', 'text/plain'); | ||
$response->setContents(json_encode($result)); | ||
return $response; | ||
} | ||
} |
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
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
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
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,14 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="content"> | ||
<block class="Magento\Backend\Block\Template" template="Cloudinary_Cloudinary::cms/images.phtml" name="cms_block_edit_images_update" /> | ||
</referenceContainer> | ||
</body> | ||
</page> |
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,15 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<update handle="editor"/> | ||
<body> | ||
<referenceContainer name="content"> | ||
<block class="Magento\Backend\Block\Template" template="Cloudinary_Cloudinary::cms/images.phtml" name="cms_page_edit_images_update" /> | ||
</referenceContainer> | ||
</body> | ||
</page> |
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
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,12 @@ | ||
<?php | ||
/** | ||
* @var Magento\Backend\Block\Template $block | ||
*/ | ||
?> | ||
<script type="text/x-magento-init"> | ||
{"*": { | ||
"updateCmsImages": { "ajaxUrl": "<?= $block->getUrl('cloudinary/ajax/updateadminimage') ?>" } | ||
}} | ||
|
||
</script> | ||
|
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,53 @@ | ||
define( | ||
['jquery','Magento_PageBuilder/js/events','mage/url'], | ||
function($,_PBEvents, urlBuilder){ | ||
'use strict' | ||
return function (config, element) { | ||
var updateHandler = { | ||
images: [], | ||
init: function () { | ||
let self = this; | ||
_PBEvents.on('image:renderAfter', function (event){ | ||
let elem = event.element, key = event.id; | ||
let image = $(elem).find('img'); | ||
let src = {'remote_image': image.attr('src')}; | ||
self.images.push(src); | ||
|
||
self.update(key); | ||
}); | ||
$('#save-button').on('click', function (e){ | ||
self.images.each(function(elem){ | ||
if (elem.cld_image) { | ||
let cld_src = elem.cld_image; | ||
let img = $('img[src="' + cld_src +'"]'); | ||
return (img.length) ? img.attr('src', elem.remote_image) : ''; | ||
} | ||
}); | ||
}); | ||
}, | ||
update: function(key) { | ||
let self = this; | ||
this.images.each(function(elem,ind){ | ||
$.ajax({ | ||
url: config.ajaxUrl, | ||
type: 'POST', | ||
dataType: 'json', | ||
data: elem, | ||
success: function(image) { | ||
self.images[ind].cld_image = image; | ||
let img = $('img[src="' + self.images[ind].remote_image +'"]'); | ||
if (img.length) { | ||
$('img[src="' + self.images[ind].remote_image +'"]').attr('src', self.images[ind].cld_image); | ||
} | ||
}, | ||
error: function(xhr, textStatus, errorThrown) { | ||
console.log('Error:', textStatus, errorThrown); | ||
} | ||
}); | ||
|
||
}) | ||
} | ||
}; | ||
return updateHandler.init(); | ||
} | ||
}); |