{"id":1808,"date":"2003-09-23T21:05:28","date_gmt":"2003-09-24T01:05:28","guid":{"rendered":"http:\/\/www.alquier.org\/linfa\/create\/2003\/09\/23\/how_to_replace\/"},"modified":"2003-09-23T21:05:28","modified_gmt":"2003-09-24T01:05:28","slug":"how_to_replace","status":"publish","type":"post","link":"http:\/\/www.alquier.org\/laurent\/sites\/2003\/09\/23\/how_to_replace\/","title":{"rendered":"How to replace the default entry textarea by an HTML editor"},"content":{"rendered":"<p>I have been trying to replace the default entry textarea by an HTML editor such as this one (&nbsp;<a href=\"http:\/\/www.fredck.com\/FCKeditor\/\">FCK Editor&nbsp;&nbsp;&#8211; FREE web based HTML editor<\/a> )<\/p>\n<p>Getting the editor to work is relatively straight forward. Just install the zip files in their destination on your website, edit the editor javascript (or .htc) files to point to the new location and copy\/paste the HTML code from the test pages into the \ufffdedit_entry.tmpl\ufffd template (MT\/tmpl\/cms folder).<\/p>\n<p>Problems showed up when&nbsp;I tried to edit an entry :&nbsp;all HTML codes were replaced by their escaped equivalent.<\/p>\n<p>For example :&nbsp;&nbsp; &lt;\/A&gt;&nbsp;<\/a>becomes &amp; lt ;\/A &amp; gt ;<\/p>\n<p>This makes WYSIWYG editing completely useless.&nbsp;&nbsp; But the good news is &#8211; I finally got it to work&#8230;&nbsp;&nbsp;<\/p>\n<p><!--more--><\/p>\n<p><strong><font size=\"3\"><u>Explanation<\/u> <\/font><\/strong><\/p>\n<p>After some digging around, here is what MT editor is doing : when you add a new link, it automatically creates the HTML code for that link. So what you see on your form is (for example).<\/p>\n<p><font face=\"Courier New\">&lt;a href=&#8221;http:\/\/www.renderosity.com\/homepage.ez?Who=agiel&#8221;&gt;Personal gallery&lt;\/a&gt;<\/font><\/p>\n<p>But if you look at the source of your page, what is actually in the page is :<\/p>\n<p><font face=\"Courier New\">&lt; textarea class=&#8221;width500&#8243; name=&#8221;text&#8221; rows=&#8221;20&#8243; wrap=&#8221;virtual&#8221; &gt;<\/p>\n<p>&amp; lt ; a href=&#8221;http:\/\/www.renderosity.com\/homepage.ez?Who=agiel&#8221; &amp; gt ;Personal gallery&amp; glt ;\/a &amp; gt ;<\/p>\n<p>&lt; \/textarea &gt;<\/font><\/p>\n<p>So, MT has to convert \ufffd&lt;\ufffd \ufffd&gt;\ufffd symbols to \ufffd&amp; lt ;\ufffd and \ufffd&amp; gt ;\ufffd in order to display them correctly in the editor and convert them back to their original value to be displayed correctly in the final HTML page.<\/p>\n<p>Now, when you use a WYSIWYG editor, the editor is doing that conversion for you by displaying URLs as clickable links directly in the editor, and not just as HTML code.<\/p>\n<p>So what I want to see in the source of the page is :<\/p>\n<p><font face=\"Courier New\">&lt; open HTML editor &gt;<\/p>\n<p>&lt;a href=&#8221;http:\/\/www.renderosity.com\/homepage.ez?Who=agiel&#8221;&gt;Personal gallery&lt;\/a&gt;<\/p>\n<p>&lt; closeHTML editor &gt;<\/font><\/p>\n<p>Two modules are involved in this HTML filtering. <\/p>\n<p><strong>MT\/lib\/mt\/Utils.pm<\/strong>&nbsp;defines two procedures (encode_html and decode_html)<br \/><strong>MT\/lib\/mt\/App\/CMS.pm<\/strong> applies \ufffdencode_html\ufffd before building the edit page from the \ufffdedit_entry.tmpl\ufffd template.<\/p>\n<p><font size=\"3\"><strong><u>Solution<\/u><\/strong><\/font><\/p>\n<p>It took some time to figure it out, but the solution is relatively simple.<\/p>\n<p>Just edit line&nbsp;437 in the module CMS.pm:<\/p>\n<p><font face=\"Courier New\">unless ( ((($col) eq &#8220;text&#8221;) or (($col) eq &#8220;text_more&#8221;)) and ($type eq \ufffdentry\ufffd))<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ $param{$col} = encode_html($param{$col}, 1); }<\/font><\/p>\n<p>and add \ufffddecode_html\ufffd to the list of procedures loaded by the same module:<\/p>\n<p><font face=\"Courier New\">line 11: use MT::Util qw( encode_html decode_html format_ts offset_time_list remove_html get_entry );<\/font><\/p>\n<p>This will effectively disable the automatic HTML encoding for the \ufffdentry body\ufffd and \ufffdentry body more\ufffd fields and make it possible to replace the main textarea by an HTML editor. <\/p>\n<p><strong>The result is an enhanced HTML editor for MT, complete with image upload and formatting options.<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/linfa-net\/diary\/images\/MThtml-editor.jpg\" border=\"0\"><\/p>\n<p><em>Note that the line numbers will likely work only with MT 2.6.4 (my current version).<\/em> <\/p>\n<p>I know it is not ideal to edit one of the core modules, so if someone has another suggestion, I am open to apply it <!--emo&amp;:)--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been trying to replace the default entry textarea by an HTML editor such as this one (&nbsp;FCK Editor&nbsp;&nbsp;&#8211; FREE web based HTML editor ) Getting the editor to work is relatively straight forward. Just install the zip files in their destination on your website, edit the editor javascript (or .htc) files to point to the new location and&hellip; <\/p>\n<p><a class=\"more-link\" href=\"http:\/\/www.alquier.org\/laurent\/sites\/2003\/09\/23\/how_to_replace\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[123,1],"tags":[154],"class_list":["post-1808","post","type-post","status-publish","format-standard","hentry","category-tips","category-uncategorized","tag-movable-type","xfolkentry","clearfix"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8frwa-ta","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":0,"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.alquier.org\/laurent\/sites\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}