/** * 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)); }
/** * 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, ); }
if ($newname != $visitor['name']) { $data = strtr(base64_encode(myiconv($mibew_encoding, "utf-8", $newname)), '+/=', '-_,'); setcookie($namecookie, $data, time() + 60 * 60 * 24 * 365); $visitor['name'] = $newname; } } } else { $firstmessage = NULL; $info = getgetparam('info'); $email = getgetparam('email'); $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; } $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");
/** * Returns content of the chat button. * * @param Request $request * @return string Rendered page content */ public function indexAction(Request $request) { $referer = $request->server->get('HTTP_REFERER', ''); // We need to display message about visited page only if the visitor // really change it. $new_page = empty($_SESSION[SESSION_PREFIX . 'last_visited_page']) || $_SESSION[SESSION_PREFIX . 'last_visited_page'] != $referer; // Display message about page change if ($referer && isset($_SESSION[SESSION_PREFIX . 'threadid']) && $new_page) { $thread = Thread::load($_SESSION[SESSION_PREFIX . 'threadid']); if ($thread && $thread->state != Thread::STATE_CLOSED) { $msg = getlocal("Visitor navigated to {0}", array($referer), $thread->locale, true); $thread->postMessage(Thread::KIND_FOR_AGENT, $msg); } } $_SESSION[SESSION_PREFIX . 'last_visited_page'] = $referer; $image = $request->query->get('i', ''); if (!preg_match("/^\\w+\$/", $image)) { $image = 'mibew'; } $lang = $request->query->get('lang', ''); if (!preg_match("/^[\\w-]{2,5}\$/", $lang)) { $lang = ''; } if (!$lang || !locale_is_available($lang)) { $lang = get_current_locale(); } $group_id = $request->query->get('group', ''); if (!preg_match("/^\\d{1,8}\$/", $group_id)) { $group_id = false; } if ($group_id) { if (Settings::get('enablegroups') == '1') { $group = group_by_id($group_id); if (!$group) { $group_id = false; } } else { $group_id = false; } } // Get image file content $image_postfix = has_online_operators($group_id) ? "on" : "off"; $file_name = "locales/{$lang}/button/{$image}_{$image_postfix}.png"; $content_type = 'image/png'; if (!is_readable($file_name)) { // Fall back to .gif image $file_name = "locales/{$lang}/button/{$image}_{$image_postfix}.gif"; $content_type = 'image/gif'; } $fh = fopen($file_name, 'rb'); if ($fh) { // Create response with image in body $file_size = filesize($file_name); $content = fread($fh, $file_size); fclose($fh); $response = new Response($content, 200); // Set correct content info $response->headers->set('Content-Type', $content_type); $response->headers->set('Content-Length', $file_size); } else { $response = new Response('Not found', 404); } // Disable caching $response->headers->addCacheControlDirective('no-cache', true); $response->headers->addCacheControlDirective('no-store', true); $response->headers->addCacheControlDirective('must-revalidate', true); $response->setExpires(new \DateTime('yesterday noon')); $response->headers->set('Pragma', 'no-cache'); return $response; }
if (!$lang || !locale_exists($lang)) { $lang = $current_locale; } $groupid = verifyparam("group", "/^\\d{1,8}\$/", ""); if ($groupid) { loadsettings(); if ($settings['enablegroups'] == '1') { $group = group_by_id($groupid); if (!$group) { $groupid = ""; } } else { $groupid = ""; } } $image_postfix = has_online_operators($groupid) ? "on" : "off"; $filename = "locales/{$lang}/button/{$image}_{$image_postfix}.gif"; $fp = fopen($filename, 'rb') or die("no image"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-Type: image/gif"); header("Content-Length: " . filesize($filename)); if (function_exists('fpassthru')) { @fpassthru($fp); } else { while (!feof($fp) && connection_status() == 0) { print fread($fp, 1024 * 8); flush(); } fclose($fp);