Related Categories: Web Dev

I added FCKeditor to my blog the other day, and I am quite happy I did.  One thing the editor does, however, is alter things like the < more/ > tag.  So I have been looking around this evening for a way to protect those tags. I found a few people asking for the functionality, but very little that seemed conclusively to work.  Time to do some google searches.

It turns out there is an easy line of code you can add to the config script that specifies tags that should be protected.  Makes sense huh? 

The trick looked like it would be this line:

FCKConfig.ProtectedTags = 'more|code' ;

It tells FCK to ignore the more and code tags, and thus not try to 'fix' them when the editor loads up.  You can easily add more to the list.

I should also note how to setup FCK in general as well.

My FCKinstall looks like this.  It is in the /tags/textarea.cfm file.

<cfscript>
fckEditor = createObject("component", "fckeditor.fckeditor");
fckEditor.instanceName = #attributes.fieldname#;
fckEditor.value = #attributes.value#;
fckEditor.basePath = "/fckeditor/";
fckEditor.width = "100%";
fckEditor.height = 600;
fckEditor.ToolbarSet = 'Default';
fckEditor.create(); // create the editor.
</cfscript>

Note you also have to modify a few JS files and Application.cfm to set the paths correctly and set it to use CF for filebrowsing, etc.

But where to put the protectedTags line?  I suspected in the cfscript, but that didn't work.  So then I tried the config.js file... still no working.  Arg.  Time to think about another approach.

I then notice that what FCK was doing is taking my More/ tag and making it < more > < /more >.  Same for Code.  So maybe I just change blogcfc (easy enough) to check for that instead?

Plus, I have some code that automatically adds the more tag in if you have more than 3 paragraphs.  That way I don't have to remember to use it (which I never do).  May as well bring that up to snuff at the same time.

So I edit /admin/entry.cfm:

<cfset origbody = form.body>

<!--- check to see if there needs to be a more tag --->
        <cfset myposition1 = REFindNoCase('<p>(.*)</p>', form.body)>
<cfset myposition2 = REFindNoCase('<p>(.*)</p>', form.body, evaluate(myposition1 + 1))>
<cfset myposition3 = REFindNoCase('<p>(.*)</p>', form.body, evaluate(myposition2 + 1))>
<cfset findmore = REFindNoCase('</more>', form.body)>

<cfif myposition2 GT 0 AND myposition3 GT 0 AND findmore eq 0>
    <cfset form.body = "#ReplaceAtNoCase(form.body,  '</p>','</p><more></more>', myposition1)#">

</cfif>
<!--- alter the more tag check here to match the full open close that fckeditor likes --->
       
        <!--- Handle potential <more></more> --->
        <!--- fix by Andrew --->
        <cfset strMoreTag = "<more></more>">
        <cfset moreStart = findNoCase(strMoreTag,form.body)>
        <cfif moreStart gt 1>
            <cfset moreText = trim(mid(form.body,(moreStart+len(strMoreTag)),len(form.body)))>
            <cfset form.body = trim(left(form.body,moreStart-1))>
        <cfelseif moreStart is 1>
            <cfset arrayAppend(errors, application.resourceBundle.getResource("mustincludebody"))>
        <cfelse>
            <cfset moreText = "">
        </cfif>


Like this entry? Subscribe to my blog.

Comments (moderation on)

When showing FCKeditor to an officemate, he commented
"There is no you in F.C.K. editor".
# Posted By Phillip Senn | 4/24/07 10:24 AM
I heard a rumor that cf8 was going to have fckeditor.
Does it?
# Posted By Phillip Senn | 6/1/07 4:06 PM
Yes it does. There are questions about the file browsing support though. I have yet to test out cf8 in that regard.
# Posted By Joshua Cyr | 6/1/07 4:07 PM

Sponsors


Savvy Content Manager