//转载
$atlist = $atlist_tmp = $ateduids = array(); preg_match_all("/@([^ ]*?)s/i", $message.' ', $atlist_tmp);//解析内容里的被@到的名字。 $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $_G['group']['allowat']);//应该是提取用户名吧。。 $atnum = $maxselect = 0; foreach(C::t('home_notification')->fetch_all_by_authorid_fromid($_G['uid'], $_G['tid'], 'at') as $row) { $atnum ++;//这个循环暂时搞不懂。还没看过这个表是干嘛的。 $ateduids[$row[uid]] = $row['uid']; } $maxselect = $_G['group']['allowat'] - $atnum; if($maxselect > 0 && !empty($atlist_tmp)) { if(empty($_G['setting']['at_anyone'])) {//判断是否只能@好友,如果只能@好友的话,那就从下面的home_follow表中找出在好友列表里的人的姓名。其他的就@不到了。 foreach(C::t('home_follow')->fetch_all_by_uid_fusername($_G['uid'], $atlist_tmp) as $row) { if(!in_array($row['followuid'], $ateduids)) { $atlist[$row[followuid]] = $row['fusername']; } if(count($atlist) == $maxselect) { break; } } if(count($atlist) < $maxselect) {//判断@上限。 $query = C::t('home_friend')->fetch_all_by_uid_username($_G['uid'], $atlist_tmp);//不用说了吧 foreach($query as $row) { if(!in_array($row['followuid'], $ateduids)) { $atlist[$row[fuid]] = $row['fusername']; } } } } else { foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) { if(in_array($row['uid'], $ateduids)) { $atlist[$row[uid]] = $row['username']; } if(count($atlist) == $maxselect) { break; } } } } if($atlist) {//提醒和加链接。 foreach($atlist as $atuid => $atusername) { $notic = array('subject' => '铂金小猪我爱你', 'message' => '铂金小猪你好,红薯在评论回复中说他爱你', 'from_id' => 0, 'from_idtype' => 'sendnotice'); notification_add($atuid,'system','system_notice',$notic,1);//发送提醒给被@到的用户。$notic是提醒的内容。 $atsearch[] = "/@$atusername /i"; $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";//加链接,但不是a标签。 } $message = preg_replace($atsearch, $atreplace, $message.' ', 1); } require_once libfile('function/followcode'); require_once libfile('function/discuzcode'); $cont=followcode($message);//格式化代码中的标签