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

Commit 04c40d1

Browse files
author
Pniel (Pini) Cohen
authored
Merge pull request #53 from cloudinary/v3.0.1
V3.0.1
2 parents 4d7cc09 + b596633 commit 04c40d1

File tree

55 files changed

+3042
-361
lines changed

Some content is hidden

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

55 files changed

+3042
-361
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Magento 1 module for integration with Cloudinary.
44

55
---
66

7+
## Install From Magento Admin (Using Magento Connect Manager)
8+
1. Log into your Magento admin panel & navigate to System > Magento Connect > Magento Connect Manager.
9+
2. Under "Direct package file upload", upload the package file that's included in this repository (var/connect/Cloudinary_Cloudinary-\*.tgz).
10+
3. Install the package...
11+
712
## Install Manually
813
1. Download & copy/drag the directories `app`, `lib` & `skin` into your Magento 1 root dir.
914
2. Clear cache from Magento admin panel or by running `rm -rf var/cache/* var/full_page_cache/*` under your Magento 1 root dir.

app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/Catalog/Product/Edit/Tab.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

3-
class Cloudinary_Cloudinary_Block_Adminhtml_Catalog_Product_Edit_Tab extends Mage_Adminhtml_Block_Widget
4-
implements Mage_Adminhtml_Block_Widget_Tab_Interface
3+
class Cloudinary_Cloudinary_Block_Adminhtml_Catalog_Product_Edit_Tab extends Mage_Adminhtml_Block_Widget implements Mage_Adminhtml_Block_Widget_Tab_Interface
54
{
65
public function canShowTab()
76
{
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
3+
class Cloudinary_Cloudinary_Block_Adminhtml_Cms_Wysiwyg_Images_Content_Uploader extends Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content_Uploader
4+
{
5+
/**
6+
* Default browse button ID suffix
7+
*/
8+
const DEFAULT_CLD_ML_BUTTON_ID_SUFFIX = 'cld_ml';
9+
10+
/**
11+
* Template used for uploader
12+
*
13+
* @var string
14+
*/
15+
protected $_template = 'cloudinary/media/uploader.phtml';
16+
17+
/**
18+
* Render block HTML
19+
*
20+
* @return string
21+
*/
22+
protected function _toHtml()
23+
{
24+
$this->setTemplate('cloudinary/media/uploader.phtml');
25+
return parent::_toHtml();
26+
}
27+
28+
/**
29+
* Prepare layout, create buttons, set front-end elements ids
30+
*
31+
* @return Mage_Core_Block_Abstract
32+
*/
33+
protected function _prepareLayout()
34+
{
35+
parent::_prepareLayout();
36+
37+
if (Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
38+
$this->setChild(
39+
'cloudinary_ml_button',
40+
$this->getLayout()->createBlock('adminhtml/widget_button')
41+
->addData(array(
42+
// Workaround for IE9
43+
'before_html' => sprintf(
44+
'<div style="display:inline-block;" id="%s">',
45+
$this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX)
46+
),
47+
'after_html' => '</div>
48+
<script type="text/javascript">
49+
//<![CDATA[
50+
var ' . self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_instance_' . $this->getHtmlId() . ' = new CloudinaryMediaLibrary(' . $this->getCloudinaryMediaLibraryWidgetOptions() . ');
51+
//]]>
52+
</script>',
53+
'id' => $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
54+
'label' => Mage::helper('uploader')->__('Add From Cloudinary...'),
55+
'type' => 'button',
56+
))
57+
);
58+
}
59+
60+
return $this;
61+
}
62+
63+
/**
64+
* Get CLD ML button html
65+
*
66+
* @return string
67+
*/
68+
public function getCldMLButtonHtml()
69+
{
70+
return $this->getChildHtml('cloudinary_ml_button');
71+
}
72+
73+
/**
74+
* Get Cloudinary media library widget options
75+
*
76+
* @param bool $multiple Allow multiple
77+
* @param bool $refresh Refresh options
78+
* @return string
79+
*/
80+
public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refresh = false)
81+
{
82+
if (!($cloudinaryMLoptions = Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLOptions($multiple, $refresh))) {
83+
return null;
84+
}
85+
return Mage::helper('core')->jsonEncode(array(
86+
'htmlId' => $this->getHtmlId(),
87+
'cldMLid' => self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_' . $this->getHtmlId(),
88+
'imageUploaderUrl' => $this->getCldImageUploaderUrl(),
89+
'buttonSelector' => '#' . $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
90+
'triggerSelector' => $this->getTriggerSelector(),
91+
'triggerEvent' => $this->getTriggerEvent(),
92+
'callbackHandler' => $this->getCallbackHandler(),
93+
'callbackHandlerMethod' => $this->getCallbackHandlerMethod(),
94+
'useDerived' => $this->getUseDerived(),
95+
'addTmpExtension' => $this->getAddTmpExtension(),
96+
'cloudinaryMLoptions' => $cloudinaryMLoptions,
97+
'cloudinaryMLshowOptions' => Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLshowOptions('image'),
98+
));
99+
}
100+
101+
/**
102+
* @return string
103+
*/
104+
protected function getCldImageUploaderUrl()
105+
{
106+
return Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/cloudinaryretrieveimage/upload', array('type' => 'wysiwyg_image'));
107+
}
108+
109+
/**
110+
* @return bool
111+
*/
112+
protected function getAddTmpExtension()
113+
{
114+
return true;
115+
}
116+
117+
/**
118+
* @return bool
119+
*/
120+
protected function getUseDerived()
121+
{
122+
return false;
123+
}
124+
125+
/**
126+
* @return mixed
127+
*/
128+
protected function getTriggerEvent()
129+
{
130+
return 'addItem';
131+
}
132+
133+
/**
134+
* @return mixed
135+
*/
136+
protected function getTriggerSelector()
137+
{
138+
return 'triggerSelector';
139+
}
140+
141+
/**
142+
* @return mixed
143+
*/
144+
protected function getCallbackHandler()
145+
{
146+
return 'window.MediabrowserInstance';
147+
}
148+
149+
/**
150+
* @return mixed
151+
*/
152+
protected function getCallbackHandlerMethod()
153+
{
154+
return 'selectFolder';
155+
}
156+
}

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

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22

33
class Cloudinary_Cloudinary_Block_Adminhtml_Manage extends Mage_Adminhtml_Block_Widget_Grid_Container
44
{
5+
/**
6+
* @var Cloudinary_Cloudinary_Model_Migration
7+
*/
58
private $_migrationTask;
9+
610
private $_cloudinaryConfig;
711

812
public function __construct()
913
{
1014
$this->_blockGroup = 'cloudinary_cloudinary';
11-
1215
$this->_controller = 'adminhtml_manage';
13-
14-
$this->_headerText = Mage::helper('cloudinary_cloudinary')
15-
->__('Manage Cloudinary');
16-
17-
$this->_migrationTask = Mage::getModel('cloudinary_cloudinary/migration')
18-
->load(Cloudinary_Cloudinary_Model_Migration::CLOUDINARY_MIGRATION_ID);
19-
16+
$this->_headerText = Mage::helper('cloudinary_cloudinary')->__('Manage Cloudinary');
17+
$this->_migrationTask = Mage::getModel('cloudinary_cloudinary/migration')->loadType($this->getType());
2018
$this->_cloudinaryConfig = Mage::getModel('cloudinary_cloudinary/configuration');
21-
2219
parent::__construct();
2320
}
2421

22+
public function getType()
23+
{
24+
return Mage::registry('cloudinary_migration_type');
25+
}
26+
2527
public function isFolderedMigration()
2628
{
2729
return $this->_cloudinaryConfig->isFolderedMigration();
@@ -70,34 +72,45 @@ public function isAutoUploadMappingEnabled()
7072
public function allImagesSynced()
7173
{
7274
try {
73-
return $this->getSynchronizedImageCount() === $this->getTotalImageCount();
75+
return
76+
($type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->getSynchronizedImageCount() === $this->getTotalImageCount()) ||
77+
($type === Cloudinary_Cloudinary_Model_Migration::DOWNLOAD_MIGRATION_TYPE && !$this->getMigrationInfo()->getData('more_expected') && $this->getMigrationInfo()->getData('resources_count_total') && $this->getMigrationInfo()->getData('resources_processed_total') === $this->getMigrationInfo()->getData('resources_count_total'));
7478
} catch (Exception $e) {
7579
return false;
7680
}
7781
}
7882

83+
public function getMigrationInfo()
84+
{
85+
if (!$this->hasData('migration_info')) {
86+
$this->setData('migration_info', new Varien_Object($this->_migrationTask->getInfo()));
87+
}
88+
return $this->getData('migration_info');
89+
}
90+
7991
public function getMigrateButton()
8092
{
93+
$type = $this->getType();
8194
if ($this->_migrationTask->hasStarted()) {
8295
$startLabel = 'Stop Migration';
8396
$startAction = 'stopMigration';
84-
return $this->_makeButton($startLabel, $startAction, $this->allImagesSynced());
97+
return $this->_makeButton($startLabel, $startAction, $type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->allImagesSynced());
8598
}
8699

87100
return $this->getLayout()
88101
->createBlock('adminhtml/widget_button')
89102
->setData(array(
90-
'id' => 'cloudinary_migration_start',
103+
'id' => 'cloudinary_migration_start_' . $type,
91104
'label' => $this->helper('adminhtml')->__('Start Migration'),
92-
'disabled' => $this->allImagesSynced(),
93-
'onclick' => 'openCloudinaryMigrationPopup();'
105+
'disabled' => $type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->allImagesSynced(),
106+
'onclick' => 'openCloudinaryMigrationPopup(\''.$type.'\');'
94107
))
95108
->toHtml();
96109
}
97110

98111
public function getStartMigrationUrl()
99112
{
100-
return $this->getUrl('*/cloudinary/startMigration');
113+
return $this->getUrl('*/cloudinary/startMigration/type/' . $this->getType());
101114
}
102115

103116
public function getClearErrorsButton()
@@ -110,10 +123,10 @@ private function _makeButton($label, $action, $disabled = false)
110123
{
111124
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
112125
->setData(array(
113-
'id' => 'cloudinary_migration_start',
126+
'id' => 'cloudinary_migration_start_' . $action,
114127
'label' => $this->helper('adminhtml')->__($label),
115128
'disabled' => $disabled,
116-
'onclick' => "setLocation('{$this->getUrl(sprintf('*/cloudinary/%s', $action))}')"
129+
'onclick' => "setLocation('{$this->getUrl(sprintf('*/cloudinary/%s/type/%s', $action, $this->getType()))}')"
117130
));
118131

119132
return $button->toHtml();
@@ -126,8 +139,9 @@ public function getCloudinaryConfigurationLink()
126139

127140
public function getErrors()
128141
{
129-
$coll = Mage::getModel('cloudinary_cloudinary/migrationError')->getCollection();
130-
$coll->addOrder('timestamp');
131-
return $coll->getItems();
142+
return Mage::getModel('cloudinary_cloudinary/migrationError')->getCollection()
143+
->addFieldToFilter('type', $this->getType())
144+
->addOrder('timestamp')
145+
->getItems();
132146
}
133147
}

0 commit comments

Comments
 (0)