完善discuz的@圈人功能

来源:互联网 发布:淘宝网每天的访问量 编辑:程序博客网 时间:2024/05/16 00:55

对于原始的discuz的@圈人功能,存在一下几个缺陷:

1/ 如果在圈人的时候,在其后不小心对人名进行了字体/颜色/大小之类的样式设定时,如[i]@02nice[/i],后台逻辑代码中分析到的人名会无法匹配

2/ 如果在圈人的时候,在人名之后换行,后台也会无法匹配


修改方式:

在论坛用户发表主题/回复/发帖时,对于用户编辑内容提交过程中,圈人增加用户链接的效果内容是会保存在数据库中的。

主要有三个文件,三处内容相似:

post_newthread.php

post_newreply.php

post_editpost.php

修改方式$tmp_search ,通过正则表达式,将获取到的人名进行过滤,将包含[/b],[/color],[/u]等样式字符过滤掉,保留原始的人名,当然这里所不考虑含有这些字符串的人名。

if($_G['group']['allowat']) {     $atlist = $atlist_tmp = array();     preg_match_all("/@([^\r\n]*?)\s/i", $message.' ', $atlist_tmp);     $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $_G['group']['allowat']);     if(!empty($atlist_tmp)) {         if(empty($_G['setting']['at_anyone'])) {             foreach(C::t('home_follow')->fetch_all_by_uid_fusername($_G['uid'], $atlist_tmp) as $row) {                 $atlist[$row['followuid']] = $row['fusername'];             }             if(count($atlist) < $_G['group']['allowat']) {                 $query = C::t('home_friend')->fetch_all_by_uid_username($_G['uid'], $atlist_tmp);                 foreach($query as $row) {                     $atlist[$row['fuid']] = $row['fusername'];                 }             }         } else {                         // edit,修复@,                         foreach ($atlist_tmp as $atlist_key => $atlist_value) {                                 $tmp_search = "/\[\/(b|color|u|i|size|strong|backcolor|font)\]/";                                 $atlist_value = preg_replace($tmp_search, "", $atlist_value);                                 $atlist_tmp[$atlist_key] = $atlist_value;                             }             foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {                 $atlist[$row['uid']] = $row['username'];             }         }     }     if($atlist) {                 //   edit,修复@,         foreach($atlist as $atuid => $atusername) {             $atsearch[] = "/@".str_replace('/', '\/', preg_quote($atusername))."/i";             $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url]";         }         $message = preg_replace($atsearch, $atreplace, $message.' ', 1);     } }


原创粉丝点击