7

I am having trouble with my Magento install, in the CMS when I go to insert an image with the wysiwig editor the folder keeps opening repeatedly.

The folder structure should be:

- infortis
    - brands
    - fortis
    - ultimo

But what I get is:

-infortis
    -infortis
        -infortis
            -infortis
                -infortis

And this just keeps repeating.

Magento Version 1.8.1. Any help appreciated.

ConquestXD
  • 754
  • 1
  • 8
  • 18
  • just to verify, are you using any 3th party extensions or plugins for you editor or media browser? Does this happen on other PC's/browsers as well? Is the directory structure in the `media/wysiwyg` directory correct? and last: are you getting any javascript errors when opening the editor or the image uploader? Sorry for all the questions, just trying to get a better picture of the issue :) – Sander Mangel Jan 30 '14 at 15:55
  • @sandermangel I can confirm that this is a problem we are also having the same issue :( seems that `Mage_Cms_Helper_Wysiwyg_Images` does not deal well with links – dmanners Jan 30 '14 at 15:57
  • Same problem confirmed on EE 1.13.1.0 – Giel Berkers Feb 27 '15 at 15:12

3 Answers3

11

I have found that the following edits makes it work as expected, and works with non-symlinked (dev) resources as well:

In the same class as mentiond Mage_Cms_Helper_Wysiwyg_Images, apply these patches:

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>Images.php (<b>Today 4:14:50 PM</b>)</html>
+++ <html><b>Current File</b></html>
@@ -223,7 +223,7 @@
     public function getCurrentUrl()
     {
         if (!$this->_currentUrl) {
-            $path = str_replace(Mage::getConfig()->getOptions()->getMediaDir(), '', $this->getCurrentPath());
+            $path = str_replace(realpath(Mage::getConfig()->getOptions()->getMediaDir()), '', $this->getCurrentPath());
             $path = trim($path, DS);
             $this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
                                  $this->convertPathToUrl($path) . '/';



# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>Images.php (<b>f47f0ff</b>)</html>
+++ <html><b>Current File</b></html>
@@ -68,7 +68,7 @@
      */
     public function getStorageRoot()
     {
-        return Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
+        return realpath(Mage::getConfig()->getOptions()->getMediaDir()) . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
             . DS;
     }
proxiblue
  • 433
  • 5
  • 19
  • 1
    I have raised a bug for this: http://www.magentocommerce.com/bug-tracking/issue?issue=16088 – proxiblue Feb 04 '14 at 08:40
  • This seems to break the thumbnails of the image popup in the wysiwyg editor though.. it fails to put "wysiwyg" in the url, so it looks like this: `https://blabla.com/media//.thumbs/img.png?rand=1399016538 `Will debug when I get the chance – Erfan May 02 '14 at 07:43
  • 2
    @Erfan Been there, done that:) http://magento.stackexchange.com/questions/14820/magento-1-8-1-0-wysiwyg-editor-is-not-displaying-thumbnails-in-image-manager – proxiblue May 03 '14 at 15:10
  • 3
    I've bundled this fix up in a mini-module if anyone finds it useful: https://github.com/eyemagine/Magento-MediaSymlink – Steve Robbins May 19 '14 at 19:10
  • Thanks @SteveRobbins, you're plugin did the trick! Thanks for sharing! – Giel Berkers Feb 27 '15 at 15:26
2

Found the issue in Mage_Cms_Helper_Wysiwyg_Images::convertIdToPath

The core code is as follows.

public function convertIdToPath($id)
{
    $path = $this->idDecode($id);
    if (!strstr($path, $this->getStorageRoot())) {
        $path = $this->getStorageRoot() . $path;
    }
    return $path;
}

And the fix is to use realpath when getting the storage root as follows.

public function convertIdToPath($id)
{
    $path = $this->idDecode($id);
    $realpath = $this->getStorageRoot();
    if (is_link(rtrim($realpath,'/'))) {
        $realpath = realpath($realpath);
    }
    if (!strstr($path, $realpath)) {
        $path = $realpath . $path;
    }
    return $path;
}

So what we have done is to rewrite Mage_Cms_Helper_Wysiwyg_Images and use the updated converIdToPath function. I found the original solution on a German website, but that will break if say you have a dev system without links and another system with a link.

dmanners
  • 2,062
  • 1
  • 18
  • 24
0

We recently ran into this issue as well and I wanted to share a little more info to save the next person some time. If you are running the Magento Enterprise Edition and have an active support agreement in place there is an official patch available. Just open a support ticket and request the patch directly. The patch name is "PATCH_SUPEE-2662_EE_1.13.1.0_v1".

Dale
  • 1