diff --git a/src/mibew/client.php b/src/mibew/client.php deleted file mode 100644 index 5d092bb4..00000000 --- a/src/mibew/client.php +++ /dev/null @@ -1,203 +0,0 @@ -render('nochat', $page); - exit; -} - -$action = verify_param("act", "/^(invitation|mailthread)$/", "default"); - -if ($action == 'invitation' && Settings::get('enabletracking')) { - // Check if user invited to chat - $invitation_state = invitation_state($_SESSION['visitorid']); - - if ($invitation_state['invited'] && $invitation_state['threadid']) { - $thread = Thread::load($invitation_state['threadid']); - - // Prepare page - $page = setup_invitation_view($thread); - - // Build js application options - $page['invitationOptions'] = json_encode($page['invitation']); - // Expand page - $chat_style->render('chat', $page); - exit; - } -} - -if (!isset($_GET['token']) || !isset($_GET['thread'])) { - - $thread = null; - if (isset($_SESSION['threadid'])) { - $thread = Thread::reopen($_SESSION['threadid']); - } - - if (!$thread) { - - // Load group info - $group_id = ""; - $group_name = ""; - $group = null; - if (Settings::get('enablegroups') == '1') { - $group_id = verify_param("group", "/^\d{1,8}$/", ""); - if ($group_id) { - $group = group_by_id($group_id); - if (!$group) { - $group_id = ""; - } else { - $group_name = get_group_name($group); - } - } - } - - // Get operator code - $operator_code = empty($_GET['operator_code']) ? '' : $_GET['operator_code']; - if (!preg_match("/^[A-z0-9_]+$/", $operator_code)) { - $operator_code = false; - } - - // Get visitor info - $visitor = visitor_from_request(); - $info = get_get_param('info'); - $email = get_get_param('email'); - - // Get referrer - $referrer = isset($_GET['url']) - ? $_GET['url'] - : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""); - - if (isset($_GET['referrer']) && $_GET['referrer']) { - $referrer .= "\n" . $_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'] = json_encode($page['leaveMessage']); - $chat_style->render('chat', $page); - exit; - } - - // Get invitation info - if (Settings::get('enabletracking')) { - $invitation_state = invitation_state($_SESSION['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'] = json_encode($page['survey']); - $chat_style->render('chat', $page); - exit; - } - - // Start chat thread - $thread = chat_start_for_user( - $group_id, - $requested_operator, - $visitor['id'], - $visitor['name'], - $referrer, - $info - ); - } - $thread_id = $thread->id; - $token = $thread->lastToken; - $chat_style_name = verify_param("style", "/^\w+$/", ""); - $redirect_to = MIBEW_WEB_ROOT . "/client.php?thread=" . intval($thread_id) - . "&token=" . urlencode($token) - . ($chat_style_name ? "&style=" . urlencode($chat_style_name) : ""); - header("Location: " . $redirect_to); - exit; -} - -$token = verify_param("token", "/^\d{1,8}$/"); -$thread_id = verify_param("thread", "/^\d{1,8}$/"); - -$thread = Thread::load($thread_id, $token); -if (!$thread) { - die("wrong thread"); -} - -$page = setup_chatview_for_user($thread); - -if ($action == "mailthread") { - $chat_style->render('mail', $page); -} else { - // Build js application options - $page['chatOptions'] = json_encode($page['chat']); - // Expand page - $chat_style->render('chat', $page); -} diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index 855c6cea..023481e1 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -526,14 +526,14 @@ function setup_chatview_for_user(Thread $thread) $params = "thread=" . $thread->id . "&token=" . $thread->lastToken; // Set link to send mail page - $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/client.php?" + $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/chat?" . $params . "&act=mailthread"; // Set SSL link if (Settings::get('enablessl') == "1" && !is_secure_request()) { $data['chat']['links']['ssl'] = get_app_location(true, true) - . "/client.php?" + . "/chat?" . $params; } diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php new file mode 100644 index 00000000..81cfd1d1 --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php @@ -0,0 +1,232 @@ +sslRedirect($request); + if ($ssl_redirect !== false) { + return $ssl_redirect; + } + + // Do not support old browsers at all + if (get_remote_level($request->headers->get('User-Agent')) == 'old') { + // Create page array + $page = array_merge_recursive( + setup_logo() + ); + + return $this->render('nochat', $page); + } + + $action = $request->query->get('act'); + if (!in_array($action, array('invitation', 'mailthread'))) { + $action = 'default'; + } + + if ($action == 'invitation' && Settings::get('enabletracking')) { + // Check if user invited to chat + $invitation_state = invitation_state($_SESSION['visitorid']); + + if ($invitation_state['invited'] && $invitation_state['threadid']) { + $thread = Thread::load($invitation_state['threadid']); + + // Prepare page + $page = setup_invitation_view($thread); + + // Build js application options + $page['invitationOptions'] = json_encode($page['invitation']); + + // Expand page + return $this->render('chat', $page); + } + } + + if (!$request->query->has('token') || !$request->query->has('thread')) { + return $this->startChat($request); + } + + // Get and validate thread id + $thread_id = $request->query->get('thread'); + if (!preg_match("/^\d{1,10}$/", $thread_id)) { + throw new BadRequestException('Wrong value of "thread" argument.'); + } + + // Get token and verify it + $token = $request->query->get('token'); + if (!preg_match("/^\d{1,10}$/", $token)) { + throw new BadRequestException('Wrong value of "token" argument.'); + } + + $thread = Thread::load($thread_id, $token); + if (!$thread) { + throw new BadRequestException('Wrong thread.'); + } + + $page = setup_chatview_for_user($thread); + + if ($action == 'mailthread') { + return $this->render('mail', $page); + } else { + // Build js application options + $page['chatOptions'] = json_encode($page['chat']); + + // Expand page + return $this->render('chat', $page); + } + } + + protected function startChat(Request $request) + { + $thread = null; + if (isset($_SESSION['threadid'])) { + $thread = Thread::reopen($_SESSION['threadid']); + } + + 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'] = json_encode($page['leaveMessage']); + + return $this->render('chat', $page); + } + + // Get invitation info + if (Settings::get('enabletracking')) { + $invitation_state = invitation_state($_SESSION['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'] = json_encode($page['survey']); + + 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' => 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)); + } +} diff --git a/src/mibew/libs/classes/Mibew/Controller/WidgetController.php b/src/mibew/libs/classes/Mibew/Controller/WidgetController.php index d58b1281..ddfd1968 100644 --- a/src/mibew/libs/classes/Mibew/Controller/WidgetController.php +++ b/src/mibew/libs/classes/Mibew/Controller/WidgetController.php @@ -118,8 +118,7 @@ class WidgetController extends AbstractController $response_data['data']['invitation'] = array( 'operatorName' => htmlspecialchars($operator_name), 'avatarUrl' => htmlspecialchars($operator['vcavatar']), - 'threadUrl' => ($request->getUriForPath('/client.php') - . '?act=invitation'), + 'threadUrl' => $this->generateUrl('chat_user', array('act' => 'invitation')), 'acceptCaption' => getlocal('invitation.accept.caption'), ); diff --git a/src/mibew/libs/getcode.php b/src/mibew/libs/getcode.php index 65f203af..89665d3f 100644 --- a/src/mibew/libs/getcode.php +++ b/src/mibew/libs/getcode.php @@ -54,7 +54,7 @@ function generate_button( $disable_invitation ) { $app_location = get_app_location($show_host, $force_secure); - $link = $app_location . "/client.php"; + $link = $app_location . "/chat"; if ($locale) { $link = append_query($link, "locale=$locale"); } diff --git a/src/mibew/libs/routing.yml b/src/mibew/libs/routing.yml index f193bd8e..fd85d722 100644 --- a/src/mibew/libs/routing.yml +++ b/src/mibew/libs/routing.yml @@ -13,6 +13,12 @@ chat_operator_redirect: _controller: Mibew\Controller\Chat\Operator\RedirectController::indexAction _access_check: Mibew\AccessControl\Check\LoggedInCheck +## User's chat +chat_user: + path: /chat + defaults: + _controller: Mibew\Controller\Chat\User\ChatController::indexAction + # Pages that are available for all users button: path: /b