I am using TinyMCE + IMCE to insert photos to newsletter. When I copy&paste the template for newsletter to TinyMCE window, absolute URL is converted into relative url.

I thought this may be an issue with TinyMCE, so I googled and found out TinyMCE has the option to enable/disable relative uls conversion:
http://tinymce.moxiecode.com/punbb/viewtopic.php?pid=6134

However, when I saw the setting in tinymce.module, it was already disabled by default (line 493):
$init['relative_urls'] = 'false';

So I thought this conversion is done by IMCE, but I could not find relevant information or a way to fix it.

If you know how to solve this problem, please let me know.

Comments

ufku’s picture

IMCE always sends relative URLs to tinymce however it has nothing to do with conversion. If the URLs are converted to relative even after you enter them manually, then it is probably a tinymce issue. If you want IMCE to send absolute URLs then add path=location.host+path; to the first line of imceFinitor function in imce_browse.js

--Geneticists from METU

dokumori’s picture

I followed your instruction, modified imce_browse.jp and uploaded to the site. But then drupal became unstable and I could no longer create new nodes / make any change to settings. Do you think this is related to the change I made?
I rolled back imce_browse.js to the previous version and even reinstalled IMCE, but it didn't make any difference... Maybe this is caused by something else...

ufku’s picture

it's just a little javascript change. it doesnt affect drupal.

--
Geneticists from METU

dokumori’s picture

Thanks. Yeah, that's what I thought too... It's still a test site anyway. I will just reinstall everything.

dokumori’s picture

The problem was that convert_urls had to be 'false' (not 'relative_urls'). I found this in readme.txt of Pathfilter module.

I also followed ufku's advice and added path='http://' +location.host+path; to the first line of imceFinitor function in imce_browse.js.

Now it does not convert absolute URLs to relative URLs and inserted images have absolute URLs by default.

Thanks ufku for the hint, and that strange drupal error did not recur after reinstalling everything. Wonder what it was.

adub’s picture

Been going nuts with this all day. If anyone else is trying to add pictures to newsletters and getting stuck with relative paths, try this + the following settings in phptemplate_tinymce_theme:

$init['convert_urls'] = 'true';
$init['relative_urls'] = 'false';
$init['remove_script_host'] = 'false';
$init['document_base_url'] = "base_path()";

selwynpolit’s picture

Hi Chu,
thanks for your help. I dug around a bit and found that this should go in modules/tinymce/tinymce.module - I found the function tinymce_config which looks like this:

/**
* Return an array of initial tinymce config options from the current role.
*/
function tinymce_config($profile) {
global $user;

down a few lines I found this:

$init['theme_advanced_resize_horizontal'] = 'false';
$init['theme_advanced_resizing_use_cookie'] = 'false';

and added your code below like this:
//selwyn add this 6-13-08
$init['convert_urls'] = 'true';
$init['relative_urls'] = 'false';
$init['remove_script_host'] = 'false';
$init['document_base_url'] = "base_path()";
//end selwyn add this 6-13-08

Hope this helps some folks out who are trying to figure out where to put this fix.

cheerio
Selwyn

ps. This appears to break relative paths - so if you have used imce to insert an image, your system can't find it at /files/image1.jpg, now it expects it to be at http://mysite/files/image1.jpg. I hope this is clear.

profek’s picture

Hi everybody,

I did not find "tinymce.module" (where is this?!), so I simply edited tiny_mce.js like the following:

Find:
relative_urls:1,remove_script_host:1,

and set both to 0, like this:

relative_urls:0,remove_script_host:0

For me: it works fine.

eagereyes’s picture

Wow, what an annoying problem! I thought I was going crazy when I made changes (even in plain HTML), and my absolute links became relative ones by themselves. I really like relative links (well, starting with a /) in general, but they don't work in RSS/Atom streams.

Anyway, thanks to the info here, I was able to solve the problem quickly. Is there any chance to get the relevant setup options into tinymce and imce?

EagerEyes.org

eagereyes’s picture

This issue raises its ugly head again in 5.1. This is what I have in my tinymce.module (5.x-1.x-dev, tinyMCE 2.1.1.1):

  $init['relative_urls']      = 'false';
  $init['document_base_url']  = "$host";

How do I change that to not change my absolute URLs? Is there perhaps an option in tinyMCE now (couldn't find anything in the role setup, though)?

EagerEyes.org

skilip’s picture

Here's what I did:

Find:

  $init['theme_advanced_resizing_use_cookie'] = 'false';

Replace with:

  $init['theme_advanced_resizing_use_cookie'] = 'false';

  /*	========================================	BEGIN Patch	========================================	*/
  /*
  	In order to configure TinyMCE to not remove the host name, set 'remove_script_host' to false.
  	If you don't use this, TinyMCE removes the hostname of urls in the editor.
  	For example: If you add a picture to the editor, by default the url of the image will be relative (e.a. /files/images/image.gif).
  	With 'remove_script_host' set to false, the url will stay absolute (e.a. http://yourdomain.com/files/images/image.gif).
  	
  	I've added the option to set this value in the edit role page form. (See linenumber 949) 
  */
  $init['remove_script_host'] = $settings['remove_script_host'] ? $settings['remove_script_host'] : 'true';
  /*	========================================	END Patch	========================================	*/	

Find:

  $form['output']['apply_source_formatting'] = array(
     '#type' => 'select',
     '#title' => t('Apply source formatting'),
     '#default_value' => $edit->settings['apply_source_formatting'],
     '#options' => array('true' => 'true', 'false' => 'false'),
     '#description' => t('This option makes TinyMCE apply source formatting.  Set this to true for a cleaner HTML source.  Choose false to avoid conflicts with some filters.')
  );

Replace width:

  $form['output']['apply_source_formatting'] = array(
     '#type' => 'select',
     '#title' => t('Apply source formatting'),
     '#default_value' => $edit->settings['apply_source_formatting'],
     '#options' => array('true' => 'true', 'false' => 'false'),
     '#description' => t('This option makes TinyMCE apply source formatting.  Set this to true for a cleaner HTML source.  Choose false to avoid conflicts with some filters.')
  );

  /*	========================================	BEGIN Patch	========================================	*/
  $form['output']['remove_script_host'] = array(
     '#type' => 'select',
     '#title' => t('Remove script host'),
     '#default_value' => $edit->settings['remove_script_host'],
     '#options' => array('true' => 'true', 'false' => 'false'),
     '#description' => t('Set this option to false if you want to use absolute url for added links or images (e.a.: http://yourdomain.com/files/image.jpg). If it\'s set to true, the file-path will be relative (e.a.: /files/image.jpg)')
  );
  /*	========================================	END Patch	========================================	*/

eagereyes’s picture

Wonderful, thanks! Have you submitted this as a patch for tinyMCE?

EagerEyes.org

skilip’s picture

I haven't figured out how to write a patch yet, but I am planning to do so. Maybe someone is willing to help?

ariana’s picture

I don't know why I can't get this fix to work.. it's changing the URLs to absolute, but for some reason the images don't display. They are there if I go back to edit the page, but not when I view it. In the view page source code there is no reference to an image. Is this a drupal setting I need to change maybe?

Nevermind, I'm an idiot, I didn't realize you had to use unfiltered html. The fix worked great, thanks!

hedac’s picture

thank you for this !!!!!!
should be appplied

spiffyd’s picture

I checkd my tinymce module file and can't find

<?php
  $form['output']['apply_source_formatting'] = array(
     '#type' => 'select',
     '#title' => t('Apply source formatting'),
     '#default_value' => $edit->settings['apply_source_formatting'],
     '#options' => array('true' => 'true', 'false' => 'false'),
     '#description' => t('This option makes TinyMCE apply source formatting.  Set this to true for a cleaner HTML source.  Choose false to avoid conflicts with some filters.')
  );
?>

Is this the wrong place to look?

I'm using Drupal 6.x tinymce-6.x-1.1-dev.tar

Folkert’s picture

Nice one Skilip. I can help you live with patching code ;)

Geldora@drupal.ru’s picture

I found a new way - this module helps http://drupal.org/project/abssrc

I don-t touch any files of imce or tinymce, but I see on html output of my rss feed, that pathesare correct. Well, i just installed module, so let`s see!

One problem - in 5 version autor used a bit of 6v code. There is a patch for it, but the autor of module didn`t upload a new version...

Well, lets see...

ursika’s picture

I had a similar problem, thanks for the help! I had to change to

relative_urls: 0
remove_script_host : 0,

in both files, \sites\all\modules\tinytinymce\tinymce\jscripts\tiny_mce\tiny_mce.js and \sites\all\modules\tinytinymce\tinymce\jscripts\tiny_mce\tiny_mce_src.js

lulyx’s picture

ursika I tried your suggestion and didn't work for me. I still have absolute path even after I clear cache :(... this is frustrating

lulyx’s picture

The pathologic module solved the problem....yeah! - great module!
http://drupal.org/project/pathologic