sub emoticonify
{
my ($post) = shift;					# Get the data we want to replace the text emotions in.
my (%emote,$key,$imgtag,$alt); 		# Declare our variables as local to this subroutine.


# The following hash (%emote) defines the patterns to search for, and the corrosponding filename.
# This can be extended or modified as you please, by adding or changing key/value pairs.
# The format is: 'pattern' => 'filename' (e.g. ':-)' => 'smiley.gif')

%emote = (
':-)' => 'regular_smile.gif'    , ':-D' => 'teeth_smile.gif' , ':-O' => 'omg_smile.gif', 
':-P' => 'tounge_smile.gif'     , ';-)' => 'wink_smile.gif'  , ':-(' => 'sad_smile.gif',
':-S' => 'confused_smile.gif'   , ':-|' => 'what_smile.gif'  , "\:\'\(" => 'cry_smile.gif',
':-$' => 'embaressed_smile.gif' , '(H)' => 'shades_smile.gif', ':-@' => 'angry_smile.gif'
);


# If emoticons are enabled, do the following:

# 1. Loop over each key (text emotion) in %emote, and do this:

# 	a. Prepare our image tag by starting with a blank space ("&nbsp;").
# 	b. Prepare the alternative text for the image, by removing the .gif from the image name.
#	  (After first copying the image name to the $alt variable).
	 
# 	c. Next, in the alt text, replace any underscores with spaces.
# 	d. Continue with our image tag, filling in size, alt text and image source, etc.
# 	e. Replace text emotions in our input ($post) that have either a space before them, or are at the start of a line.
# 	f. Now repeat the search but without the '-' in it (ie. :-) becomes :) ).

# 2. Return the data ($post) now containing the new graphical emotions (emoticons).

# N.B.
# In both the above cases we replace the text emotion (e.g ":-)") with the image (e.g. smiley.gif).
# You can customise %emote (above) if you would like to add or remove any emoticons.


if ($iconpath){
 foreach $key (keys %emote){
  $imgtag = '&nbsp;';
  $alt = $emote{$key};
  $alt =~ s!\.gif$!!gi;
  $alt =~ s!_! !g;
  $imgtag .= qq(<img src="$iconpath/$emote{$key}" width="19" Height="19" alt="Emoticon: $alt">);
  $post =~ s!\s\Q$key\E!$imgtag!gi;
  $post =~ s!^\Q$key\E!$imgtag!gi;
  $key =~ s!\-!!g;
  $post =~ s!\s\Q$key\E!$imgtag!gix;
  $post =~ s!^\Q$key\E!$imgtag!gi;
 }
}
return $post;
}
1;