Re: Options for converting URLs.

HSTRAF, thank you. 

I am familiar with the Post/submit instructions on the server, so can implement this and appreciate the confidence your reply inspires. 

To confirm my understanding:
1   Is it a stretch to dedicate an entire page to such a post, for say a traditional "Home" or "about" page, and as these sorts of pages are primarily images and text?  My assumption (hope) is that such a page could have a single large block of text, and the end-user could simply free-form edit using tinyMCE. 
2  In such a situation, would the post/submit on the server side simply update the page (php or html)?

thanks again, pauln


Re: Options for converting URLs.

Yes, I think this is possible. 

My own application (www.snippetmaster.com) might give you an idea of how the tinyMCE editor "fits" with the editing of a page or snippet of code. 

Be warned, however, that what you are proposing is a LOT of work and requires a fair amount of understanding of the server-side programming language to make it work.  TinyMCE is only used to actually edit/create the HTML code for your page, but you must create your own program/system to do everything else.


Re: Options for converting URLs.

And... Why TinyMCE doesn't like this config:

    mode : "none",
    theme : "advanced",
    relative_urls : "",
    document_base_url : "/drupalnew/",
    language : "ru_UTF-8",
    safari_warning : false,
    entity_encoding : "raw",
    verify_html : true,
    preformatted : false,
    convert_fonts_to_styles : true,
    remove_linebreaks : false,
    apply_source_formatting : true,
    convert_urls : "",
    urlconverter_callback : "myCustomURLConverter",
    plugins : "advhr,autosave,emotions,flash,fullscreen,insertdatetime,paste,table,drupalbreak",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_path_location : "bottom",
    theme_advanced_resizing : true,
    theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
    theme_advanced_buttons3 : "advhr,cut,copy,paste,emotions,flash,fullscreen,pasteword,tablecontrols,drupalbreak,drupalpagebreak",
    theme_advanced_buttons1 : "bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "image,sup,sub,insertdate,inserttime",
    extended_valid_elements : "hr[class|width|size|noshade],img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|obj|param|embed]",
    plugin_insertdate_dateFormat : "%Y-%m-%d",
    plugin_insertdate_timeFormat : "%H:%M:%S",
    content_css : "/drupalnew/themes/friendselectric/style.css",
    elements : "edit-body"

Problem is same, like "how I can tell TinyMCE not to convert www.example.com to <a ...". When function myCustomURLConverter is called, text already have been converted.


Re: Options for converting URLs.

why when i have ? at the begining of a link like href="?link&etc" it adds a / in fron of the sign - href="/?lint&etc"


Re: Options for converting URLs.

I posted a solution for the anchor links a while ago. Here it is:

There is an easier solution to this problem, by commenting the code that does this.

in the file themes\advanced\jscripts\link.js uncomment the lines near "make anchors absolute". Over here it's line 61 and 62. This should fix the problem when editing the URL's in the built-in URL editor.

There's still another problem, when editing the HTML code directly or saving the content. To fix this save the original tiny_mce.js as .bak or similar and rename tiny_mce_src.js to tiny_mce.js. Uncomment the lines near "Convert relative anchors to". Should be lines 3686 and 3687.

These should fix the absolute anchor link conversion problems. At least, over here it works like a charm.

Now, anyone who knows a solution to the "first paragraph problem"? Meaning TinyMCE doesn't convert the first paragraph to .. well.. a paragraph, unless the enter-key has been pressed.




Re: Options for converting URLs.

good day... how about multiple support for document base url

relative_urls : true,
    document_base_url : "http://www.sample1.com/"

it doesn't change the the path with "www.sample1.com/"

any alternative or is it not posible?


Re: Options for converting URLs.

TinyMCE does the work of htmlentities. If & is getting converted to & (of course this is not a bug, that's a functionality), you can reconvert that back as -

$text = eregi_replace('&','&',$text);


Re: Options for converting URLs.

Hmmm ... I'm looking for a similar stuff ... I want -

<a href="http://xxx.org/home/page.asp?target=nfo-loc&LNG=fr&DOKO=1">


<a href="http://xxx.org/home/page.asp?target=nfo-loc&LNG=fr&DOKO=1" target="somevalue" class="somevalue" etc="etc">

should all be converted to -

<a href="http://xxx.org/home/page.asp?target=nfo-loc&LNG=fr&DOKO=1" target="_blank" class="myclass">

Is there any solution already for this?

Thanks for ur help.

Last edited by kigoobe (2007-04-07 14:46:06)


Re: Options for converting URLs.

Logically, this can be done using preg match ... 

first, get <a ... >

then, get href="..." inside <a ...>

then, keep href="..." inside <a...> and delete the rest

then, write this as you want.

I'm thinking aloud, wondering how this can be achieved ...


Re: Options for converting URLs.

Well, thinking aloud helps ... I found this, incase someone else need it ...

$content = preg_replace('/<a(.*?)href="(.*?)"(.*?)>/i', '<a href="$2" target="_blank" class="myclass">', $content);

Last edited by kigoobe (2007-04-07 15:00:00)


Re: Options for converting URLs.

Why 'convert_urls : false' is unavailable,if add fullpage to plugins.


Re: Options for converting URLs.

I am trying to have TinyMCE not modify URLs entered into a textarea changed at all by TinyMCE, I have read everything I can find in the Wiki and the forums but for me with ver 2.1.2 at the following in my int settings I cannot make it work (relative_urls : false, convert_urls : false,).
We have existing logic in our app to handle URL conversions the way we would like and have several million messages we need to preserve backward compatibility with that were created prior to our use of TinyMCE.

This topic seems to have died down on the forums, am I missing something?
Any type of link, either with the http in front or not becomes a properly structured a tag, we want it to leave the text alone so we can do it.
any suggestions would be greatly appreciated


Re: Options for converting URLs.

I have done some more testing and able to now add that the problem seems to be restricted to IE.

Text I typed manually into textarea;
AAAA www.bell.ca BBBB http://www.bell.ca CCCCC  //this line has no links in it, they appear when I post this msg

When I dump the value my submit gets from FF and MCE I get;
AAAA www.bell.ca BBBB http://www.bell.ca CCCCC

When I dump the value my submit gets from IE and MCE I get;
AAAA <a href="http://www.bell.ca/">www.bell.ca</a> BBBB <a href="http://www.bell.ca/">http://www.bell.ca</a> CCCCC

When I pasted the text into MCE under IE I got;
AAAA www.bell.ca BBBB http://www.bell.ca CCCCC

and you could see that the url were converted when I hit the space character after typing the URL and when I pasted the content this event never occurred.

Does anyone out there have this behavior figured out? I need to get URLs passed as they were typed with no changes.

Last edited by bearface (2007-10-18 17:56:21)


Re: Options for converting URLs.

I am also having troubles with the URL's. I have spent a considerable amount of time going through web articles and tweaking the code. This is what I have done and the results are below:

I set the default values for the following fields to false:
* this._def("convert_urls", false);
* this._def("relative_urls", false);
* this._def("cleanup", false);

I also found those values defined in a js file and set the values to match the above (all false). Lastly, following the init statement, I hard coded all values to false.

After all is said and done, I am really close. I can see the absolute path in the editor so I thought I had it. However, when viewed in a browser it was still incorrect. After reviewing the HTML code, I found this:


I can see the full path because apparently, the application displays the value as defined in "mce_src". It fails to render correctly in a browser because the browser uses the value defined in the field "src".

One other noteworthy item - all images located on other domains correctly used the absolute path rather than the relative path.

So, at this point I think I have two options.
1.) Is there any way I can make the "src" entry the same as the "mce_src" variable?
2.) If images on other domains load correctly, can I trick the application into believing the images are on a different domain? It seems I could hard code the BaseURL to the IP address but I could not get that to work either. Please note, my js skills are not very good.

Any thoughts or suggestions?



Re: Options for converting URLs.

tommya wrote:
notorious_kev wrote:
kentharris wrote:

Issue:  When I insert a link (that has an '&' in it) into the WYSIWYG editor like sayfor example, http://www.site.com/viewcatalog.asp?cat … prodID=53, the html that is spit out changes the '&' to &amp like this...  http://www.site.com/viewcatalog.asp?cat … prodID=53.  This breaks the link! 

Anyone else encountered/conquered this bug?  If so any suggestions would be greatedly appreciated.

Why do you think this is a bug?  The ampersand in the URL *must* be represented by an entity reference in a CDATA attribute such as href.

Perhaps because the last url won't work as intended

i have the same problem with links (tinymce, to see if this is a bug, try to edit link with advanced link, and you'll see how link looks like.
example: in FF is bug: url: ?page=philosophy&lang=ro after save and relaoad from DB i try to edit link and i see: ?page=philosophy?=ro and in html code i have ...?=ro when it should be &lang=ro because this i recive from DB. in IE is working fine, and in old version also is working.

Last edited by matei (2008-03-03 17:49:00)


Re: Options for converting URLs.

Have you encoded the page correctly: http://wiki.moxiecode.com/index.php/Tin … en_text.3F

Best regards,
Spocke - Main developer of TinyMCE


Re: Options for converting URLs.

i want to convert emailadresses (mailto: links) to images or escape them with php to make it harder for emailharvesters to get the emails from a page. is it posible to call php-code somehow using the callback-function or is javascript the only way?


Re: Options for converting URLs.

Dear TinyMCE Gods:

Please remove or make optional the default hard-coded & -> & transformation. It is not needed and causes problems with URLs in links with query strings with more than one parameter.

webget wrote:

Indeed, URLs like "zz.php?ee&t=eee" works fine with FF or IE...

Sadly, this does not work for link URLs created outside of TinyMCE, URLs which use "&" but not "&".

If your URL that you are linking to is "zz.php?ee&t=eee", TinyMCE will convert it to "zz.php?ee&t=eee" which will behave as if you used the link "zz.php?ee" with the remainder of the URL truncated.

Try typing a link with & converted to & in the location bar. Does not work in FF or any other browser because "&" in the middle of a URL is also completely valid and distinct from "&" in the same URL string.

If you are adding a URL with "&" but not "&" in the URL, which is very common with php-based sites, TinyMCE 3.0 will break your links. Every time the code "cleans up" -- going in and out of the HTML editor for example, The entities property will not override it. Omitting "38" will not fix it. Sadly, the conversion is HARD CODED into TinyMCE. This should be changed. The only time & is ever necessary is when posting human-readable descriptions of html entities. And the people who write these are fully capable of typing &bull; instead of • in the TinyMCE Rich Text entry area.

For our html email software, we had to add CPU-cycle sucking code using the hooks provided. . .

Check out the repetitious (but currently necessary) global search and replace functions in my_urlconverter_callback and my_cleanup_callback(). . .

<script language="javascript" type="text/javascript">
            mode : "textareas",
            theme : "advanced",
            plugins : "safari,spellchecker,inlinepopups,preview,contextmenu,paste",
            theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,bullist,numlist,outdent,indent,|,image,charmap,hr,anchor,link,unlink,|,spellchecker,code,cleanup",
            theme_advanced_buttons2 : "fontselect,fontsizeselect,justifyleft,justifycenter,justifyright,justifyfull,|,bold,italic,underline,strikethrough,sub,sup,|,forecolor,backcolor,removeformat",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_path : false,
            theme_advanced_resizing : true,
            extended_valid_elements : "a[name|href|target|title|onclick|style],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
            ask : true,
            forced_root_block : false,
            convert_newlines_to_brs : false,
            force_br_newlines : true,
            force_p_newlines : false,
            convert_urls : true,
            urlconverter_callback : "my_urlconverter_callback",
            cleanup_callback : "my_cleanup_callback",
            convert_fonts_to_spans : false

        function my_urlconverter_callback(url, node, on_save) {
            // see http://wiki.moxiecode.com/index.php/Tin … r_callback
            // if(!on_save && node !== null && node) {
                url = url.replace(/&/g, "&");
            return url;
        function my_cleanup_callback(type, value) {
            // see http://wiki.moxiecode.com/index.php/Tin … p_callback
            switch(type) {
                case "get_from_editor":
                    value = value.replace(/&/g, "&");
                case "insert_to_editor":
                    value = value.replace(/&/g, "&");
                case "submit_content":
                    value = value.replace(/&/g, "&");
            return value;


Last edited by Pepi (2008-03-21 17:00:55)


Re: Options for converting URLs.

I am trying to utilize the relative_url functionality...I have this code:

convert_urls : false,
relative_urls : true,

but, it does not switch to relative paths when I save images to the form...It maintains the absolute path...Is there anything else that I need to do in order for the images to be saved with a relative path???Thanks in advance for any help/suggestions...


Re: Options for converting URLs.


Could you clarify the issue?

Ampersands in the HTML itself, NEED to be escaped, so when writing a link tag with an ampersand, for it to be valid, it has to be escaped:

<a href="mylink.php?query1=value&query2=value">link</a>

That is correct, and it makes sense that TinyMCE converts that.

Is the issue if you are pasting in a URL that already has been escaped? If so, I can imagine you'd end up with this:

<a href="mylink.php?query1=value&amp;query2=value">link</a>

Which would be broken. However, I find it unlikely that a person would be cutting-and-pasting in an already escaped URL as the only way to get to it would be digging through source code.

Or am I misunderstanding the issue?


Re: Options for converting URLs.

darrel wrote:

Could you clarify the issue?

Unlike almost all other entities, ampersands in HTML do not need to be formatted as entities. The "&" character is a valid in raw html by itself and will appear as "&" if left alone.

Very few uses (for example, individuals writing about html entities) would ever need to use "" or "&bull;" so as to avoid displaying the entity and just show the underlying (escaped) code. Any user writing this text is competent to edit the raw html.

Our problem is users using the link tool or copy-pasting into the raw html any link that contains a query string with more than one parameter.

We need to fix TinyMCE so it works for users, not programmers.

If a user adds a link using the Link tool <a href="mylink.php?query1=value&query2=value">link</a>

then TinyMCE currently corrupts as <a href="mylink.php?query1=value&query2=value">link</a>

which breaks the link. This link may go to an offsite location, so it is not an option for us to change the server to recognize these links as equivalent.

This corruption is hard-coded in the source files for version 3 and even affects urls in links

1. turn off the default search and replace of all instances of "&"
2. add a parameter to turn off the default search and replace of all instances of "&"

In any event, hard-coding entity conversion is bad form.

I have used the hooks provided to repeatedly replace all instances of "&" with "&", but it's a performance hit. (And requires anyone writing about entities to use &#38 to avoid replacement.)

This said, I love TinyMCE.

Last edited by Pepi (2008-03-26 18:49:57)


Re: Options for converting URLs.


Maybe this explains the issue better:


"then TinyMCE currently corrupts as <a href="mylink.php?query1=value&query2=value">link</a>"

That's not corrupted. Rather, that's completely valid and proper HTML.

"which breaks the link"

How does it break for you? A link like that, on an HTML page displayed in a browser, will work just fine when someone clicks on it.

The link will NOT work if you cut-and-paste the source code into the address bar of the browser window...is that what you're doing?


Re: Options for converting URLs.

here's a real-world example:


On the main navigation bar, go to BOXING and select RANKINGS from the fly-out menu. Click the link and you will be taken to this page with this URL:

http://sports.espn.go.com/sports/boxing … id=3015590

(note the ampersand)

However, if you go back to the home page, and VIEW SOURCE, you will see that the URL is properly encoded as such:

http://sports.espn.go.com/sports/boxing … id=3015590


Re: Options for converting URLs.

ah crap...the forum here turned those into links.

let's try it again without the domain:

url in address bar:


url in actual HTML markup:



Re: Options for converting URLs.

No amount of forum posts will convince me that TinyMCE should break valid links that use "&" in the URL.

The problem is that I'm talking about users who need to add a Link URL to their text to link to an external php URL with multiple parameters (a very common need). When adding a Link URL with more than one parameter, TinyMCE 3.01 will corrupt the link by converting each instance of "&" to "&".

We are not talking about programmers or coders. We're talking about everyday business people adding a live Link URL to an article in an email newsletter.

I've provided working init code with the cycle-intensive work-around above.

We'd prefer, for performance reasons, to have a way to turn off the automatic conversion of "&" to "&".

Sadly, this conversion is hard-coded into the source code, so we can't even use the provided entities init parameter.

At a minimum, to remove the hard-coded parts, make the following mods by line number in "tiny_mce_src.js" and re-compress. (Not tested, since I don't have a source-code compressor.)

I don't know where the default set of entities is stored, but this may need to be modified as well.

in tiny_mce_src.js,

change line 1996:
    return s ? ('' + s).replace(/[<>&\"]/g, function (c, b) {
    return s ? ('' + s).replace(/[<>\"]/g, function (c, b) {

delete lines 1998-2000 & 3276-3278:
        case '&':
            return '&';

change line 3268:
    return s.replace(/[<>&"]/g, function(v) {
    return s.replace(/[<>"]/g, function(v) {

change lines 3467-3468:
    // Don't add default & " etc.
    if (v == 34 || v == 38 || v == 60 || v == 62)
    // Don't add default " etc.
    if (v == 34 || v == 60 || v == 62)

Last edited by Pepi (2008-03-27 20:27:49)