
Automatic more/ with BlogCFC
I wanted to have BlogCFC automatically add the more/ tag into my blog posts. I first thought that I should count the chars of the post, and if over a certain size add the tag somewhere in the middle. However that really didn't offer much control or predictability.
Next I thought it would be fun to check if there were three paragraphs or more. If so to place the more/ tag between the first and second paragraph. Seemed easy enough however in my wine drinking furry I ran into many stumbling blocks. I rewrote the code many times looking for the most elegant solution.
This is what I came up with. It is just entered into the entry.cfm file right after the cfif for form.submission.
First use this handy user defined function I got off of CFLib.org.
/**
* Replaces oldSubString with newSubString from a specified starting position while ignoring case.
*
* @param theString The string to modify. (Required)
* @param oldSubString The substring to replace. (Required)
* @param newSubString The substring to use as a replacement. (Required)
* @param startIndex Where to start replacing in the string. (Required)
* @param theScope Number of replacements to make. Default is "ONE". Value can be "ONE" or "ALL." (Optional)
* @return Returns a string.
* @author Shawn Seley (shawnse@aol.com)
* @version 1, June 26, 2002
*/
function ReplaceAtNoCase(theString, oldSubString, newSubString, startIndex){
var targetString = "";
var preString = "";
var theScope = "ONE";
if(ArrayLen(Arguments) GTE 5) theScope = Arguments[5];
if (startIndex LTE Len(theString)) {
targetString = Right(theString, Len(theString)-startIndex+1);
if (startIndex GT 1) preString = Left(theString, startIndex-1);
return preString & ReplaceNoCase(targetString, oldSubString, newSubString, theScope);
} else {
return theString;
}
}
</cfscript>
Next right after rays code replaces the smart quotes (see his funny comments).
<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/>', myposition1)#">
</cfif>
So, will it work? Does my new FCKeditor put in the .code style correctly? Lets all hope this post proves yes!
Update: I forgot to check if the post was being edited and thus didn't need to have it added. I ammended the code above to reflect that.

NAVIGATION
HomeAbout Me
RSS
Search
Subscribe
Recent Entries
Flash Camp BostonNew Blog Design
Pre-Conference Training at cf.Objective()
FireFox 3.6 KTML Editor Fix
I am now a part of the Adobe Community Professionals Group
Recent Comments
FireFox 3.6 KTML Editor Fix
Fred said: Found another bug in Firefox 3.6
When inserting a table you can't select the number of columns.
So I...
[More]
Repeating Events Question
ueghbxedu said: UaejcB <a href="http://ysyhrmkbkhco.com/&...;, [url=http://pwncz...
[More]
Repeating Events Question
fadxkfyuadn said: n6qVCL <a href="http://bdiorhdtbwzb.com/&...;, [url=http://uvnao...
[More]
FireFox 3.6 KTML Editor Fix
Joshua said: While changing that far will load the editor, does it show the drop down class menu correctly now?
[More]
FireFox 3.6 KTML Editor Fix
Al Johnson said: HI,
I am still fighting to keep my code going as there is nothing better than KTML nad I have writt...
[More]
Calendar
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Archives By Subject
blogs (31) [RSS]books (4) [RSS]
Crazy (39) [RSS]
DIY (8) [RSS]
Flex (3) [RSS]
games (10) [RSS]
GRRR (13) [RSS]
Ideas (11) [RSS]
Local (14) [RSS]
LOLpics (2) [RSS]
money (9) [RSS]
music (3) [RSS]
Personal (27) [RSS]
Photos (8) [RSS]
Politics (8) [RSS]
Projects (22) [RSS]
Review (18) [RSS]
RPM (9) [RSS]
Spam (16) [RSS]
Technology (66) [RSS]
Testing (3) [RSS]
TV (15) [RSS]
video (32) [RSS]
Web Dev (218) [RSS]
World of Warcraft (16) [RSS]
