Test
Test
By lincanbin
at 2014-11-26
0 collector • 1003 pageviews
- Requires Login
1 Replies | Last update 2014-11-26
function AddingNotifications($Content, $TopicID, $PostID, $FilterUser='') { /* Type: 1:新回复 2:@ 到我的 */ global $Prefix, $DB, $TimeStamp, $CurUserName; //例外列表 $ExceptionUser = array($CurUserName); if ($FilterUser != $CurUserName) { $ExceptionUser[] = $FilterUser; } // 正则跟用户注册、登录保持一致 preg_match_all('/\B\@([a-zA-Z0-9\x80-\xff\-_.]{4,20})/', $Content, $out, PREG_PATTERN_ORDER); $TemporaryUserList = array_unique($out[1]);//排重 $TemporaryUserList = array_diff($TemporaryUserList, $ExceptionUser); if($TemporaryUserList) { $UserList = $DB->row('SELECT ID FROM `'.$Prefix.'users` WHERE `UserName` in (?)', $TemporaryUserList); if($UserList && count($UserList) <= 20) //最多@ 20人,防止骚扰 { foreach ($UserList as $UserID) { $DB->query('INSERT INTO `'.$Prefix.'notifications`(`ID`,`UserID`, `UserName`, `Type`, `TopicID`, `PostID`, `Time`, `IsRead`) VALUES (null,?,?,?,?,?,?,?)',array($UserID, $CurUserName, 2, $TopicID, $PostID, $TimeStamp, 0)); $DB->query('UPDATE `'.$Prefix.'users` SET `NewMessage` = NewMessage+1 WHERE ID = :UserID',array('UserID' => $UserID)); } } } }