Exemplo n.º 1
0
function IHomeServiceCreateComplainReply($params = NULL)
{
    global $_SGLOBAL;
    $cpid = 0;
    # complain 表中的 id
    $relay_times = 0;
    if ($params['uid']) {
        if ($params['uid'] <= 0) {
            $errorMsg = array("errorNo" => "4002", "content" => "the format of parameter is not correct.the parameter uid must be a positive integer.");
            return json_encode($errorMsg);
        } else {
            $query = $_SGLOBAL['db']->query("select name,username  from " . tname('space') . " where uid = " . $params['uid']);
            if ($row = $_SGLOBAL['db']->fetch_array($query)) {
                if ($row['name']) {
                    $params['uname'] = $row['name'];
                } else {
                    $params['uname'] = $row['username'];
                }
            } else {
                $errorMsg = array("errorNo" => "500", "content" => "the uid is not exist");
                return json_encode($errorMsg);
            }
        }
    } else {
        $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter.the parameter uid is not exist or is not a positive integer.");
        return json_encode($errorMsg);
    }
    $complain = array();
    if ($params['complainId']) {
        if ($params['complainId'] <= 0) {
            $errorMsg = array("errorNo" => "4002", "content" => "the format of parameter is not correct.the parameter complainId must be a positive integer.");
            return json_encode($errorMsg);
        } else {
            $query = $_SGLOBAL['db']->query("select * from " . tname('complain') . " where doid = " . $params['complainId']);
            if ($complain = $_SGLOBAL['db']->fetch_array($query)) {
                if (isblacklist($complain['uid'])) {
                    $errorMsg = array("errorNo" => "500", "content" => "the user of complain is in blacklist.");
                    return json_encode($errorMsg);
                }
            } else {
                $errorMsg = array("errorNo" => "500", "content" => "the complain id is not exist");
                return json_encode($errorMsg);
            }
        }
    } else {
        $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter.the parameter complainId is not exist or is not a positive integer.");
        return json_encode($errorMsg);
    }
    if (!$params['message']) {
        $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter message.");
        return json_encode($errorMsg);
    }
    $params['timestamp'] = time();
    $doid = $params['complainId'];
    $message = getstr($params['message'], 480, 1, 1, 1);
    preg_match_all("/[@](.*)[(]([\\d]+)[)]\\s*/U", $params['message'], $matches, PREG_SET_ORDER);
    preg_match_all("/回复[@](.*)[(]([\\d]+)[)]\\s*/U", $params['message'], $reply_matches, PREG_SET_ORDER);
    if ($reply_matches) {
        $exclude_relay = 1;
    }
    # 如果带有回复字眼,则默认不为relay
    $newid = 0;
    $addtype = 0;
    $query = $_SGLOBAL['db']->query("select * from " . tname('complain') . " where doid=" . $params['complainId'] . ' and atuid=' . $params['uid']);
    if ($row = $_SGLOBAL['db']->fetch_array($query)) {
        $complain = $row;
        $addtype = 2;
        $cpid = $complain['id'];
        $relay_times = $complain['relay_times'];
    }
    $isrelay = 0;
    if ($addtype && $matches && !$exclude_relay) {
        $isrelay = 1;
    }
    if ($isrelay && $relay_times >= 3) {
        $errorMsg = array("errorNo" => "500", "content" => "relay times reach the ceiling'.");
        return json_encode($errorMsg);
    }
    $UserIds = array();
    $relay_depid = 0;
    foreach ($matches as $value) {
        $TmpString = $value[0];
        $TmpName = $value[1];
        $UserId = $value[2];
        $result = $_SGLOBAL['db']->query("select uid,username,name from " . tname('space') . " where uid=" . $UserId);
        if ($rs = $_SGLOBAL['db']->fetch_array($result)) {
            $realname = $rs['name'];
            if (empty($realname)) {
                $realname = $rs['username'];
            }
            $ValidValue = getAtName($TmpString, $TmpName, $realname);
            $ValidValue = trim($ValidValue);
            $at_friend = "space.php?uid=" . $UserId;
            if ($ValidValue != false) {
                $message = str_replace($ValidValue, "<a href={$at_friend}>@" . $realname . "</a> ", $message);
                if (!in_array($UserId, $UserIds)) {
                    $UserIds[] = $UserId;
                }
            }
        }
        if ($isrelay) {
            $q = $_SGLOBAL['db']->query("select * from " . tname('powerlevel') . " where dept_uid = " . $UserId);
            if ($r = $_SGLOBAL['db']->fetch_array($q)) {
                $relay_depid = $UserId;
            }
        }
    }
    $message = preg_replace("/\\[am:(\\d+):]/is", "<img src=\"image/face_new/face_1/\\1.gif\" class=\"face\">", $message);
    $message = preg_replace("/\\[em:(\\d+):]/is", "<img src=\"image/face/\\1.gif\" class=\"face\">", $message);
    $message = preg_replace("/\\[bm:(\\d+):]/is", "<img src=\"image/face_new/face_2/\\1.gif\" class=\"face\">", $message);
    $message = preg_replace("/\\<br.*?\\>/is", ' ', $message);
    $params['message'] = $message;
    if (strlen($message) < 1) {
        $errorMsg = array("errorNo" => "4002", "content" => "the parameter message is too short'.");
        return json_encode($errorMsg);
    }
    if (!$addtype) {
        if ($UserIds) {
            $temp = implode(',', $UserIds);
            $_SGLOBAL['db']->query("UPDATE " . tname('complain') . " SET locked=0 WHERE doid= " . $params['complainId'] . " AND uid=" . $params['uid'] . " AND locked AND atuid in ({$temp})");
        }
        $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('doing') . " WHERE doid=" . $params['complainId']);
        $updo = $_SGLOBAL['db']->fetch_array($query);
        $updo['id'] = intval($updo['id']);
        $updo['grade'] = intval($updo['grade']);
        $setarr = array('doid' => $updo['doid'], 'upid' => $updo['id'], 'uid' => $params['uid'], 'username' => $params['uname'], 'dateline' => $_SGLOBAL['timestamp'], 'message' => $message, 'ip' => getonlineip(), 'grade' => $updo['grade'] + 1);
        if ($params['ip']) {
            $setarr['ip'] = $params['ip'];
        } else {
            $params['ip'] = $setarr['ip'];
        }
        if ($updo['grade'] >= 3) {
            $setarr['upid'] = $updo['upid'];
        }
        $newid = inserttable('docomment', $setarr, 1);
        $params['id'] = $newid;
        $params['operation'] = 0;
        $_SGLOBAL['db']->query("UPDATE " . tname('doing') . " SET replynum=replynum+1 WHERE doid='{$updo['doid']}'");
        $note = cplang('note_complain_reply', array("space.php?do=complain_item&doid={$setarr['doid']}"));
        notification_add($userId, 'complain', $note);
        if (empty($UserIds)) {
            // not @
            $query = $_SGLOBAL['db']->query("SELECT * FROM ihome_complain where doid=" . $updo[doid]);
            $value = $_SGLOBAL['db']->fetch_array($query);
            if ($value['from'] == $params['uid']) {
                //发起方
                notification_add($value['atuid'], 'complain', $note);
            } else {
                notification_add($value['from'], 'complain', $note);
            }
        }
        unset($params['complainId']);
        return json_encode($params);
    }
    $optype = 2;
    if ($isrelay) {
        $optype = 3;
        $addtype = 0;
    }
    $oparr = array('doid' => $params['complainId'], 'message' => $params['message'], 'uid' => $params['uid'], 'username' => $params['uname'], 'optype' => $optype, 'dateline' => time(), 'opvalue' => $relay_depid, 'finish' => $addtype == 2 ? 1 : 0);
    $params['operation'] = $opid = inserttable('complain_op', $oparr, true);
    $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('doing') . " WHERE doid=" . $params['complainId']);
    $updo = $_SGLOBAL['db']->fetch_array($query);
    $updo['id'] = intval($updo['id']);
    $updo['grade'] = intval($updo['grade']);
    $setarr = array('doid' => $updo['doid'], 'upid' => $updo['id'], 'uid' => $params['uid'], 'username' => $params['uname'], 'dateline' => $_SGLOBAL['timestamp'], 'message' => $message, 'ip' => getonlineip(), 'grade' => $updo['grade'] + 1, 'complainBorn' => 1, 'complainopid' => $opid);
    if ($params['ip']) {
        $setarr['ip'] = $params['ip'];
    } else {
        $params['ip'] = $setarr['ip'];
    }
    if ($updo['grade'] >= 3) {
        $setarr['upid'] = $updo['upid'];
    }
    $params['id'] = $newid = inserttable('docomment', $setarr, 1);
    $_SGLOBAL['db']->query("UPDATE " . tname('doing') . " SET replynum=replynum+1 WHERE doid='{$updo['doid']}'");
    if ($optype == 3) {
        $query = $_SGLOBAL['db']->query("select * from " . tname("space") . " where uid = {$relay_depid}");
        $relay_dep = $_SGLOBAL['db']->fetch_array($query);
        if (empty($relay_dep)) {
            $errorMsg = array("errorNo" => 500, "content" => "the at user is not exist ");
            return json_encode($errorMsg);
        }
        updatetable('complain', array("status" => 3, 'lastopid' => $opid), array('id' => $cpid));
        #status = 3 relayed
        $query = $_SGLOBAL['db']->query("select * from " . tname("complain") . " where doid= " . $params['complainId'] . " and atuid={$relay_depid} and status != 3");
        $already = $_SGLOBAL['db']->fetch_array($query);
        if (!$already) {
            if ($complain['relayed_by']) {
                $relayed_by = $complain['relayed_by'] . $params['uid'] . ',';
            } else {
                $relayed_by = ',' . $params['uid'] . ',';
            }
            $newComplain = $complain;
            unset($newComplain['id']);
            $newComplain['atdeptuid'] = $relay_depid;
            $newComplain['atuid'] = $relay_depid;
            $newComplain['atuname'] = $relay_dep['name'];
            $newComplain['atdepartment'] = $relay_dep['name'];
            $newComplain['dateline'] = $_SGLOBAL['timestamp'];
            $newComplain['times'] = 1;
            $newComplain['issendmsg'] = 0;
            $newComplain['relay_times'] = $complain['relay_times'] + 1;
            $newComplain['relayed_by'] = $relayed_by;
            $newComplainId = inserttable('complain', $newComplain, 1);
            if ($complain['lastopid'] == 0) {
                $result = $_SGLOBAL['db']->query("select * from " . tname('complain_dep') . " where uid = " . $params['uid']);
                $dep = $_SGLOBAL['db']->fetch_array($result);
                if (empty($dep)) {
                    $arr = array();
                    $arr['uid'] = $params['uid'];
                    $arr['username'] = $params['uname'];
                    $arr['upnum'] = 0;
                    $arr['downnum'] = 0;
                    $arr['allreplynum'] = 1;
                    $arr['allreplysecs'] = $_SGLOBAL['timestamp'] - $complain['dateline'];
                    $arr['score'] = 0;
                    $arr['aversecs'] = 0;
                    $arr['lastupdate'] = 0;
                    inserttable('complain_dep', $arr);
                } else {
                    $arr['allreplynum'] = $dep['allreplynum'] + 1;
                    $arr['allreplysecs'] = $dep['allreplysecs'] + $_SGLOBAL['timestamp'] - $complain['dateline'];
                    updatetable("complain_dep", $arr, array('uid' => $params['uid']));
                }
            }
            $note = cplang('complain_relay', array($complain['atuname'], "space.php?do=complain_item&doid={$complain['doid']}"));
            notification_complain_add($relay_depid, 'complain', $note);
        }
        inserttable('complain_resp', array('uid' => $params['uid'], 'doid' => $doid, 'opid' => $opid, 'replysecs' => $_SGLOBAL['timestamp'] - $complain['dateline'], 'dateline' => $_SGLOBAL['timestamp']));
    } else {
        if ($optype == 2) {
            if ($addtype == 2) {
                updatetable('complain', array('status' => 1, 'lastopid' => $opid, 'replytime' => $_SGLOBAL['timestamp'], 'dateline' => $_SGLOBAL['timestamp']), array('id' => $cpid));
            } else {
                updatetable('complain', array('locked' => 1, 'replytime' => $_SGLOBAL['timestamp'], 'dateline' => $_SGLOBAL['timestamp']), array('id' => $cpid));
            }
            if ($complain['lastopid'] == 0) {
                $result = $_SGLOBAL['db']->query("select * from " . tname('complain_dep') . " where uid =" . $params['uid']);
                $dep = $_SGLOBAL['db']->fetch_array($result);
                if (empty($dep)) {
                    $arr = array();
                    $arr['uid'] = $params['uid'];
                    $arr['username'] = $params['uname'];
                    $arr['upnum'] = 0;
                    $arr['downnum'] = 0;
                    $arr['allreplynum'] = 1;
                    $arr['allreplysecs'] = $_SGLOBAL['timestamp'] - $complain['dateline'];
                    $arr['score'] = 0;
                    $arr['aversecs'] = 0;
                    $arr['lastupdate'] = 0;
                    inserttable('complain_dep', $arr);
                } else {
                    $arr['allreplynum'] = $dep['allreplynum'] + 1;
                    $arr['allreplysecs'] = $dep['allreplysecs'] + $_SGLOBAL['timestamp'] - $complain['dateline'];
                    updatetable("complain_dep", $arr, array('uid' => $params['uid']));
                }
            }
            inserttable('complain_resp', array('uid' => $params['uid'], 'doid' => $doid, 'opid' => $opid, 'replysecs' => $_SGLOBAL['timestamp'] - $complain['dateline'], 'dateline' => $_SGLOBAL['timestamp']));
            $note = cplang('note_doingcomplain_reply', array("space.php?do=complain_item&doid={$complain['doid']}"));
            notification_complain_add($complain['uid'], 'complain', $note, $params['uid'], $params['uname']);
        }
    }
    unset($params['complainId']);
    return json_encode($params);
}
Exemplo n.º 2
0
 } else {
     //处理评论的@功能 Add by am 2013-12-07 start
     //提取AT用户
     preg_match_all("/[@](.*)[(]([\\d]+)[)]\\s/U", $Message, $matches, PREG_SET_ORDER);
     foreach ($matches as $value) {
         $TmpString = $value[0];
         $TmpName = $value[1];
         $UserId = $value[2];
         $result = $_SGLOBAL['db']->query("select uid,username,name from " . tname('space') . " where uid={$UserId}");
         if ($rs = $_SGLOBAL['db']->fetch_array($result)) {
             $realname = $rs['name'];
             if (empty($realname)) {
                 $realname = $rs['username'];
             }
             //调用检查函数将@后的内容进行验证,为UID对应的姓名相同则返回@与姓名,不相同则继续判断下一个@,没有找到匹配的最终将返回false
             $ValidValue = getAtName($TmpString, $TmpName, $realname);
             $ValidValue = trim($ValidValue);
             $at_friend = "space.php?uid=" . $UserId;
             if ($ValidValue != false) {
                 $Message = str_replace($ValidValue, "<a href={$at_friend}>@" . $realname . "</a> ", $Message);
                 $UserIds[] = $UserId;
             }
         }
     }
     //Add by Add by am 2013-12-07  end
     $arr = array('tid' => intval($Commentid), "tagid" => intval($TagId), "uid" => intval($userid), "username" => getstr($username, 15, 1, 1, 1), "message" => getstr($Message, 5000, 1, 1, 1), "ip" => getonlineip(), 'dateline' => $_SGLOBAL['timestamp'], "isthread" => 0);
     $pid = inserttable('post', $arr, 1);
     //更新统计数据
     $_SGLOBAL['db']->query("UPDATE " . tname('thread') . "\r\n\tSET replynum=replynum+1, lastpost='{$_SGLOBAL['timestamp']}', lastauthor='{$username}', lastauthorid='{$userid}'\r\n\tWHERE tid='{$Commentid}'");
     //通知
     $note = cplang('note_thread_reply') . " <a href=\"space.php?uid={$userid}&do=thread&id={$Commentid}&pid={$pid}\" target=\"_blank\">{$thread['subject']}</a>";
Exemplo n.º 3
0
function getAtName($Str, $TmpName, $Name)
{
    //echo "----Str: ".$Str."----TmpName: ".$TmpName."----TMPREALNAME: ".$Name;
    if ($TmpName == $Name) {
        return $Str;
    } else {
        $position = strpos($TmpName, "@");
        //echo ">>>>POSITION: ".$position;
        if ($position != false) {
            $TmpStr = substr($Str, 1);
            $TmpStr = substr($TmpStr, strpos($TmpStr, "@"));
            //echo "=====TMPTMPSTR: ".$TmpStr;
            $SubTmpName = substr($TmpName, $position + 1);
            //echo "^^^^SubTmpName: ".$SubTmpName;
            return getAtName($TmpStr, $SubTmpName, $Name);
        } else {
            return false;
        }
    }
}