Adding your own smileys

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Adding your own smileys

Post by Henrie »

A few days ago i received a private message with the question if it was possible to add any smileys. Because maybe more people want to add their own smileys I decided to post the answer in the forum.

To add your own smileys/emoticons the most easy way is to replace the existing icon images (in the images folder in the gbook folder). But as a result you will lose the existing icon.

To add new smileys you will have to edit two files, the smileys.htm file and the gbook.php file.

smileys.htm file
In the smileys.htm file an icon is displayed and linked with a line similar like the following

Code: Select all

<a href="javascript:void(0)" onClick="Javascript:insertSmiley(':smiley01:');return false;"><img src="images/smiley01.gif" border="0" alt=""></a> &nbsp; 
In this code :smiley01: is the text-string which will be inserted in the comments entry field. The image to be displayed in the smileys.htm page is images/smiley01.gif.

gbook.php file
In the gbook.php file the function which parses the comments entry and replaces the inserted smiley text-string with a link to the image to be displayed starts at line 305 function processsmileys($text) {.
When you add a new image in the smileys.htm file you will also have to add it to this function. To do this you will have to add a line like this:

Code: Select all

$text = preg_replace("/\:smiley01\:/i","<img src=\"images/smiley01.gif\" border=\"0\" alt=\"\">",$text);
This replaces the :smiley01: text-string with the image link to images/smiley01.gif in the actual message.

In this example i have used the same name for the image and the inserted code. These don't have to be the same but it makes it a lot easier to read and write. However, the text-string inserted by smileys.htm must be the same as in the gbook.php function and also the image links should be the same.

Also you should be careful with using special characters in the code to be inserted. Some characters can not be used and some characters have to be treated special because they have special meanings in php code.
I will try to explain what i mean.
For example, you can simply insert a : in smileys.htm but you have to put \: in gbook.php to be parsed properly. This is also true for for example / [ ( and some more characters (if you try them yourself you will see what happens).
And sometimes you will have to use the named character instead of the actual character. For example when you use < in smileys.htm, you will have to put < in gbook.php
For an overview of named characters see the following link http://www.leeanne.com/usinghtml/htmlnamedentities.html

I hope this explanation is clear enough, if not post your question in this topic.

Greetings,
Henrie
Post Reply