Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.1",
"license": "MIT",
"require": {
"cloudinary/cloudinary_php": "*"
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.1">
<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.1",
"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;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ define([

initialize: function(options) {
var widget = this;
options = widget.mergeOptions(widget.options, options);
options = this.mergeOptions(this.options, options);
this.cldLazyloadInit(options);
setInterval(function() {
widget.cldLazyloadInit(options);
}, 4000);
},

cldLazyloadInit: function(options) {
if ($(".cloudinary-lazyload").length) {
var widget = this;
try {
$(".cloudinary-lazyload").lazyload(widget.options);
$(".cloudinary-lazyload").lazyload(options || widget.options);
$(".cloudinary-lazyload").addClass("cloudinary-lazyload-processed").removeClass("cloudinary-lazyload");
} catch (err) {
console.warn("Notice: An error occured while initializing Lazyload (" + err + "). Trying to fix automatically...");
$(".cloudinary-lazyload").each(function() {
Expand All @@ -40,11 +49,10 @@ define([
} else {
$(this).css("background-image", "url('" + $(this).attr("data-original") + "')");
}
$(this).removeClass("cloudinary-lazyload");
$(this).addClass("cloudinary-lazyload-processed").removeClass("cloudinary-lazyload");
});
}
}

},

/**
Expand Down
19 changes: 12 additions & 7 deletions view/frontend/templates/product/image.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
* See COPYING.txt for license details.
*/
?>
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>

<img class="photo image cloudinary-lazyload <?= $block->escapeHtmlAttr($block->getClass()) ?>"
<?= $block->escapeHtml($block->getCustomAttributes()) ?>
<?php
/** @var $block \Magento\Catalog\Block\Product\Image */
/** @var $escaper \Magento\Framework\Escaper */
?>
<!--deprecated template as image_with_borders is a primary one-->
<img class="photo image cloudinary-lazyload <?= $escaper->escapeHtmlAttr($block->getClass()) ?>"
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
<?= $escaper->escapeHtmlAttr($name) ?>="<?= $escaper->escapeHtmlAttr($value) ?>"
<?php endforeach; ?>
src="<?= $block->getLazyloadPlaceholder() ?>"
data-original="<?= $block->escapeUrl($block->getImageUrl()) ?>"
width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>" />
width="<?= $escaper->escapeHtmlAttr($block->getWidth()) ?>"
height="<?= $escaper->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>" />
Loading