WCTL String Manipulation

Another reason I like WCTL is because it has a number of very handy string methods.

Here are some of my favorite slightly less common ones:
  1. markObjectionable: mark objectionable words

    This ties into the moderation system, but if you get a tiny bit creative you can do interesting things with it. First, you need to define some objectionable words in the Control Panel or folder in which you are working. Then, when you display message content, you do this:

    %% string.markObjectionable( HTMLbefore, HTMLafter ) %%

    This is normally used to highlight objectionable words in the preview pane before moderated users submit their posts, and in fact, the default values for HTMLbefore and HTMLafter are: ( "<font color=red>", "</font>" )

    However, you can also use this to comment out the actual objectionable word and replace it with @#$%* as we do in the Tabular Message View plugin:

    %% pathBodyFormatted.markObjectionable( "<!--", "-->@#$%*" ) %%

    If you aren't using the moderation machinery for anything else you could also use it to highlight desirable terms such as names of sponsors, etc.

  2. randomString: a random 11-character string

    %% randomString %% simply spits out 11 random mixed upper- and lower-case letters, which is handy for setting default passwords, creating unique names of things, etc. (Astute observers will notice it's not actually random, but for most purposes it will do just fine.)

    For example: nojfarsSJmD

  3. htmlToPlainText: converts HTML to similarly-formatted plain text

    Specifically, all SGML-escaped characters are converted. HTML-formatted white space is converted to plain-text. <p>, <br>, and <pre> are converted to similar-looking newlines. <li> is converted to an asterisk and a space. &nbsp; is converted to a normal space. </table> and </tr> are converted to newlines, and </td> is converted to a space.

    Handy if you are creating plain-text emails from HTML content.
These are just a few examples!

No comments:

Post a Comment