ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4require_once 'Services/Block/classes/class.ilBlockGUI.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
6require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
7require_once 'Services/JSON/classes/class.ilJsonUtil.php';
8require_once 'Modules/Chatroom/classes/class.ilChatroomBlock.php';
9require_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 getBlockType()
47 {
48 return self::$block_type;
49 }
50
55 public static function isRepositoryObject()
56 {
57 return false;
58 }
59
64 public static function getScreenMode()
65 {
66 switch($_GET['cmd'])
67 {
68 default:
69 return IL_SCREEN_SIDE;
70 break;
71 }
72 }
73
77 public function executeCommand()
78 {
82 global $ilCtrl;
83
84 $cmd = $ilCtrl->getCmd('getHTML');
85
86 return $this->$cmd();
87 }
88
92 public function getHTML()
93 {
95
96 $chatSetting = new ilSetting('chatroom');
97 if($this->getCurrentDetailLevel() == 0 || !$chatSetting->get('chat_enabled', 0) || !(bool)ilChatroomServerConnector::checkServerConnection())
98 {
99 return '';
100 }
101 else
102 {
103 return parent::getHTML();
104 }
105 }
106
110 public function fillDataSection()
111 {
117 global $tpl, $lng, $ilCtrl;
118
119 //@todo: Dirty hack
120 if($ilCtrl->isAsynch() && isset($_GET['chatBlockCmd']))
121 {
122 return $this->dispatchAsyncCommand($_GET['chatBlockCmd']);
123 }
124
125 $tpl->addJavascript('./Modules/Chatroom/js/chatviewer.js');
126 $tpl->addCss('./Modules/Chatroom/templates/default/style.css');
127
128 $body_tpl = new ilTemplate('tpl.chatroom_block_message_body.html', true, true, 'Modules/Chatroom');
129
130 $body_tpl->setVariable('TXT_ENABLE_AUTOSCROLL', $lng->txt('chat_enable_autoscroll'));
131 $body_tpl->setVariable('LOADER_PATH', ilUtil::getImagePath('loader.svg'));
132
133 $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', 'block_' . $this->getBlockType() . '_' . (int)$this->getBlockId());
134 $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '#__ref_id');
135 $body_tpl->setVariable('CHATBLOCK_BASE_URL', $ilCtrl->getLinkTargetByClass('ilcolumngui', 'updateBlock', '', true));
136 $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', '');
137 $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '');
138
139 $smilieys = array();
141 if($settings->getSmiliesEnabled())
142 {
143 $smilies_array = ilChatroomSmilies::_getSmilies();
144 foreach($smilies_array as $smiley_array)
145 {
146 foreach($smiley_array as $key => $value)
147 {
148 if($key == 'smiley_keywords')
149 {
150 $new_keys = explode("\n", $value);
151 }
152
153 if($key == 'smiley_fullpath')
154 {
155 $new_val = $value;
156 }
157 }
158
159 foreach($new_keys as $new_key)
160 {
161 $smilieys[$new_key] = $new_val;
162 }
163 }
164 }
165 else
166 {
167 $smilieys = new stdClass();
168 }
169 $body_tpl->setVariable('SMILIES', json_encode($smilieys));
170
171 $js_translations = array(
172 'LBL_CONNECT' => 'chat_connection_established',
173 'LBL_DISCONNECT' => 'chat_connection_disconnected',
174 'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
175 'LBL_DATEFORMAT' => 'lang_dateformat'
176 );
177 foreach($js_translations as $placeholder => $lng_variable)
178 {
179 $body_tpl->setVariable($placeholder, json_encode($lng->txt($lng_variable)));
180 }
181
182 $content = $body_tpl->get();
183 $this->setDataSection($content);
184 }
185
189 protected function dispatchAsyncCommand($cmd)
190 {
191 switch($cmd)
192 {
193 case 'getChatroomSelectionList':
194 return $this->getChatroomSelectionList();
195 break;
196
197 case 'getMessages':
198 default;
199 return $this->getMessages();
200 break;
201 }
202 }
203
204 protected function getChatroomSelectionList()
205 {
206 $result = new stdClass();
207 $result->ok = true;
208
209 $chatblock = new ilChatroomBlock();
210 $result->html = $chatblock->getRoomSelect();
211
212 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
214 exit();
215 }
216
220 protected function getMessages()
221 {
227 global $rbacsystem, $ilUser, $lng;
228
229 $result = new stdClass();
230 $result->ok = false;
231
232 if(!(int)$_REQUEST['ref_id'])
233 {
235 exit();
236 }
237
241 $object = ilObjectFactory::getInstanceByRefId((int)$_REQUEST['ref_id'], false);
242 if(!$object || !$rbacsystem->checkAccess('read', (int)$_REQUEST['ref_id']))
243 {
245 (
246 $ilUser->getId(), 'chatviewer_last_selected_room',
247 0
248 );
249
250 $result->errormsg = $lng->txt('msg_no_perm_read');
252 exit();
253 }
254
255 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
256 $room = ilChatroom::byObjectId($object->getId());
257
258 $block = new ilChatroomBlock();
259 $msg = $block->getMessages($room);
260
261 $ilUser->setPref
262 (
263 'chatviewer_last_selected_room',
264 $object->getRefId()
265 );
267 (
268 $ilUser->getId(), 'chatviewer_last_selected_room',
269 $object->getRefId()
270 );
271
272 $result->messages = array_reverse($msg);
273 $result->ok = true;
274
275 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
277 exit();
278 }
279}
$result
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
const IL_SCREEN_SIDE
This class represents a block method of a block.
setImage($a_image)
Set Image.
getCurrentDetailLevel()
Get Current Detail Level.
getBlockId()
Get Block Id.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
fillDataSection()
Standard implementation for row based data.
setTitle($a_title)
Set Title.
Class ilChatroomBlockGUI.
static _getSmilies()
Fetches smilies from database.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static encode($mixed, $suppress_native=false)
static _writePref($a_usr_id, $a_keyword, $a_value)
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initJson()
Init YUI JSON component.
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilUser
Definition: imgupload.php:15