
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
Inception Plot QuestionsRandom Chuck Norris Fact Generator With A Twist
Virtual Currency for Buses
Applying ColdFusion Security Patches Gotcha
Privacy, Walled Gardens, Standards and Our Future
Recent Comments
FireFox 3.6 KTML Editor Fix
rock guitar said: Is the ktml realy discontinued for dreamweaver
[More]
FireFox 3.6 KTML Editor Fix
Joshua said: Hi Wayne,
I just tried opening the editor in IE from the link you supplied. I was able to open the ...
[More]
FireFox 3.6 KTML Editor Fix
wayne said: Hi everybody, thanks for your reply joshua. I still have a bug for ktml in asp for a link properties...
[More]
Inception Plot Questions
said:
[More]
Inception Plot Questions
Taylor said: Hey there Josh,
Great questions all. You seem to think this is more of a Jacob's Ladder equivalent ...
[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 |
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 (19) [RSS]
RPM (9) [RSS]
Spam (16) [RSS]
Technology (68) [RSS]
Testing (3) [RSS]
TV (15) [RSS]
video (32) [RSS]
Web Dev (224) [RSS]
World of Warcraft (16) [RSS]
