Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
Nicholas_Bostaph #1
Codesweeper UDF?
I've spent hours scouring the web for a tutorial or udf or something that would
help me do this and have come up with nothing. So I'm really hoping someone
here can offer some insight; it's my last chance. If you have any thoughts,
please post them. Even a little help is better than none at all. So I run a
free forum system. I let webmasters create forums for use on their websites.
Up until now, I've only allowed {B}, {I}, and {U} tags in posts, which would be
converted to html on viewing of the thread, and all other html tags show up as
bracketed text. This was, obviously, less than optimal. Now I'm looking at
offering users a rich text editor, which I think will be a big hit. However, I
must also allow the option of the plain textarea for those who can't, or don't
want to, install the rich text control. Here is where the problem comes in.
Javascript can be pretty easily removed with a few search/replace runs.
Imagine though if somebody enters the html {TABLE}{TR}{TD}Test!{/TD}{/TR} into
the textarea and submits it. This will throw off the entire format of the page
because of the missing {/TABLE} tag. Many other unterminated HTML tags will be
similarly as destructive. This is something that I need to be able to control
before I can release this update. I looked everywhere and no one has a CF
function that will clean html and verify all the end tags are there, so I
assume that I will need to write one myself. The problem is, I have no idea
how to go about doing this. Can anyone offer some insight to get me started?
Any thoughts on a better option than verifying the html this way could also be
very helpful. Thanks!
Nicholas_Bostaph Guest
-
Stressed_Simon #2
Re: Codesweeper UDF?
I have a UDF that I wrote to extend the HTMLSafe UDF from [url]www.cflib.org[/url] that
searches through after and converts all the greater than and less than signs
around any coldfusion tags into their HTML equivalents. It can handle tags that
don't have a closing tags as well as those that do. I don't have it here
unfortunately I don't have it here, and I am just about to take my missus out
for dinner so I'll have to post it later. I am sure you can understand that.
Should give you some ideas.
Stressed_Simon Guest
-
Nicholas_Bostaph #3
Re: Codesweeper UDF?
Simon, That would be great if I could have a look at that. I'm actually not
feeling well today, so I probably won't be working on this project again until
at least tomorrow, so take your time and have a nice night out. Much
appreciated... :)
Nicholas_Bostaph Guest
-
Stressed_Simon #4
Re: Codesweeper UDF?
The UDF I have attached is a function I wrote to make cf tags safe to show in
HTML if you want to write them in a forum, but still allow other formatting
tags.
So this would run on the result of the HTMLSafe function from [url]www.cflib.org[/url].
If you see how it looks for the cf tags then you might be able to use the
process to test for closing tags. It is a big job you have taken on, but
possible.
Good luck!
<cfscript>
function CFMLSafe(stringHTML) {
// Initialise
var FinalString = stringHTML;
var isFinished = False;
var Start = 0;
var End = 0;
var StartClose = 0;
var EndClose = 0;
var StartOfString = "";
var CFCommand = "";
var EndOfString = "";
// search for cfml tags
while (NOT isFinished) {
Start = FindNoCase("<cf", FinalString, 0) + 3;
End = FindNoCase(">", FinalString, Start);
StartClose = FindNoCase("</cf", FinalString, 0) + 4;
EndClose = FindNoCase(">", FinalString, StartClose);
// if there is an occurrence then make changes
if (Start GT 3 OR StartClose GT 4) {
// set data to hold in at the beginning
try {
StartOfString = Left(FinalString, Start - 4);
CFCommand = Mid(FinalString, Start, End - Start);
EndOfString = Right(FinalString, Len(FinalString) -
Len(StartOfString) - Len(CFCommand) - 4);
// set string
FinalString = StartOfString & "<cf" & CFCommand & ">" & EndOfString;
}
// if this fails then there is a closing tag
catch (any excptObj) {
StartOfString = Left(FinalString, StartClose - 5);
CFCommand = Mid(FinalString, StartClose, EndClose - StartClose);
EndOfString = Right(FinalString, Len(FinalString) -
Len(StartOfString) - Len(CFCommand) - 5);
// set string
FinalString = StartOfString & "</cf" & CFCommand & ">" & EndOfString;
}
}
// if not then end loop
else {
isFinished = True;
}
}
return FinalString;
}
</cfscript>
Stressed_Simon Guest



Reply With Quote

