开发者

Getting Broken link on frontend for image uploaded via Wysiwyg editor in a custom module !

M getting this :

<img alt="" }}="" es_3.jpg="" wysiwyg="" src="{{media url=">

In my form i added this code

$wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(

     array('tab_id' => 'form_section')

);

$wysiwygConfig["files_browser_window_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg_images/index');

$wysiwygConfig["directives_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive');

$wysiwygConfig["directives_url_quoted"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive');

$wysiwygConfig["widget_window_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/widget/index');

$wysiwyg开发者_如何学运维Config["files_browser_window_width"] = (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_width');

$wysiwygConfig["files_browser_window_height"] = (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_height');

$plugins = $wysiwygConfig->getData("plugins");

$plugins[0]["options"]["url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_variable/wysiwygPlugin');

$plugins[0]["options"]["onclick"]["subject"] = "MagentovariablePlugin.loadChooser('".Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_variable/wysiwygPlugin')."', '{{html_id}}');";

$plugins = $wysiwygConfig->setData("plugins",$plugins);



  $fieldset->addField('longdescription', 'editor', array(

      'name'      => 'longdescription',

      'label'     => Mage::helper('press')->__('Description'),

      'title'     => Mage::helper('press')->__('Description'),

      'style'     => 'width:500px; height:300px;',

      'config'    => $wysiwygConfig,



    ));

I m still not clear about the above code but i copied it from somewhere,But i do know that it enables to browse for images files instead of writing custom url.

After that i just call it in frontend like this:

<?php echo $item["longdescription"]; ?>

I am getting the text , but not the image and for image i am getting the broken link mentioned at top.

Am i missing something ?? if yes then what ?


add this code :

<?php $_cmsHelper = Mage::helper('cms');?>

<?php $_process = $_cmsHelper->getBlockTemplateProcessor();?>

<?php echo $_process->filter($item["longdescription"]); ?>


It looks like you might be breaking on quotes somewhere, how are you passing in the image/url of the image? If you look right here: alt="" }}="" es_3.jpg="" you can see that you are passing in closing brackets somewhere, and are skipping the SRC entirely. Try VAR_EXPORTing the $item and show me what you have.


I had the same problem today. It turns out that Mage_Adminhtml_Cms_WysiwygController::directiveAction() tries to create an image according to a url. This function calls Varien_Image_Adapter_Gd2::open() which in turn tries to open the file. This is where it goes wrong:

The image adaptor tries to get information about the image, like image size and mime type. But... when your site is on a localhost or a vagrant box or something like that, the sever tries to getimagesize('http://www.domain.com/image.jpg') instead of getimagesize('/Users/john/sites/domain.com/image.jpg') (for example).

The fix for this is to override the directiveAction() in your own module to add another catch before throwing an exception:

public function directiveAction()
{
    $directive = $this->getRequest()->getParam('___directive');
    $directive = Mage::helper('core')->urlDecode($directive);
    $url = Mage::getModel('core/email_template_filter')->filter($directive);
    try {
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open($url);
        $image->display();
    } catch (Exception $e) {
        // Try to get an absolute path:
        $path = Mage::getBaseDir().'/'.preg_replace('/http:\/\/(.*)\//Ui', '', $url);
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open($path);
        $image->display();
    } catch (Exception $e) {
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open(Mage::getSingleton('cms/wysiwyg_config')->getSkinImagePlaceholderUrl());
        $image->display();
    }
}

A nice little bonus: the broken links in your admin are now gone too! ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜