Configuring FCKeditor with BlogCFC
Every once in a while, my lazy side gets the best of me. It's not necessarily a bad thing, though. It's just that sometimes, writing blog posts in a textarea field can be a pain (no offense, Ray. BlogCFC rocks! And I saw those comments in tags/textarea.cfm
). Of course, as a programmer, I much prefer actually writing up the HTML for my markup on my own. However, this is a blog post, not a full-fledged application. I tried writing them offline in HTML and then posting them, but that didn't make things easier: formats weren't kept when I previewed the post in a browser (especially paragraphs). So I did the only thing a guy could do in such a situation: I turned to a Rich Text Editor. My editor of choice, and the one I hear the most (good) things about, is FCKeditor. It is completely open-source under the GPL, LGPL and MPL licenses. Easy to install and configure, it only took me about 5 minutes to get it up and running with BlogCFC (excluding all my FTP and wireless connection problems...). Here's how I did it.
The first thing you want to do is download the package from the web site. Once that is done, copy the fckeditor folder over to your application root (in my case, it was /blog/). You can remove the _samples folder if you want to save some space. To get it running with BlogCFC's entry editor, open up (from your blog's root) tags/textarea.cfm. Go to the bottom of the page and comment out the line surrounded by an opening and a closing CFoutput tag. Add this in it's place:
<textarea name="#attributes.fieldname#" id="#attributes.fieldname#" <cfif len(attributes.class)>class="#attributes.class#"</cfif>>#attributes.value#</textarea>
</cfoutput>
--->
<CFset basePath="/blog/fckeditor" />
<CFset fckEditor=CreateObject("component", basePath & "/fckeditor") />
<CFset fckEditor.Config['SkinPath']=basePath & "/editor/skins/office2003/" />
<CFset fckEditor.height="300px" />
<CFset fckEditor.basePath=basePath & "/" />
<CFset fckEditor.instanceName=attributes.fieldname />
<CFset fckEditor.value=attributes.value />
<CFoutput>
<CFset fckEditor.Create() />
</CFoutput>
The first line creates a path to our fckeditor. Make sure this is accurate for your installation. The next line creates an instance of the fckEditor component. We then set some properties:
- <CFset fckEditor.Config['SkinPath']=basePath & "/editor/skins/office2003/" /> sets the skin we want to use. You can ignore this line if you plan on using the default skin.
- <CFset fckEditor.height="300px" /> sets the height of the editor, including the toolbars.
- <CFset fckEditor.basePath=basePath & "/" /> is required to tell FCKeditor where it's located.
- <CFset fckEditor.instanceName=attributes.fieldname /> gives our field a name, and uses the passed in fieldname from BlogCFC.
- <CFset fckEditor.value=attributes.value /> sets the original value for the field.
Once all of our properties are set, all we need to do is call <CFset fckEditor.Create() /> (between our CFoutput tags) to draw the editor. At this point, you can safely open your BlogCFC entry editor and you should see your very own Rich Text Editor!
If you're having trouble seeing all the buttons on the toolbars, that's because they weren't set to use a limited width. Luckily for us, they're very easy to customize. Open fckconfig.js in your main fckeditor folder and look for this line: FCKConfig.ToolbarSets["Default"] = [. You can create as many toolbar sets as you want. Think of them as structures containing arrays. Every array within the toolbar set structure represents a distinct toolbar line. You can also add content separators with the '-' label. Rearrange them as you see fit. The labels are pretty much self-explanatory, so I won't go over them in detail. Once you're done editing, save your fckconfig.js file, upload it and refresh your entry editor. Buttons! However, before we can fully enjoy our new entry editor, there's one last thing we need to do.
You can't write actual HTML in the basic view of FCKeditor. This means that the <more/> and <code></code> tags we love won't work up front. We need to add them in Source mode, so make sure you keep that button on your toolbars. However, FCKeditor tends to break these tags when returning to rich-text mode, since they're not valid HTML. To make sure they are kept intact, we need to add two lines to our fckconfig.js file. Look for a line that looks like this: // FCKConfig.ProtectedSource.Add( /(<asp:[^\>]+>[\s|\S]*?<\/asp:[^\>]+>)|(<asp:[^\>]+\/>)/gi ) ;, and add the following after it:
FCKConfig.ProtectedSource.Add( /<code[\s\S]*?\/_code>/gi ); // thanks to mhagen from the Galleon Forums
Both underscores (_) in the above example have to be removed. The only reason they are there is because writing the above example correctly broke the post.
Doing so will ensure that both tags will be kept intact.
There's only one last thing to do before we're done. When BlogCFC passes the value of the entry in upon editing, it parses back the string to an HTML-safe format. With FCKeditor, that's no longer necessary (and actually not wanted!). Open up admin/entry.cfm in your client folder and look for this line:
Change it to this and finish the last step:
And so there you have it. That wasn't so hard, was it? Enjoy your new Rich Text Editor!
Edit: I'm actually still missing something... Text between code tags still get broken when submitted, and going back in to edit an entry is really bad... I'll update this post when I find a solution.
2nd edit: Thanks to Scott Pinkston for the solution. Turns out all I needed to do was remove the HTMLEditFormat from entry.cfm. More details in the post.
3rd edit: A full working solution to our tag woes can be found here: Fixing FCKeditor To Work With BlogCFC, And Vice-Versa.
I'm sure I forgot something, but I just can't remember!


<cfmodule template="../tags/textarea.cfm" fieldname="body" value="#htmlEditFormat(form.body)#" class="txtArea">
Take out the htmlEditFormat(form.body) and just use form.body.
The line numbers maybe off since this is old but it should get you close.
Thanks for the info, this got it working great! I have one last bug to squish, though. Now everything between <code> tags is invisible in the rich-text editor. I have to switch to source to see it at all. Any ideas?
:-)
http://www.miuaiga.com/index.cfm/2006/12/17/FCKing...
FCKConfig.ProtectedSource.Add()
are you sure those two RegExp patterns that you have are correct?
(yes I did take out the underscore and the <br /> tag in the codesnip)
"unterminated regular expression literal"
http://....../fckeditor/fckconfig.js
Line 58
FCKConfig.ProtectedSource.Add( {see regexp below} ) ;
regexp: remove the underscores
_/_<_more_/_>_/_gi_
commenting out both lines gets rid of the errors.
Here are the lines from my source:
// code
FCKConfig.ProtectedSource.Add( /<more\/>/gi );
FCKConfig.ProtectedSource.Add( /<code[\s\S]*?\/code>/gi );
// /code
Both these lines work on my end, however I ended up disabling them altogether (although the one for the more tag is probably harmless). I'm still having problems with the code tag, but I think I found a "solution". I just came back from vacation and got lots of things left to do, but I'll try and have a post ready towards the beginning of next week.
the code snip in the blog article was missing a back-slash on each to escape the forward slash.
that part now works fine. many thanks
(from three blogs using the same blogCFC codebase and same database):
<CFset basePath="/blogs/chandler/fckeditor" />
<CFset basePath="/blogs/barry/fckeditor" />
<CFset basePath="/blogs/fdu/fckeditor" />
or perhaps there could another way to handle FCKEditor with multiple blogs?
any suggestions?
but the process of creating a new client means a copy of all the files, the textarea custom tag included. because it's got a path in there for the current client, it's yet another thing to change. textarea is the only tag that needs this now there's a dependancy between the cfm file and the path to the fckeditor.
I'm just asking for an opinion to best handle this. replacing the path by a variable or perhaps referring to one instance of fckeditor for all are a couple of thoughts.
You can customize distinct ToolbarSets in fckconfig.js, and point to different themes with the Config['SkinPath'] variable. That way you can have different styles and layouts for each blog, without having to manage the basepath variable.
hth