Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 5601680

Browse files
author
pini-girit
committed
CLOUDINARY-69,CLOUDINARY-63,CLOUDINARY-6: Fixes on Wysiwyg & minor changes in system configuration
1 parent 1005f12 commit 5601680

File tree

4 files changed

+112
-6
lines changed

4 files changed

+112
-6
lines changed

app/code/community/Cloudinary/Cloudinary/Helper/Cms/Wysiwyg/Images.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,24 @@ public function getStorageRoot()
2222
}
2323
return $this->_storageRoot;
2424
}
25+
26+
/**
27+
* Return URL based on current selected directory or root directory for startup
28+
*
29+
* @return string
30+
*/
31+
public function getCurrentUrl()
32+
{
33+
if (!Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
34+
return parent::getCurrentUrl();
35+
}
36+
if (!$this->_currentUrl) {
37+
$mediaPath = Mage::getConfig()->getOptions()->getMediaDir();
38+
$path = str_replace($mediaPath, '', $this->getCurrentPath());
39+
$path = trim($path, DS);
40+
$this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
41+
$this->convertPathToUrl($path) . '/';
42+
}
43+
return $this->_currentUrl;
44+
}
2545
}

app/code/community/Cloudinary/Cloudinary/Model/Cms/Adminhtml/Template/Filter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function mediaDirective($construction)
4242
if (ini_get('allow_url_fopen')) {
4343
$image = $this->imageFactory->build(
4444
$this->imagePath($construction),
45-
function() use($construction) { return parent::mediaDirective($construction); }
45+
function () use ($construction) {
46+
return parent::mediaDirective($construction);
47+
}
4648
);
4749

4850
return $this->urlGenerator->generateFor($image);

app/code/community/Cloudinary/Cloudinary/Model/Cms/Wysiwyg/Images/Storage.php

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,101 @@ public function __construct()
4040
);
4141
}
4242

43+
/**
44+
* Return files
45+
*
46+
* @param string $path Parent directory path
47+
* @param string $type Type of storage, e.g. image, media etc.
48+
* @return Varien_Data_Collection_Filesystem
49+
*/
50+
public function getFilesCollection($path, $type = null)
51+
{
52+
if (!$this->_configuration->isEnabled()) {
53+
return parent::getFilesCollection($path, $type);
54+
}
55+
56+
if (Mage::helper('core/file_storage_database')->checkDbUsage()) {
57+
$files = Mage::getModel('core/file_storage_database')->getDirectoryFiles($path);
58+
59+
$fileStorageModel = Mage::getModel('core/file_storage_file');
60+
foreach ($files as $file) {
61+
$fileStorageModel->saveFile($file);
62+
}
63+
}
64+
65+
$collection = $this->getCollection($path)
66+
->setCollectDirs(false)
67+
->setCollectFiles(true)
68+
->setCollectRecursively(false)
69+
->setOrder('mtime', Varien_Data_Collection::SORT_ORDER_ASC);
70+
71+
// Add files extension filter
72+
if ($allowed = $this->getAllowedExtensions($type)) {
73+
$collection->setFilesFilter('/\.(' . implode('|', $allowed). ')$/i');
74+
}
75+
76+
$helper = $this->getHelper();
77+
78+
// prepare items
79+
foreach ($collection as $item) {
80+
$item->setId($helper->idEncode($item->getBasename()));
81+
$item->setName($item->getBasename());
82+
$item->setShortName($helper->getShortFilename($item->getBasename()));
83+
$item->setUrl($helper->getCurrentUrl() . $item->getBasename());
84+
85+
if ($this->isImage($item->getBasename())) {
86+
$thumbUrl = $this->getThumbnailUrl(
87+
Mage_Core_Model_File_Uploader::getCorrectFileName($item->getFilename()),
88+
true,
89+
$item->getFilename()
90+
);
91+
// generate thumbnail "on the fly" if it does not exists
92+
if (! $thumbUrl) {
93+
$thumbUrl = Mage::getSingleton('adminhtml/url')->getUrl('*/*/thumbnail', array('file' => $item->getId()));
94+
}
95+
96+
$size = @getimagesize($item->getFilename());
97+
98+
if (is_array($size)) {
99+
$item->setWidth($size[0]);
100+
$item->setHeight($size[1]);
101+
}
102+
} else {
103+
$thumbUrl = Mage::getDesign()->getSkinBaseUrl() . self::THUMB_PLACEHOLDER_PATH_SUFFIX;
104+
}
105+
106+
$item->setThumbUrl($thumbUrl);
107+
}
108+
109+
return $collection;
110+
}
111+
43112
/**
44113
* @param string $filePath
45114
* @param bool $checkFile
46115
* @return string
47116
*/
48-
public function getThumbnailUrl($filePath, $checkFile = false)
117+
public function getThumbnailUrl($filePath, $checkFile = false, $origFilePath = null)
49118
{
119+
$_origUrl = $origUrl = parent::getThumbnailUrl($filePath, $checkFile);
120+
121+
if (!$this->_configuration->isEnabled()) {
122+
return $_origUrl;
123+
}
124+
125+
if (!$_origUrl && !is_null($origFilePath)) {
126+
$filePath = $origFilePath;
127+
$origUrl = parent::getThumbnailUrl($filePath, $checkFile);
128+
}
129+
130+
if (!$origUrl) {
131+
return $_origUrl;
132+
}
133+
50134
$image = $this->_imageFactory->build(
51135
$filePath,
52-
function() use($filePath, $checkFile) {
53-
return parent::getThumbnailUrl($filePath, $checkFile);
136+
function () use ($_origUrl) {
137+
return (string) $_origUrl;
54138
}
55139
);
56140

@@ -71,7 +155,7 @@ function() use($filePath, $checkFile) {
71155
public function uploadFile($targetPath, $type = null)
72156
{
73157
if (!$this->_configuration->isEnabled()) {
74-
return parent::uploadFile($targetPath, $type);
158+
return parent::uploadFile($targetPath, $type);
75159
}
76160

77161
$uploader = new Cloudinary_Cloudinary_Model_Cms_Uploader('image');

app/code/community/Cloudinary/Cloudinary/etc/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</cloudinary_enabled>
5050
<cloudinary_environment_variable translate="label comment">
5151
<label>Cloudinary Account Credentials</label>
52-
<comment>Set the credentials of your Cloudinary account. Copy the "Environment variable" string from the dashboard of Cloudinary's Management Console.</comment>
52+
<comment><![CDATA[Set the credentials of your Cloudinary account. Copy the "Environment variable" string from the dashboard of Cloudinary's Management Console.<br>Format should be: cloudinary://API_Key:API_Secret@Cloud_Name]]></comment>
5353
<frontend_type>password</frontend_type>
5454
<backend_model>cloudinary_cloudinary/system_config_credentials</backend_model>
5555
<sort_order>2</sort_order>

0 commit comments

Comments
 (0)