Modified some methods. Expressions are read directly from the directory. So now you can easily add or remove expression images. Just put the images into the face directory. However, Chinese image names are not supported yet.
/*
Modify
1. You can add or remove emoticon pictures at will in the face directory (Chinese is not supported yet)
2. Supports emoji images in jpg, jpeg, png, and gif formats by defaultdescription: Comment emoticon 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';
"/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;
}
// 显示表情图片
public function smilie_faces()
{
foreach($this->face_files as $value)
{
echo "";
}echo <<
end;
}// 转换为表情图片
public function smilie_replace($comment_text)
{
$keys = array();
$smilies = array();
foreach($this->face_files as $value)
{
$keys[] = "[face:{$value['filename']}]";
$smilies[] = "";
}$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'));
}
?>