ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomViewGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
6
14{
21 public function joinWithCustomName()
22 {
27 global $ilUser, $lng;
28
29 $this->gui->switchToVisibleMode();
30 $this->setupTemplate();
31 $room = ilChatroom::byObjectId($this->gui->object->getId());
32 $chat_user = new ilChatroomUser($ilUser, $room);
33 $failure = false;
34 $username = '';
35
36 if ($_REQUEST['custom_username_radio'] == 'custom_username') {
37 $username = $_REQUEST['custom_username_text'];
38 } elseif (method_exists($chat_user, 'build' . $_REQUEST['custom_username_radio'])) {
39 $username = $chat_user->{'build' . $_REQUEST['custom_username_radio']}();
40 } else {
41 $failure = true;
42 }
43
44 if (!$failure && trim($username) != '') {
45 if (!$room->isSubscribed($chat_user->getUserId())) {
46 $chat_user->setUsername($chat_user->buildUniqueUsername($username));
47 }
48
49 $this->showRoom($room, $chat_user);
50 } else {
51 ilUtil::sendFailure($lng->txt('no_username_given'));
52 $this->showNameSelection($chat_user);
53 }
54 }
55
59 private function setupTemplate()
60 {
64 global $tpl;
65
66 $tpl->addJavaScript('Modules/Chatroom/js/chat.js');
67 $tpl->addJavaScript('Modules/Chatroom/js/iliaschat.jquery.js');
68 $tpl->addJavaScript('libs/bower/bower_components/jquery-outside-events/jquery.ba-outside-events.min.js');
69 $tpl->addJavaScript('Modules/Chatroom/js/json2.js');
70
71 $tpl->addJavaScript('./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js');
72
73 $tpl->addCSS('Modules/Chatroom/templates/default/style.css');
74 }
75
81 private function showRoom(ilChatroom $room, ilChatroomUser $chat_user)
82 {
91 global $tpl, $ilUser, $ilCtrl, $rbacsystem, $lng, $ilNavigationHistory;
92
93 $this->redirectIfNoPermission('read');
94
95 $user_id = $chat_user->getUserId($ilUser);
96
97 $ilNavigationHistory->addItem($_GET['ref_id'], $ilCtrl->getLinkTargetByClass('ilrepositorygui', 'view'), 'chtr');
98
99 if ($room->isUserBanned($user_id)) {
100 $this->cancelJoin($lng->txt('banned'));
101 return;
102 }
103
104 $scope = $room->getRoomId();
105 $connector = $this->gui->getConnector();
106 $response = @$connector->connect($scope, $user_id);
107
108 if (!$response) {
109 ilUtil::sendFailure($lng->txt('unable_to_connect'), true);
110 $ilCtrl->redirectByClass('ilinfoscreengui', 'info');
111 }
112
113 if (!$room->isSubscribed($chat_user->getUserId())) {
114 $room->connectUser($chat_user);
115 }
116
117 $subScope = 0;
118 $response = $connector->sendEnterPrivateRoom($scope, $subScope, $user_id);
119 if (!$response) {
120 ilUtil::sendFailure($lng->txt('unable_to_connect'), true);
121 $ilCtrl->redirectByClass('ilinfoscreengui', 'info');
122 }
123
124 $connection_info = json_decode($response);
125 $settings = $connector->getSettings();
126 $known_private_room = $room->getActivePrivateRooms($ilUser->getId());
127
128 $initial = new stdClass();
129 $initial->users = $room->getConnectedUsers();
130 $initial->private_rooms = array_values($known_private_room);
131 $initial->redirect_url = $ilCtrl->getLinkTarget($this->gui, 'view-lostConnection', '', false, false);
132 $initial->profile_image_url = $ilCtrl->getLinkTarget($this->gui, 'view-getUserProfileImages', '', true, false);
133 $initial->no_profile_image_url = ilUtil::getImagePath('no_photo_xxsmall.jpg');
134 $initial->private_rooms_enabled = (boolean) $room->getSetting('private_rooms_enabled');
135 $initial->subdirectory = $settings->getSubDirectory();
136
137 $initial->userinfo = array(
138 'moderator' => ilChatroom::checkUserPermissions('moderate', (int) $_GET['ref_id'], false),
139 'id' => $chat_user->getUserId(),
140 'login' => $chat_user->getUsername()
141 );
142
143 $smileys = array();
144
145 include_once('Modules/Chatroom/classes/class.ilChatroomSmilies.php');
146
147 if ($settings->getSmiliesEnabled()) {
148 $smileys_array = ilChatroomSmilies::_getSmilies();
149 foreach ($smileys_array as $smiley_array) {
150 $new_keys = array();
151 $new_val = '';
152 foreach ($smiley_array as $key => $value) {
153 if ($key == 'smiley_keywords') {
154 $new_keys = explode("\n", $value);
155 }
156
157 if ($key == 'smiley_fullpath') {
158 $new_val = $value;
159 }
160 }
161
162 if (!$new_keys || !$new_val) {
163 continue;
164 }
165
166 foreach ($new_keys as $new_key) {
167 $smileys[$new_key] = $new_val;
168 }
169 }
170
171 $initial->smileys = $smileys;
172 } else {
173 $initial->smileys = '{}';
174 }
175
176 $initial->messages = array();
177
178 if (isset($_REQUEST['sub'])) {
179 if ($known_private_room[$_REQUEST['sub']]) {
180 if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $_REQUEST['sub'])) {
181 $initial->messages[] = array(
182 'type' => 'error',
183 'message' => $lng->txt('not_allowed_to_enter'),
184 );
185 } else {
186 $scope = $room->getRoomId();
187 $params = array();
188 $params['user'] = $chat_user->getUserId();
189 $params['sub'] = $_REQUEST['sub'];
190
191 $params['message'] = json_encode(
192 array(
193 'type' => 'private_room_entered',
194 'user' => $user_id
195 )
196 );
197
198 $connector = $this->gui->getConnector();
199 $response = $connector->sendEnterPrivateRoom($scope, $_REQUEST['sub'], $chat_user->getUserId());
200
201 if ($this->isSuccessful($response)) {
202 $room->subscribeUserToPrivateRoom($params['sub'], $params['user']);
203 }
204
205 $initial->enter_room = $_REQUEST['sub'];
206 }
207 } else {
208 $initial->messages[] = array(
209 'type' => 'error',
210 'message' => $lng->txt('user_invited'),
211 );
212 }
213 }
214
215 if ((int) $room->getSetting('display_past_msgs')) {
216 $initial->messages = array_merge($initial->messages, array_reverse($room->getLastMessages($room->getSetting('display_past_msgs'), $chat_user)));
217 }
218
219 $roomTpl = new ilTemplate('tpl.chatroom.html', true, true, 'Modules/Chatroom');
220 $roomTpl->setVariable('SESSION_ID', $connection_info->{'session-id'});
221 $roomTpl->setVariable('BASEURL', $settings->generateClientUrl());
222 $roomTpl->setVariable('INSTANCE', $settings->getInstance());
223 $roomTpl->setVariable('SCOPE', $scope);
224 $roomTpl->setVariable('MY_ID', $user_id);
225 $roomTpl->setVariable('INITIAL_DATA', json_encode($initial));
226 $roomTpl->setVariable('POSTURL', $ilCtrl->getLinkTarget($this->gui, 'postMessage', '', true, true));
227
228 $roomTpl->setVariable('ACTIONS', $lng->txt('actions'));
229 $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM', $lng->txt('create_private_room_label'));
230 $roomTpl->setVariable('LBL_USER', $lng->txt('user'));
231 $roomTpl->setVariable('LBL_USER_TEXT', $lng->txt('invite_username'));
232 $roomTpl->setVariable('LBL_AUTO_SCROLL', $lng->txt('auto_scroll'));
233
234 $roomTpl->setVariable('INITIAL_USERS', json_encode($room->getConnectedUsers()));
235
236 $this->renderFileUploadForm($roomTpl);
237 $this->renderSendMessageBox($roomTpl);
238 $this->renderLanguageVariables($roomTpl);
239
240 require_once 'Services/UIComponent/Modal/classes/class.ilModalGUI.php';
242
243 $roomRightTpl = new ilTemplate('tpl.chatroom_right.html', true, true, 'Modules/Chatroom');
244 $this->renderRightUsersBlock($roomRightTpl);
245
246 require_once 'Services/UIComponent/Panel/classes/class.ilPanelGUI.php';
247 $right_content_panel = ilPanelGUI::getInstance();
248 $right_content_panel->setHeading($lng->txt('users'));
249 $right_content_panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY);
250 $right_content_panel->setHeadingStyle(ilPanelGUI::HEADING_STYLE_BLOCK);
251 $right_content_panel->setBody($roomRightTpl->get());
252
253 $tpl->setContent($roomTpl->get());
254 $tpl->setRightContent($right_content_panel->getHTML());
255 }
256
261 private function cancelJoin($message)
262 {
264 }
265
270 public function renderFileUploadForm(ilTemplate $roomTpl)
271 {
272 // @todo: Not implemented yet
273 return;
274
275 require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
276 $formFactory = new ilChatroomFormFactory();
277 $file_upload = $formFactory->getFileUploadForm();
278 //$file_upload->setFormAction( $ilCtrl->getFormAction($this->gui, 'UploadFile-uploadFile') );
279 $roomTpl->setVariable('FILE_UPLOAD', $file_upload->getHTML());
280 }
281
285 protected function renderSendMessageBox(ilTemplate $roomTpl)
286 {
290 global $lng;
291
292 $roomTpl->setVariable('LBL_MESSAGE', $lng->txt('chat_message'));
293 $roomTpl->setVariable('LBL_TOALL', $lng->txt('chat_message_to_all'));
294 $roomTpl->setVariable('LBL_OPTIONS', $lng->txt('chat_message_options'));
295 $roomTpl->setVariable('LBL_DISPLAY', $lng->txt('chat_message_display'));
296 $roomTpl->setVariable('LBL_SEND', $lng->txt('send'));
297 }
298
302 protected function renderLanguageVariables(ilTemplate $roomTpl)
303 {
307 global $lng;
308
309 $js_translations = array(
310 'LBL_MAINROOM' => 'chat_mainroom',
311 'LBL_LEAVE_PRIVATE_ROOM' => 'leave_private_room',
312 'LBL_LEFT_PRIVATE_ROOM' => 'left_private_room',
313 'LBL_JOIN' => 'chat_join',
314 'LBL_DELETE_PRIVATE_ROOM' => 'delete_private_room',
315 'LBL_DELETE_PRIVATE_ROOM_QUESTION' => 'delete_private_room_question',
316 'LBL_INVITE_TO_PRIVATE_ROOM' => 'invite_to_private_room',
317 'LBL_KICK' => 'chat_kick',
318 'LBL_BAN' => 'chat_ban',
319 'LBL_KICK_QUESTION' => 'kick_question',
320 'LBL_BAN_QUESTION' => 'ban_question',
321 'LBL_ADDRESS' => 'chat_address',
322 'LBL_WHISPER' => 'chat_whisper',
323 'LBL_CONNECT' => 'chat_connection_established',
324 'LBL_DISCONNECT' => 'chat_connection_disconnected',
325 'LBL_TO_MAINROOM' => 'chat_to_mainroom',
326 'LBL_CREATE_PRIVATE_ROOM_JS' => 'chat_create_private_room_button',
327 'LBL_WELCOME_TO_CHAT' => 'welcome_to_chat',
328 'LBL_USER_INVITED' => 'user_invited',
329 'LBL_USER_KICKED' => 'user_kicked',
330 'LBL_USER_INVITED_SELF' => 'user_invited_self',
331 'LBL_PRIVATE_ROOM_CLOSED' => 'private_room_closed',
332 'LBL_PRIVATE_ROOM_ENTERED' => 'private_room_entered',
333 'LBL_PRIVATE_ROOM_LEFT' => 'private_room_left',
334 'LBL_PRIVATE_ROOM_ENTERED_USER' => 'private_room_entered_user',
335 'LBL_KICKED_FROM_PRIVATE_ROOM' => 'kicked_from_private_room',
336 'LBL_OK' => 'ok',
337 'LBL_INVITE' => 'chat_invite',
338 'LBL_CANCEL' => 'cancel',
339 'LBL_WHISPER_TO' => 'whisper_to',
340 'LBL_SPEAK_TO' => 'speak_to',
341 'LBL_HISTORY_CLEARED' => 'history_cleared',
342 'LBL_CLEAR_ROOM_HISTORY' => 'clear_room_history',
343 'LBL_CLEAR_ROOM_HISTORY_QUESTION' => 'clear_room_history_question',
344 'LBL_END_WHISPER' => 'end_whisper',
345 'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
346 'LBL_DATEFORMAT' => 'lang_dateformat'
347 );
348 foreach ($js_translations as $placeholder => $lng_variable) {
349 $roomTpl->setVariable($placeholder, json_encode($lng->txt($lng_variable)));
350 }
351
352 $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM', $lng->txt('chat_create_private_room_button'));
353 $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM_TEXT', $lng->txt('create_private_room_text'));
354 $roomTpl->setVariable('LBL_LAYOUT', $lng->txt('layout'));
355 $roomTpl->setVariable('LBL_SHOW_SETTINGS', $lng->txt('show_settings'));
356 $roomTpl->setVariable('LBL_USER_IN_ROOM', $lng->txt('user_in_room'));
357 $roomTpl->setVariable('LBL_USER_IN_ILIAS', $lng->txt('user_in_ilias'));
358 }
359
363 protected function renderRightUsersBlock(ilTemplate $roomTpl)
364 {
368 global $lng;
369
370 $roomTpl->setVariable('LBL_NO_FURTHER_USERS', $lng->txt('no_further_users'));
371 }
372
379 private function showNameSelection(ilChatroomUser $chat_user)
380 {
386 global $lng, $ilCtrl, $tpl;
387
388 require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
389
390 $name_options = $chat_user->getChatNameSuggestions();
391 $formFactory = new ilChatroomFormFactory();
392 $selectionForm = $formFactory->getUserChatNameSelectionForm($name_options);
393
394 $ilCtrl->saveParameter($this->gui, 'sub');
395
396 $selectionForm->addCommandButton('view-joinWithCustomName', $lng->txt('enter'));
397 $selectionForm->setFormAction(
398 $ilCtrl->getFormAction($this->gui, 'view-joinWithCustomName')
399 );
400
401 $tpl->setVariable('ADM_CONTENT', $selectionForm->getHtml());
402 }
403
410 public function executeDefault($method)
411 {
417 global $ilUser, $lng, $ilCtrl;
418
419 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
420
421 $this->redirectIfNoPermission('read');
422
423 $this->gui->switchToVisibleMode();
424 $this->setupTemplate();
425
426 $chatSettings = new ilSetting('chatroom');
427 if (!$chatSettings->get('chat_enabled')) {
428 $ilCtrl->redirect($this->gui, 'settings-general');
429 exit;
430 }
431
432 $room = ilChatroom::byObjectId($this->gui->object->getId());
433
434 if (!$room->getSetting('allow_anonymous') && $ilUser->isAnonymous()) {
435 $this->cancelJoin($lng->txt('chat_anonymous_not_allowed'));
436 return;
437 }
438
439 $chat_user = new ilChatroomUser($ilUser, $room);
440
441 if ($room->getSetting('allow_custom_usernames')) {
442 if ($room->isSubscribed($chat_user->getUserId())) {
443 $chat_user->setUsername($chat_user->getUsername());
444 $this->showRoom($room, $chat_user);
445 } else {
446 $this->showNameSelection($chat_user);
447 }
448 } else {
449 $chat_user->setUsername($ilUser->getLogin());
450 $this->showRoom($room, $chat_user);
451 }
452 }
453
457 public function invitePD()
458 {
463 global $ilUser, $ilCtrl;
464
465 $chatSettings = new ilSetting('chatroom');
466 if (!$chatSettings->get('chat_enabled')) {
467 $ilCtrl->redirect($this->gui, 'settings-general');
468 }
469
470 $room = ilChatroom::byObjectId($this->gui->object->getId());
471 $chat_user = new ilChatroomUser($ilUser, $room);
472 $user_id = $_REQUEST['usr_id'];
473 $connector = $this->gui->getConnector();
474 $title = $room->getUniquePrivateRoomTitle($chat_user->buildLogin());
475 $subRoomId = $room->addPrivateRoom($title, $chat_user, array('public' => false));
476
477 $room->inviteUserToPrivateRoom($user_id, $subRoomId);
478 $connector->sendCreatePrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $title);
479 $connector->sendInviteToPrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $user_id);
480
481 $room->sendInvitationNotification($this->gui, $chat_user, $user_id, $subRoomId);
482
483 $_REQUEST['sub'] = $subRoomId;
484
485 $_SESSION['show_invitation_message'] = $user_id;
486
487 $ilCtrl->setParameter($this->gui, 'sub', $subRoomId);
488 $ilCtrl->redirect($this->gui, 'view');
489 }
490
494 public function logout()
495 {
500 global $tree, $ilCtrl;
501
505 $pid = $tree->getParentId($this->gui->getRefId());
506 $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', $pid);
507 $ilCtrl->redirectByClass('ilrepositorygui', '');
508 }
509
513 public function lostConnection()
514 {
519 global $lng, $ilCtrl;
520
521 if (isset($_GET['msg'])) {
522 switch ($_GET['msg']) {
523 case 'kicked':
524 ilUtil::sendFailure($lng->txt('kicked'), true);
525 break;
526
527 case 'banned':
528 ilUtil::sendFailure($lng->txt('banned'), true);
529 break;
530
531 default:
532 ilUtil::sendFailure($lng->txt('lost_connection'), true);
533 break;
534 }
535 } else {
536 ilUtil::sendFailure($lng->txt('lost_connection'), true);
537 }
538
539 $ilCtrl->redirectByClass('ilinfoscreengui', 'info');
540 }
541
542 public function getUserProfileImages()
543 {
544 global $DIC;
545
546 $response = array();
547
548 if (!$DIC->user()) {
549 echo json_encode($response);
550 exit();
551 }
552
553 if (!isset($_GET['usr_ids']) || strlen($_GET['usr_ids']) == 0) {
554 echo json_encode($response);
555 exit();
556 }
557
558 $DIC['lng']->loadLanguageModule('user');
559
560 require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
562
563 $user_ids = array_filter(array_map('intval', array_map('trim', explode(',', $_GET['usr_ids']))));
564 require_once 'Services/User/classes/class.ilUserUtil.php';
565 $public_data = ilUserUtil::getNamePresentation($user_ids, true, false, '', false, true, false, true);
566 $public_names = ilUserUtil::getNamePresentation($user_ids, false, false, '', false, true, false, false);
567
568 foreach ($user_ids as $usr_id) {
569 $public_image = isset($public_data[$usr_id]) && isset($public_data[$usr_id]['img']) ? $public_data[$usr_id]['img'] : '';
570
571 $public_name = '';
572 if (isset($public_names[$usr_id])) {
573 $public_name = $public_names[$usr_id];
574 if ('unknown' == $public_name && isset($public_data[$usr_id]) && isset($public_data[$usr_id]['login'])) {
575 $public_name = $public_data[$usr_id]['login'];
576 }
577 }
578
579 $response[$usr_id] = array(
580 'public_name' => $public_name,
581 'profile_image' => $public_image
582 );
583 }
584
585 echo json_encode($response);
586 exit();
587 }
588}
$tpl
Definition: ilias.php:10
$failure
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
Class ilChatroomFormFactory.
Class ilChatroomGUIHandler.
Class ilChatroomUser.
getChatNameSuggestions()
Returns an array of chat-name suggestions.
getUserId()
Returns Ilias User ID.
setUsername($username)
Sets and stores given username in SESSION.
buildLogin()
Returns user login.
getUsername()
Returns username from Object or SESSION.
Class ilChatroomViewGUI.
renderFileUploadForm(ilTemplate $roomTpl)
Prepares Fileupload form and displays it.
cancelJoin($message)
Calls ilUtil::sendFailure method using given $message as parameter.
Class ilChatroom.
isSubscribed($chat_userid)
Returns true if entry exists in userTable matching given $chat_userid and $this->roomId.
isUserBanned($user_id)
Returns true if there's an entry in banTable matching roomId and given $user_id.
addPrivateRoom($title, ilChatroomUser $owner, $settings)
connectUser(ilChatroomUser $user)
Connects user by inserting userdata into userTable.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
getConnectedUsers($only_data=true)
Returns an array of connected users.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
getActivePrivateRooms($userid)
subscribeUserToPrivateRoom($room_id, $user_id)
getLastMessages($number, $chatuser=null)
getRoomId()
Returns roomID from $this->roomId.
getUniquePrivateRoomTitle($title)
getSetting($name)
Returns setting from $this->settings array by given name.
isAllowedToEnterPrivateRoom($chat_userid, $proom_id)
inviteUserToPrivateRoom($user_id, $proom_id)
static initJS(ilTemplate $a_main_tpl=null)
Init javascript.
const PANEL_STYLE_SECONDARY
const HEADING_STYLE_BLOCK
static getInstance()
Get instance.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
$key
Definition: croninfo.php:18
global $ilCtrl
Definition: ilias.php:18
catch(Exception $e) $message
global $lng
Definition: privfeed.php:17
$response
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18
$params
Definition: disable.php:11