Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Controller/Adminhtml/Ajax/RetrieveImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Magento\Framework\Validator\AllowedProtocols;
use Magento\MediaStorage\Model\File\Validator\NotProtectedExtension;
use Magento\MediaStorage\Model\ResourceModel\File\Storage\File as FileUtility;
use Magento\PageBuilder\Controller\Adminhtml\ContentType\Image\Upload as PageBuilderContentTypeUpload;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Theme\Model\Design\Config\FileUploader\FileProcessor;

Expand Down Expand Up @@ -196,6 +197,9 @@ protected function getBaseTmpMediaPath()
case 'design_config_fileUploader':
$baseTmpMediaPath = 'tmp/' . FileProcessor::FILE_DIR;
break;
case 'pagebuilder_contenttype':
$baseTmpMediaPath = PageBuilderContentTypeUpload::UPLOAD_DIR;
break;
case 'category_image':
$baseTmpMediaPath = 'catalog/tmp/category';
break;
Expand All @@ -213,6 +217,7 @@ protected function getLocalTmpFileName($remoteFileUrl)
{
$localFileName = Uploader::getCorrectFileName(basename($remoteFileUrl));
switch ($this->getRequest()->getParam('type')) {
case 'pagebuilder_contenttype':
case 'design_config_fileUploader':
case 'category_image':
$localTmpFileName = DIRECTORY_SEPARATOR . $localFileName;
Expand Down
7 changes: 4 additions & 3 deletions Controller/Adminhtml/Cms/Wysiwyg/Images/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Cloudinary\Cloudinary\Controller\Adminhtml\Cms\Wysiwyg\Images;

use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Cloudinary\Cloudinary\Model\Framework\File\Uploader;
use Cloudinary\Cloudinary\Model\MediaLibraryMapFactory;
use Magento\Backend\App\Action\Context;
use Magento\Catalog\Model\Product\Media\Config;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Filesystem\DirectoryResolver;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Exception\LocalizedException;
use Cloudinary\Cloudinary\Model\Framework\File\Uploader;
use Magento\Framework\Filesystem;
use Magento\Framework\HTTP\Adapter\Curl;
use Magento\Framework\Image\AdapterFactory;
Expand Down Expand Up @@ -100,7 +101,7 @@ class Upload extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Upload
* @param Context $context
* @param Registry $coreRegistry
* @param JsonFactory $resultJsonFactory
* @param \Magento\Framework\App\Filesystem\DirectoryResolver|null $directoryResolver
* @param DirectoryResolver|null $directoryResolver
* @param DirectoryList $directoryList
* @param Config $mediaConfig
* @param Filesystem $fileSystem
Expand All @@ -116,7 +117,7 @@ public function __construct(
Context $context,
Registry $coreRegistry,
JsonFactory $resultJsonFactory,
$directoryResolver = null,
DirectoryResolver $directoryResolver = null,
DirectoryList $directoryList,
Config $mediaConfig,
Filesystem $fileSystem,
Expand Down
3 changes: 2 additions & 1 deletion Model/Api/ProductGalleryManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ public function addItems($items)
$result["items"][$i]["message"] = $this->configuration->isEnabledProductgalleryApiQueue() ? "The item was added to the queue." : "success";
$this->processOrQueue(
(isset($item["url"])) ? $item["url"] : null,
(isset($item["sku"])) ? $item["sku"] : null(isset($item["publicId"])) ? $item["publicId"] : null,
(isset($item["sku"])) ? $item["sku"] : null,
(isset($item["publicId"])) ? $item["publicId"] : null,
(isset($item["roles"])) ? $item["roles"] : null,
(isset($item["label"])) ? $item["label"] : null,
(isset($item["disabled"])) ? $item["disabled"] : null,
Expand Down
2 changes: 1 addition & 1 deletion Model/BatchUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class BatchUploader
{
const ERROR_MIGRATION_ALREADY_RUNNING = 'Cannot start upload - a migration is in progress or was interrupted. If you are sure a migration is not running elsewhere run the cloudinary:upload:stop command before attempting another upload.';
const ERROR_MIGRATION_ALREADY_RUNNING = 'Cannot start upload - a migration is in progress or was interrupted. If you are sure a migration is not running elsewhere run the cloudinary:migration:stop command before attempting another upload.';
const ERROR_AUTO_UPLOAD1 = 'Manual migration is not required when auto upload mapping is enabled.';
const ERROR_AUTO_UPLOAD2 = 'Please disable auto upload mapping and refresh the configuration cache ' .
'if you wish to perform a manual migration.';
Expand Down
14 changes: 7 additions & 7 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public function parseCloudinaryUrl($url, $publicId = null)
*
* @return array
*/
public function mbParseUrl($url, $component=-1)
public function mbParseUrl($url, $component = -1)
{
$enc_url = preg_replace_callback(
'%[^:/@?&=#]+%usD',
Expand Down Expand Up @@ -653,12 +653,12 @@ public function addUniquePrefixToBasename($filename, $uniqid = null)
}

/**
* Log to var/log/cloudinary_cloudinary.log
* @method log
* @param mixed $message
* @param array $data
* @return $this
*/
* Log to var/log/cloudinary_cloudinary.log
* @method log
* @param mixed $message
* @param array $data
* @return $this
*/
public function log($message, $data = [], $prefix = '[Cloudinary Log] ')
{
$this->cloudinaryLogger->info($prefix . json_encode($message), $data);
Expand Down
3 changes: 2 additions & 1 deletion Plugin/Catalog/Block/Product/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ public function aroundCreate(CatalogImageFactory $catalogImageFactory, callable
}

if ($this->configuration->isEnabledLazyload()) {
$useOldImageTheme = is_string($imageBlock->getCustomAttributes()) ? 'old_' : '';
$imageBlock->setTemplate(
\preg_match('/\/image_with_borders.phtml$/', $imageBlock->getTemplate()) ?
'Cloudinary_Cloudinary::product/image_with_borders.phtml' : 'Cloudinary_Cloudinary::product/image.phtml'
'Cloudinary_Cloudinary::product/' . $useOldImageTheme . 'image_with_borders.phtml' : 'Cloudinary_Cloudinary::' . $useOldImageTheme . 'product/image.phtml'
);
$imageBlock->setLazyloadPlaceholder(Configuration::LAZYLOAD_DATA_PLACEHOLDER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private function processMediaPerStore(
array $mediaGalleryData,
array $newMediaValues,
array $valueToProductId
) {
) {
$multiInsertData = [];
$multiInsertDataVideos = [];
$dataForSkinnyTable = [];
Expand Down
2 changes: 2 additions & 0 deletions Plugin/Ui/Component/Form/Element/DataType/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function afterPrepare(\Magento\Ui\Component\Form\Element\DataType\Media $
$type = 'design_config_fileUploader';
} elseif (strpos($uploaderConfigUrl, '/category_image/') !== false) {
$type = 'category_image';
} elseif (strpos($uploaderConfigUrl, '/pagebuilder/contenttype/') !== false) {
$type = 'pagebuilder_contenttype';
} else {
$type = null;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cloudinary/cloudinary-magento2",
"description": "Cloudinary Magento 2 Integration.",
"type": "magento2-module",
"version": "1.13.0",
"version": "1.14.4",
"license": "MIT",
"require": {
"cloudinary/cloudinary_php": "*"
Expand Down
83 changes: 8 additions & 75 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,35 @@
<policies>
<policy id="script-src">
<values>
<value id="cloudinary_main" type="host">cloudinary.com</value>
<value id="cloudinary_main_www" type="host">www.cloudinary.com</value>
<value id="cloudinary_api" type="host">api.cloudinary.com</value>
<value id="cloudinary_media_library" type="host">media-library.cloudinary.com</value>
<value id="cloudinary_product_gallery" type="host">product-gallery.cloudinary.com</value>
<value id="cloudinary_analytics_api" type="host">analytics-api.cloudinary.com</value>
<value id="cloudinary_main" type="host">*.cloudinary.com</value>
<value id="cloudinary_cloudflare_cdnjs" type="host">cdnjs.cloudflare.com</value>
<value id="cloudinary_res" type="host">res.cloudinary.com</value>
<value id="cloudinary_res_1" type="host">res-1.cloudinary.com</value>
<value id="cloudinary_res_2" type="host">res-2.cloudinary.com</value>
<value id="cloudinary_res_3" type="host">res-3.cloudinary.com</value>
<value id="cloudinary_res_4" type="host">res-4.cloudinary.com</value>
<value id="cloudinary_res_5" type="host">res-5.cloudinary.com</value>
</values>
</policy>
<policy id="connect-src">
<policy id="frame-src">
<values>
<value id="cloudinary_main" type="host">cloudinary.com</value>
<value id="cloudinary_main_www" type="host">www.cloudinary.com</value>
<value id="cloudinary_api" type="host">p.cloudinary.com</value>
<value id="cloudinary_media_library" type="host">media-library.cloudinary.com</value>
<value id="cloudinary_product_gallery" type="host">product-gallery.cloudinary.com</value>
<value id="cloudinary_analytics_api" type="host">analytics-api.cloudinary.com</value>
<value id="cloudinary_main" type="host">*.cloudinary.com</value>
<value id="cloudinary_cloudflare_cdnjs" type="host">cdnjs.cloudflare.com</value>
<value id="cloudinary_res" type="host">res.cloudinary.com</value>
<value id="cloudinary_res_1" type="host">res-1.cloudinary.com</value>
<value id="cloudinary_res_2" type="host">res-2.cloudinary.com</value>
<value id="cloudinary_res_3" type="host">res-3.cloudinary.com</value>
<value id="cloudinary_res_4" type="host">res-4.cloudinary.com</value>
<value id="cloudinary_res_5" type="host">res-5.cloudinary.com</value>
</values>
</policy>
<policy id="frame-src">
<policy id="connect-src">
<values>
<value id="cloudinary_main" type="host">cloudinary.com</value>
<value id="cloudinary_main_www" type="host">www.cloudinary.com</value>
<value id="cloudinary_api" type="host">p.cloudinary.com</value>
<value id="cloudinary_media_library" type="host">media-library.cloudinary.com</value>
<value id="cloudinary_product_gallery" type="host">product-gallery.cloudinary.com</value>
<value id="cloudinary_analytics_api" type="host">analytics-api.cloudinary.com</value>
<value id="cloudinary_cloudflare_cdnjs" type="host">cdnjs.cloudflare.com</value>
<value id="cloudinary_res" type="host">res.cloudinary.com</value>
<value id="cloudinary_res_1" type="host">res-1.cloudinary.com</value>
<value id="cloudinary_res_2" type="host">res-2.cloudinary.com</value>
<value id="cloudinary_res_3" type="host">res-3.cloudinary.com</value>
<value id="cloudinary_res_4" type="host">res-4.cloudinary.com</value>
<value id="cloudinary_res_5" type="host">res-5.cloudinary.com</value>
<value id="cloudinary_main" type="host">*.cloudinary.com</value>
</values>
</policy>
<policy id="form-action">
<values>
<value id="cloudinary_main" type="host">cloudinary.com</value>
<value id="cloudinary_main_www" type="host">www.cloudinary.com</value>
<value id="cloudinary_api" type="host">p.cloudinary.com</value>
<value id="cloudinary_media_library" type="host">media-library.cloudinary.com</value>
<value id="cloudinary_product_gallery" type="host">product-gallery.cloudinary.com</value>
<value id="cloudinary_analytics_api" type="host">analytics-api.cloudinary.com</value>
<value id="cloudinary_res" type="host">res.cloudinary.com</value>
<value id="cloudinary_res_1" type="host">res-1.cloudinary.com</value>
<value id="cloudinary_res_2" type="host">res-2.cloudinary.com</value>
<value id="cloudinary_res_3" type="host">res-3.cloudinary.com</value>
<value id="cloudinary_res_4" type="host">res-4.cloudinary.com</value>
<value id="cloudinary_res_5" type="host">res-5.cloudinary.com</value>
<value id="cloudinary_main" type="host">*.cloudinary.com</value>
</values>
</policy>
<policy id="img-src">
<values>
<value id="cloudinary_main" type="host">cloudinary.com</value>
<value id="cloudinary_main_www" type="host">www.cloudinary.com</value>
<value id="cloudinary_api" type="host">p.cloudinary.com</value>
<value id="cloudinary_media_library" type="host">media-library.cloudinary.com</value>
<value id="cloudinary_product_gallery" type="host">product-gallery.cloudinary.com</value>
<value id="cloudinary_analytics_api" type="host">analytics-api.cloudinary.com</value>
<value id="cloudinary_res" type="host">res.cloudinary.com</value>
<value id="cloudinary_res_1" type="host">res-1.cloudinary.com</value>
<value id="cloudinary_res_2" type="host">res-2.cloudinary.com</value>
<value id="cloudinary_res_3" type="host">res-3.cloudinary.com</value>
<value id="cloudinary_res_4" type="host">res-4.cloudinary.com</value>
<value id="cloudinary_res_5" type="host">res-5.cloudinary.com</value>
<value id="cloudinary_main" type="host">*.cloudinary.com</value>
<value id="data" type="host">data:</value>
</values>
</policy>
<policy id="style-src">
<values>
<value id="cloudinary_main" type="host">cloudinary.com</value>
<value id="cloudinary_main_www" type="host">www.cloudinary.com</value>
<value id="cloudinary_api" type="host">p.cloudinary.com</value>
<value id="cloudinary_media_library" type="host">media-library.cloudinary.com</value>
<value id="cloudinary_product_gallery" type="host">product-gallery.cloudinary.com</value>
<value id="cloudinary_analytics_api" type="host">analytics-api.cloudinary.com</value>
<value id="cloudinary_res" type="host">res.cloudinary.com</value>
<value id="cloudinary_res_1" type="host">res-1.cloudinary.com</value>
<value id="cloudinary_res_2" type="host">res-2.cloudinary.com</value>
<value id="cloudinary_res_3" type="host">res-3.cloudinary.com</value>
<value id="cloudinary_res_4" type="host">res-4.cloudinary.com</value>
<value id="cloudinary_res_5" type="host">res-5.cloudinary.com</value>
<value id="cloudinary_main" type="host">*.cloudinary.com</value>
</values>
</policy>
</policies>
Expand Down
3 changes: 2 additions & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Cloudinary_Cloudinary" setup_version="1.13.0">
<module name="Cloudinary_Cloudinary" setup_version="1.14.4">
<sequence>
<module name="Magento_ProductVideo"/>
<module name="Magento_PageBuilder"/>
</sequence>
</module>
</config>
2 changes: 1 addition & 1 deletion marketplace.composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cloudinary/cloudinary",
"description": "Cloudinary Magento 2 Integration.",
"type": "magento2-module",
"version": "1.13.0",
"version": "1.14.4",
"license": "MIT",
"require": {
"cloudinary/cloudinary_php": "*"
Expand Down
8 changes: 8 additions & 0 deletions view/adminhtml/layout/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="before.body.end">
<block class="Cloudinary\Cloudinary\Block\Lazyload" name="cloudinary_lazyload" template="Cloudinary_Cloudinary::lazyload.phtml" ifconfig="cloudinary/lazyload/enabled"/>
</referenceContainer>
</body>
</page>
14 changes: 14 additions & 0 deletions view/adminhtml/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ var config = {
cloudinarySpinsetModal: 'Cloudinary_Cloudinary/js/cloudinary-spinset-modal',
cldspinsetDialog: 'Cloudinary_Cloudinary/js/cloudinary-spinset-dialog',
productGallery: 'Cloudinary_Cloudinary/js/product-gallery',
cloudinaryLazyload: 'Cloudinary_Cloudinary/js/cloudinary-lazyload'
}
},
paths: {
'jquery.lazyload': "Cloudinary_Cloudinary/js/jquery.lazyload.min",
cloudinaryMediaLibraryAll: "//media-library.cloudinary.com/global/all",
es6Promise: "//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min"
},
shim: {
'jquery.lazyload': {
deps: ['jquery']
},
},
config: {
mixins: {
'Magento_Ui/js/lib/validation/validator': {
'Cloudinary_Cloudinary/js/form/element/validator-rules-mixin': true
},
}
}
};
9 changes: 9 additions & 0 deletions view/adminhtml/templates/lazyload.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* @var \Cloudinary\Cloudinary\Block\Lazyload $block
*/
?>
<?php if (!$block->isEnabledLazyload()) {
return;
} ?>
<script type="text/x-magento-init">{"*": {"cloudinaryLazyload": <?= $block->getLazyloadOptions() ?>}}</script>
21 changes: 21 additions & 0 deletions view/adminhtml/ui_component/pagebuilder_video_form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd" extends="pagebuilder_base_form">
<fieldset name="general" sortOrder="20">
<field name="video_source" formElement="input">
<settings>
<validation>
<rule name="validate-video-url" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Video URL</label>
<notice translate="true">YouTube, Vimeo and Cloudinary are supported</notice>
</settings>
</field>
</fieldset>
</form>
38 changes: 38 additions & 0 deletions view/adminhtml/web/js/form/element/validator-rules-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'underscore',
'Magento_Ui/js/lib/validation/utils'
], function($, _, utils) {
'use strict';

/**
* Validate that string is url
* @param {String} href
* @return {Boolean}
*/
function validateIsUrl(href) {
return (/^(http|https|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i).test(href); //eslint-disable-line max-len
}

return function(validator) {
validator.addRule(
'validate-video-url',
function(href) {
if (utils.isEmptyNoTrim(href)) {
return true;
}

href = (href || '').replace(/^\s+/, '').replace(/\s+$/, '');

return validateIsUrl(href) && (href.match(/youtube\.com|youtu\.be/) || href.match(/vimeo\.com/) || href.match(/cloudinary\.com/));
},
$.mage.__('Please enter a valid video URL.')
);
return validator;
};
});
Loading