Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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

  2. #2

    Default 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

  3. #3

    Default 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

  4. #4

    Default 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 & "&lt;cf" & CFCommand & "&gt;" & 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 & "&lt;/cf" & CFCommand & "&gt;" & EndOfString;
    }
    }
    // if not then end loop
    else {
    isFinished = True;
    }
    }

    return FinalString;
    }
    </cfscript>

    Stressed_Simon Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139