コード例 #1
0
function publishCometMessages($broadcast, $id)
{
    global $userid;
    global $plugins;
    global $blockpluginmode;
    if (in_array('block', $plugins)) {
        $blockedIds = getBlockedUserIDs(0, 1);
        for ($i = 0; $i < sizeof($broadcast); $i++) {
            if ($blockpluginmode == 1 && in_array($broadcast[$i]['to'], $blockedIds)) {
                if ($broadcast[$i]['dir'] == 1) {
                    $broadcast[$i]['dir'] = 3;
                } else {
                    $broadcast[$i]['dir'] = 2;
                }
            } else {
                if (in_array($broadcast[$i]['to'], $blockedIds)) {
                    array_splice($broadcast, $i, 1);
                }
            }
        }
    }
    $sizeof_broadcast = sizeof($broadcast);
    for ($i = 0; $i < $sizeof_broadcast; $i++) {
        $insertedid = $id + $i;
        $key = '';
        if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) {
            $key = KEY_A . KEY_B . KEY_C;
        }
        $key_prefix = $broadcast[$i]['dir'] === 2 ? $userid : $broadcast[$i]['to'];
        $from = $broadcast[$i]['dir'] === 2 ? $broadcast[$i]['to'] : $userid;
        $self = $broadcast[$i]['dir'] === 2 ? 1 : 0;
        $channel = md5($key_prefix . $key);
        $comet = new Comet(KEY_A, KEY_B);
        if (method_exists($comet, 'processChannel')) {
            $channel = processChannel($channel);
        }
        if ($broadcast[$i]['dir'] != 3 && empty($broadcast[$i]['type'])) {
            $info = $comet->publish(array('channel' => $channel, 'message' => array("id" => $insertedid, "from" => $from, "message" => $broadcast[$i]['message'], "sent" => getTimeStamp(), "self" => $self, "direction" => $broadcast[$i]['dir'])));
        } else {
            $channel = md5($userid . $key);
            $self = 1;
            $from = $broadcast[$i]['to'];
            $info = $comet->publish(array('channel' => $channel, 'message' => array("id" => $insertedid, "from" => $from, "message" => $broadcast[$i]['message'], "sent" => getTimeStamp(), "self" => $self, "direction" => $broadcast[$i]['dir'])));
        }
        if ($broadcast[$i]['dir'] != 1 || $broadcast[$i]['dir'] != 3 && empty($broadcast[$i]['type'])) {
            $key_prefix = $userid;
            $from = $broadcast[$i]['to'];
            $channel = md5($key_prefix . $key);
            $self = 1;
            $info = $comet->publish(array('channel' => $channel, 'message' => array("id" => $insertedid, "from" => $from, "message" => $broadcast[$i]['message'], "sent" => getTimeStamp(), "self" => $self, "direction" => 0)));
        }
        if (function_exists('hooks_message')) {
            hooks_message($userid, $broadcast[$i]['to'], $broadcast[$i]['message'], $broadcast[$i]['dir']);
        }
    }
}
コード例 #2
0
            $insertedid = mysql_insert_id();
            if (defined('DEV_MODE') && DEV_MODE == '1') {
                echo mysql_error();
            }
            if (empty($_SESSION['cometchat']['cometchat_user_' . $to])) {
                $_SESSION['cometchat']['cometchat_user_' . $to] = array();
            }
            $_SESSION['cometchat']['cometchat_user_' . $to][] = array("id" => $insertedid, "from" => $to, "message" => sanitize($message), "self" => 1, "old" => 1, 'sent' => getTimeStamp() + $_SESSION['cometchat']['timedifference']);
            if (isset($_GET['callback'])) {
                header('content-type: application/json; charset=utf-8');
                echo $_GET['callback'] . '(' . $insertedid . ')';
            } else {
                echo $insertedid;
            }
        } else {
            $sql = "insert into cometchat (cometchat.from,cometchat.to,cometchat.message,cometchat.sent,cometchat.read,cometchat.direction) values ('" . mysql_real_escape_string($userid) . "', '" . mysql_real_escape_string($to) . "','" . mysql_real_escape_string(sanitize($bannedMessage)) . "','" . getTimeStamp() . "',0,2)";
            $query = mysql_query($sql);
            if (defined('DEV_MODE') && DEV_MODE == '1') {
                echo mysql_error();
            }
            if (isset($_GET['callback'])) {
                header('content-type: application/json; charset=utf-8');
                echo $_GET['callback'] . '()';
            }
        }
        if (function_exists('hooks_message')) {
            hooks_message($userid, $to, $message);
        }
    }
    exit(0);
}
コード例 #3
0
function publishCometMessages($broadcast, $id)
{
    global $userid;
    global $plugins;
    if (in_array('block', $plugins)) {
        $blockedIds = getBlockedUserIDs();
        foreach ($broadcast as $tokey => $tovalue) {
            if (in_array($tovalue['to'], $blockedIds)) {
                array_splice($broadcast, $tokey, 1);
            }
        }
    }
    $sizeof_broadcast = sizeof($broadcast);
    for ($i = 0; $i < $sizeof_broadcast; $i++) {
        $insertedid = $id + $i;
        $key = '';
        if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) {
            $key = KEY_A . KEY_B . KEY_C;
        }
        $key_prefix = $broadcast[$i]['dir'] === 2 ? $userid : $broadcast[$i]['to'];
        $from = $broadcast[$i]['dir'] === 2 ? $broadcast[$i]['to'] : $userid;
        $self = $broadcast[$i]['dir'] === 2 ? 1 : 0;
        $channel = md5($key_prefix . $key);
        $comet = new Comet(KEY_A, KEY_B);
        $info = $comet->publish(array('channel' => $channel, 'message' => array("id" => $insertedid, "from" => $from, "message" => $broadcast[$i]['message'], "sent" => getTimeStamp(), "self" => $self)));
        if (function_exists('hooks_message')) {
            hooks_message($userid, $broadcast[$i]['to'], $broadcast[$i]['message']);
        }
    }
}
コード例 #4
0
ファイル: cometchat_shared.php プロジェクト: hughnguy/php
function broadcastMessage($broadcast)
{
    global $userid;
    global $cookiePrefix;
    global $chromeReorderFix;
    if (!empty($broadcast) && $userid > 0) {
        for ($i = 0; $i < sizeof($broadcast); $i++) {
            if (empty($broadcast[$i]['to']) || !isset($broadcast[$i]['message']) || $broadcast[$i]['to'] == '' || $broadcast[$i]['message'] == '') {
                array_splice($broadcast, $i, 1);
            }
            if ($broadcast[$i]['dir'] === 0) {
                $broadcast[$i]['message'] = str_ireplace('CC^CONTROL_', '', $broadcast[$i]['message']);
            }
        }
    }
    if (!empty($broadcast) && $userid > 0) {
        $sizeof_broadcast = sizeof($broadcast);
        if (!empty($_REQUEST['callback'])) {
            if (!empty($_SESSION['cometchat']['duplicates'][$_REQUEST['callback']])) {
                exit;
            }
            $_SESSION['cometchat']['duplicates'][$_REQUEST['callback']] = 1;
        }
        if (USE_COMET == 1) {
            $send_response = array();
            for ($i = 0; $i < $sizeof_broadcast; $i++) {
                $broadcast[$i]['message'] = $broadcast[$i]['message'];
                $insertedid = getTimeStamp() . rand(100, 999);
                $response = array("id" => $insertedid, "m" => $broadcast[$i]['message'], "from" => $broadcast[$i]['to']);
                array_push($send_response, $response);
                if (empty($_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to']])) {
                    if (empty($_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to'] . '_clear'])) {
                        unset($_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to'] . '_clear']);
                    }
                    $_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to']] = array();
                }
                $_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to']][$chromeReorderFix . $response['id']] = array("id" => $response['id'], "from" => $broadcast[$i]['to'], "message" => $response['m'], "self" => 1, "old" => 1, 'sent' => getTimeStamp());
                $key = '';
                if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) {
                    $key = KEY_A . KEY_B . KEY_C;
                }
                $key_prefix = $broadcast[$i]['dir'] === 2 ? $userid : $broadcast[$i]['to'];
                $from = $broadcast[$i]['dir'] === 2 ? $broadcast[$i]['to'] : $userid;
                $self = $broadcast[$i]['dir'] === 2 ? 1 : 0;
                $channel = md5($key_prefix . $key);
                $comet = new Comet(KEY_A, KEY_B);
                $info = $comet->publish(array('channel' => $channel, 'message' => array("from" => $from, "message" => $broadcast[$i]['message'], "sent" => $insertedid, "self" => $self)));
                if (function_exists('hooks_message')) {
                    hooks_message($userid, $broadcast[$i]['to'], $broadcast[$i]['message']);
                }
            }
            if (defined('SAVE_LOGS') && SAVE_LOGS == 1) {
                $sqlpart = "('" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "', '" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[0]['to']) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[0]['message']) . "','" . getTimeStamp() . "',0," . $broadcast[0]['dir'] . ")";
                for ($i = 1; $i < $sizeof_broadcast; $i++) {
                    $sqlpart .= ",('" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "', '" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[$i]['to']) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[$i]['message']) . "','" . getTimeStamp() . "',0," . $broadcast[$i]['dir'] . ")";
                }
                $sql = "insert into cometchat (cometchat.from,cometchat.to,cometchat.message,cometchat.sent,cometchat.read, cometchat.direction) values" . $sqlpart;
                $query = mysqli_query($GLOBALS['dbh'], $sql);
            }
        } else {
            $sqlpart = "('" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "', '" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[0]['to']) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[0]['message']) . "','" . getTimeStamp() . "',0," . $broadcast[0]['dir'] . ")";
            for ($i = 1; $i < $sizeof_broadcast; $i++) {
                $sqlpart .= ",('" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "', '" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[$i]['to']) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $broadcast[$i]['message']) . "','" . getTimeStamp() . "',0," . $broadcast[$i]['dir'] . ")";
            }
            $sql = "insert into cometchat (cometchat.from,cometchat.to,cometchat.message,cometchat.sent,cometchat.read, cometchat.direction) values" . $sqlpart;
            $query = mysqli_query($GLOBALS['dbh'], $sql);
            if (defined('DEV_MODE') && DEV_MODE == '1') {
                echo mysqli_error($GLOBALS['dbh']);
            }
            $insertedid = mysqli_insert_id($GLOBALS['dbh']);
            $send_response = array();
            for ($i = 0; $i < $sizeof_broadcast; $i++) {
                $response = array("id" => $insertedid + $i, "m" => $broadcast[$i]['message'], "from" => $broadcast[$i]['to']);
                array_push($send_response, $response);
                if (empty($_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to']])) {
                    if (empty($_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to'] . '_clear'])) {
                        unset($_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to'] . '_clear']);
                    }
                    $_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to']] = array();
                }
                $_SESSION['cometchat']['cometchat_user_' . $broadcast[$i]['to']][$chromeReorderFix . $response['id']] = array("id" => $response['id'], "from" => $broadcast[$i]['to'], "message" => $response['m'], "self" => 1, "old" => 1, 'sent' => getTimeStamp());
                if (function_exists('hooks_message')) {
                    hooks_message($userid, $broadcast[$i]['to'], $broadcast[$i]['message']);
                }
            }
        }
        return $send_response;
    }
}