ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
43  protected function isRepositoryObject() : bool
44  {
45  return false;
46  }
47 
52  public static function getScreenMode()
53  {
54  switch ($_GET['cmd']) {
55  default:
56  return IL_SCREEN_SIDE;
57  break;
58  }
59  }
60 
64  public function executeCommand()
65  {
66  $cmd = $this->ctrl->getCmd('getHTML');
67 
68  return $this->$cmd();
69  }
70 
74  public function getHTML()
75  {
77 
78  $chatSetting = new ilSetting('chatroom');
79  if ($this->getCurrentDetailLevel() == 0 || !$chatSetting->get('chat_enabled', 0) || !(bool) ilChatroomServerConnector::checkServerConnection()) {
80  return '';
81  } else {
82  return parent::getHTML();
83  }
84  }
85 
89  public function fillDataSection()
90  {
91  if ($this->ctrl->isAsynch() && isset($_GET['chatBlockCmd'])) {
92  return $this->dispatchAsyncCommand($_GET['chatBlockCmd']);
93  }
94 
95  $this->main_tpl->addJavascript('./Modules/Chatroom/js/chatviewer.js');
96  $this->main_tpl->addCss('./Modules/Chatroom/templates/default/style.css');
97 
98  $body_tpl = new ilTemplate('tpl.chatroom_block_message_body.html', true, true, 'Modules/Chatroom');
99 
100  $body_tpl->setVariable('TXT_ENABLE_AUTOSCROLL', $this->lng->txt('chat_enable_autoscroll'));
101  $body_tpl->setVariable('LOADER_PATH', ilUtil::getImagePath('loader.svg'));
102 
103  $this->ctrl->setParameterByClass('ilcolumngui', 'block_id', 'block_' . $this->getBlockType() . '_' . (int) $this->getBlockId());
104  $this->ctrl->setParameterByClass('ilcolumngui', 'ref_id', '#__ref_id');
105  $body_tpl->setVariable('CHATBLOCK_BASE_URL', $this->ctrl->getLinkTargetByClass('ilcolumngui', 'updateBlock', '', true));
106  $this->ctrl->setParameterByClass('ilcolumngui', 'block_id', '');
107  $this->ctrl->setParameterByClass('ilcolumngui', 'ref_id', '');
108 
109  $smilieys = array();
111  if ($settings->getSmiliesEnabled()) {
112  $smilies_array = ilChatroomSmilies::_getSmilies();
113  foreach ($smilies_array as $smiley_array) {
114  foreach ($smiley_array as $key => $value) {
115  if ($key == 'smiley_keywords') {
116  $new_keys = explode("\n", $value);
117  }
118 
119  if ($key == 'smiley_fullpath') {
120  $new_val = $value;
121  }
122  }
123 
124  foreach ($new_keys as $new_key) {
125  $smilieys[$new_key] = $new_val;
126  }
127  }
128  } else {
129  $smilieys = new stdClass();
130  }
131  $body_tpl->setVariable('SMILIES', json_encode($smilieys));
132 
133  $js_translations = array(
134  'LBL_CONNECT' => 'chat_connection_established',
135  'LBL_DISCONNECT' => 'chat_connection_disconnected',
136  'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
137  'LBL_DATEFORMAT' => 'lang_dateformat'
138  );
139  foreach ($js_translations as $placeholder => $lng_variable) {
140  $body_tpl->setVariable($placeholder, json_encode($this->lng->txt($lng_variable)));
141  }
142 
143  $content = $body_tpl->get();
144  $this->setDataSection($content);
145  }
146 
150  protected function dispatchAsyncCommand($cmd)
151  {
152  switch ($cmd) {
153  case 'getChatroomSelectionList':
154  return $this->getChatroomSelectionList();
155  break;
156 
157  case 'getMessages':
158  default:
159  return $this->getMessages();
160  break;
161  }
162  }
163 
164  protected function getChatroomSelectionList()
165  {
166  $result = new stdClass();
167  $result->ok = true;
168  $result->has_records = false;
169 
170  $chatblock = new ilChatroomBlock();
171  $result->html = $chatblock->getRoomSelect($result);
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 
235  public function getBlockType() : string
236  {
237  return self::$block_type;
238  }
239 }
$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.
getBlockId()
Get Block Id.
fillDataSection()
Fill data section.
exit
Definition: backend.php:16
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.