Inside the zip, you will find three text files:
The first step is to insert the contents of
fun_filters.php.txt at the end of your
b2-includes/b2functions.php file (but before the final ‘
Next, open up your
b2-includes/b2vars.php file and scroll down to the bottom. Look for this line:
Just before that line, insert the contents of the
activate_filters.php.txt file. With this code in place, your blog will automatically switch on the pirate filter on Talk Like a Pirate Day (September 19). Also, any of the other filters can be activated by adding ‘
?filter=filtername‘ to the end of your URL (where filtername is one of ‘pirate‘, ‘chef‘, ‘fudd‘, ‘jive‘, or ‘kraut‘).
This started when I added a pirate filter to my blog for Talk Like a Pirate Day. My first version was easier than I expected it to be (though it had flaws), which inspired me to locate and convert some of Kalsey’s MovableJive filters.
The biggest flaw in the earliest version was that it would filter text inside of HTML tags, causing it to mangle links and such. I fixed this by borrowing an idea from Simon Willison. Simon’s use of a callback function to only match text that was not part of a tag was good, but it included the ‘>’ and ‘<‘ brackets from surrounding tags in the matched text being substituted, requiring you to hack them back in at the end of your content filter.
After an afternoon studying the pcre pattern syntax and wrestling regexes with the help of the Regex Coach I came up with an improved pattern, which doesn’t require us to tack the ‘>’ and ‘<‘ back on manually. Cool, huh? Here’s the regex pattern I came up with:
And yes, I know, it’s not perfect. But it should work okay for HTML that’s moderately clean. You’d probably have to try hard to bust it. It doesn’t even seem to get confused if you have angle brackets inside of an attribute in a tag, even though I thought it would.