-
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 pull request #24 from cloudinary/v1.9.0
V1.9.0
- Loading branch information
Showing
79 changed files
with
4,742 additions
and
418 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,76 @@ | ||
<?php | ||
|
||
namespace Cloudinary\Cloudinary\Block\Adminhtml\Cms\Wysiwyg\Images; | ||
|
||
use Cloudinary\Cloudinary\Helper\MediaLibraryHelper; | ||
use Magento\Backend\Block\Widget\Context; | ||
use Magento\Framework\Json\EncoderInterface; | ||
|
||
/** | ||
* Wysiwyg Images content block | ||
* | ||
* @api | ||
* @since 100.0.2 | ||
*/ | ||
class Content extends \Magento\Cms\Block\Adminhtml\Wysiwyg\Images\Content | ||
{ | ||
/** | ||
* MediaLibraryHelper | ||
* @var array|null | ||
*/ | ||
protected $mediaLibraryHelper; | ||
|
||
/** | ||
* @param Context $context | ||
* @param EncoderInterface $jsonEncoder | ||
* @param MediaLibraryHelper $mediaLibraryHelper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
EncoderInterface $jsonEncoder, | ||
MediaLibraryHelper $mediaLibraryHelper, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $jsonEncoder, $data); | ||
$this->mediaLibraryHelper = $mediaLibraryHelper; | ||
} | ||
|
||
/** | ||
* Get Cloudinary media library widget options | ||
* | ||
* @param bool $multiple Allow multiple | ||
* @param bool $refresh Refresh options | ||
* @return string | ||
*/ | ||
public function getCloudinaryMediaLibraryWidgetOptions($multiple = false, $refresh = false) | ||
{ | ||
if (!($cloudinaryMLoptions = $this->mediaLibraryHelper->getCloudinaryMLOptions($multiple, $refresh))) { | ||
return null; | ||
} | ||
return $this->_jsonEncoder->encode( | ||
[ | ||
'cldMLid' => 'wysiwyg_media_gallery', | ||
'imageUploaderUrl' => $this->_urlBuilder->addSessionParam()->getUrl('cloudinary/cms_wysiwyg_images/upload', ['type' => $this->_getMediaType()]), | ||
'triggerSelector' => '.media-gallery-modal', | ||
'triggerEvent' => 'fileuploaddone', | ||
'cloudinaryMLoptions' => $cloudinaryMLoptions, | ||
'addTmpExtension' => false, | ||
'cloudinaryMLshowOptions' => $this->mediaLibraryHelper->getCloudinaryMLshowOptions("image"), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Return current media type based on request or data | ||
* | ||
* @return string | ||
*/ | ||
protected function _getMediaType() | ||
{ | ||
if ($this->hasData('media_type')) { | ||
return $this->_getData('media_type'); | ||
} | ||
return $this->getRequest()->getParam('type'); | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* Catalog product form gallery content | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
* | ||
* @method \Magento\Framework\Data\Form\Element\AbstractElement getElement() | ||
*/ | ||
namespace Cloudinary\Cloudinary\Block\Adminhtml\Product\Helper\Form\Gallery; | ||
|
||
use Cloudinary\Cloudinary\Helper\MediaLibraryHelper; | ||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Catalog\Model\Product\Media\Config; | ||
use Magento\Framework\Json\EncoderInterface; | ||
|
||
/** | ||
* Block for gallery content. | ||
*/ | ||
class Content extends \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $_template = 'Cloudinary_Cloudinary::catalog/product/helper/gallery.phtml'; | ||
|
||
/** | ||
* MediaLibraryHelper | ||
* @var array|null | ||
*/ | ||
protected $mediaLibraryHelper; | ||
|
||
/** | ||
* @param Context $context | ||
* @param EncoderInterface $jsonEncoder | ||
* @param Config $mediaConfig | ||
* @param MediaLibraryHelper $mediaLibraryHelper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
EncoderInterface $jsonEncoder, | ||
Config $mediaConfig, | ||
MediaLibraryHelper $mediaLibraryHelper, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $jsonEncoder, $mediaConfig, $data); | ||
$this->mediaLibraryHelper = $mediaLibraryHelper; | ||
} | ||
|
||
/** | ||
* Get Cloudinary media library widget options | ||
* | ||
* @param bool $multiple Allow multiple | ||
* @param bool $refresh Refresh options | ||
* @return string | ||
*/ | ||
public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refresh = false) | ||
{ | ||
if (!($cloudinaryMLoptions = $this->mediaLibraryHelper->getCloudinaryMLOptions($multiple, $refresh))) { | ||
return null; | ||
} | ||
return $this->_jsonEncoder->encode( | ||
[ | ||
'htmlId' => $this->getHtmlId(), | ||
'cldMLid' => 'product_gallery_' . $this->getHtmlId(), | ||
'imageUploaderUrl' => $this->_urlBuilder->addSessionParam()->getUrl('cloudinary/ajax/retrieveImage'), | ||
'triggerSelector' => '#media_gallery_content', | ||
'triggerEvent' => 'addItem', | ||
'useDerived' => false, | ||
'addTmpExtension' => true, | ||
'cloudinaryMLoptions' => $cloudinaryMLoptions, | ||
'cloudinaryMLshowOptions' => $this->mediaLibraryHelper->getCloudinaryMLshowOptions(null), | ||
] | ||
); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Cloudinary\Cloudinary\Block\Adminhtml\System\Config\Form\Field; | ||
|
||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class ColorPicker extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
|
||
/** | ||
* add color picker in admin configuration fields | ||
* @param AbstractElement $element | ||
* @return string script | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
$html = $element->getElementHtml(); | ||
$value = $element->getData('value'); | ||
|
||
$html .= '<script type="text/javascript"> | ||
require(["jquery", "jquery/colorpicker/js/colorpicker"], function ($) { | ||
$(document).ready(function () { | ||
var $el = $("#' . $element->getHtmlId() . '"); | ||
$el.css("backgroundColor", $el.val()).val("#" + $el.val().replace(/^(#)/,"").substring(0, 6)); | ||
$el.ColorPicker({ | ||
color: "#" + $el.val().replace(/^(#)/,"").substring(0, 6), | ||
onChange: function (hsb, hex, rgb) { | ||
$el.css("backgroundColor", "#" + hex).val("#" + hex); | ||
} | ||
}); | ||
$el.on("change keyup focus", function(){ | ||
var currentVal = $(this).val().replace(/^(#)/,"").substring(0, 6); | ||
$(this).val("#" + currentVal); | ||
$(this).css("backgroundColor", "#" + currentVal); | ||
$(this).ColorPickerSetColor("#" + currentVal); | ||
}); | ||
}); | ||
}); | ||
</script>'; | ||
|
||
return $html; | ||
} | ||
} |
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,96 @@ | ||
<?php | ||
|
||
namespace Cloudinary\Cloudinary\Command; | ||
|
||
use Cloudinary\Cloudinary\Model\BatchDownloader; | ||
use Cloudinary\Cloudinary\Model\Logger\OutputLogger; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
class DownloadImages extends Command | ||
{ | ||
/**#@+ | ||
* Keys and shortcuts for input arguments and options | ||
*/ | ||
const OVERRIDE = 'override'; | ||
/**#@- */ | ||
|
||
const OVERRIDE_CONFIRM_MESSAGE = "<question>Are you sure you want to override local files (y/n)[n]?</question>"; | ||
|
||
private $_override = false; | ||
|
||
/** | ||
* @var BatchDownloader | ||
*/ | ||
private $batchDownloader; | ||
|
||
/** | ||
* @var OutputLogger | ||
*/ | ||
private $outputLogger; | ||
|
||
/** | ||
* @param BatchDownloader $batchDownloader | ||
*/ | ||
public function __construct(BatchDownloader $batchDownloader, OutputLogger $outputLogger) | ||
{ | ||
parent::__construct('cloudinary:download:all'); | ||
|
||
$this->batchDownloader = $batchDownloader; | ||
$this->outputLogger = $outputLogger; | ||
} | ||
|
||
/** | ||
* Configure the command | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('cloudinary:download:all'); | ||
$this->setDescription('Download images from Cloudinary to the local pub/media dir'); | ||
$this->setDefinition([ | ||
new InputOption( | ||
self::OVERRIDE, | ||
'-o', | ||
InputOption::VALUE_NONE, | ||
'Override local images if already exists' | ||
), | ||
]); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
try { | ||
if ($input->getOption(self::OVERRIDE) && $this->confirmQuestion(self::OVERRIDE_CONFIRM_MESSAGE, $input, $output)) { | ||
$this->_override = true; | ||
} | ||
$this->outputLogger->setOutput($output); | ||
$this->batchDownloader->downloadUnsynchronisedImages($this->outputLogger, $this->_override); | ||
} catch (\Exception $e) { | ||
$output->writeln($e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @method confirmQuestion | ||
* @param string $message | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return bool | ||
*/ | ||
private function confirmQuestion(string $message, InputInterface $input, OutputInterface $output) | ||
{ | ||
$confirmationQuestion = new ConfirmationQuestion($message, false); | ||
return (bool)$this->getHelper('question')->ask($input, $output, $confirmationQuestion); | ||
} | ||
} |
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
Oops, something went wrong.