Пример #1
0
function sendChatroomMessage($to = 0, $message = '', $notsilent = 1)
{
    global $userid;
    global $cookiePrefix;
    global $chromeReorderFix;
    global $bannedUserIDs;
    global $lang;
    $stickersflag = 0;
    if ($to == 0 && empty($_POST['currentroom']) || $message == '' && $notsilent == 0 || isset($_POST['message']) && $_POST['message'] == '' || empty($userid) || in_array($userid, $bannedUserIDs)) {
        return;
    }
    if (isset($_POST['message']) && !empty($_POST['currentroom'])) {
        $to = mysqli_real_escape_string($GLOBALS['dbh'], $_POST['currentroom']);
        $message = $_POST['message'];
    }
    if (isset($message) && $message != '') {
        if (strpos($message, 'CC^CONTROL_') !== false) {
            $message = str_ireplace('CC^CONTROL_', '', $message);
            $message = sanitize($message);
            $controlparameters = json_decode($message, true);
            $chatroommode = $controlparameters['params']['chatroommode'];
            switch ($controlparameters['name']) {
                case 'avchat':
                    $grp = $controlparameters['params']['grp'];
                    switch ($controlparameters['method']) {
                        case 'endcall':
                            $message = 'CC^CONTROL_PLUGIN_AVCHAT_ENDCALL_' . $grp . '_' . $chatroommode;
                            break;
                        case 'rejectcall':
                            $message = 'CC^CONTROL_PLUGIN_AVCHAT_REJECTCALL_' . $grp . '_' . $chatroommode;
                            break;
                        case 'noanswer':
                            $message = 'CC^CONTROL_PLUGIN_AVCHAT_NOANSWER_' . $grp . '_' . $chatroommode;
                            break;
                        case 'canceloutgoingcall':
                            $message = 'CC^CONTROL_PLUGIN_AVCHAT_CANCELCALL_' . $grp . '_' . $chatroommode;
                            break;
                        case 'busycall':
                            $message = 'CC^CONTROL_PLUGIN_AVCHAT_BUSYCALL_' . $grp . '_' . $chatroommode;
                            break;
                        default:
                            $message = '';
                            break;
                    }
                    break;
                case 'audiochat':
                    $grp = $controlparameters['params']['grp'];
                    switch ($controlparameters['method']) {
                        case 'endcall':
                            $message = 'CC^CONTROL_PLUGIN_AUDIOCHAT_ENDCALL_' . $grp . '_' . $chatroommode;
                            break;
                        case 'rejectcall':
                            $message = 'CC^CONTROL_PLUGIN_AUDIOCHAT_REJECTCALL_' . $grp . '_' . $chatroommode;
                            break;
                        case 'noanswer':
                            $message = 'CC^CONTROL_PLUGIN_AUDIOCHAT_NOANSWER_' . $grp . '_' . $chatroommode;
                            break;
                        case 'canceloutgoingcall':
                            $message = 'CC^CONTROL_PLUGIN_AUDIOCHAT_CANCELCALL_' . $grp . '_' . $chatroommode;
                            break;
                        case 'busycall':
                            $message = 'CC^CONTROL_PLUGIN_AUDIOCHAT_BUSYCALL_' . $grp . '_' . $chatroommode;
                            break;
                        default:
                            $message = '';
                            break;
                    }
                    break;
                case 'broadcast':
                    $grp = $controlparameters['params']['grp'];
                    switch ($controlparameters['method']) {
                        case 'endcall':
                            $message = 'CC^CONTROL_PLUGIN_BROADCAST_ENDCALL_' . $grp . '_' . $chatroommode;
                            break;
                        default:
                            $message = '';
                            break;
                    }
                    break;
                case 'stickers':
                    $stickersflag = 1;
                    $message = 'CC^CONTROL_' . $message;
                    break;
                case 'chatroom':
                    $delid = $controlparameters['params']['id'];
                    switch ($controlparameters['method']) {
                        case 'deletemessage':
                            $message = 'CC^CONTROL_deletemessage_' . $delid;
                            break;
                        case 'kicked':
                            $message = 'CC^CONTROL_kicked_' . $delid;
                            break;
                        case 'banned':
                            $message = 'CC^CONTROL_banned_' . $delid;
                            break;
                        default:
                            $message = '';
                            break;
                    }
                    break;
                default:
                    break;
            }
        }
    }
    if ($notsilent !== 0 && $stickersflag == 0) {
        $message = str_ireplace('CC^CONTROL_', '', $message);
        $message = sanitize($message);
    }
    $styleStart = '';
    $styleEnd = '';
    if (!empty($_COOKIE[$cookiePrefix . 'chatroomcolor']) && preg_match('/^[a-f0-9]{6}$/i', $_COOKIE[$cookiePrefix . 'chatroomcolor']) && $notsilent == 1 && $stickersflag == 0) {
        $styleStart = '<span style="color:#' . mysqli_real_escape_string($GLOBALS['dbh'], $_COOKIE[$cookiePrefix . 'chatroomcolor']) . '">';
        $styleEnd = '</span>';
    }
    $timestamp = getTimeStamp();
    if (empty($_SESSION['cometchat']['cometchat_chatroom_' . $to])) {
        $_SESSION['cometchat']['cometchat_chatroom_' . $to] = array();
    }
    if (USE_COMET == 1 && COMET_CHATROOMS == 1) {
        if (empty($_SESSION['cometchat']['username'])) {
            $name = '';
            $sql = getUserDetails($userid);
            if ($userid > 10000000) {
                $sql = getGuestDetails($userid);
            }
            $result = mysqli_query($GLOBALS['dbh'], $sql);
            if ($row = mysqli_fetch_assoc($result)) {
                if (function_exists('processName')) {
                    $row['username'] = processName($row['username']);
                }
                $name = $row['username'];
            }
            $_SESSION['cometchat']['username'] = $name;
        } else {
            $name = $_SESSION['cometchat']['username'];
        }
        if (!empty($name)) {
            $sql = "insert into cometchat_chatroommessages (userid,chatroomid,message,sent) values ('" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "', '" . mysqli_real_escape_string($GLOBALS['dbh'], $to) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $styleStart) . mysqli_real_escape_string($GLOBALS['dbh'], $message) . mysqli_real_escape_string($GLOBALS['dbh'], $styleEnd) . "','" . $timestamp . "')";
            $query = mysqli_query($GLOBALS['dbh'], $sql);
            $insertedid = mysqli_insert_id($GLOBALS['dbh']);
            $channel = md5('chatroom_' . $to . KEY_A . KEY_B . KEY_C);
            $comet = new Comet(KEY_A, KEY_B);
            if (method_exists($comet, 'processChannel')) {
                $channel = processChannel($channel);
            }
            if (defined('DEV_MODE') && DEV_MODE == '1') {
                echo mysqli_error($GLOBALS['dbh']);
            }
            $info = $comet->publish(array('channel' => $channel, 'message' => array("id" => $insertedid, "from" => $name, "fromid" => $userid, "message" => $styleStart . $message . $styleEnd, "sent" => $timestamp * 1000, "roomid" => $to)));
            $_SESSION['cometchat']['cometchat_chatroom_' . $to][$insertedid] = array('id' => $insertedid, 'from' => $_SESSION['cometchat']['username'], 'fromid' => $userid, 'chatroomid' => $to, 'message' => $styleStart . $message . $styleEnd, 'sent' => $timestamp);
            krsort($_SESSION['cometchat']['cometchat_chatroom_' . $to]);
            if ($notsilent == 1) {
                sendCCResponse(json_encode(array("id" => $insertedid, "m" => $styleStart . $message . $styleEnd, "sent" => $timestamp)));
            }
        }
    } else {
        $sql = "insert into cometchat_chatroommessages (userid,chatroomid,message,sent) values ('" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "', '" . mysqli_real_escape_string($GLOBALS['dbh'], $to) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $styleStart) . mysqli_real_escape_string($GLOBALS['dbh'], $message) . mysqli_real_escape_string($GLOBALS['dbh'], $styleEnd) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $timestamp) . "')";
        $query = mysqli_query($GLOBALS['dbh'], $sql);
        $insertedid = mysqli_insert_id($GLOBALS['dbh']);
        if (defined('DEV_MODE') && DEV_MODE == '1') {
            echo mysqli_error($GLOBALS['dbh']);
        }
        $name = '';
        $sql = getUserDetails($userid);
        if ($userid > 10000000) {
            $sql = getGuestDetails($userid);
        }
        $result = mysqli_query($GLOBALS['dbh'], $sql);
        if ($row = mysqli_fetch_assoc($result)) {
            if (function_exists('processName')) {
                $row['username'] = processName($row['username']);
            }
            $name = $row['username'];
        }
        $_SESSION['cometchat']['cometchat_chatroom_' . $to][$insertedid] = array('id' => $insertedid, 'from' => $name, 'fromid' => $userid, 'chatroomid' => $to, 'message' => $styleStart . $message . $styleEnd, 'sent' => $timestamp);
        krsort($_SESSION['cometchat']['cometchat_chatroom_' . $to]);
        if ($notsilent == 1) {
            sendCCResponse(json_encode(array("id" => $insertedid, "m" => $styleStart . $message . $styleEnd, "sent" => $timestamp)));
        }
    }
    $parsedmessage = $message;
    if (strpos($message, 'BROADCAST_ENDCALL') !== false || strpos($message, 'jqcc.ccbroadcast.join') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "broadcast" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $broadcast_language;
        if (strpos($message, 'BROADCAST_ENDCALL') !== false) {
            $parsedmessage = $broadcast_language[24];
        }
        //This broadcast has ended
        if (strpos($message, 'jqcc.ccbroadcast.join') !== false) {
            $parsedmessage = $broadcast_language[17];
        }
        //has started a video broadcast.
    } elseif (strpos($message, 'jqcc.ccavchat.join') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "avchat" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $avchat_language;
        $parsedmessage = $avchat_language[19];
        //has started a video conversation.
    } elseif (strpos($message, 'jqcc.ccaudiochat.join') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "audiochat" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $audiochat_language;
        $parsedmessage = $audiochat_language[19];
        //has started a audio conversation.
    } elseif (strpos($message, 'CC^CONTROL_{"type":"plugins","name":"stickers","method":"sendSticker"') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "stickers" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $stickers_language;
        $parsedmessage = $stickers_language[2];
        //has sent a sticker.
    } elseif (strpos($message, 'CC^CONTROL_kicked_kicked') !== false || strpos($message, 'CC^CONTROL_banned_') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR . "chatrooms" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $chatrooms_language;
        if (strpos($message, 'CC^CONTROL_kicked_kicked') !== false) {
            $parsedmessage = $chatrooms_language[36];
        }
        //You have been kicked from this chatroom.
        if (strpos($message, 'CC^CONTROL_banned_') !== false) {
            $parsedmessage = $chatrooms_language[37];
        }
        //You have been banned from chatroom
    } elseif (strpos($message, 'jqcc.ccwhiteboard.accept') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "whiteboard" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $whiteboard_language;
        $parsedmessage = $whiteboard_language[7];
        //has shared a whiteboard.
    } elseif (strpos($message, 'jqcc.ccwriteboard.accept') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "writeboard" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $writeboard_language;
        $parsedmessage = $writeboard_language[2];
        //has shared a writeboard.
    } elseif (strpos($message, 'jqcc.ccscreenshare.accept') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "screenshare" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $screenshare_language;
        $parsedmessage = $screenshare_language[2];
        //has shared his/her screen with you.
    } elseif (strpos($message, '/writable/handwrite/uploads/') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "handwrite" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $handwrite_language;
        $parsedmessage = $handwrite_language[1];
        //has successfully sent a handwritten message
    } elseif (strpos($message, 'plugins/filetransfer/download.php') !== false) {
        include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . "filetransfer" . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . $lang . ".php";
        global $filetransfer_language;
        $parsedmessage = $filetransfer_language[9];
        //has shared a file
    }
    pushMobileNotification($to, $insertedid, $parsedmessage, '1', 0, $timestamp);
    $sql = "update cometchat_chatrooms set lastactivity = '" . mysqli_real_escape_string($GLOBALS['dbh'], $timestamp) . "' where id = '" . mysqli_real_escape_string($GLOBALS['dbh'], $to) . "'";
    $query = mysqli_query($GLOBALS['dbh'], $sql);
    if ($notsilent == 0) {
        return $insertedid;
    }
}
Пример #2
0
         }
     }
 }
 if (!empty($_REQUEST['status'])) {
     setStatus($_REQUEST['status']);
 }
 if (!empty($_REQUEST['initialize']) && $_REQUEST['initialize'] == 1) {
     if (USE_COMET == 1) {
         $key = '';
         if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) {
             $key = KEY_A . KEY_B . KEY_C;
         }
         $response['cometid']['id'] = md5($userid . $key);
         $comet = new Comet(KEY_A, KEY_B);
         if (method_exists($comet, 'processChannel')) {
             $response['cometid']['id'] = processChannel($response['cometid']['id']);
         }
         if (empty($_SESSION['cometchat']['cometmessagesafter'])) {
             $_SESSION['cometchat']['cometmessagesafter'] = getTimeStamp() . '999';
         }
         $response['initialize'] = 0;
         $response['init'] = '1';
     } else {
         $sql = "select max(id) as id from cometchat";
         $query = mysqli_query($GLOBALS['dbh'], $sql);
         if (defined('DEV_MODE') && DEV_MODE == '1') {
             echo mysqli_error($GLOBALS['dbh']);
         }
         $result = mysqli_fetch_assoc($query);
         $response['init'] = '1';
         $response['initialize'] = '0';