/** * Prepares and displays chatroom and connects user to it. * @param ilChatroom $room * @param ilChatroomUser $chat_user */ private function showRoom(ilChatroom $room, ilChatroomUser $chat_user) { /** * @var $tpl ilTemplate $tpl * @var $ilUser ilObjUser * @var $ilCtrl ilCtrl * @var $rbacsystem ilRbacSystem * @var $lng ilLanguage * @var $ilNavigationHistory ilNavigationHistory */ global $tpl, $ilUser, $ilCtrl, $rbacsystem, $lng, $ilNavigationHistory; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID); $ilCtrl->redirectByClass('ilrepositorygui', ''); } $user_id = $chat_user->getUserId($ilUser); $ilNavigationHistory->addItem($_GET['ref_id'], $ilCtrl->getLinkTargetByClass('ilrepositorygui', 'view'), 'chtr'); if ($room->isUserBanned($user_id)) { $this->cancelJoin($lng->txt('banned')); return; } $scope = $room->getRoomId(); $connector = $this->gui->getConnector(); $response = @$connector->connect($scope, $user_id); if (!$response) { ilUtil::sendFailure($lng->txt('unable_to_connect'), true); $ilCtrl->redirectByClass('ilinfoscreengui', 'info'); } if (!$room->isSubscribed($chat_user->getUserId()) && $room->connectUser($chat_user)) { $messageObject = array('type' => 'connected', 'users' => array(array('login' => $chat_user->getUsername(), 'id' => $user_id)), 'timestamp' => time() * 1000); $message = json_encode($messageObject); $connector->sendMessage($scope, $message); $room->addHistoryEntry($messageObject); } $connection_info = json_decode($response); $settings = $connector->getSettings(); $known_private_room = $room->getActivePrivateRooms($ilUser->getId()); $initial = new stdClass(); $initial->users = $room->getConnectedUsers(); $initial->private_rooms = array_values($known_private_room); $initial->redirect_url = $ilCtrl->getLinkTarget($this->gui, 'view-lostConnection', '', false, false); $initial->private_rooms_enabled = (bool) $room->getSetting('private_rooms_enabled'); $initial->userinfo = array('moderator' => $rbacsystem->checkAccess('moderate', (int) $_GET['ref_id']), 'userid' => $chat_user->getUserId()); $smileys = array(); include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php'; if ($settings->getSmiliesEnabled()) { $smileys_array = ilChatroomSmilies::_getSmilies(); foreach ($smileys_array as $smiley_array) { $new_keys = array(); $new_val = ''; foreach ($smiley_array as $key => $value) { if ($key == 'smiley_keywords') { $new_keys = explode("\n", $value); } if ($key == 'smiley_fullpath') { $new_val = $value; } } if (!$new_keys || !$new_val) { continue; } foreach ($new_keys as $new_key) { $smileys[$new_key] = $new_val; } } $initial->smileys = $smileys; } else { $initial->smileys = '{}'; } $initial->messages = array(); if (isset($_REQUEST['sub'])) { if ($known_private_room[$_REQUEST['sub']]) { if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $_REQUEST['sub'])) { $initial->messages[] = array('type' => 'error', 'message' => $lng->txt('not_allowed_to_enter')); } else { $scope = $room->getRoomId(); $params = array(); $params['user'] = $chat_user->getUserId(); $params['sub'] = $_REQUEST['sub']; $params['message'] = json_encode(array('type' => 'private_room_entered', 'user' => $user_id)); $query = http_build_query($params); $connector = $this->gui->getConnector(); $response = $connector->enterPrivateRoom($scope, $query); $responseObject = json_decode($response); if ($responseObject->success == true) { $room->subscribeUserToPrivateRoom($params['sub'], $params['user']); } $message = json_encode(array('type' => 'private_room_entered', 'user' => $params['user'], 'sub' => $params['sub'])); $connector->sendMessage($room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub'])); $initial->enter_room = $_REQUEST['sub']; $initial->messages[] = array('type' => 'notice', 'user' => $params['user'], 'sub' => $params['sub'], 'entersub' => 1); } if ($_SESSION['show_invitation_message']) { $initial->messages[] = array('type' => 'notice', 'message' => $lng->txt('user_invited'), 'sub' => $_REQUEST['sub']); unset($_SESSION['show_invitation_message']); } } else { $initial->messages[] = array('type' => 'error', 'message' => $lng->txt('user_invited')); } } if ((int) $room->getSetting('display_past_msgs')) { $initial->messages = array_merge($initial->messages, array_reverse($room->getLastMessages($room->getSetting('display_past_msgs'), $chat_user))); } $roomTpl = new ilTemplate('tpl.chatroom.html', true, true, 'Modules/Chatroom'); $roomTpl->setVariable('SESSION_ID', $connection_info->{'session-id'}); $roomTpl->setVariable('BASEURL', $settings->getBaseURL()); $roomTpl->setVariable('INSTANCE', $settings->getInstance()); $roomTpl->setVariable('SCOPE', $scope); $roomTpl->setVariable('MY_ID', $user_id); $roomTpl->setVariable('INITIAL_DATA', json_encode($initial)); $roomTpl->setVariable('POSTURL', $ilCtrl->getLinkTarget($this->gui, 'postMessage', '', true, true)); $roomTpl->setVariable('ACTIONS', $lng->txt('actions')); $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM', $lng->txt('create_private_room_label')); $roomTpl->setVariable('LBL_USER', $lng->txt('user')); $roomTpl->setVariable('LBL_USER_TEXT', $lng->txt('invite_username')); $roomTpl->setVariable('LBL_AUTO_SCROLL', $lng->txt('auto_scroll')); $roomTpl->setVariable('INITIAL_USERS', json_encode($room->getConnectedUsers())); $this->renderFontSettings($roomTpl, array()); $this->renderFileUploadForm($roomTpl); $this->renderSendMessageBox($roomTpl); $this->renderLanguageVariables($roomTpl); $roomRightTpl = new ilTemplate('tpl.chatroom_right.html', true, true, 'Modules/Chatroom'); $this->renderRightUsersBlock($roomRightTpl); require_once 'Services/UIComponent/Panel/classes/class.ilPanelGUI.php'; $right_content_panel = ilPanelGUI::getInstance(); $right_content_panel->setHeading($lng->txt('users')); $right_content_panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY); $right_content_panel->setHeadingStyle(ilPanelGUI::HEADING_STYLE_BLOCK); $right_content_panel->setBody($roomRightTpl->get()); $tpl->setContent($roomTpl->get()); $tpl->setRightContent($right_content_panel->getHTML()); }