前面看见有人贴了,但是好像是1.1的,我就把自己写的贴出来把,不知道有没有什么漏洞,顺便看看。
自从SaBlog1.6,添加文章内容时可以加入表情了,那就要好好利用了。就给文章评论上也加入这些表情。
首先,在global.php文件里加入:
复制内容到剪贴板
代码:
//取文件夹中的所有表情
function getsmiles() {
if ($handle = opendir(SABLOG_ROOT.'/images/smiles')) {
while (false !== ($file = readdir($handle))) {
if (preg_match('/(.+?)[.]gif/ie',$file, $name)) {
$result[$name[1]]=$file;
}
}
closedir($handle);
return $result;
}else{
return;
}
}
// 评论表情
function displaysmiley($smile) {
$smile=htmlspecialchars($smile);
//过滤不存在的图片
if(is_file(SABLOG_ROOT.'/images/smiles/'.$smile.'.gif')) {
$img='<img src="./images/smiles/'.$smile.'.gif" alt="">';
}
return $img;
}然后就要修改index.php文件了,查找到“// 获取文章信息”字符,在他的前面加入:
复制内容到剪贴板
代码:
//读取评论用的表情
$smiles=getsmiles();再查找到“// 标签 (Tags)”字符,然后向上数11,12行左右,可以看到“$comment['content'] = html_clean($comment['content']);”这句,在这句下面加入:
复制内容到剪贴板
代码:
//引用评论时使用,避免引用是出现"<>"字符,而不表情图片
$comment['quote'] = $comment['content'];
$comment['content'] = preg_replace("/[:](.+?)[:]/ies", "displaysmiley('\\1')", $comment['content']); 随后在include目录下的common.js里,最后加入:
复制内容到剪贴板
代码:
function insertsmiley(icon) {
var tr = document.getElementById('content');
tr.value += ':'+icon+':';
}接下来,打开你当前使用的模板文件夹,我这里以默认模板为例(
不同模板代码位置各有不同),编辑show.php,查找“<p>评论内容 (必填):<br />”,在他上面加入:
复制内容到剪贴板
代码:
<p>
<!--
EOT;
foreach($smiles as $key => $value){
print <<<EOT
-->
<img src="./images/smiles/$value" alt="" style="cursor:pointer" onclick="insertsmiley('$key')"/>
<!--
EOT;
}print <<<EOT
-->
</p> 最后找到“<p class="lessdate">”,把<p class="lessdate">...</p>中的内容替换成:
复制内容到剪贴板
代码:
<p class="lessdate">Post by $comment[author] on $comment[dateline] <img style="cursor: hand" onclick="addquote('comm_$comment[commentid]_quote','$comment[quoteuser]')" src="templates/$options[templatename]/img/quote.gif" border="0" alt="引用此文发表评论" /> <font color="#000000">#<strong>$comment[cmtorderid]</strong></font><div id="comm_$comment[commentid]_quote" style="display:none">$comment[quote]</div></p>这段主要是让引用评论的时候,也引用到表情符。如果不需要,则可以不添加这段,并且同时可以删除前面index.php里添加的:复制内容到剪贴板
代码:
//引用评论时使用,避免引用是出现"<>"字符,而不表情图片
$comment['quote'] = $comment['content'];表情添加就好了。效果见我的BLOG,
http://www.wa666.cn/?action=show&id=97
PS:论坛上复制过去的代码,每行后面都有一些空格,可能会影响到表情图片的显示,请记得删除啊!
[
本帖最后由 moufer 于 2007-7-16 16:16 编辑 ]