wordpress 评论表情插件_PHP教程
/*
修改
1. face目录中可以任意增减表情图片(暂不支持中文)
2. 默认支持 jpg, jpeg, png, 与gif 格式表情图片description: 评论表情插件
*/
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;
}
// 显示表情图片
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'));
}
?>
推荐阅读
-
ThinkPHP3.2.2的插件控制器功能简述,thinkphp3.2.2简述_PHP教程
-
typecho插件编写教程(四):插件挂载,typecho挂载_PHP教程
-
WordPress中对访客评论功能的一些优化方法,wordpress评论功能_PHP教程
-
在WordPress中安装使用视频播放器插件Hana Flv Player,wordpresshana_PHP教程
-
30个WordPress博客书签收藏分享代码_PHP教程
-
VPS用LNMP安装WordPress,vpslnmpwordpress_PHP教程
-
9条建议让你的WordPress网站更快运行如飞,9条wordpress_PHP教程
-
WordPress禁止输出错误信息设置方法_PHP教程
-
WordPress开发中的get_post_custom()函数使用解析,wordpressgetpost_PHP教程
-
Yii2框架引用bootstrap中日期插件yii2-date-picker的方法,yii2datepicker_PHP教程