diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index e6ac16d8..a374eead 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -23,6 +23,8 @@ use Mibew\Settings; use Mibew\Thread; use Mibew\Style\ChatStyle; use Mibew\Style\PageStyle; +use Mibew\Routing\Generator\SecureUrlGeneratorInterface as UrlGeneratorInterface; +use Symfony\Component\HttpFoundation\Request; /** * Convert messages to formated text @@ -525,11 +527,18 @@ function setup_chatview_for_user(Thread $thread) /** * Prepare some data for chat for operator * - * @param Thread $thread thread object + * @param UrlGeneratorInterface $url_generator A URL generator object. + * @param Request $request The current request. + * @param Thread $thread thread object. + * @param array $operator Operator's data. * @return array Array of chat view data */ -function setup_chatview_for_operator(Thread $thread, $operator) -{ +function setup_chatview_for_operator( + UrlGeneratorInterface $url_generator, + Request $request, + Thread $thread, + $operator +) { $data = setup_chatview($thread); // Load JavaScript plugins and JavaScripts, CSS files required by them @@ -549,23 +558,29 @@ function setup_chatview_for_operator(Thread $thread, $operator) ); // Set SSL link - if (Settings::get('enablessl') == "1" && !is_secure_request()) { - $data['chat']['links']['ssl'] = get_app_location(true, true) - . "/operator/chat/" . $thread->id . '/' . $thread->lastToken; + if (Settings::get('enablessl') == "1" && !$request->isSecure()) { + $data['chat']['links']['ssl'] = $url_generator->generateSecure( + 'chat_operator', + array( + 'thread_id' => $thread->id, + 'token' => $thread->lastToken, + ), + UrlGeneratorInterface::ABSOLUTE_URL + ); } // Set history window params - $data['chat']['links']['history'] = MIBEW_WEB_ROOT - . '/operator/history/user/' - . ((string) $thread->userId); + $data['chat']['links']['history'] = $url_generator->generate( + 'history_user', + array('user_id' => $thread->userId) + ); // Set tracking params if (Settings::get('enabletracking')) { $visitor = track_get_visitor_by_thread_id($thread->id); - $tracked_link_params = array("visitor" => "" . $visitor['visitorid']); - $data['chat']['links']['tracked'] = add_params( - MIBEW_WEB_ROOT . "/operator/history/user-track", - $tracked_link_params + $data['chat']['links']['tracked'] = $url_generator->generate( + 'history_user_track', + array('visitor' => $visitor['visitorid']) ); } @@ -592,8 +607,13 @@ function setup_chatview_for_operator(Thread $thread, $operator) $data['chat']['messageForm']['predefinedAnswers'] = $predefined_answers; } // Set link to user redirection page - $data['chat']['links']['redirect'] = MIBEW_WEB_ROOT . "/operator/chat/" - . $thread->id . '/' . $thread->lastToken . '/redirection-links'; + $data['chat']['links']['redirect'] = $url_generator->generate( + 'chat_operator_redirection_links', + array( + 'thread_id' => $thread->id, + 'token' => $thread->lastToken, + ) + ); $data['namePostfix'] = ""; diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/OperatorChatController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/OperatorChatController.php index 0faed538..b002c880 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/OperatorChatController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/OperatorChatController.php @@ -61,7 +61,12 @@ class OperatorChatController extends AbstractController return $this->showErrors(array('Cannot view threads')); } - $page = setup_chatview_for_operator($thread, $operator); + $page = setup_chatview_for_operator( + $this->getRouter(), + $request, + $thread, + $operator + ); // Build js application options $page['chatOptions'] = json_encode($page['chat']); diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php index 5b045826..d979641c 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php @@ -63,8 +63,18 @@ class RedirectController extends AbstractController } $page = array_merge_recursive( - setup_chatview_for_operator($thread, $operator), - setup_redirect_links($this->getRouter()->getGenerator(), $thread_id, $operator, $token) + setup_chatview_for_operator( + $this->getRouter(), + $request, + $thread, + $operator + ), + setup_redirect_links( + $this->getRouter()->getGenerator(), + $thread_id, + $operator, + $token + ) ); // Render the page with redirection links.