4 require_once
'Modules/Chatroom/classes/class.ilChatroom.php';
5 require_once
'Modules/Chatroom/classes/class.ilChatroomUser.php';
56 $ilCtrl->setParameterByClass(
'ilrepositorygui',
'ref_id', ROOT_FOLDER_ID);
57 $ilCtrl->redirectByClass(
'ilrepositorygui',
'');
60 $user_id = $chat_user->
getUserId($ilUser);
62 $ilNavigationHistory->addItem(
$_GET[
'ref_id'], $ilCtrl->getLinkTargetByClass(
'ilrepositorygui',
'view'),
'chtr');
71 $connector = $this->gui->getConnector();
72 $response = @$connector->connect($scope, $user_id);
77 $ilCtrl->redirectByClass(
'ilinfoscreengui',
'info');
82 $messageObject = array(
83 'type' =>
'connected',
90 'timestamp' => time() * 1000
92 $message = json_encode($messageObject);
93 $connector->sendMessage(
101 $connection_info = json_decode($response);
102 $settings = $connector->getSettings();
105 $initial =
new stdClass();
107 $initial->private_rooms = array_values($known_private_room);
108 $initial->redirect_url = $ilCtrl->getLinkTarget($this->gui,
'view-lostConnection',
'',
false,
false);
109 $initial->private_rooms_enabled = (boolean)$room->
getSetting(
'private_rooms_enabled');
111 $initial->userinfo = array(
112 'moderator' => $rbacsystem->checkAccess(
'moderate', (
int)
$_GET[
'ref_id']),
118 include_once(
'Modules/Chatroom/classes/class.ilChatroomSmilies.php');
120 if($settings->getSmiliesEnabled())
123 foreach($smileys_array as $smiley_array)
127 foreach($smiley_array as $key => $value)
129 if($key ==
'smiley_keywords')
131 $new_keys = explode(
"\n", $value);
134 if($key ==
'smiley_fullpath')
140 if(!$new_keys || !$new_val)
145 foreach($new_keys as $new_key)
147 $smileys[$new_key] = $new_val;
151 $initial->smileys = $smileys;
155 $initial->smileys =
'{}';
158 $initial->messages = array();
162 if($known_private_room[
$_REQUEST[
'sub']])
166 $initial->messages[] = array(
168 'message' => $lng->txt(
'not_allowed_to_enter'),
175 $params[
'user'] = $chat_user->
getUserId();
176 $params[
'sub'] = $_REQUEST[
'sub'];
178 $params[
'message'] = json_encode(
180 'type' =>
'private_room_entered',
185 $query = http_build_query($params);
186 $connector = $this->gui->getConnector();
187 $response = $connector->enterPrivateRoom($scope,
$query);
189 $responseObject = json_decode($response);
191 if($responseObject->success ==
true)
196 $message = json_encode(array(
197 'type' =>
'private_room_entered',
198 'user' => $params[
'user'],
199 'sub' => $params[
'sub']
202 $connector->sendMessage($room->
getRoomId(), $message, array(
'public' => 1,
'sub' => $params[
'sub']));
204 $initial->enter_room = $_REQUEST[
'sub'];
205 $initial->messages[] = array(
207 'user' => $params[
'user'],
208 'sub' => $params[
'sub'],
215 $initial->messages[] = array(
217 'message' => $lng->txt(
'user_invited'),
218 'sub' => $_REQUEST[
'sub']
220 unset(
$_SESSION[
'show_invitation_message']);
225 $initial->messages[] = array(
227 'message' => $lng->txt(
'user_invited'),
232 if((
int)$room->
getSetting(
'display_past_msgs'))
234 $initial->messages = array_merge($initial->messages, array_reverse($room->
getLastMessages($room->
getSetting(
'display_past_msgs'), $chat_user)));
237 $roomTpl =
new ilTemplate(
'tpl.chatroom.html',
true,
true,
'Modules/Chatroom');
238 $roomTpl->setVariable(
'SESSION_ID', $connection_info->{
'session-id'});
239 $roomTpl->setVariable(
'BASEURL', $settings->getBaseURL());
240 $roomTpl->setVariable(
'INSTANCE', $settings->getInstance());
241 $roomTpl->setVariable(
'SCOPE', $scope);
242 $roomTpl->setVariable(
'MY_ID', $user_id);
243 $roomTpl->setVariable(
'INITIAL_DATA', json_encode($initial));
244 $roomTpl->setVariable(
'POSTURL', $ilCtrl->getLinkTarget($this->gui,
'postMessage',
'',
true,
true));
246 $roomTpl->setVariable(
'ACTIONS', $lng->txt(
'actions'));
247 $roomTpl->setVariable(
'LBL_CREATE_PRIVATE_ROOM', $lng->txt(
'create_private_room_label'));
248 $roomTpl->setVariable(
'LBL_USER', $lng->txt(
'user'));
249 $roomTpl->setVariable(
'LBL_USER_TEXT', $lng->txt(
'invite_username'));
250 $roomTpl->setVariable(
'LBL_AUTO_SCROLL', $lng->txt(
'auto_scroll'));
254 $this->renderFontSettings($roomTpl, array());
256 $this->renderSendMessageBox($roomTpl);
257 $this->renderRightUsersDock($roomTpl);
259 $tpl->setVariable(
'ADM_CONTENT', $roomTpl->get());
265 protected function renderRightUsersDock(
ilTemplate $roomTpl)
272 $js_translations = array(
273 'LBL_MAINROOM' =>
'chat_mainroom',
274 'LBL_LEAVE_PRIVATE_ROOM' =>
'leave_private_room',
275 'LBL_JOIN' =>
'chat_join',
276 'LBL_DELETE_PRIVATE_ROOM' =>
'delete_private_room',
277 'LBL_INVITE_TO_PRIVATE_ROOM' =>
'invite_to_private_room',
278 'LBL_KICK' =>
'chat_kick',
279 'LBL_BAN' =>
'chat_ban',
280 'LBL_KICK_QUESTION' =>
'kick_question',
281 'LBL_BAN_QUESTION' =>
'ban_question',
282 'LBL_ADDRESS' =>
'chat_address',
283 'LBL_WHISPER' =>
'chat_whisper',
284 'LBL_CONNECT' =>
'chat_connection_established',
285 'LBL_DISCONNECT' =>
'chat_connection_disconnected',
286 'LBL_TO_MAINROOM' =>
'chat_to_mainroom',
287 'LBL_CREATE_PRIVATE_ROOM_JS' =>
'chat_create_private_room_button',
288 'LBL_WELCOME_TO_CHAT' =>
'welcome_to_chat',
289 'LBL_USER_INVITED' =>
'user_invited',
290 'LBL_USER_KICKED' =>
'user_kicked',
291 'LBL_USER_INVITED_SELF' =>
'user_invited_self',
292 'LBL_PRIVATE_ROOM_CLOSED' =>
'private_room_closed',
293 'LBL_PRIVATE_ROOM_ENTERED' =>
'private_room_entered',
294 'LBL_PRIVATE_ROOM_LEFT' =>
'private_room_left',
295 'LBL_PRIVATE_ROOM_ENTERED_USER' =>
'private_room_entered_user',
296 'LBL_KICKED_FROM_PRIVATE_ROOM' =>
'kicked_from_private_room',
298 'LBL_CANCEL' =>
'cancel',
299 'LBL_WHISPER_TO' =>
'whisper_to',
300 'LBL_SPEAK_TO' =>
'speak_to',
301 'LBL_HISTORY_CLEARED' =>
'history_cleared',
302 'LBL_CLEAR_ROOM_HISTORY' =>
'clear_room_history',
303 'LBL_CLEAR_ROOM_HISTORY_QUESTION' =>
'clear_room_history_question',
304 'LBL_END_WHISPER' =>
'end_whisper',
305 'LBL_SHOW_SETTINGS_JS' =>
'show_settings',
306 'LBL_HIDE_SETTINGS' =>
'hide_settings',
307 'LBL_TIMEFORMAT' =>
'lang_timeformat_no_sec',
308 'LBL_DATEFORMAT' =>
'lang_dateformat'
310 foreach($js_translations as $placeholder => $lng_variable)
312 $roomTpl->
setVariable($placeholder, json_encode($lng->txt($lng_variable)));
315 $roomTpl->
setVariable(
'LBL_CREATE_PRIVATE_ROOM', $lng->txt(
'chat_create_private_room_button'));
316 $roomTpl->
setVariable(
'LBL_CREATE_PRIVATE_ROOM_TEXT', $lng->txt(
'create_private_room_text'));
317 $roomTpl->
setVariable(
'LBL_USERS', $lng->txt(
'users'));
318 $roomTpl->
setVariable(
'LBL_LAYOUT', $lng->txt(
'layout'));
319 $roomTpl->
setVariable(
'LBL_SHOW_SETTINGS', $lng->txt(
'show_settings'));
320 $roomTpl->
setVariable(
'LBL_NO_FURTHER_USERS', $lng->txt(
'no_further_users'));
321 $roomTpl->
setVariable(
'LBL_USER_IN_ROOM', $lng->txt(
'user_in_room'));
322 $roomTpl->
setVariable(
'LBL_USER_IN_ILIAS', $lng->txt(
'user_in_ilias'));
328 protected function renderSendMessageBox(
ilTemplate $roomTpl)
335 $roomTpl->
setVariable(
'LBL_MESSAGE', $lng->txt(
'chat_message'));
336 $roomTpl->
setVariable(
'LBL_TOALL', $lng->txt(
'chat_message_to_all'));
337 $roomTpl->
setVariable(
'LBL_OPTIONS', $lng->txt(
'chat_message_options'));
338 $roomTpl->
setVariable(
'LBL_DISPLAY', $lng->txt(
'chat_message_display'));
339 $roomTpl->
setVariable(
'LBL_SEND', $lng->txt(
'send'));
357 require_once
'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
361 $selectionForm = $formFactory->getUserChatNameSelectionForm($name_options);
363 $ilCtrl->saveParameter($this->gui,
'sub');
365 $selectionForm->addCommandButton(
'view-joinWithCustomName', $lng->txt(
'enter'));
366 $selectionForm->setFormAction(
367 $ilCtrl->getFormAction($this->gui,
'view-joinWithCustomName')
370 $tpl->setVariable(
'ADM_CONTENT', $selectionForm->getHtml());
376 private function setupTemplate()
383 $tpl->addJavaScript(
'Modules/Chatroom/js/colorpicker/jquery.colorPicker.js');
384 $tpl->addJavaScript(
'Modules/Chatroom/js/chat.js');
385 $tpl->addJavaScript(
'Modules/Chatroom/js/iliaschat.jquery.js');
386 $tpl->addJavaScript(
'Services/jQuery/js/jquery.outside.events.min.js');
387 $tpl->addJavaScript(
'Modules/Chatroom/js/json2.js');
389 $tpl->addJavaScript(
'./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js');
391 $tpl->addCSS(
'Modules/Chatroom/js/colorpicker/colorPicker.css');
392 $tpl->addCSS(
'Modules/Chatroom/templates/default/style.css');
401 public function joinWithCustomName()
409 $this->gui->switchToVisibleMode();
410 $this->setupTemplate();
416 if($_REQUEST[
'custom_username_radio'] ==
'custom_username')
418 $username = $_REQUEST[
'custom_username_text'];
420 elseif(method_exists($chat_user,
'build' . $_REQUEST[
'custom_username_radio']))
422 $username = $chat_user->{
'build' . $_REQUEST[
'custom_username_radio']}();
429 if(!
$failure && trim($username) !=
'')
431 $chat_user->setUsername($username);
432 $this->showRoom($room, $chat_user);
437 $this->showNameSelection($chat_user);
447 public function executeDefault($method)
456 include_once
'Modules/Chatroom/classes/class.ilChatroom.php';
460 $this->gui->switchToVisibleMode();
461 $this->setupTemplate();
463 $chatSettings =
new ilSetting(
'chatroom');
464 if(!$chatSettings->get(
'chat_enabled'))
466 $ilCtrl->redirect($this->gui,
'settings-general');
472 if(!$room->
getSetting(
'allow_anonymous') && $ilUser->isAnonymous())
474 $this->cancelJoin($lng->txt(
'anonymous_not_allowed'));
480 if($room->
getSetting(
'allow_custom_usernames'))
484 $chat_user->setUsername($chat_user->getUsername());
485 $this->showRoom($room, $chat_user);
489 $this->showNameSelection($chat_user);
494 $chat_user->setUsername($ilUser->getLogin());
495 $this->showRoom($room, $chat_user);
502 public function invitePD()
510 $chatSettings =
new ilSetting(
'chatroom');
511 if(!$chatSettings->get(
'chat_enabled'))
513 $ilCtrl->redirect($this->gui,
'settings-general');
518 $user_id = $_REQUEST[
'usr_id'];
519 $connector = $this->gui->getConnector();
521 $response = $connector->createPrivateRoom($room,
$title, $chat_user);
522 $connector->inviteToPrivateRoom($room, $response->id, $ilUser, $user_id);
523 $room->sendInvitationNotification($this->gui, $chat_user, $user_id, $response->id);
525 $_REQUEST[
'sub'] = $response->id;
527 $_SESSION[
'show_invitation_message'] = $user_id;
529 $ilCtrl->setParameter($this->gui,
'sub', $response->id);
530 $ilCtrl->redirect($this->gui,
'view');
539 private function renderFontSettings(
ilTemplate $roomTpl, array $defaultSettings)
547 $font_family = array(
548 'sans' =>
'Sans Serif',
550 'monospace' =>
'Monospace',
554 'italic' => $lng->txt(
'italic'),
555 'bold' => $lng->txt(
'bold'),
556 'normal' => $lng->txt(
'normal'),
557 'underlined' => $lng->txt(
'underlined'),
561 'small' => $lng->txt(
'small'),
562 'normal' => $lng->txt(
'normal'),
563 'large' => $lng->txt(
'large')
566 $default_font_color =
'#000000';
568 $default_font_family = (
569 isset($defaultSettings[
'font_family']) &&
570 isset($font_family[$defaultSettings[
'font_family']]) ?
571 $defaultSettings[
'font_family'] :
'sans'
574 $default_font_style = (
575 isset($defaultSettings[
'font_style']) &&
576 isset($font_family[$defaultSettings[
'font_style']]) ?
577 $defaultSettings[
'font_style'] :
'normal'
580 $default_font_size = (
581 isset($defaultSettings[
'font_size']) &&
582 isset($font_family[$defaultSettings[
'font_size']]) ?
583 $defaultSettings[
'font_size'] :
'normal'
586 $roomTpl->
setVariable(
'VAL_FONTCOLOR', $default_font_color);
588 foreach($font_family as $font => $label)
594 'SELECTED_FONTFAMILY', $font == $default_font_family ?
595 'selected="selected"' :
''
600 foreach($font_style as $font => $label)
606 'SELECTED_FONTSTYLE', $font == $default_font_style ?
607 'selected="selected"' :
''
612 foreach($font_size as $font => $label)
619 $font == $default_font_size ?
'selected="selected"' :
''
624 $roomTpl->
setVariable(
'LBL_FONTCOLOR', $lng->txt(
'fontcolor'));
625 $roomTpl->
setVariable(
'LBL_FONTFAMILY', $lng->txt(
'fontfamily'));
626 $roomTpl->
setVariable(
'LBL_FONTSTYLE', $lng->txt(
'fontstyle'));
627 $roomTpl->
setVariable(
'LBL_FONTSIZE', $lng->txt(
'fontsize'));
629 $logoutLink = $ilCtrl->getLinkTarget($this->gui,
'view-logout');
642 require_once
'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
644 $file_upload = $formFactory->getFileUploadForm();
646 $roomTpl->
setVariable(
'FILE_UPLOAD', $file_upload->getHTML());
652 public function logout()
663 $pid = $tree->getParentId($this->gui->getRefId());
664 $ilCtrl->setParameterByClass(
'ilrepositorygui',
'ref_id', $pid);
665 $ilCtrl->redirectByClass(
'ilrepositorygui',
'');
671 public function lostConnection()
680 $ilCtrl->redirectByClass(
'ilinfoscreengui',
'info');