cancel
Showing results for 
Search instead for 
Did you mean: 

Tiny MCE replaces paths with relative urls

stevewickii
Champ in-the-making
Champ in-the-making
Alfresco 2.9.0B is using Tiny MCE to edit HTML content inline.  My problem is that when my A/@HREF or IMG/@SRC does not start with "http://" or "/", tiny MCE prepends the path of the editor to the URLs!

The configuration is:
tinyMCE.init({
theme : "advanced",
mode : "exact",
relative_urls: false,
elements : "editor",
save_callback : "saveContent",
plugins : "table",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
theme_advanced_buttons2_add : "separator,forecolor,backcolor",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_disable: "styleselect",
extended_valid_elements : "a[href|target|name],font[face|size|color|style],span[class|align|style]"
});

When HTML content is edited in alfresco with the TinyMCE editor, "/alfresco/faces/jsp/browse/" is prepended to img/@src and a/@href values.  I have tested and verified that this only occurs in the following situations:
    when src or href does not start with "http://" or "/".
    Example 1: "${context}/images/test.gif" gets replaced with "/alfresco/faces/jsp/browse/${context}/images/test.gif"
    Example 2: "@CONTEXT@/images/test.gif" gets replaced with "/alfresco/faces/jsp/browse/@CONTEXT@/images/test.gif"
The conversion occurs when I click the "Update" button on the Tiny MCE HTML Source editor.  I verified this by changing the @src of an img tag from "/images/text.gif" to "${context}/images/text.gif", then clicking on the Image properties in the Tiny MCE advanced editor.  The path had already been changed to "/alfresco/faces/jsp/browse/${context}/images/test.gif".

The "Insert/edit Image" dialog also exhibits this behavior.

I have multiple web sites configured to pull HTML content from one Alfresco server via the web service client API.  In order for href and src URLs to point to the right place, I must use a token within the URL to represent the destination context.  This token is replaced by the website requesting the content, with the context in which the website has been deployed, not alfresco.  The Alfresco web server is not publically accessible.

What I am trying to accomplish is this - when a piece of content is pulled from Alfresco like '<img src="${context}/images/text.gif">', then the website replaces ${context} with the webapp's context like this '<img src="/testapp1/images/text.gif">'.  Then the content is sent to the browser and the image will load properly from the public website.
4 REPLIES 4

tonizz
Champ in-the-making
Champ in-the-making
maybe if you change the configuration:

relative_urls: false for  relative_urls: true, the behavior is good.

But, I have a question:

¿Where can you modify this Tiny MCE configuration? ¿Which is the right file?

ctrl
Champ in-the-making
Champ in-the-making
it took us weeks of playing with the config to learn this but it appears that this is an issue only in IE6, IE7 however it works alright in FF. Anyway there is a fix for it


Change tiny_mce_extensions.js  located at /jsp/scripts/ajax/ add the following code to the alfresco_TinyMCE_urlconverter_callback() function…

if (tinyMCE.isMSIE)
{
   var server = document.location.protocol + "//" + document.location.host;
   if (href && href.startsWith(server))
   {
      result = href.substring(server.length);
   }
}

Add it to the end of the method i.e. just before the "return result;"

Credit to Gavin and Tom… !

stevewickii
Champ in-the-making
Champ in-the-making
I appreciate the suggestion!  Unfortunately, it doesn't work for me.

I am using Alfresco 2.9.0B build 683, so things may have been moved around.

First, I couldn't find tiny_mce_extensions.js or a folder named /jsp/scripts/ajax.
So, I tried adding the code you suggested to a file I do have: /scripts/ajax/tine_mcs_wcm_extensions.js.
Unfortunately, this didn't fix my problem.  I also tried adding an alert() to the beginning of the alfresco_TinyMCE_urlconverter_callback() function, and it never gets invoked, so I don't think this javascript is even being executed by tiny mce.

Any suggestions?

zhunjier
Champ in-the-making
Champ in-the-making
We can not deny the fact that the economy is experiencing financial crisis. RealtyTrac's quarterly report on the foreclosure industry showed that more than a fourth of all domestic home sales during the first quarter of the year were deals on foreclosure properties. Excessive foreclosures bring down the cost of homes, making market recover more difficult. The news, regarded with last week’s grim jobs report, further supports the conclusion that the slow economic recovery is not picking up much steam at the moment. Article resource: https://personalmoneynetwork.com/