Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cloudinary 4 #10

Merged
merged 6 commits into from
Dec 13, 2018
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
6 changes: 5 additions & 1 deletion Core/CloudinaryImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public function upload(Image $image)
*/
public function retrieveTransformed(Image $image, Transformation $transformation)
{
$imagePath = \cloudinary_url($image->getId(), ['transformation' => $transformation->build(), 'secure' => true]);
$imagePath = \cloudinary_url($image->getId(), [
'transformation' => $transformation->build(),
'secure' => true,
'sign_url' => $this->configuration->getUseSignedUrls()
]);

if ($this->configuration->getUseRootPath()) {
$imagePath = str_replace(".com/{$this->configuration->getCloud()}/image/upload/", ".com/{$this->configuration->getCloud()}/", $imagePath);
Expand Down
4 changes: 2 additions & 2 deletions Core/Image/Transformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Transformation

public function __construct()
{
$this->crop = 'pad';
$this->crop = 'lpad';
$this->flags = [];
}

public function withGravity(Gravity $gravity)
{
$this->gravity = $gravity;
$this->crop = ((string)$gravity) ? 'crop' : 'pad';
$this->crop = ((string)$gravity) ? 'crop' : 'lpad';
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Image/Transformation/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Crop
{
const PAD = 'pad';
const PAD = 'lpad';
const FIT = 'fit';

private $value;
Expand Down
11 changes: 10 additions & 1 deletion Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Configuration implements ConfigurationInterface
const CONFIG_PATH_SECURE_BASE_URL = "web/secure/base_url";
const CONFIG_PATH_UNSECURE_BASE_URL = "web/unsecure/base_url";
const CONFIG_PATH_USE_SECURE_IN_FRONTEND = "web/secure/use_in_frontend";
const CONFIG_PATH_USE_SIGNED_URLS = 'cloudinary/advanced/use_signed_urls';

const USE_FILENAME = true;
const UNIQUE_FILENAME = false;
Expand Down Expand Up @@ -158,7 +159,7 @@ public function getCdnSubdomainStatus()
*/
public function getUserPlatform()
{
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.4', '2.0.0');
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.5', '2.0.0');
}

/**
Expand Down Expand Up @@ -279,6 +280,14 @@ public function getUseRootPath()
return (bool) $this->configReader->getValue(self::CONFIG_PATH_REMOVE_VERSION_NUMBER);
}

/**
* @return bool
*/
public function getUseSignedUrls()
{
return (bool) $this->configReader->getValue(self::CONFIG_PATH_USE_SIGNED_URLS);
}

/**
* @method getMediaBaseUrl
* @return string
Expand Down
12 changes: 6 additions & 6 deletions Plugin/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Cloudinary\Cloudinary\Plugin;

use Cloudinary\Cloudinary\Core\Image\Transformation;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Cloudinary\Cloudinary\Core\Image\ImageFactory;
use Cloudinary\Cloudinary\Core\Image\Transformation\Dimensions;
use Cloudinary\Cloudinary\Core\Image\Transformation;
use Cloudinary\Cloudinary\Core\Image\Transformation\Crop;
use Cloudinary\Cloudinary\Core\Image\Transformation\Dimensions;
use Cloudinary\Cloudinary\Core\UrlGenerator;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Helper\Image as CatalogImageHelper;
use Cloudinary\Cloudinary\Model\Transformation as TransformationModel;
use Cloudinary\Cloudinary\Model\TransformationFactory;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Helper\Image as CatalogImageHelper;

class ImageHelper
{
Expand Down Expand Up @@ -158,7 +158,7 @@ private function createTransformation(CatalogImageHelper $helper)
$transform = $this->configuration->getDefaultTransformation()->withDimensions($dimensions);

if ($this->keepFrame) {
$transform->withCrop(Crop::fromString('pad'))
$transform->withCrop(Crop::fromString('lpad'))
->withDimensions(Dimensions::squareMissingDimension($dimensions));
} else {
$transform->withCrop(Crop::fromString('fit'));
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.6.4",
"version": "1.6.5",
"minimum-stability": "dev",
"license": "MIT",
"repositories": {
Expand Down
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
<comment>Remove "/image/upload/" from URLs</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="use_signed_urls" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Use signed URLs</label>
<comment>A signed Cloudinary image delivery URL is a dynamic URL that has its signature validated before making it available for view</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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.6.4">
<module name="Cloudinary_Cloudinary" setup_version="1.6.5">
<sequence>
<module name="Magento_ProductVideo"/>
</sequence>
Expand Down