wordpress 评论表情插件_PHP教程

WBOY
发布: 2016-07-13 10:54:43
原创
1259 人浏览过

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

/*
修改
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 "{$value[";
            }

            echo            
end;
        }

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

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632308.htmlTechArticle修改了部分方法. 表情直接从目录中读取.所以现在可以方便的增减表情图片了.只需把图片放入face目录即可.不过暂时还不支持中文图片名称...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板