Skip to content

Commit

Permalink
Merge pull request #35 from cloudinary/v2.9.0
Browse files Browse the repository at this point in the history
V2.9.0
  • Loading branch information
Pini authored Dec 13, 2018
2 parents 9dba349 + ecd9a10 commit 9cdb27b
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public function getMediaUrl($file)
*/
public function getTmpMediaUrl($file)
{
//Comment this line & uncomment the next paragraph if you insist on using cloudinary for tmp media images
return parent::getTmpMediaUrl($file);
/*
$file = DS . ltrim($this->getBaseTmpMediaUrlAddition(), DS) . $file;
$image = $this->_imageFactory->build($file, function() use($file) { return parent::getTmpMediaUrl($file); });

return $this->_urlGenerator->generateFor($image);
*/
}
}
13 changes: 11 additions & 2 deletions app/code/community/Cloudinary/Cloudinary/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Cloudinary_Cloudinary_Model_Configuration implements ConfigurationInterfac
//= Advanced
const CONFIG_PATH_REMOVE_VERSION_NUMBER = 'cloudinary/advanced/remove_version_number';
const CONFIG_PATH_USE_ROOT_PATH = 'cloudinary/advanced/use_root_path';
const CONFIG_PATH_USE_SIGNED_URLS = 'cloudinary/advanced/use_signed_urls';

private $environmentVariable;

Expand Down Expand Up @@ -250,8 +251,8 @@ private function getDefaultGlobalFreeform()
}

/**
* @return bool
*/
* @return bool
*/
public function getRemoveVersionNumber()
{
return (bool) Mage::getStoreConfig(self::CONFIG_PATH_REMOVE_VERSION_NUMBER);
Expand All @@ -263,4 +264,12 @@ public function getUseRootPath()
{
return (bool) Mage::getStoreConfig(self::CONFIG_PATH_REMOVE_VERSION_NUMBER);
}

/**
* @return bool
*/
public function getUseSignedUrls()
{
return (bool) Mage::getStoreConfig(self::CONFIG_PATH_USE_SIGNED_URLS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct()
$this->absolutePathRegex = "#^$baseDir/.*#"; //anything starting with the magento base dir
$this->mediaPathRegex = "#^$mediaDir/.*#"; //anything starting with the media folder
$this->wysiwygPathRegex = "#^/wysiwyg/.*#"; // anything starting with the /wysiwyg folder
$this->productPathRegex = "#(^/cache/.*|^/(\\w/){2})#"; // any path that has '/cache/' prefix, or '/l/l/' structure, where l is a single letter
$this->productPathRegex = "#(^/cache/.*|^/([\\w-]/){2})#"; // any path that has '/cache/' prefix, or '/l/l/' structure, where l is a single letter
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ class Cloudinary_Cloudinary_Model_Resource_Cms_Synchronisation_Collection
public function __construct()
{
$categoryImages = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category';
$this->addTargetDir($categoryImages);
$this->addTargetDir(Mage::getBaseDir('media').DS.Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY);
if(realpath($categoryImages)){
$this->addTargetDir($categoryImages);
}

$wysiwygImages = Mage::getBaseDir('media') . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY;
if(realpath($wysiwygImages)){
$this->addTargetDir($wysiwygImages);
}

$this->setItemObjectClass('cloudinary_cloudinary/cms_synchronisation');
$this->setFilesFilter(
sprintf('#^[a-z0-9\.\-\_]+\.(?:%s)$#i', implode('|', $this->allowedImgExtensions))
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Cloudinary/Cloudinary/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Cloudinary_Cloudinary>
<version>2.8.4</version>
<version>2.9.0</version>
</Cloudinary_Cloudinary>
</modules>
<global>
Expand Down
10 changes: 10 additions & 0 deletions app/code/community/Cloudinary/Cloudinary/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<show_in_store>0</show_in_store>
<source_model>adminhtml/system_config_source_yesno</source_model>
</use_root_path>
<use_signed_urls>
<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>
<frontend_type>select</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<source_model>adminhtml/system_config_source_yesno</source_model>
</use_signed_urls>
</fields>
</advanced>
</groups>
Expand Down
6 changes: 5 additions & 1 deletion lib/CloudinaryExtension/CloudinaryImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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 lib/CloudinaryExtension/Image/Transformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,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 lib/CloudinaryExtension/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

0 comments on commit 9cdb27b

Please sign in to comment.