WordPress Comment Emoticons Plugin _php tutorial

Source: Internet
Author: User
Some methods have been modified. The expression is read directly from the directory. So now you can easily increase or decrease the image of the expression. Just put the picture in the face directory. However, the Chinese image name is not supported at the moment.

/*
Modify
1. The face directory can be arbitrarily increased or decreased the expression picture (Chinese is not currently supported)
2. Default support JPG, JPEG, PNG, emoji image with GIF format

Description: Comment Emoticons Plugin

*/

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 ' and $fileinfo [0],
' Extension ' = $fileinfo [1],
);
}
}
Closedir ($DH);
}
}
return $files;
}


Show emoji Pictures
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
}

Convert to emoji pictures
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 '));
}
?>

http://www.bkjia.com/PHPjc/632308.html www.bkjia.com true http://www.bkjia.com/PHPjc/632308.html techarticle Some methods have been modified. Emoticons are read directly from the directory. So now you can easily increase or decrease the image of the expression. Just put the picture in the face directory. However, the Chinese image name is not supported at the moment ...

  • 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.