ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Block/classes/class.ilBlockGUI.php';
5 require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
6 require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
7 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
8 require_once 'Modules/Chatroom/classes/class.ilChatroomBlock.php';
9 require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
10 
18 {
23  public static $block_type = 'chatviewer';
24 
28  public function __construct()
29  {
30  global $lng;
31 
33 
34  $lng->loadLanguageModule('chat');
35  $lng->loadLanguageModule('chatroom');
36 
37  $this->setImage(ilUtil::getImagePath('icon_chat.gif'));
38  $this->setTitle($lng->txt('chat_chatviewer'));
39  $this->setAvailableDetailLevels(1, 0);
40  $this->allow_moving = true;
41  }
42 
47  public static function getBlockType()
48  {
49  return self::$block_type;
50  }
51 
56  public static function isRepositoryObject()
57  {
58  return false;
59  }
60 
65  public static function getScreenMode()
66  {
67  switch($_GET['cmd'])
68  {
69  default:
70  return IL_SCREEN_SIDE;
71  break;
72  }
73  }
74 
78  public function executeCommand()
79  {
83  global $ilCtrl;
84 
85  $cmd = $ilCtrl->getCmd('getHTML');
86 
87  return $this->$cmd();
88  }
89 
93  public function getHTML()
94  {
96 
97  $chatSetting = new ilSetting('chatroom');
98  if($this->getCurrentDetailLevel() == 0 || !$chatSetting->get('chat_enabled', 0) || !(bool)@ilChatroomServerConnector::checkServerConnection())
99  {
100  return '';
101  }
102  else
103  {
104  return parent::getHTML();
105  }
106  }
107 
111  public function fillDataSection()
112  {
118  global $tpl, $lng, $ilCtrl;
119 
120  //@todo: Dirty hack
121  if($ilCtrl->isAsynch())
122  {
123  return $this->getMessages();
124  }
125 
126  $tpl->addJavascript('./Modules/Chatroom/js/chatviewer.js');
127  $tpl->addCss('./Modules/Chatroom/templates/default/style.css');
128 
129  $chatblock = new ilChatroomBlock();
130  $body_tpl = new ilTemplate('tpl.chatroom_block_message_body.html', true, true, 'Modules/Chatroom');
131 
132  $height = 120;
133  if($this->getCurrentDetailLevel() > 0 && $this->getCurrentDetailLevel() <= 3)
134  {
135  $height *= $this->getCurrentDetailLevel();
136  }
137  $body_tpl->setVariable('BLOCK_HEIGHT', $height);
138  $body_tpl->setVariable('TXT_ENABLE_AUTOSCROLL', $lng->txt('chat_enable_autoscroll'));
139 
140  $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', 'block_' . $this->getBlockType() . '_' . (int)$this->getBlockId());
141  $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '#__ref_id');
142  $body_tpl->setVariable('CHATBLOCK_BASE_URL', $ilCtrl->getLinkTargetByClass('ilcolumngui', 'updateBlock', '', true));
143  $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', '');
144  $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '');
145 
146  $smilieys = array();
148  if($settings->getSmiliesEnabled())
149  {
150  $smilies_array = ilChatroomSmilies::_getSmilies();
151  foreach($smilies_array as $smiley_array)
152  {
153  foreach($smiley_array as $key => $value)
154  {
155  if($key == 'smiley_keywords')
156  {
157  $new_keys = explode("\n", $value);
158  }
159 
160  if($key == 'smiley_fullpath')
161  {
162  $new_val = $value;
163  }
164  }
165 
166  foreach($new_keys as $new_key)
167  {
168  $smilieys[$new_key] = $new_val;
169  }
170  }
171  }
172  else
173  {
174  $smilieys = new stdClass();
175  }
176  $body_tpl->setVariable('SMILIES', json_encode($smilieys));
177 
178  $body_tpl->setVariable('LBL_MAINROOM', $lng->txt('chat_mainroom'));
179  $body_tpl->setVariable('LBL_LEAVE_PRIVATE_ROOM', $lng->txt('leave_private_room'));
180  $body_tpl->setVariable('LBL_JOIN', $lng->txt('chat_join'));
181  $body_tpl->setVariable('LBL_DELETE_PRIVATE_ROOM', $lng->txt('delete_private_room'));
182  $body_tpl->setVariable('LBL_INVITE_TO_PRIVATE_ROOM', $lng->txt('invite_to_private_room'));
183  $body_tpl->setVariable('LBL_KICK', $lng->txt('chat_kick'));
184  $body_tpl->setVariable('LBL_BAN', $lng->txt('chat_ban'));
185  $body_tpl->setVariable('LBL_KICK_QUESTION', $lng->txt('kick_question'));
186  $body_tpl->setVariable('LBL_BAN_QUESTION', $lng->txt('ban_question'));
187  $body_tpl->setVariable('LBL_ADDRESS', $lng->txt('chat_address'));
188  $body_tpl->setVariable('LBL_WHISPER', $lng->txt('chat_whisper'));
189  $body_tpl->setVariable('LBL_CONNECT', $lng->txt('chat_connection_established'));
190  $body_tpl->setVariable('LBL_DISCONNECT', $lng->txt('chat_connection_disconnected'));
191  $body_tpl->setVariable('LBL_INVITE_USERS', $lng->txt('chat_invite_users'));
192  $body_tpl->setVariable('LBL_USER_TAB', $lng->txt('chat_right_box_user'));
193  $body_tpl->setVariable('LBL_PRIVATE_ROOM', $lng->txt('chat_private_room'));
194  $body_tpl->setVariable('LBL_CREATE_NEW_PRIVATE_ROOM', $lng->txt('chat_create_new_private_room'));
195  $body_tpl->setVariable('LBL_TO_MAINROOM', $lng->txt('chat_to_mainroom'));
196  $body_tpl->setVariable('LBL_CREATE_PRIVATE_ROOM', $lng->txt('chat_create_private_room_button'));
197  $body_tpl->setVariable('LBL_CREATE_PRIVATE_ROOM_TEXT', $lng->txt('create_private_room_text'));
198 
199  $body_tpl->setVariable('LBL_WELCOME_TO_CHAT', $lng->txt('welcome_to_chat'));
200  $body_tpl->setVariable('LBL_USER_INVITED', $lng->txt('user_invited'));
201  $body_tpl->setVariable('LBL_USER_KICKED', $lng->txt('user_kicked'));
202  $body_tpl->setVariable('LBL_USER_INVITED_SELF', $lng->txt('user_invited_self'));
203  $body_tpl->setVariable('LBL_PRIVATE_ROOM_CLOSED', $lng->txt('private_room_closed'));
204  $body_tpl->setVariable('LBL_PRIVATE_ROOM_ENTERED', $lng->txt('private_room_entered'));
205  $body_tpl->setVariable('LBL_PRIVATE_ROOM_LEFT', $lng->txt('private_room_left'));
206  $body_tpl->setVariable('LBL_PRIVATE_ROOM_ENTERED_USER', $lng->txt('private_room_entered_user'));
207  $body_tpl->setVariable('LBL_KICKED_FROM_PRIVATE_ROOM', $lng->txt('kicked_from_private_room'));
208  $body_tpl->setVariable('LBL_OK', $lng->txt('ok'));
209  $body_tpl->setVariable('LBL_CANCEL', $lng->txt('cancel'));
210  $body_tpl->setVariable('LBL_WHISPER_TO', $lng->txt('whisper_to'));
211  $body_tpl->setVariable('LBL_SPEAK_TO', $lng->txt('speak_to'));
212 
213  $body_tpl->setVariable('LBL_USER_IN_ROOM', $lng->txt('user_in_room'));
214  $body_tpl->setVariable('LBL_USER_IN_ILIAS', $lng->txt('user_in_ilias'));
215 
216  $body_tpl->setVariable('LBL_HISTORY_CLEARED', $lng->txt('history_cleared'));
217  $body_tpl->setVariable('LBL_CLEAR_ROOM_HISTORY', $lng->txt('clear_room_history'));
218  $body_tpl->setVariable('LBL_CLEAR_ROOM_HISTORY_QUESTION', $lng->txt('clear_room_history_question'));
219 
220  $body_tpl->setVariable('LBL_LAYOUT', $lng->txt('layout'));
221  $body_tpl->setVariable('LBL_SHOW_SETTINGS', $lng->txt('show_settings'));
222  $body_tpl->setVariable('LBL_HIDE_SETTINGS', $lng->txt('hide_settings'));
223  $body_tpl->setVariable('LBL_NO_FURTHER_USERS', $lng->txt('no_further_users'));
224  $body_tpl->setVariable('LBL_USERS', $lng->txt('users'));
225  $body_tpl->setVariable('LBL_END_WHISPER', $lng->txt('end_whisper'));
226 
227  $content = $body_tpl->get() . $chatblock->getRoomSelect();
228  $this->setDataSection($content);
229  }
230 
234  protected function getMessages()
235  {
241  global $ilAccess, $ilUser, $lng;
242 
243  $result = new stdClass();
244 
248  $object = ilObjectFactory::getInstanceByRefId((int)$_REQUEST['ref_id'], false);
249  if(!$object || !$ilAccess->checkAccess('read', '', $_REQUEST['ref_id']))
250  {
252  (
253  $ilUser->getId(), 'chatviewer_last_selected_room',
254  0
255  );
256 
257  $result->ok = false;
258  $result->errormsg = $lng->txt('msg_no_perm_read');
260  exit;
261  }
262 
263  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
264  $room = ilChatroom::byObjectId($object->getId());
265 
266  $block = new ilChatroomBlock();
267  $msg = $block->getMessages($room);
268 
269  $ilUser->setPref
270  (
271  'chatviewer_last_selected_room',
272  $object->getRefId()
273  );
275  (
276  $ilUser->getId(), 'chatviewer_last_selected_room',
277  $object->getRefId()
278  );
279 
280  $result->messages = array_reverse($msg);
281  $result->ok = true;
282 
283  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
285  exit;
286  }
287 }