听dj战歌,就上傲气战歌网!2015年传奇家族玩家最喜爱的家族战歌网
战歌推荐:战歌网 战歌网dj Mc战歌网 DJ战歌网下载 激情战歌-冰雪战歌网 客服Q:350317
新闻搜索:

实现wordpress更换评论表情的实用插件

作者:     来源:    发表时间:2011-04-12 08:53

修改了部分方法. 表情直接从目录中读取.所以现在可以方便的增减表情图片了.只需把图片放入face目录即可.不过暂时还不支持中文图片名称.

    <?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 "<img src='{$this->img_path}/{$value['filename']}.{$value['extension']}' style='cursor:pointer;width=42px;height:42px;' onclick='return inface("{$value['filename']}");'>";
                }

                echo <<<end
                <script type="text/网页特效">
                function inface(img)
                {
                    document.getelementbyid("comment").value += '[face:' + img + ']';
                }
                </script>
    end;
            }

            // 转换为表情图片
            public function smilie_replace($comment_text)
            {
                $keys = array();
                $smilies = array();
                foreach($this->face_files as $value)
                {
                    $keys[] = "[face:{$value['filename']}]";
                    $smilies[] = "<img src='{$this->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'));
}
?>

数据统计中!!

最新评论共有  位网友发表了评论
发表评论(评论内容:请文明参与评论,禁止谩骂攻击!)
不能超过250字节,请自觉遵守互联网相关政策法规.
昵称:    发表评论 (Ctrl+Enter快速回复)
推荐新闻

关于本站 | 合作加盟 | 合作说明 | 免责声明 | 广告服务 | 网站地图

健康游戏忠告:抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活

如有意见和建议,请惠赐E-mail至350317@qq.com 联系QQ:350317

Copyright © 2010-2013 Www.27zG.CoM
苏ICP备11049833号