给DEDE织梦评论增加加粗,加色,图片,链接

本文介绍如何将DEDE文章评论样式调整为类似DISCUZ风格的方法,包括修改反馈模板、添加转换函数及调整评论编辑器等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DEDE的文章评论没有DISCUZ的评论好看,客户要求改成基本一样。

没办法,两个都对比研究了一下,终于基本解决了。

 

1、先从 详细评论页 开始

修改步骤:

修改评论模板文件 feedback_templet.html

 

A、在头部增加引用


<script src="http://bbs.xxx.com/static/js/common.js?w3w" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://bbs.xxx.com/data/cache/style_2_common.css?w3w" />
<link rel="stylesheet" type="text/css" href="http://bbs.xxx.com/data/cache/style_2_forum_viewthread.css?w3w" />

 

B、在 <body class="commentpage"> 后面增加

转换函数,因为发表表情以后,还要转换成HTML能够识别的标签才行。比如把 [b][/b] 转换成 <strong></strong>

<?php
function convertem($message){
 
  $message = str_replace(array('[b]', '[/b]'), array('<strong>','</strong>'), $message );
 
   $message = str_replace('[color=','<font color=', $message );
   $message = str_replace('[/color]','</font>', $message );  
  
    $message = str_replace('[url=www.','<a href=http://www.', $message );
 $message = str_replace('[url=WWW.','<a href=http://WWW.', $message );
 
 $message = str_replace('[url=','<a href=', $message );
 
 
  $message = str_replace('[/url]','</a>', $message );
 
  $message = str_replace('[img','<img src=', $message );
  $message = str_replace('[/img]','</img>', $message ); 
 
  $message = str_replace(']','>', $message );
 
return $message;
}
?>

 

//本div是参考discuz的js文件的要求增加的,用来定位的。

<div id="append_parent"></div><div id="ajaxwaitid"></div>

 

C、找到{dede:field.msg function="Quote_replace(@me)"/}

替换成

<?php echo convertem($fields['msg']) ;    ?>

 

D、找到

 <textarea cols="60" name="msg"  id="fastpostmessage"  rows="5" class="ipt-txt"></textarea>
替换成

 

<div class="bar">
</span><div class="fpd">
<a href="javascript:;" title="文字加粗" class="fbld" onclick="seditor_insertunit('fastpost', '[b]', '[/b]')"><img src="/static/image/attach_b.gif"></a>
<a href="javascript:;" title="设置文字颜色" class="fclr" id="fastpostforecolor" onclick="showColorBox(this.id, 2, 'fastpost');doane(event)"><img

src="/static/image/attach_fontcolor.gif"></a>
<a id="fastpostimg" href="javascript:;" title="图片" class="fmg" onclick="seditor_menu('fastpost', 'img')"><img src="/static/image/attachimg.gif"></a>
<a id="fastposturl" href="javascript:;" title="添加链接" class="flnk" onclick="seditor_menu('fastpost', 'url')"><img src="/static/image/attachurl.gif"></a>
</div></div>

     
 
<div class="area">  

      <textarea cols="60" name="msg"  id="fastpostmessage"  rows="5" class="ipt-txt"></textarea>
     </div></div>

 

注意:attach_b.gif,attach_fontcolor.gif 这两张图片我没找到,是我自己做的,其他的图片可以搜到。

这里主要是模仿disuz的评论编辑器的效果

 

2、文档页面修改方法相同,只是涉及页面多一些,稍微复杂一点点

A、修改 article_article.html


<script src="http://bbs.xxx.com/static/js/common.js?w3w" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://bbs.xxx.com/data/cache/style_2_common.css?w3w" />
<link rel="stylesheet" type="text/css" href="http://bbs.xxx.com/data/cache/style_2_forum_viewthread.css?w3w" />

 

B、<body class="articleview"> 后增加一行

<div id="append_parent"></div><div id="ajaxwaitid"></div>

 

C、修改ajaxfeedback.html,找到

 <textarea cols="60" name="msg"  id="fastpostmessage"  rows="5" class="ipt-txt"></textarea>
替换成

 

<div class="bar">
</span><div class="fpd">
<a href="javascript:;" title="文字加粗" class="fbld" onclick="seditor_insertunit('fastpost', '[b]', '[/b]')"><img src="/static/image/attach_b.gif"></a>
<a href="javascript:;" title="设置文字颜色" class="fclr" id="fastpostforecolor" onclick="showColorBox(this.id, 2, 'fastpost');doane(event)"><img

src="/static/image/attach_fontcolor.gif"></a>
<a id="fastpostimg" href="javascript:;" title="图片" class="fmg" onclick="seditor_menu('fastpost', 'img')"><img src="/static/image/attachimg.gif"></a>
<a id="fastposturl" href="javascript:;" title="添加链接" class="flnk" onclick="seditor_menu('fastpost', 'url')"><img src="/static/image/attachurl.gif"></a>
</div></div>

     
 
<div class="area">  

      <textarea cols="60" name="msg"  id="fastpostmessage"  rows="5" class="ipt-txt"></textarea>
     </div></div>

 

D、修改feedback_ajax.php

在文件前面空白地方增加转换函数

function convertem($message){
 
  $message = str_replace(array('[b]', '[/b]'), array('<strong>','</strong>'), $message );
 
   $message = str_replace('[color=','<font color=', $message );
   $message = str_replace('[/color]','</font>', $message );  
  
    $message = str_replace('[url=www.','<a href=http://www.', $message );
 $message = str_replace('[url=WWW.','<a href=http://WWW.', $message );
 
 $message = str_replace('[url=','<a href=', $message );
 
 
  $message = str_replace('[/url]','</a>', $message );
 
  $message = str_replace('[img','<img src=', $message );
  $message = str_replace('[/img]','</img>', $message ); 
 
  $message = str_replace(']','>', $message );
 
return $message;
}

E、把<?php echo  $msg ; ?>

替换成

 <?php echo  convertem( $msg) ; ?>

 

整个网站更新,即可。

 

 

另附 图片转换函数:


function replaceimg($s)
{

// 例如将 [img=128,128]www.abcceo.com/lcl.jpg[/img] 转换成 <img width=128 heigth=128 src="www.abcceo.com/lcl.jpg" </img>


$r =$s;

while (stripos($r,'[img]')>0)
{

//考虑没有长宽的情况

$p=stripos($r,'[img]');

$a=substr($r,0,$p+5);
$b=substr($r,$p+5,strlen($r)-$p);
$e=stripos($b,'[');
$c=substr($b,$e,strlen($b)-$e );
$b=substr($b,0,stripos($b,'['));

$r=str_replace('[img]','<img src="',$a).$b.'">'.$c;

 }


while (stripos($r,'[img=')>0)
{

//考虑有长宽的情况
$p=stripos($r,'[img=');

$a=substr($r,0,$p+4);
$b=substr($r,$p+4,strlen($r)-$p);
$e=stripos($b,']');
$c=substr($b,$e+1,strlen($b)-$e );
$b=substr($b,1,stripos($b,']')-1);

$r= str_replace('[img','<img ',$a).' width='.str_replace(',',' height=',$b).' src="'.str_replace('[/img]','" ></img>',$c);
 
 }


$r=str_replace('[/img]','</img>',$r);

return $r ;

}

 

 

 

我写的转换函数,还有些缺陷,还不够完善,谁要是修改完善了,记得发一个最新版给我。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值