Skip to content

Commit 54dba1a

Browse files
author
Pniel (Pini) Cohen
authored
Merge pull request #65 from GiritInteractive/v3.0.2
v3.0.2: Applied Magento 1 coding standards.
2 parents 4db41f3 + d69fb2a commit 54dba1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+287
-165
lines changed

app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/Cms/Wysiwyg/Images/Content/Uploader.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected function _prepareLayout()
3838
$this->setChild(
3939
'cloudinary_ml_button',
4040
$this->getLayout()->createBlock('adminhtml/widget_button')
41-
->addData(array(
41+
->addData(
42+
array(
4243
// Workaround for IE9
4344
'before_html' => sprintf(
4445
'<div style="display:inline-block;" id="%s">',
@@ -53,7 +54,8 @@ protected function _prepareLayout()
5354
'id' => $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
5455
'label' => Mage::helper('uploader')->__('Add From Cloudinary...'),
5556
'type' => 'button',
56-
))
57+
)
58+
)
5759
);
5860
}
5961

@@ -82,7 +84,9 @@ public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refres
8284
if (!($cloudinaryMLoptions = Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLOptions($multiple, $refresh))) {
8385
return null;
8486
}
85-
return Mage::helper('core')->jsonEncode(array(
87+
88+
return Mage::helper('core')->jsonEncode(
89+
array(
8690
'htmlId' => $this->getHtmlId(),
8791
'cldMLid' => self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_' . $this->getHtmlId(),
8892
'imageUploaderUrl' => $this->getCldImageUploaderUrl(),
@@ -95,7 +99,8 @@ public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refres
9599
'addTmpExtension' => $this->getAddTmpExtension(),
96100
'cloudinaryMLoptions' => $cloudinaryMLoptions,
97101
'cloudinaryMLshowOptions' => Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLshowOptions('image'),
98-
));
102+
)
103+
);
99104
}
100105

101106
/**

app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/Manage.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function getMigrationInfo()
8585
if (!$this->hasData('migration_info')) {
8686
$this->setData('migration_info', new Varien_Object($this->_migrationTask->getInfo()));
8787
}
88+
8889
return $this->getData('migration_info');
8990
}
9091

@@ -99,12 +100,14 @@ public function getMigrateButton()
99100

100101
return $this->getLayout()
101102
->createBlock('adminhtml/widget_button')
102-
->setData(array(
103+
->setData(
104+
array(
103105
'id' => 'cloudinary_migration_start_' . $type,
104106
'label' => $this->helper('adminhtml')->__('Start Migration'),
105107
'disabled' => $type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->allImagesSynced(),
106108
'onclick' => 'openCloudinaryMigrationPopup(\''.$type.'\');'
107-
))
109+
)
110+
)
108111
->toHtml();
109112
}
110113

@@ -122,12 +125,14 @@ public function getClearErrorsButton()
122125
private function _makeButton($label, $action, $disabled = false)
123126
{
124127
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
125-
->setData(array(
128+
->setData(
129+
array(
126130
'id' => 'cloudinary_migration_start_' . $action,
127131
'label' => $this->helper('adminhtml')->__($label),
128132
'disabled' => $disabled,
129133
'onclick' => "setLocation('{$this->getUrl(sprintf('*/cloudinary/%s/type/%s', $action, $this->getType()))}')"
130-
));
134+
)
135+
);
131136

132137
return $button->toHtml();
133138
}

app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/Reset/Edit/Form.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ protected function _prepareForm()
2020

2121
$fieldset = $form->addFieldset('display', array('class' => 'fieldset-wide'));
2222

23-
$fieldset->addField('password', 'password', array(
23+
$fieldset->addField(
24+
'password', 'password', array(
2425
'name' => 'password',
2526
'label' => Mage::helper('cloudinary_cloudinary')->__('Enter your admin password to confirm reset')
26-
));
27+
)
28+
);
2729

2830
return parent::_prepareForm();
2931
}

app/code/community/Cloudinary/Cloudinary/Block/Uploader/Multiple.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ protected function _prepareLayout()
2727
$this->setChild(
2828
'cloudinary_ml_button',
2929
$this->getLayout()->createBlock('adminhtml/widget_button')
30-
->addData(array(
30+
->addData(
31+
array(
3132
// Workaround for IE9
3233
'before_html' => sprintf(
3334
'<div style="display:inline-block;" id="%s">',
@@ -42,7 +43,8 @@ protected function _prepareLayout()
4243
'id' => $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
4344
'label' => Mage::helper('uploader')->__('Add From Cloudinary...'),
4445
'type' => 'button',
45-
))
46+
)
47+
)
4648
);
4749
}
4850

@@ -71,7 +73,9 @@ public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refres
7173
if (!($cloudinaryMLoptions = Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLOptions($multiple, $refresh))) {
7274
return null;
7375
}
74-
return Mage::helper('core')->jsonEncode(array(
76+
77+
return Mage::helper('core')->jsonEncode(
78+
array(
7579
'htmlId' => $this->getHtmlId(),
7680
'cldMLid' => self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_' . $this->getHtmlId(),
7781
'imageUploaderUrl' => $this->getCldImageUploaderUrl(),
@@ -84,7 +88,8 @@ public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refres
8488
'addTmpExtension' => $this->getAddTmpExtension(),
8589
'cloudinaryMLoptions' => $cloudinaryMLoptions,
8690
'cloudinaryMLshowOptions' => Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLshowOptions('image'),
87-
));
91+
)
92+
);
8893
}
8994

9095
/**

app/code/community/Cloudinary/Cloudinary/Block/Uploader/Single.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ protected function _prepareLayout()
2727
$this->setChild(
2828
'cloudinary_ml_button',
2929
$this->getLayout()->createBlock('adminhtml/widget_button')
30-
->addData(array(
30+
->addData(
31+
array(
3132
// Workaround for IE9
3233
'before_html' => sprintf(
3334
'<div style="display:inline-block;" id="%s">',
@@ -42,7 +43,8 @@ protected function _prepareLayout()
4243
'id' => $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
4344
'label' => Mage::helper('uploader')->__('Add From Cloudinary...'),
4445
'type' => 'button',
45-
))
46+
)
47+
)
4648
);
4749
}
4850

@@ -71,7 +73,9 @@ public function getCloudinaryMediaLibraryWidgetOptions($multiple = false, $refre
7173
if (!($cloudinaryMLoptions = Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLOptions($multiple, $refresh))) {
7274
return null;
7375
}
74-
return Mage::helper('core')->jsonEncode(array(
76+
77+
return Mage::helper('core')->jsonEncode(
78+
array(
7579
'htmlId' => $this->getHtmlId(),
7680
'cldMLid' => self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_' . $this->getHtmlId(),
7781
'imageUploaderUrl' => $this->getCldImageUploaderUrl(),
@@ -84,7 +88,8 @@ public function getCloudinaryMediaLibraryWidgetOptions($multiple = false, $refre
8488
'addTmpExtension' => $this->getAddTmpExtension(),
8589
'cloudinaryMLoptions' => $cloudinaryMLoptions,
8690
'cloudinaryMLshowOptions' => Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLshowOptions('image'),
87-
));
91+
)
92+
);
8893
}
8994

9095
/**

app/code/community/Cloudinary/Cloudinary/Helper/Autoloader.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ private function _registerCloudinaryExtensionAutoloader()
2121
{
2222
spl_autoload_register(
2323
function ($className) {
24-
if(
25-
strpos($className, Cloudinary_Cloudinary_Helper_Autoloader::CLOUDINARY_EXTENSION_LIB_PATH . '\\') === 0 ||
24+
if(strpos($className, Cloudinary_Cloudinary_Helper_Autoloader::CLOUDINARY_EXTENSION_LIB_PATH . '\\') === 0 ||
2625
strpos($className, Cloudinary_Cloudinary_Helper_Autoloader::CLOUDINARY_LIB_PATH . '\\') === 0
2726
) {
2827
include_once preg_replace(Cloudinary_Cloudinary_Helper_Autoloader::CONVERT_CLASS_TO_PATH_REGEX, '/', $className) . '.php';

app/code/community/Cloudinary/Cloudinary/Helper/BatchDownloader.php

+20-10
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,27 @@ public function downloadImages()
115115
$this->_info["iteration"]++;
116116
$this->log('Iteration #' . $this->_info["iteration"]);
117117
$this->migrationTask->setBatchCount($this->_info["iteration"]);
118-
$this->saveInfo(array(
118+
$this->saveInfo(
119+
array(
119120
"iteration" => $this->_info["iteration"],
120121
"resources_count" => 0,
121122
"resources_processed" => 0,
122123
"resources_downloaded" => 0,
123124
"resources_skipped" => 0,
124125
"resources_failed" => 0,
125-
));
126+
)
127+
);
126128

127129
$response = $this->getResources($this->_info["next_cursor"]);
128130
$response->setResourcesCount(count($response->getResources()));
129-
$this->saveInfo(array(
131+
$this->saveInfo(
132+
array(
130133
"next_cursor" => $response->getNextCursor(),
131134
"more_expected" => ($response->getNextCursor())? true : false,
132135
"resources_count" => $this->_info["resources_count"] + $response->getResourcesCount(),
133136
"resources_count_total" => $this->_info["resources_count_total"] + $response->getResourcesCount(),
134-
));
137+
)
138+
);
135139
if ($response->getResourcesCount() > 0) {
136140
$this->log('Found ' . $response->getResourcesCount() . ' image(s) to sync on this round. ' . (($response->getNextCursor()) ? '*More Rounds Expected*' : '*Last Round*'));
137141
foreach ($response->getResources() as $i => &$resource) {
@@ -174,14 +178,16 @@ public function downloadImages()
174178
$res = Cloudinary_Cloudinary_Helper_Data::curlGetContents($remoteFileUrl);
175179
if (!$res || $res->getError() || empty(($image = $res->getBody()))) {
176180
throw new Mage_Core_Exception(
177-
__('The preview image information is unavailable. Check your connection and try again.')
178-
);
181+
__('The preview image information is unavailable. Check your connection and try again.')
182+
);
179183
}
184+
180185
$this->log('=== [Processing] Saving...');
181186
Mage::getSingleton('core/file_storage_file')->saveFile(array('filename' => $localFileName, 'content' => $image), true);
182187
if (!@file_exists($localFilePath)) {
183188
throw new Mage_Core_Exception(__("Image not saved."));
184189
}
190+
185191
$this->log('=== [Processing] Saved.');
186192
$this->saveInfo(array("resources_downloaded" => $this->_info["resources_downloaded"]+1, "resources_downloaded_total" => $this->_info["resources_downloaded_total"]+1));
187193
}
@@ -228,13 +234,15 @@ public function downloadImages()
228234
*/
229235
private function getResources($nextCursor = null)
230236
{
231-
$response = $this->api->resources(array(
237+
$response = $this->api->resources(
238+
array(
232239
"resource_type" => 'image',
233240
"type" => "upload",
234241
"prefix" => 'media' . DIRECTORY_SEPARATOR,
235242
"max_results" => self::API_REQUEST_MAX_RESULTS,
236243
"next_cursor" => $nextCursor,
237-
));
244+
)
245+
);
238246
$this->_rateLimitResetAt = $response->rate_limit_reset_at;
239247
$this->_rateLimitAllowed = $response->rate_limit_allowed;
240248
$this->_rateLimitRemaining = $response->rate_limit_remaining;
@@ -255,6 +263,7 @@ private function log($message, $type = 'notice')
255263
$this->logger->notice($message);
256264
break;
257265
}
266+
258267
return $this;
259268
}
260269

@@ -268,7 +277,7 @@ private function log($message, $type = 'notice')
268277
private function validateRemoteFileExtensions($filePath)
269278
{
270279
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
271-
if (!in_array($extension, ['jpg','jpeg','gif','png'])) {
280+
if (!in_array($extension, array('jpg','jpeg','gif','png'))) {
272281
throw new Mage_Core_Exception(__('Disallowed file type.'));
273282
}
274283
}
@@ -290,13 +299,14 @@ private function getCredentialsFromEnvironmentVariable($environmentVariable)
290299
if (Cloudinary::config_get('private_cdn')) {
291300
$credentials["private_cdn"] = Cloudinary::config_get('private_cdn');
292301
}
302+
293303
return $credentials;
294304
} catch (\Exception $e) {
295305
throw new Mage_Core_Exception(__(self::CREDENTIALS_CHECK_FAILED));
296306
}
297307
}
298308

299-
private function saveInfo(array $info = [])
309+
private function saveInfo(array $info = array())
300310
{
301311
$this->_info = array_merge($this->_info, $info);
302312
$this->migrationTask->setInfo($this->_info)->save();

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

+4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ public function getStorageRoot()
1616
if (!Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
1717
return parent::getStorageRoot();
1818
}
19+
1920
if (!$this->_storageRoot) {
2021
$this->_storageRoot = Mage::getConfig()->getOptions()->getMediaDir()
2122
. DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY . DS;
2223
}
24+
2325
return $this->_storageRoot;
2426
}
2527

@@ -33,13 +35,15 @@ public function getCurrentUrl()
3335
if (!Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
3436
return parent::getCurrentUrl();
3537
}
38+
3639
if (!$this->_currentUrl) {
3740
$mediaPath = Mage::getConfig()->getOptions()->getMediaDir();
3841
$path = str_replace($mediaPath, '', $this->getCurrentPath());
3942
$path = trim($path, DS);
4043
$this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
4144
$this->convertPathToUrl($path) . '/';
4245
}
46+
4347
return $this->_currentUrl;
4448
}
4549
}

app/code/community/Cloudinary/Cloudinary/Helper/Config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private function doFlatten($key, $value, array &$output)
2828
$this->doFlatten(sprintf('%s/%s', $key, $childKey), $childValue, $output);
2929
}
3030
} else {
31-
$output[substr($key, 0, -6)] = $value;
31+
$output[substr($key, 0, -6)] = $value;
3232
}
3333
}
3434
}

app/code/community/Cloudinary/Cloudinary/Helper/Data.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ public static function curlGetContents($url)
1313
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
1414
$err = curl_error($ch);
1515
curl_close($ch);
16-
return new Varien_Object(array(
16+
return new Varien_Object(
17+
array(
1718
"code" => $httpCode,
1819
"body" => $result,
1920
"error" => $err
20-
));
21+
)
22+
);
2123
}
2224
}

app/code/community/Cloudinary/Cloudinary/Helper/Image.php

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function __toString()
109109
if (!$this->_configuration->isEnabled()) {
110110
return parent::__toString();
111111
}
112+
112113
$image = $this->_imageFactory->build(
113114
$this->_getRequestedImageFile(),
114115
function () {

app/code/community/Cloudinary/Cloudinary/Helper/MediaLibraryHelper.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,21 @@ public function getCloudinaryMLOptions($multiple = false, $refresh = true)
6969
if (($this->credentials["username"] = $this->configuration->getAutomaticLoginUser())) {
7070
$this->cloudinaryMLoptions["timestamp"] = $this->timestamp;
7171
$this->cloudinaryMLoptions["username"] = $this->credentials["username"];
72-
$this->cloudinaryMLoptions["signature"] = $this->signature = hash('sha256', urldecode(http_build_query([
73-
'cloud_name' => $this->credentials['cloud_name'],
74-
'timestamp' => $this->timestamp,
75-
'username' => $this->credentials['username'],
76-
])) . $this->credentials['api_secret']);
72+
$this->cloudinaryMLoptions["signature"] = $this->signature = hash(
73+
'sha256', urldecode(
74+
http_build_query(
75+
array(
76+
'cloud_name' => $this->credentials['cloud_name'],
77+
'timestamp' => $this->timestamp,
78+
'username' => $this->credentials['username'],
79+
)
80+
)
81+
) . $this->credentials['api_secret']
82+
);
7783
}
7884
}
7985
}
86+
8087
if ($this->cloudinaryMLoptions) {
8188
$this->cloudinaryMLoptions['multiple'] = $multiple;
8289
}
@@ -92,13 +99,14 @@ public function getCloudinaryMLOptions($multiple = false, $refresh = true)
9299
*/
93100
public function getCloudinaryMLshowOptions($resourceType = null, $path = "")
94101
{
95-
$options = [];
102+
$options = array();
96103
if ($resourceType || $resourceType) {
97104
$options["folder"] = array(
98105
"path" => $path,
99106
"resource_type" => $resourceType,
100107
);
101108
}
109+
102110
return $options;
103111
}
104112
}

0 commit comments

Comments
 (0)