Wordpress comments emojis plugin

Source: Internet
Author: User
Tags comments php tutorial

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 '));
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.