Some methods have been modified. The emoticon can be directly read from the directory. Now you can easily add or remove emoticon images. You only need to put the images in the face directory. However, Chinese image names are not supported yet.
<? Php tutorial
/*
Modify
1. You can add or remove emoticon images in the face directory (Chinese characters are not supported currently)
2. jpg, jpeg, png, and gif emojis are supported by default.
Description: Review plug-in
*/
If (! Class_exists ('silver _ smilies '))
{
Class silver_smilies
{
Private $ img_dir;
Private $ img_path;
Private $ face_files = array ();
Private $ allow_extension = array ();
Public function _ construct ($ allow_extension)
{
$ This-> img_path = get_settings ('siteurl'). '/wp-content/plugins/silver_smilies/face ';
$ This-> img_dir = wp_plugin_dir. "/silver_smilies/face ";
$ This-> allow_extension = $ allow_extension;
$ This-> face_files = $ this-> get_face_files ();
Add_action ('comment _ Form', array (& $ this, 'smilie _ faces '));
Add_filter ('comment _ text', array (& $ this, 'smilie _ replace '));
}
Private function get_face_files ()
{
$ Files = array ();
If (is_dir ($ this-> img_dir ))
{
If ($ dh = opendir ($ this-> img_dir ))
{
While ($ file = readdir ($ dh ))! = False)
{
If ($ file = '.') continue;
If ($ file = '..') continue;
$ Fileinfo = explode ('.', (basename ($ file )));
If (in_array ($ fileinfo [1], $ this-> allow_extension ))
{
$ Files [] = array (
'Filename' => $ fileinfo [0],
'Extension' => $ fileinfo [1],
);
}
}
Closedir ($ dh );
}
}
Return $ files;
}
// Display emoticons
Public function smilie_faces ()
{
Foreach ($ this-> face_files as $ value)
{
Echo " img_path}/{$ value ['filename']}. {$ value ['extension']} 'alt = '{$ value ['filename']}' style = 'cursor: pointer; width = 42px; height: 42px; 'onclick = 'Return inface ("{$ value ['filename']}"); '> ";
}
Echo <end
<Script type = "text/Webpage effects">
Function inface (img)
{
Document. getelementbyid ("comment"). value + = '[face:' + img + ']';
}
</Script>
End;
}
// Convert to emoticon Image
Public function smilie_replace ($ comment_text)
{
$ Keys = array ();
$ Smilies = array ();
Foreach ($ this-> face_files as $ value)
{
$ Keys [] = "[face: {$ value ['filename']}]";
$ Smilies [] = " img_path}/{$ value ['filename']}. {$ value ['extension']} 'alt = '{$ value ['filename']}'> ";
}
$ Comment_text = str_replace ($ keys, $ smilies, $ comment_text );
Return $ comment_text;
}
}
}
If (! Isset ($ silver_smilies ))
{
$ Silver_smilies = & new silver_smilies (array ('gif', 'jpeg ', 'jpg', 'png '));
}
?>