Exemplo n.º 1
0
    /**
     * Process chat pages.
     *
     * @param Request $request Incoming request.
     * @return string Rendered page content or a redirect response.
     * @throws NotFoundException If the thread with specified ID and token is
     * not found.
     */
    public function indexAction(Request $request)
    {
        $thread_id = $request->attributes->getInt('thread_id');
        $token = $request->attributes->get('token');

        // We have to check that the thread is owned by the user.
        $is_own_thread = isset($_SESSION[SESSION_PREFIX . 'own_threads'])
            && in_array($thread_id, $_SESSION[SESSION_PREFIX . 'own_threads']);

        $thread = Thread::load($thread_id, $token);
        if (!$thread || !$is_own_thread) {
            throw new NotFoundException('The thread is not found.');
        }

        $page = setup_chatview_for_user(
            $this->getRouter(),
            $this->getAssetManager()->getUrlGenerator(),
            $request,
            $thread
        );

        // Build js application options
        $page['chatOptions'] = $page['chat'];

        // Initialize client side application
        $this->getAssetManager()->attachJs('js/compiled/chat_app.js');
        $this->getAssetManager()->attachJs(
            $this->startJsApplication($request, $page),
            AssetManagerInterface::INLINE,
            1000
        );

        // Expand page
        return $this->render('chat', $page);
    }
Exemplo n.º 2
0
        }
    }
    closedir($handle);
}
$preview = verifyparam("preview", "/^\\w+\$/", "default");
if (!in_array($preview, $stylelist)) {
    $preview = $stylelist[0];
}
$show = verifyparam("show", "/^(chat|chatsimple|nochat|mail|mailsent|survey|leavemessage|leavemessagesent|redirect|redirected|agentchat|agentrochat|error)\$/", "");
$showerrors = verifyparam("showerr", "/^on\$/", "") == "on";
$errors = array();
if ($showerrors || $show == 'error') {
    $errors[] = "Test error";
}
if ($show == 'chat' || $show == 'mail' || $show == 'leavemessage' || $show == 'leavemessagesent' || $show == 'chatsimple' || $show == 'nochat') {
    setup_chatview_for_user(array('threadid' => 0, 'userName' => getstring("chat.default.username"), 'ltoken' => 123), "ajaxed");
    $page['mailLink'] = "{$webimroot}/operator/themes.php?preview={$preview}&show=mail";
    $page['info'] = "";
    expand("../styles", "{$preview}", "{$show}.tpl");
    exit;
}
if ($show == 'survey') {
    loadsettings();
    setup_survey("Visitor", "", "", "", "http://google.com");
    setup_logo();
    expand("../styles", "{$preview}", "{$show}.tpl");
    exit;
}
if ($show == 'mailsent' || $show == 'error') {
    $page['email'] = "*****@*****.**";
    setup_logo();
Exemplo n.º 3
0
    /**
     * Process submitted prechat survey.
     *
     * @param array $args Associative array of arguments. It must contains the
     *   following keys:
     *    - 'threadId': for this function this param equals to null;
     *    - 'token': for this function this param equals to null;
     *    - 'name': string, user name;
     *    - 'email': string, user email;
     *    - 'message': string, first user message;
     *    - 'info': string, some info about user;
     *    - 'referrer': page user came from;
     *    - 'groupId': selected group id.
     * @return array Array of results. It contains following keys:
     *    - 'next': string, indicates what module run next;
     *    - 'options': options array for next module.
     */
    protected function apiProcessSurvey($args)
    {
        $visitor = visitor_from_request();

        // Get form values
        $first_message = $args['message'];
        $info = $args['info'];
        $email = $args['email'];
        $referrer = $args['referrer'];

        // Verify group id
        $group_id = '';
        $group = null;
        if (Settings::get('enablegroups') == '1') {
            if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) {
                $group = group_by_id($args['groupId']);
                if ($group) {
                    $group_id = $args['groupId'];
                }
            }
        }

        if (Settings::get('usercanchangename') == "1" && !empty($args['name'])) {
            $newname = $args['name'];
            if ($newname != $visitor['name']) {
                $data = strtr(base64_encode($newname), '+/=', '-_,');
                setcookie(USERNAME_COOKIE_NAME, $data, time() + 60 * 60 * 24 * 365);
                $visitor['name'] = $newname;
            }
        }

        // Check if there are online operators
        if (!has_online_operators($group_id)) {
            // Display leave message page
            $client_data = setup_leavemessage(
                $visitor['name'],
                $email,
                $group_id,
                $info,
                $referrer
            );
            $options = $client_data['leaveMessage'];
            $options['page'] += setup_logo($group);

            return array(
                'next' => 'leaveMessage',
                'options' => $options,
            );
        }

        // Initialize dialog
        $thread = chat_start_for_user(
            $group_id,
            false,
            $visitor['id'],
            $visitor['name'],
            $referrer,
            $info
        );

        // Send some messages
        if ($email) {
            $thread->postMessage(
                Thread::KIND_FOR_AGENT,
                getlocal('E-Mail: {0}', array($email), get_current_locale(), true)
            );
        }

        if ($first_message) {
            $posted_id = $thread->postMessage(
                Thread::KIND_USER,
                $first_message,
                array('name' => $visitor['name'])
            );
            $thread->shownMessageId = $posted_id;
            $thread->save();
        }

        // Prepare chat options
        $client_data = setup_chatview_for_user(
            $this->getRouter(),
            $this->getAssetManager()->getUrlGenerator(),
            $this->currentRequest,
            $thread
        );
        $options = $client_data['chat'];
        $options['page'] += setup_logo($group);

        return array(
            'next' => 'chat',
            'options' => $options,
        );
    }
Exemplo n.º 4
0
    $token = $thread['ltoken'];
    $level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
    $chatstyle = verifyparam("style", "/^\\w+\$/", "");
    header("Location: {$mibewroot}/client.php?thread={$threadid}&token={$token}&level={$level}" . ($chatstyle ? "&style={$chatstyle}" : ""));
    exit;
}
$token = verifyparam("token", "/^\\d{1,10}\$/");
$threadid = verifyparam("thread", "/^\\d{1,10}\$/");
$level = verifyparam("level", "/^(ajaxed|simple|old)\$/");
// We have to check that the thread is owned by the user.
$is_own_thread = isset($_SESSION['own_threads']) && in_array($threadid, $_SESSION['own_threads']);
$thread = thread_by_id($threadid);
if (!$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] || !$is_own_thread) {
    die("wrong thread");
}
setup_chatview_for_user($thread, $level);
$pparam = verifyparam("act", "/^(mailthread)\$/", "default");
if ($pparam == "mailthread") {
    expand("styles", getchatstyle(), "mail.tpl");
} else {
    if ($level == "ajaxed") {
        expand("styles", getchatstyle(), "chat.tpl");
    } else {
        if ($level == "simple") {
            expand("styles", getchatstyle(), "chatsimple.tpl");
        } else {
            if ($level == "old") {
                expand("styles", getchatstyle(), "nochat.tpl");
            }
        }
    }