Skip to content

Commit

Permalink
CLOUDINARY-69,CLOUDINARY-63,CLOUDINARY-6: Fixes on Wysiwyg & minor ch…
Browse files Browse the repository at this point in the history
…anges in system configuration
  • Loading branch information
pini-girit committed Dec 31, 2018
1 parent 1005f12 commit 5601680
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@ public function getStorageRoot()
}
return $this->_storageRoot;
}

/**
* Return URL based on current selected directory or root directory for startup
*
* @return string
*/
public function getCurrentUrl()
{
if (!Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
return parent::getCurrentUrl();
}
if (!$this->_currentUrl) {
$mediaPath = Mage::getConfig()->getOptions()->getMediaDir();
$path = str_replace($mediaPath, '', $this->getCurrentPath());
$path = trim($path, DS);
$this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
$this->convertPathToUrl($path) . '/';
}
return $this->_currentUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function mediaDirective($construction)
if (ini_get('allow_url_fopen')) {
$image = $this->imageFactory->build(
$this->imagePath($construction),
function() use($construction) { return parent::mediaDirective($construction); }
function () use ($construction) {
return parent::mediaDirective($construction);
}
);

return $this->urlGenerator->generateFor($image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,101 @@ public function __construct()
);
}

/**
* Return files
*
* @param string $path Parent directory path
* @param string $type Type of storage, e.g. image, media etc.
* @return Varien_Data_Collection_Filesystem
*/
public function getFilesCollection($path, $type = null)
{
if (!$this->_configuration->isEnabled()) {
return parent::getFilesCollection($path, $type);
}

if (Mage::helper('core/file_storage_database')->checkDbUsage()) {
$files = Mage::getModel('core/file_storage_database')->getDirectoryFiles($path);

$fileStorageModel = Mage::getModel('core/file_storage_file');
foreach ($files as $file) {
$fileStorageModel->saveFile($file);
}
}

$collection = $this->getCollection($path)
->setCollectDirs(false)
->setCollectFiles(true)
->setCollectRecursively(false)
->setOrder('mtime', Varien_Data_Collection::SORT_ORDER_ASC);

// Add files extension filter
if ($allowed = $this->getAllowedExtensions($type)) {
$collection->setFilesFilter('/\.(' . implode('|', $allowed). ')$/i');
}

$helper = $this->getHelper();

// prepare items
foreach ($collection as $item) {
$item->setId($helper->idEncode($item->getBasename()));
$item->setName($item->getBasename());
$item->setShortName($helper->getShortFilename($item->getBasename()));
$item->setUrl($helper->getCurrentUrl() . $item->getBasename());

if ($this->isImage($item->getBasename())) {
$thumbUrl = $this->getThumbnailUrl(
Mage_Core_Model_File_Uploader::getCorrectFileName($item->getFilename()),
true,
$item->getFilename()
);
// generate thumbnail "on the fly" if it does not exists
if (! $thumbUrl) {
$thumbUrl = Mage::getSingleton('adminhtml/url')->getUrl('*/*/thumbnail', array('file' => $item->getId()));
}

$size = @getimagesize($item->getFilename());

if (is_array($size)) {
$item->setWidth($size[0]);
$item->setHeight($size[1]);
}
} else {
$thumbUrl = Mage::getDesign()->getSkinBaseUrl() . self::THUMB_PLACEHOLDER_PATH_SUFFIX;
}

$item->setThumbUrl($thumbUrl);
}

return $collection;
}

/**
* @param string $filePath
* @param bool $checkFile
* @return string
*/
public function getThumbnailUrl($filePath, $checkFile = false)
public function getThumbnailUrl($filePath, $checkFile = false, $origFilePath = null)
{
$_origUrl = $origUrl = parent::getThumbnailUrl($filePath, $checkFile);

if (!$this->_configuration->isEnabled()) {
return $_origUrl;
}

if (!$_origUrl && !is_null($origFilePath)) {
$filePath = $origFilePath;
$origUrl = parent::getThumbnailUrl($filePath, $checkFile);
}

if (!$origUrl) {
return $_origUrl;
}

$image = $this->_imageFactory->build(
$filePath,
function() use($filePath, $checkFile) {
return parent::getThumbnailUrl($filePath, $checkFile);
function () use ($_origUrl) {
return (string) $_origUrl;
}
);

Expand All @@ -71,7 +155,7 @@ function() use($filePath, $checkFile) {
public function uploadFile($targetPath, $type = null)
{
if (!$this->_configuration->isEnabled()) {
return parent::uploadFile($targetPath, $type);
return parent::uploadFile($targetPath, $type);
}

$uploader = new Cloudinary_Cloudinary_Model_Cms_Uploader('image');
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Cloudinary/Cloudinary/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</cloudinary_enabled>
<cloudinary_environment_variable translate="label comment">
<label>Cloudinary Account Credentials</label>
<comment>Set the credentials of your Cloudinary account. Copy the "Environment variable" string from the dashboard of Cloudinary's Management Console.</comment>
<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>
<frontend_type>password</frontend_type>
<backend_model>cloudinary_cloudinary/system_config_credentials</backend_model>
<sort_order>2</sort_order>
Expand Down

0 comments on commit 5601680

Please sign in to comment.