Skip to content

Commit

Permalink
Merge pull request #53 from cloudinary/v3.0.1
Browse files Browse the repository at this point in the history
V3.0.1
  • Loading branch information
Pniel (Pini) Cohen authored Aug 20, 2019
2 parents 4d7cc09 + b596633 commit 04c40d1
Show file tree
Hide file tree
Showing 55 changed files with 3,042 additions and 361 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Magento 1 module for integration with Cloudinary.

---

## Install From Magento Admin (Using Magento Connect Manager)
1. Log into your Magento admin panel & navigate to System > Magento Connect > Magento Connect Manager.
2. Under "Direct package file upload", upload the package file that's included in this repository (var/connect/Cloudinary_Cloudinary-\*.tgz).
3. Install the package...

## Install Manually
1. Download & copy/drag the directories `app`, `lib` & `skin` into your Magento 1 root dir.
2. Clear cache from Magento admin panel or by running `rm -rf var/cache/* var/full_page_cache/*` under your Magento 1 root dir.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

class Cloudinary_Cloudinary_Block_Adminhtml_Catalog_Product_Edit_Tab extends Mage_Adminhtml_Block_Widget
implements Mage_Adminhtml_Block_Widget_Tab_Interface
class Cloudinary_Cloudinary_Block_Adminhtml_Catalog_Product_Edit_Tab extends Mage_Adminhtml_Block_Widget implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function canShowTab()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

class Cloudinary_Cloudinary_Block_Adminhtml_Cms_Wysiwyg_Images_Content_Uploader extends Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content_Uploader
{
/**
* Default browse button ID suffix
*/
const DEFAULT_CLD_ML_BUTTON_ID_SUFFIX = 'cld_ml';

/**
* Template used for uploader
*
* @var string
*/
protected $_template = 'cloudinary/media/uploader.phtml';

/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$this->setTemplate('cloudinary/media/uploader.phtml');
return parent::_toHtml();
}

/**
* Prepare layout, create buttons, set front-end elements ids
*
* @return Mage_Core_Block_Abstract
*/
protected function _prepareLayout()
{
parent::_prepareLayout();

if (Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
$this->setChild(
'cloudinary_ml_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->addData(array(
// Workaround for IE9
'before_html' => sprintf(
'<div style="display:inline-block;" id="%s">',
$this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX)
),
'after_html' => '</div>
<script type="text/javascript">
//<![CDATA[
var ' . self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_instance_' . $this->getHtmlId() . ' = new CloudinaryMediaLibrary(' . $this->getCloudinaryMediaLibraryWidgetOptions() . ');
//]]>
</script>',
'id' => $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
'label' => Mage::helper('uploader')->__('Add From Cloudinary...'),
'type' => 'button',
))
);
}

return $this;
}

/**
* Get CLD ML button html
*
* @return string
*/
public function getCldMLButtonHtml()
{
return $this->getChildHtml('cloudinary_ml_button');
}

/**
* Get Cloudinary media library widget options
*
* @param bool $multiple Allow multiple
* @param bool $refresh Refresh options
* @return string
*/
public function getCloudinaryMediaLibraryWidgetOptions($multiple = true, $refresh = false)
{
if (!($cloudinaryMLoptions = Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLOptions($multiple, $refresh))) {
return null;
}
return Mage::helper('core')->jsonEncode(array(
'htmlId' => $this->getHtmlId(),
'cldMLid' => self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_' . $this->getHtmlId(),
'imageUploaderUrl' => $this->getCldImageUploaderUrl(),
'buttonSelector' => '#' . $this->getElementId(self::DEFAULT_CLD_ML_BUTTON_ID_SUFFIX . '_button'),
'triggerSelector' => $this->getTriggerSelector(),
'triggerEvent' => $this->getTriggerEvent(),
'callbackHandler' => $this->getCallbackHandler(),
'callbackHandlerMethod' => $this->getCallbackHandlerMethod(),
'useDerived' => $this->getUseDerived(),
'addTmpExtension' => $this->getAddTmpExtension(),
'cloudinaryMLoptions' => $cloudinaryMLoptions,
'cloudinaryMLshowOptions' => Mage::helper('cloudinary_cloudinary/MediaLibraryHelper')->getCloudinaryMLshowOptions('image'),
));
}

/**
* @return string
*/
protected function getCldImageUploaderUrl()
{
return Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/cloudinaryretrieveimage/upload', array('type' => 'wysiwyg_image'));
}

/**
* @return bool
*/
protected function getAddTmpExtension()
{
return true;
}

/**
* @return bool
*/
protected function getUseDerived()
{
return false;
}

/**
* @return mixed
*/
protected function getTriggerEvent()
{
return 'addItem';
}

/**
* @return mixed
*/
protected function getTriggerSelector()
{
return 'triggerSelector';
}

/**
* @return mixed
*/
protected function getCallbackHandler()
{
return 'window.MediabrowserInstance';
}

/**
* @return mixed
*/
protected function getCallbackHandlerMethod()
{
return 'selectFolder';
}
}
54 changes: 34 additions & 20 deletions app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

class Cloudinary_Cloudinary_Block_Adminhtml_Manage extends Mage_Adminhtml_Block_Widget_Grid_Container
{
/**
* @var Cloudinary_Cloudinary_Model_Migration
*/
private $_migrationTask;

private $_cloudinaryConfig;

public function __construct()
{
$this->_blockGroup = 'cloudinary_cloudinary';

$this->_controller = 'adminhtml_manage';

$this->_headerText = Mage::helper('cloudinary_cloudinary')
->__('Manage Cloudinary');

$this->_migrationTask = Mage::getModel('cloudinary_cloudinary/migration')
->load(Cloudinary_Cloudinary_Model_Migration::CLOUDINARY_MIGRATION_ID);

$this->_headerText = Mage::helper('cloudinary_cloudinary')->__('Manage Cloudinary');
$this->_migrationTask = Mage::getModel('cloudinary_cloudinary/migration')->loadType($this->getType());
$this->_cloudinaryConfig = Mage::getModel('cloudinary_cloudinary/configuration');

parent::__construct();
}

public function getType()
{
return Mage::registry('cloudinary_migration_type');
}

public function isFolderedMigration()
{
return $this->_cloudinaryConfig->isFolderedMigration();
Expand Down Expand Up @@ -70,34 +72,45 @@ public function isAutoUploadMappingEnabled()
public function allImagesSynced()
{
try {
return $this->getSynchronizedImageCount() === $this->getTotalImageCount();
return
($type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->getSynchronizedImageCount() === $this->getTotalImageCount()) ||
($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'));
} catch (Exception $e) {
return false;
}
}

public function getMigrationInfo()
{
if (!$this->hasData('migration_info')) {
$this->setData('migration_info', new Varien_Object($this->_migrationTask->getInfo()));
}
return $this->getData('migration_info');
}

public function getMigrateButton()
{
$type = $this->getType();
if ($this->_migrationTask->hasStarted()) {
$startLabel = 'Stop Migration';
$startAction = 'stopMigration';
return $this->_makeButton($startLabel, $startAction, $this->allImagesSynced());
return $this->_makeButton($startLabel, $startAction, $type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->allImagesSynced());
}

return $this->getLayout()
->createBlock('adminhtml/widget_button')
->setData(array(
'id' => 'cloudinary_migration_start',
'id' => 'cloudinary_migration_start_' . $type,
'label' => $this->helper('adminhtml')->__('Start Migration'),
'disabled' => $this->allImagesSynced(),
'onclick' => 'openCloudinaryMigrationPopup();'
'disabled' => $type === Cloudinary_Cloudinary_Model_Migration::UPLOAD_MIGRATION_TYPE && $this->allImagesSynced(),
'onclick' => 'openCloudinaryMigrationPopup(\''.$type.'\');'
))
->toHtml();
}

public function getStartMigrationUrl()
{
return $this->getUrl('*/cloudinary/startMigration');
return $this->getUrl('*/cloudinary/startMigration/type/' . $this->getType());
}

public function getClearErrorsButton()
Expand All @@ -110,10 +123,10 @@ private function _makeButton($label, $action, $disabled = false)
{
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'id' => 'cloudinary_migration_start',
'id' => 'cloudinary_migration_start_' . $action,
'label' => $this->helper('adminhtml')->__($label),
'disabled' => $disabled,
'onclick' => "setLocation('{$this->getUrl(sprintf('*/cloudinary/%s', $action))}')"
'onclick' => "setLocation('{$this->getUrl(sprintf('*/cloudinary/%s/type/%s', $action, $this->getType()))}')"
));

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

public function getErrors()
{
$coll = Mage::getModel('cloudinary_cloudinary/migrationError')->getCollection();
$coll->addOrder('timestamp');
return $coll->getItems();
return Mage::getModel('cloudinary_cloudinary/migrationError')->getCollection()
->addFieldToFilter('type', $this->getType())
->addOrder('timestamp')
->getItems();
}
}
Loading

0 comments on commit 04c40d1

Please sign in to comment.