$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(); expand("../styles", "{$preview}", "{$show}.tpl"); exit; } if ($show == 'redirect' || $show == 'redirected' || $show == 'agentchat' || $show == 'agentrochat') { setup_chatview_for_operator(array('threadid' => 0, 'userName' => getstring("chat.default.username"), 'remote' => "1.2.3.4", 'agentId' => 1, 'groupid' => 0, 'userid' => 'visitor1', 'locale' => $current_locale, 'ltoken' => $show == 'agentrochat' ? 124 : 123), array('operatorid' => $show == 'agentrochat' ? 2 : 1)); if ($show == 'redirect') { setup_redirect_links(0, $show == 'agentrochat' ? 124 : 123); } elseif ($show == 'redirected') {
} if (!has_online_operators($groupid)) { $page = array(); setup_logo(); setup_leavemessage($visitor['name'], $email, $firstmessage, $groupid, $groupname, $info, $referrer, can_show_captcha()); expand("styles", getchatstyle(), "leavemessage.tpl"); exit; } $show_survey = $settings['enablepresurvey'] == '1' && (!(isset($_POST['survey']) && $_POST['survey'] == 'on') || $settings["surveyaskcaptcha"] == "1" && !empty($survey_captcha_failed)); if ($show_survey) { $page = array(); setup_logo(); if (!empty($survey_captcha_failed)) { $errors[] = getlocal('errors.captcha'); } setup_survey($visitor['name'], $email, $groupid, $info, $referrer, can_show_captcha()); expand("styles", getchatstyle(), "survey.tpl"); exit; } $remoteHost = get_remote_host(); $userbrowser = $_SERVER['HTTP_USER_AGENT']; $link = connect(); if (!check_connections_from_remote($remoteHost, $link)) { mysql_close($link); die("number of connections from your IP is exceeded, try again later"); } $thread = create_thread($groupid, $visitor['name'], $remoteHost, $referrer, $current_locale, $visitor['id'], $userbrowser, $state_loading, $link); $_SESSION['threadid'] = $thread['threadid']; // Store own thread ids to restrict access for other people if (!isset($_SESSION['own_threads'])) { $_SESSION['own_threads'] = array();
/** * Starts the chat. * * @param Request $request Incoming request. * @return string|\Symfony\Component\HttpFoundation\RedirectResponse * Rendered page content or a redirect response. * @todo Split the action into pieces. */ public function startAction(Request $request) { // Check if we should force the user to use SSL $ssl_redirect = $this->sslRedirect($request); if ($ssl_redirect !== false) { return $ssl_redirect; } // Initialize client side application $this->getAssetManager()->attachJs('js/compiled/chat_app.js'); $thread = null; // Try to get thread from the session if (isset($_SESSION[SESSION_PREFIX . 'threadid'])) { $thread = Thread::reopen($_SESSION[SESSION_PREFIX . 'threadid']); } // Create new thread if (!$thread) { // Load group info $group_id = ''; $group_name = ''; $group = null; if (Settings::get('enablegroups') == '1') { $group_id = $request->query->get('group'); if (!preg_match("/^\d{1,10}$/", $group_id)) { $group_id = false; } if ($group_id) { $group = group_by_id($group_id); if (!$group) { $group_id = false; } else { $group_name = get_group_name($group); } } } // Get operator code $operator_code = $request->query->get('operator_code'); if (!preg_match("/^[A-z0-9_]+$/", $operator_code)) { $operator_code = false; } // Get visitor info $visitor = visitor_from_request(); $info = $request->query->get('info'); $email = $request->query->get('email'); // Get referrer $referrer = $request->query->get('url', $request->headers->get('referer')); if ($request->query->get('referrer')) { $referrer .= "\n" . $request->query->get('referrer'); } // Check if there are online operators if (!has_online_operators($group_id)) { // Display leave message page $page = array_merge_recursive( setup_logo($group), setup_leavemessage( $visitor['name'], $email, $group_id, $info, $referrer ) ); $page['leaveMessageOptions'] = $page['leaveMessage']; $this->getAssetManager()->attachJs( $this->startJsApplication($request, $page), AssetManagerInterface::INLINE, 1000 ); return $this->render('chat', $page); } // Get invitation info if (Settings::get('enabletracking') && !empty($_SESSION[SESSION_PREFIX . 'visitorid'])) { $invitation_state = invitation_state($_SESSION[SESSION_PREFIX . 'visitorid']); $visitor_is_invited = $invitation_state['invited']; } else { $visitor_is_invited = false; } // Get operator info $requested_operator = false; if ($operator_code) { $requested_operator = operator_by_code($operator_code); } // Check if survey should be displayed if (Settings::get('enablepresurvey') == '1' && !$visitor_is_invited && !$requested_operator) { // Display prechat survey $page = array_merge_recursive( setup_logo($group), setup_survey( $visitor['name'], $email, $group_id, $info, $referrer ) ); $page['surveyOptions'] = $page['survey']; $this->getAssetManager()->attachJs( $this->startJsApplication($request, $page), AssetManagerInterface::INLINE, 1000 ); return $this->render('chat', $page); } // Start chat thread $thread = chat_start_for_user( $group_id, $requested_operator, $visitor['id'], $visitor['name'], $referrer, $info ); } $path_args = array( 'thread_id' => intval($thread->id), 'token' => urlencode($thread->lastToken), ); $chat_style_name = $request->query->get('style'); if (preg_match("/^\w+$/", $chat_style_name)) { $path_args['style'] = $chat_style_name; } return $this->redirect($this->generateUrl('chat_user', $path_args)); }
$referrer = isset($_GET['url']) ? $_GET['url'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""); if (isset($_GET['referrer']) && $_GET['referrer']) { $referrer .= "\n" . $_GET['referrer']; } } if (!has_online_operators($groupid)) { $page = array(); setup_logo(); setup_leavemessage($visitor['name'], $email, $firstmessage, $groupid, $groupname, $info, $referrer, can_show_captcha()); expand("styles", getchatstyle(), "leavemessage.tpl"); exit; } if ($settings['enablepresurvey'] == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on')) { $page = array(); setup_logo(); setup_survey($visitor['name'], $email, $groupid, $info, $referrer); expand("styles", getchatstyle(), "survey.tpl"); exit; } $remoteHost = get_remote_host(); $userbrowser = $_SERVER['HTTP_USER_AGENT']; $link = connect(); if (!check_connections_from_remote($remoteHost, $link)) { mysql_close($link); die("number of connections from your IP is exceeded, try again later"); } $thread = create_thread($groupid, $visitor['name'], $remoteHost, $referrer, $current_locale, $visitor['id'], $userbrowser, $state_loading, $link); $_SESSION['threadid'] = $thread['threadid']; if ($referrer) { post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.came.from', array($referrer)), $link); }