iaian7 » code » txp   John Einselen, 22.07.07 (updated 15.06.11)    

an7_filter replaces text strings defined by a customizable array. In short, this lets you insert emoticons, instant messenger style! It can also be used for undesirable language filtering or keyword link insertion.

While an7_filter does not automate this process entirely, it makes it fairly easy. Used as a wrap tag, it will filter the contained text using an array specified in the plugin (the default is setup for emoticon replacement).


plugin settings:

... $imga = '<img src="/images/emoticons/'; $imgb = '.png" class="emoticon" />'; $replacements = array( "text" => "****", ": )" => $imga."smile".$imgb, ...

textpattern template:

... <txp:an7_filter><txp:body /></txp:an7_filter> ...

raw text:

this text is being filtered. : )

final result:

this **** is being filtered. emoticon

Please note that the plugin is currently case-sensitive.

plugin options

an7_filter comes ready for use as an emoticon plugin. It’s suggested that you wrap <txp:body />, <txp:excerpt />, <txp:message />, <txp:search_result_excerpt />, and similar tags, as these are the most common places to find replaceable text. I’m not sure about the impact on the server if one were to try to wrapping an entire page, it might not be the best idea. The listed tags should be sufficient, and keep PHP processing time to a minimum.

To avoid some specific code issues, I’ve added a space before each text string. This prevents links from being corrupted by :/ (short variation of :undecided:), but still allows a string of emoticons separated only by single spaces.

  emoticon   emoticon   emoticon   emoticon   emoticon   emoticon   emoticon   emoticon
>:o :[ 8) :’( :! :( :o :D
:angry: :blush: :cool: :cry: :eeeih: :frown: :gasp: :grin:

  emoticon   emoticon   emoticon   emoticon   emoticon   emoticon   emoticon
0:) :* :P :$ :x :) :/
:halo: :kiss: :laugh: :money: :sealed: :smile: :undecided:

(this is a partial list, there are other variations for many of the emoticons, and of course this is entirely customizable)

For emoticon images, you must edit the 'imga' and 'imgb' attributes to reflect your file structure and image types. For other text replacement features, the array can be edited to handle just about anything.


This plugin is currently in beta

1 (version 0.2.0)


Copy the plugin text into your textpattern “install plugin” field and click “upload”. Enable the plugin and edit the source to customize the replacement array ("text" => "replacement";).

If you want to use emoticons, find a good icon pack and upload it to your images folder (for organization, probably under a “emoticons” subfolder). I don’t have an “official” pack yet, but once the plugin goes live I hope to have a default installation ready.

Edit your page or article templates by wrapping desired tags with <txp:an7_filter> and </txp:an7_filter>. Save any changes, and that should be it!

version history

— beta, added simple documentation and correctly validating image code
— alpha, undergoing testing

help and support

For questions and support, please visit the an7_filter post in the Textpattern Forums.


The template from thresholdstate.com was helpful as always. <3

Sisushka, 19.08.07

Brilliant plugin, thank you! emoticon

alexandre, 26.04.08


I installd your plugin today and seems to be very cool. Unhappilly, it is returning an error message:

Parse error: syntax error, unexpected ‘;’, expecting ‘)’ in /home/mosapyr/public_html/textpattern/lib/txplib_misc.php(574) : eval()‘d code on line 27
Os erros acima descritos foram causados pelo plugin:an7_filter

Is there anything else that I can do?

Thank you,


alexandre, 27.04.08


I’m back, rsrsrs…
The plugin is working now, I included what was missing…
By the way, I wrote you a message in Textpattern forum, I would like to use your plugin in the comments form. Like we see below emoticon