ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
32  parent::__construct();
33 
34  $lng->loadLanguageModule('chatroom');
35 
36  $this->setImage(ilUtil::getImagePath('icon_chat.svg'));
37  $this->setTitle($lng->txt('chat_chatviewer'));
38  $this->setAvailableDetailLevels(1, 0);
39  $this->allow_moving = true;
40  }
41 
46  public static function isRepositoryObject()
47  {
48  return false;
49  }
50 
55  public static function getScreenMode()
56  {
57  switch($_GET['cmd'])
58  {
59  default:
60  return IL_SCREEN_SIDE;
61  break;
62  }
63  }
64 
68  public function executeCommand()
69  {
73  global $ilCtrl;
74 
75  $cmd = $ilCtrl->getCmd('getHTML');
76 
77  return $this->$cmd();
78  }
79 
83  public function getHTML()
84  {
86 
87  $chatSetting = new ilSetting('chatroom');
88  if($this->getCurrentDetailLevel() == 0 || !$chatSetting->get('chat_enabled', 0) || !(bool)ilChatroomServerConnector::checkServerConnection())
89  {
90  return '';
91  }
92  else
93  {
94  return parent::getHTML();
95  }
96  }
97 
101  public function fillDataSection()
102  {
108  global $tpl, $lng, $ilCtrl;
109 
110  //@todo: Dirty hack
111  if($ilCtrl->isAsynch() && isset($_GET['chatBlockCmd']))
112  {
113  return $this->dispatchAsyncCommand($_GET['chatBlockCmd']);
114  }
115 
116  $tpl->addJavascript('./Modules/Chatroom/js/chatviewer.js');
117  $tpl->addCss('./Modules/Chatroom/templates/default/style.css');
118 
119  $body_tpl = new ilTemplate('tpl.chatroom_block_message_body.html', true, true, 'Modules/Chatroom');
120 
121  $body_tpl->setVariable('TXT_ENABLE_AUTOSCROLL', $lng->txt('chat_enable_autoscroll'));
122  $body_tpl->setVariable('LOADER_PATH', ilUtil::getImagePath('loader.svg'));
123 
124  $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', 'block_' . $this->getBlockType() . '_' . (int)$this->getBlockId());
125  $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '#__ref_id');
126  $body_tpl->setVariable('CHATBLOCK_BASE_URL', $ilCtrl->getLinkTargetByClass('ilcolumngui', 'updateBlock', '', true));
127  $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', '');
128  $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '');
129 
130  $smilieys = array();
131  $settings = ilChatroomServerSettings::loadDefault();
132  if($settings->getSmiliesEnabled())
133  {
134  $smilies_array = ilChatroomSmilies::_getSmilies();
135  foreach($smilies_array as $smiley_array)
136  {
137  foreach($smiley_array as $key => $value)
138  {
139  if($key == 'smiley_keywords')
140  {
141  $new_keys = explode("\n", $value);
142  }
143 
144  if($key == 'smiley_fullpath')
145  {
146  $new_val = $value;
147  }
148  }
149 
150  foreach($new_keys as $new_key)
151  {
152  $smilieys[$new_key] = $new_val;
153  }
154  }
155  }
156  else
157  {
158  $smilieys = new stdClass();
159  }
160  $body_tpl->setVariable('SMILIES', json_encode($smilieys));
161 
162  $js_translations = array(
163  'LBL_CONNECT' => 'chat_connection_established',
164  'LBL_DISCONNECT' => 'chat_connection_disconnected',
165  'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
166  'LBL_DATEFORMAT' => 'lang_dateformat'
167  );
168  foreach($js_translations as $placeholder => $lng_variable)
169  {
170  $body_tpl->setVariable($placeholder, json_encode($lng->txt($lng_variable)));
171  }
172 
173  $content = $body_tpl->get();
174  $this->setDataSection($content);
175  }
176 
180  protected function dispatchAsyncCommand($cmd)
181  {
182  switch($cmd)
183  {
184  case 'getChatroomSelectionList':
185  return $this->getChatroomSelectionList();
186  break;
187 
188  case 'getMessages':
189  default;
190  return $this->getMessages();
191  break;
192  }
193  }
194 
195  protected function getChatroomSelectionList()
196  {
197  $result = new stdClass();
198  $result->ok = true;
199 
200  $chatblock = new ilChatroomBlock();
201  $result->html = $chatblock->getRoomSelect();
202 
203  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
205  exit();
206  }
207 
210  protected function getMessages()
211  {
217  global $rbacsystem, $ilUser, $lng;
218 
219  $result = new stdClass();
220  $result->ok = false;
221 
222  if(!(int)$_REQUEST['ref_id'])
223  {
225  exit();
226  }
227 
231  $object = ilObjectFactory::getInstanceByRefId((int)$_REQUEST['ref_id'], false);
232  if(!$object || !$rbacsystem->checkAccess('read', (int)$_REQUEST['ref_id']))
233  {
235  (
236  $ilUser->getId(), 'chatviewer_last_selected_room',
237  0
238  );
239 
240  $result->errormsg = $lng->txt('msg_no_perm_read');
242  exit();
243  }
244 
245  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
246  $room = ilChatroom::byObjectId($object->getId());
247 
248  $block = new ilChatroomBlock();
249  $msg = $block->getMessages($room);
250 
251  $ilUser->setPref
252  (
253  'chatviewer_last_selected_room',
254  $object->getRefId()
255  );
257  (
258  $ilUser->getId(), 'chatviewer_last_selected_room',
259  $object->getRefId()
260  );
261 
262  $result->messages = array_reverse($msg);
263  $result->ok = true;
264 
265  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
267  exit();
268  }
269 
274  public static function getBlockType()
275  {
276  return self::$block_type;
277  }
278 }
ILIAS Setting Class.
$result
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
static _writePref($a_usr_id, $a_keyword, $a_value)
static initJson()
Init YUI JSON component.
$cmd
Definition: sahs_server.php:35
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setImage($a_image)
Set Image.
static encode($mixed, $suppress_native=false)
setTitle($a_title)
Set Title.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static checkServerConnection($use_cache=true)
special template class to simplify handling of ITX/PEAR
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
Class ilChatroomBlockGUI.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
getBlockId()
Get Block Id.
global $lng
Definition: privfeed.php:17
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
This class represents a block method of a block.
fillDataSection()
Standard implementation for row based data.
const IL_SCREEN_SIDE
getCurrentDetailLevel()
Get Current Detail Level.