Ejemplo n.º 1
0
/**
 * Ajax Callback
 *
 * @access public
 * @return void
 */
function sc_chat_ajax_callback()
{
    $response = array();
    try {
        // Handling the supported actions:
        switch ($_GET['mode']) {
            case 'login':
                $response = Chat::login(@$_POST['f_chat_user_name'], @$_POST['f_chat_user_email'], $_POST['f_chat_is_admin']);
                break;
            case 'send_contact_from':
                $response = Chat::send_contact_from($_POST);
                break;
            case 'is_user_logged_in':
                $response = Chat::is_user_logged_in();
                break;
            case 'logout':
                $response = Chat::logout();
                break;
            case 'online':
                $response = Chat::online();
                break;
            case 'offline':
                $response = Chat::offline();
                break;
            case 'send_chat_msg':
                $response = Chat::send_chat_msg($_POST);
                break;
            case 'get_online_users':
                $response = Chat::get_online_users();
                break;
            case 'get_chat_lines':
                $response = Chat::get_chat_lines($_GET['last_log_ID'], $_GET['sender']);
                break;
            case 'user_info':
                $response = Chat::user_info($_GET['ID']);
                break;
            default:
                throw new Exception('Wrong action');
        }
    } catch (Exception $e) {
        $response['error'] = $e->getMessage();
    }
    // Response output
    header("Content-Type: application/json");
    echo json_encode($response);
    exit;
}
Ejemplo n.º 2
0
require "classes/ChatUser.class.php";
session_name('webchat');
session_start();
if (get_magic_quotes_gpc()) {
    // If magic quotes is enabled, strip the extra slashes
    array_walk_recursive($_GET, create_function('&$v,$k', '$v = stripslashes($v);'));
    array_walk_recursive($_POST, create_function('&$v,$k', '$v = stripslashes($v);'));
}
try {
    // Connecting to the database
    DB::init($dbOptions);
    $response = array();
    // Handling the supported actions:
    switch ($_GET['action']) {
        case 'login':
            $response = Chat::login($_POST['name'], $_POST['email']);
            break;
        case 'checkLogged':
            $response = Chat::checkLogged();
            break;
        case 'logout':
            $response = Chat::logout();
            break;
        case 'submitChat':
            $response = Chat::submitChat($_POST['chatText']);
            break;
        case 'getUsers':
            $response = Chat::getUsers();
            break;
        case 'getChats':
            $response = Chat::getChats($_GET['lastID']);