ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  parent::__construct();
31 
32  $this->lng->loadLanguageModule('chatroom');
33 
34  $this->setImage(ilUtil::getImagePath('icon_chat.svg'));
35  $this->setTitle($this->lng->txt('chat_chatviewer'));
36  $this->setAvailableDetailLevels(1, 0);
37  $this->allow_moving = true;
38  }
39 
44  public static function isRepositoryObject()
45  {
46  return false;
47  }
48 
53  public static function getScreenMode()
54  {
55  switch ($_GET['cmd']) {
56  default:
57  return IL_SCREEN_SIDE;
58  break;
59  }
60  }
61 
65  public function executeCommand()
66  {
67  $cmd = $this->ctrl->getCmd('getHTML');
68 
69  return $this->$cmd();
70  }
71 
75  public function getHTML()
76  {
78 
79  $chatSetting = new ilSetting('chatroom');
80  if ($this->getCurrentDetailLevel() == 0 || !$chatSetting->get('chat_enabled', 0) || !(bool) ilChatroomServerConnector::checkServerConnection()) {
81  return '';
82  } else {
83  return parent::getHTML();
84  }
85  }
86 
90  public function fillDataSection()
91  {
92  if ($this->ctrl->isAsynch() && isset($_GET['chatBlockCmd'])) {
93  return $this->dispatchAsyncCommand($_GET['chatBlockCmd']);
94  }
95 
96  $this->main_tpl->addJavascript('./Modules/Chatroom/js/chatviewer.js');
97  $this->main_tpl->addCss('./Modules/Chatroom/templates/default/style.css');
98 
99  $body_tpl = new ilTemplate('tpl.chatroom_block_message_body.html', true, true, 'Modules/Chatroom');
100 
101  $body_tpl->setVariable('TXT_ENABLE_AUTOSCROLL', $this->lng->txt('chat_enable_autoscroll'));
102  $body_tpl->setVariable('LOADER_PATH', ilUtil::getImagePath('loader.svg'));
103 
104  $this->ctrl->setParameterByClass('ilcolumngui', 'block_id', 'block_' . $this->getBlockType() . '_' . (int) $this->getBlockId());
105  $this->ctrl->setParameterByClass('ilcolumngui', 'ref_id', '#__ref_id');
106  $body_tpl->setVariable('CHATBLOCK_BASE_URL', $this->ctrl->getLinkTargetByClass('ilcolumngui', 'updateBlock', '', true));
107  $this->ctrl->setParameterByClass('ilcolumngui', 'block_id', '');
108  $this->ctrl->setParameterByClass('ilcolumngui', 'ref_id', '');
109 
110  $smilieys = array();
112  if ($settings->getSmiliesEnabled()) {
113  $smilies_array = ilChatroomSmilies::_getSmilies();
114  foreach ($smilies_array as $smiley_array) {
115  foreach ($smiley_array as $key => $value) {
116  if ($key == 'smiley_keywords') {
117  $new_keys = explode("\n", $value);
118  }
119 
120  if ($key == 'smiley_fullpath') {
121  $new_val = $value;
122  }
123  }
124 
125  foreach ($new_keys as $new_key) {
126  $smilieys[$new_key] = $new_val;
127  }
128  }
129  } else {
130  $smilieys = new stdClass();
131  }
132  $body_tpl->setVariable('SMILIES', json_encode($smilieys));
133 
134  $js_translations = array(
135  'LBL_CONNECT' => 'chat_connection_established',
136  'LBL_DISCONNECT' => 'chat_connection_disconnected',
137  'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
138  'LBL_DATEFORMAT' => 'lang_dateformat'
139  );
140  foreach ($js_translations as $placeholder => $lng_variable) {
141  $body_tpl->setVariable($placeholder, json_encode($this->lng->txt($lng_variable)));
142  }
143 
144  $content = $body_tpl->get();
145  $this->setDataSection($content);
146  }
147 
151  protected function dispatchAsyncCommand($cmd)
152  {
153  switch ($cmd) {
154  case 'getChatroomSelectionList':
155  return $this->getChatroomSelectionList();
156  break;
157 
158  case 'getMessages':
159  default:
160  return $this->getMessages();
161  break;
162  }
163  }
164 
165  protected function getChatroomSelectionList()
166  {
167  $result = new stdClass();
168  $result->ok = true;
169 
170  $chatblock = new ilChatroomBlock();
171  $result->html = $chatblock->getRoomSelect();
172 
173  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
175  exit();
176  }
177 
180  protected function getMessages()
181  {
182  global $DIC;
183 
184  $result = new stdClass();
185  $result->ok = false;
186 
187  if (!(int) $_REQUEST['ref_id']) {
189  exit();
190  }
191 
195  $object = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['ref_id'], false);
196  if (!$object || !ilChatroom::checkUserPermissions('read', (int) $_REQUEST['ref_id'], false)) {
198  $DIC->user()->getId(),
199  'chatviewer_last_selected_room',
200  0
201  );
202 
203  $result->errormsg = $DIC->language()->txt('msg_no_perm_read');
205  exit();
206  }
207 
208  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
209  $room = ilChatroom::byObjectId($object->getId());
210 
211  $block = new ilChatroomBlock();
212  $msg = $block->getMessages($room);
213 
214  $DIC->user()->setPref(
215  'chatviewer_last_selected_room',
216  $object->getRefId()
217  );
219  $DIC->user()->getId(),
220  'chatviewer_last_selected_room',
221  $object->getRefId()
222  );
223 
224  $result->messages = array_reverse($msg);
225  $result->ok = true;
226 
227  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
229  exit();
230  }
231 
236  public static function getBlockType()
237  {
238  return self::$block_type;
239  }
240 }
$result
global $DIC
Definition: saml.php:7
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.
setImage($a_image)
Set Image.
static encode($mixed, $suppress_native=false)
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
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.
Create styles array
The data for the language used.
getBlockId()
Get Block Id.
fillDataSection()
Fill data section.
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.
const IL_SCREEN_SIDE
$key
Definition: croninfo.php:18
getCurrentDetailLevel()
Get Current Detail Level.