程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> wordpress 評論表情插件

wordpress 評論表情插件

編輯:關於PHP編程

修改了部分方法. 表情直接從目錄中讀取.所以現在可以方便的增減表情圖片了.只需把圖片放入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']}' alt='{$value['filename']}' 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'));
}
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved