How to Add a Smilie Bar to Movable Type
Created by Josh Cooper

This is my first Hack form Movable Type.

My inspiration for this was from this post on adding smilies to MT and also from this post, where i found the smilies.

so she wouldn't have to remember the the codes.

There are 2 Files that will need to be edited for this:

a. /mt/lib/MT/Util.pm

b./MT/tmpl/cms/edit_entry.tmpl

You can also use this zip of smilies I found on the net or find your own.

Lets start with Util.pm

Open this file in your text editor of choice and find the lines:

my $str = shift;
$str ||= '';

Now underneath this line add the following:

$str =~ s/\:angry/<img src=\"http:\/\/yoursite.com\/smilies\/angry.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:biggrin/<img src=\"http:\/\/yoursite.com\/smilies\/biggrin.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:blush/<img src=\"http:\/\/yoursite.com\/smilies\/blush.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:drunk/<img src=\"http:\/\/yoursite.com\/smilies\/drunk.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:kiss/<img src=\"http:\/\/yoursite.com\/smilies\/kiss.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:lol/<img src=\"http:\/\/yoursite.com\/smilies\/lol.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:rofl/<img src=\"http:\/\/yoursite.com\/smilies\/rofl.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:sad/<img src=\"http:\/\/yoursite.com\/smilies\/sad.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:smile/<img src=\"http:\/\/yoursite.com\/smilies\/smile.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:talker/<img src=\"http:\/\/yoursite.com\/smilies\/talker.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:wink/<img src=\"http:\/\/yoursite.com\/smilies\/wink.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;
$str =~ s/\:yawn/<img src=\"http:\/\/yoursite.com\/smilies\/yawn.gif\" width=\"15\" height=\"15\" alt=\"\" \/>/g;

You will want to make sure you replace "yoursite.com" and if you put your files in a directory other than smilies
you'll want to change that also.

Save this file. Your now able to call the smilies directly in your post by using the following commands.

:angry
:biggrin
:blush
:drunk
:kiss
:lol
:rofl
:sad
:smile
:talker
:wink
:yawn

But lets not stop there, lets add them to to the entry screen.

Open edit_entry.tmpl in your Editor of choice.

You'll need to add this function, I added it under the function formatStr

function insertSmilies (v) {
document.forms[2].elements[6].focus();
document.selection.createRange().text = v;
}

Next search for the following:

<font class="pagetitle">Main Entry Text</font>

You'll need to change these to lines to look like this:

<td width="100"><font class="pagetitle">Main Entry Text</font></td>
<td width="432" align="right" valign="top">

Next find the following line:

if (document.selection) {

Modify this section to look like:

if (document.selection) {
document.write('<table border="0" cellspacing="0" cellpadding="1" width="170">');
document.write('<tr>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':angry\')"><img src="http://yoursite.com/smilies/angry.gif" alt="angry" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':biggrin\')"><img src="http://yoursite.com/smilies/biggrin.gif" alt="biggrin" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':blush\')"><img src="http://yoursite.com/smilies/blush.gif" alt="blush" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':kiss\')"><img src="http://yoursite.com/smilies/kiss.gif" alt="kiss" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':lol\')"><img src="http:/yoursite.com/smilies/lol.gif" alt="lol" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':rofl\')"><img src="http:/yoursite.com/smilies/rofl.gif" alt="rofl" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':sad\')"><img src="http://yoursite.com/smilies/sad.gif" alt="sad" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':smile\')"><img src="http://yoursite.com/smilies/smile.gif" alt="smile" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':talker\')"><img src="http://yoursite.com/smilies/talker.gif" alt="talker" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':wink\')"><img src="http://yoursite.com/smilies/wink.gif" alt="wink" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':yawn\')"><img src="http://yoursite.com/smilies/yawn.gif" alt="yawn" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:insertSmilies(\':drunk\')"><img src="http://yoursite.com/smilies/drunk.gif" alt="drunk" width="15" height="15" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:formatStr(\'b\')"><img src="<TMPL_VAR NAME=STATIC_URI>images/bold-button.gif" alt="bold" width="24" height="18" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:formatStr(\'i\')"><img src="<TMPL_VAR NAME=STATIC_URI>images/italic-button.gif" alt="italic" width="24" height="18" border="0"></a></td>');
document.write('<td width="24"><a href="javascript:formatStr(\'u\')"><img src="<TMPL_VAR NAME=STATIC_URI>images/underline-button.gif" alt="underline" width="24" height="18" border="0"></a></td>');
document.write('<td width="26"><a href="javascript:insertLink()"><img src="<TMPL_VAR NAME=STATIC_URI>images/url-button.gif" alt="link" width="26" height="18" border="0"></a></td>');
document.write('</tr>');
document.write('</table>');

NOTE: This is word wrapped here but will be longer lines on your site. Also don't forget to replace yoursite.com with
your address and if you changed your directories or file name change those also.

That's it now save it. Next time you enter a new entry you should see the following.

These will add the Smilie codes directly to the Main Entry Text, then when you preview or save the smilies will show
up in your posts.