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_path%7d/%7b%24value%5b filename alt={$value[ style=max-width:90% onclick='return inface({$value['>;
}
echo
end;
}
// 转换为表情图片
public function smilie_replace($comment_text)
{
$keys = array();
$smilies = array();
foreach($this->face_files as $value)
{
$keys[] = [face:{$value['filename']}];
$smilies[] = img_path%7d/%7b%24value%5b filename alt={$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'));
}
?>
http://www.bkjia.com/phpjc/632308.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/632308.htmltecharticle修改了部分方法. 表情直接从目录中读取.所以现在可以方便的增减表情图片了.只需把图片放入face目录即可.不过暂时还不支持中文图片名称...
