I've recently been evaluating using TincyMCE on my drupal site. I love the way that it works, but I'm having this problem with the base URL's for inserted images.

Basically from Firefox, when I go to edit a node with an inserted image in the body, it changes the root relative link from files/sitename/images/sample.jpg to ../../../files/netservices/sample.jpg (relative to tinyMCE?). If you then post the page, the image link is forever broken.

In IE it appears to not modify the image reference, but rather renders a broken link in TinyMCE(unless the image file link is tinymce relative.

I'm using an adjusted files location "files/sitename" rather than straight "files". I don't know if this is relavent to the problem.

TinyMCE reference a base url setting that can be passed to init to help with these kinds of troubles, but I can't find any place in the module that sets this. Should it?

Any ideas about what needs to be done to resolve this problem?

Comments

metzlerd’s picture

I was able to fix this by doing the following:

1. Create a symbolic link in my htdocs directory for files pointing to my drupal files directory.
2. Create a symbolic link in the root of my file system (linux) pointing to /files
3. Change my default site files directory to /files (instead of "files").

This is not an optimal solution, but is a viable work-around unless you are trying to protect your images.

Dave

kertal’s picture

same problem here, i discovered that it only happens when you've clean urls enabled. then tiny_mce messes with url in general. adds "../"s . Otherwise it works ... can anybody help?

andre75’s picture

I am having the same prob. Fortunately for me, the romote site still displays everything correctly.
I guess it is probably a better apache configuration. Which makes one wonder, if you could redirect requests to ../../files to files per .htaccess file? If someone knows how to write this into .htaccess please let me know.

Andre
www.aguntherphotography.com
www.opentravelinfo.com

andre75’s picture

Title: Images breaking in TinyMCE/Firefox with Img_Assist » This seems to work

This seems to work for me. Please use this at your own risk since I know nothing about Javascript. I simply replaced this:

	defParam("document_base_url", this.documentURL);

With this:

	defParam("document_base_url", ./);

in tiny_mce.js and tiny_mce_src.js. I tried a test posting and did not see any ../../ .

I'd be happy to hear some feedback. Maybe someone can come up with a cleaner implementation.

Andre
http://www.opentravelinfo.com
http://www.aguntherphotography.com

andre75’s picture

Title: This seems to work » How to fix the TinyMCE image path problem w/ a simple hack.

Sorry, I messed up the title of the issue.

gwerker’s picture

Title: How to fix the TinyMCE image path problem w/ a simple hack. » How to fix the TinyMCE image path problem -- and all path problems?

I've noticed this problem as well when I simply try to link to nodes. For instance, if I create a link to node/99, then click submit, it works fine. However, if I click edit to make more changes, TinyMCE then changes the link to ../99. If I submit and then click edit again, it changes it to ../../../99.

I tried altering the document_base_url param, but that didn't work for me. Has anyone else found a solution to this?

quicksketch’s picture

Title: How to fix the TinyMCE image path problem -- and all path problems? » Set all paths to "absolute"
Status: Active » Needs review

This will force all links and image paths to be absolute from you domain. That is, they will be of the format: "/files/images/whatever.jpg". Note the slash preceding the path. I think this will also affect all links, so it will probably work best with Drupal clean URLs enabled.

So, open up tinymce.module and find the line

  $init['document_base_url']  = "$base_url/";

Append to it so that we use absolute URLs instead.

  $init['document_base_url']  = "$base_url/";
  $init['remove_script_host']  = "true";
  $init['relative_urls']  = "false";

More information about these settings are available at the tinyMCE website, http://tinymce.moxiecode.com/tinymce/docs/reference_configuration.html.

m3avrck’s picture

Status: Needs review » Closed (fixed)

I have talked with the main developers of TinyMCE to arrive at a fix for this and it appears the finaly version of TinyMCE 2.0 has numerous fixes for path problems. I have confirmed that the path problems I have encountered are indeed fixed with TinyMCE from CVS (soon to be version 2.0 final). Closing this issue as it appears this has been resolved.

Vallenwood’s picture

Status: Closed (fixed) » Needs review

The solution to this is to upgrade the tinymce files to 2.0 and then set a new flag in tinymce.module. Here's how:

  1. Disable the "tinymce" module in your Admin section.
  2. Under /modules/tinymce, delete the entire "tinymce" directory tree--NOT the modules/tinymce directorybut the directory underneath it of the same name. (Confusing enough? Be careful! Just don't delete the "tinymce.module" file.)
  3. Download the latest version of tinymce here: http://tinymce.moxiecode.com. Either unpack it locally and upload or unpack it on your server. In either case, unpack it in the modules/tinymce folder and it should create a new "tinymce" subfolder to replace the one you just deleted.
  4. Open the "tinymce.module" file and find the line starting with "$init['document_base_url']" and add a new line underneath, so it now reads:


      $init['document_base_url'] = "$base_url/";
      $init['convert_urls']  = "false";
    
  5. Re-enable the "tinymce" module in your Admin section.
  6. The 'convert_urls' false parameter tells it to preserve whatever you type and not put crap in front of it or rewrite. This worked for me. Note that if you try to COMBINE this with some of the above-posted solutions, like also putting in a 'remove_script_host' or 'relative_urls' config parameter, it can break this solution. It did for me. Don't use them. Just add this one parameter.

    Found this out by referring to tinymce manual here:

    http://tinymce.moxiecode.com/tinymce/docs/faq.html#paths

brauchlik’s picture

It also works for me. However, I had to include the full host as well. So in tinymce.module I changed:

  $init['document_base_url']  = $host . $base_url . "/";
  $init['convert_urls']       = "false";
BryanSD’s picture

Version: 4.6.x-1.x-dev » 4.7.x-1.x-dev

I found in Drupal 4.7 all that was necessary to add was:

$init['convert_urls'] = "false";

Veggieryan’s picture

one more thing.
when dragging and dropping images from within the site, i found that they had relative url's...
to solve this I added a line

 $init['relative_urls']      = 'false';
  $init['remove_script_host'] = "false";
  $init['document_base_url'] = "$base_url/";
  $init['convert_urls']  = "true";
skilip’s picture

It seems like the function base_path gets it's value from the .htaccess file, doesn't it? That could explain why the paths become messed up when enabling clean url's.

I had my Drupal installation on a subdomain. So I had to hack the TinyMCE module to be able to get the subdomain's base URL path. There was no other way to get clean_urls working, besides TinyMCE, without the hack.

Leeteq’s picture

The following issue also mentions changes to the settings in the tinymce.module:

"TinyMCE and relative urls running with clean_urls enabled":
http://drupal.org/node/133441

graper’s picture

While I know that this is an old thread. I wanted to put in my two cents since I just found it and I think it will help others in the future.

On 4.7.8 in I was able to put into the template.php file of my theme the following lines into a tinymce_theme override function.

function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
  $init['relative_urls']='true';
  $init['document_base_urls']=$_SERVER['HTTP_REFERER'];
  $init['convert_urls']='false';
}

This allowed me to have the absolute site paths for images in newsletters to work while also allowing relative paths that IMCE puts in for images to work on other nodes.

found the code on http://drupal.org/node/133441 and just wondered if it would work in the template.php since I already have some code in there to do other things with tinymce such as to allow a bunch more html tags and remove_linebreaks to false. Hope this helps the next person until a new patch comes out.

Granville
Kirkham Systems Inc.

Mupsi’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)