Skip to content

Commit 9169ad3

Browse files
author
Pini
authored
Merge pull request #10 from cloudinary/CLOUDINARY-4
Cloudinary 4
2 parents 31d81d8 + 421b7f1 commit 9169ad3

File tree

8 files changed

+31
-13
lines changed

8 files changed

+31
-13
lines changed

Core/CloudinaryImageProvider.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ public function upload(Image $image)
9292
*/
9393
public function retrieveTransformed(Image $image, Transformation $transformation)
9494
{
95-
$imagePath = \cloudinary_url($image->getId(), ['transformation' => $transformation->build(), 'secure' => true]);
95+
$imagePath = \cloudinary_url($image->getId(), [
96+
'transformation' => $transformation->build(),
97+
'secure' => true,
98+
'sign_url' => $this->configuration->getUseSignedUrls()
99+
]);
96100

97101
if ($this->configuration->getUseRootPath()) {
98102
$imagePath = str_replace(".com/{$this->configuration->getCloud()}/image/upload/", ".com/{$this->configuration->getCloud()}/", $imagePath);

Core/Image/Transformation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class Transformation
2323

2424
public function __construct()
2525
{
26-
$this->crop = 'pad';
26+
$this->crop = 'lpad';
2727
$this->flags = [];
2828
}
2929

3030
public function withGravity(Gravity $gravity)
3131
{
3232
$this->gravity = $gravity;
33-
$this->crop = ((string)$gravity) ? 'crop' : 'pad';
33+
$this->crop = ((string)$gravity) ? 'crop' : 'lpad';
3434
return $this;
3535
}
3636

Core/Image/Transformation/Crop.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Crop
66
{
7-
const PAD = 'pad';
7+
const PAD = 'lpad';
88
const FIT = 'fit';
99

1010
private $value;

Model/Configuration.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Configuration implements ConfigurationInterface
4040
const CONFIG_PATH_SECURE_BASE_URL = "web/secure/base_url";
4141
const CONFIG_PATH_UNSECURE_BASE_URL = "web/unsecure/base_url";
4242
const CONFIG_PATH_USE_SECURE_IN_FRONTEND = "web/secure/use_in_frontend";
43+
const CONFIG_PATH_USE_SIGNED_URLS = 'cloudinary/advanced/use_signed_urls';
4344

4445
const USE_FILENAME = true;
4546
const UNIQUE_FILENAME = false;
@@ -158,7 +159,7 @@ public function getCdnSubdomainStatus()
158159
*/
159160
public function getUserPlatform()
160161
{
161-
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.4', '2.0.0');
162+
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.5', '2.0.0');
162163
}
163164

164165
/**
@@ -279,6 +280,14 @@ public function getUseRootPath()
279280
return (bool) $this->configReader->getValue(self::CONFIG_PATH_REMOVE_VERSION_NUMBER);
280281
}
281282

283+
/**
284+
* @return bool
285+
*/
286+
public function getUseSignedUrls()
287+
{
288+
return (bool) $this->configReader->getValue(self::CONFIG_PATH_USE_SIGNED_URLS);
289+
}
290+
282291
/**
283292
* @method getMediaBaseUrl
284293
* @return string

Plugin/ImageHelper.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace Cloudinary\Cloudinary\Plugin;
44

5-
use Cloudinary\Cloudinary\Core\Image\Transformation;
5+
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
66
use Cloudinary\Cloudinary\Core\Image\ImageFactory;
7-
use Cloudinary\Cloudinary\Core\Image\Transformation\Dimensions;
7+
use Cloudinary\Cloudinary\Core\Image\Transformation;
88
use Cloudinary\Cloudinary\Core\Image\Transformation\Crop;
9+
use Cloudinary\Cloudinary\Core\Image\Transformation\Dimensions;
910
use Cloudinary\Cloudinary\Core\UrlGenerator;
10-
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
11-
use Magento\Catalog\Api\Data\ProductInterface;
12-
use Magento\Catalog\Helper\Image as CatalogImageHelper;
1311
use Cloudinary\Cloudinary\Model\Transformation as TransformationModel;
1412
use Cloudinary\Cloudinary\Model\TransformationFactory;
13+
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Catalog\Helper\Image as CatalogImageHelper;
1515

1616
class ImageHelper
1717
{
@@ -158,7 +158,7 @@ private function createTransformation(CatalogImageHelper $helper)
158158
$transform = $this->configuration->getDefaultTransformation()->withDimensions($dimensions);
159159

160160
if ($this->keepFrame) {
161-
$transform->withCrop(Crop::fromString('pad'))
161+
$transform->withCrop(Crop::fromString('lpad'))
162162
->withDimensions(Dimensions::squareMissingDimension($dimensions));
163163
} else {
164164
$transform->withCrop(Crop::fromString('fit'));

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cloudinary/cloudinary-magento2",
33
"description": "Cloudinary Magento 2 Integration.",
44
"type": "magento2-module",
5-
"version": "1.6.4",
5+
"version": "1.6.5",
66
"minimum-stability": "dev",
77
"license": "MIT",
88
"repositories": {

etc/adminhtml/system.xml

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
<comment>Remove "/image/upload/" from URLs</comment>
7878
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
7979
</field>
80+
<field id="use_signed_urls" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
81+
<label>Use signed URLs</label>
82+
<comment>A signed Cloudinary image delivery URL is a dynamic URL that has its signature validated before making it available for view</comment>
83+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
84+
</field>
8085
</group>
8186
</section>
8287
</system>

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Cloudinary_Cloudinary" setup_version="1.6.4">
3+
<module name="Cloudinary_Cloudinary" setup_version="1.6.5">
44
<sequence>
55
<module name="Magento_ProductVideo"/>
66
</sequence>

0 commit comments

Comments
 (0)