Skip to content

Commit

Permalink
Merge pull request #24 from cloudinary/v1.9.0
Browse files Browse the repository at this point in the history
V1.9.0
  • Loading branch information
Pniel (Pini) Cohen authored Apr 30, 2019
2 parents 059c48c + 66c4f72 commit f2adee1
Show file tree
Hide file tree
Showing 79 changed files with 4,742 additions and 418 deletions.
76 changes: 76 additions & 0 deletions Block/Adminhtml/Cms/Wysiwyg/Images/Content.php
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');
}
}
81 changes: 81 additions & 0 deletions Block/Adminhtml/Product/Helper/Form/Gallery/Content.php
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),
]
);
}
}
43 changes: 43 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/ColorPicker.php
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;
}
}
96 changes: 96 additions & 0 deletions Command/DownloadImages.php
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);
}
}
10 changes: 5 additions & 5 deletions Command/StopMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class StopMigration extends Command
{
const NOP_MESSAGE = 'No upload running to stop.';
const STOPPED_MESSAGE = 'Upload manually stopped.';
const NOP_MESSAGE = 'No upload/download running to stop.';
const STOPPED_MESSAGE = 'Upload/Download manually stopped.';

/**
* @var MigrationTask
*/
Expand All @@ -22,7 +22,7 @@ class StopMigration extends Command
*/
public function __construct(MigrationTask $migrationTask)
{
parent::__construct('cloudinary:upload:stop');
parent::__construct('cloudinary:migration:stop');

$this->migrationTask = $migrationTask;
}
Expand All @@ -34,7 +34,7 @@ public function __construct(MigrationTask $migrationTask)
*/
protected function configure()
{
$this->setDescription('Stops any currently running upload.');
$this->setDescription('Stops any currently running upload/download.');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Controller/Adminhtml/Ajax/Free/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Cloudinary\Cloudinary\Controller\Adminhtml\Ajax\Free;

use Cloudinary\Cloudinary\Core\Image\Transformation\Freeform;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Cloudinary\Cloudinary\Core\Image\Transformation;
use Cloudinary\Cloudinary\Core\Image\Transformation\Freeform;
use Cloudinary\Cloudinary\Model\Config\Backend\Free as FreeBackendModel;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Cloudinary\Cloudinary\Model\Config\Backend\Free as FreeBackendModel;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;

class Image extends Action
{
Expand Down
Loading

0 comments on commit f2adee1

Please sign in to comment.