ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilOnScreenChatGUI.php
Go to the documentation of this file.
1 <?php
2 
10 {
11  const WAC_TTL_TIME = 60;
12 
18  protected static $frontend_initialized = false;
19 
24  protected static function isOnScreenChatAccessible(ilSetting $chatSettings)
25  {
26  global $DIC;
27 
28  return $chatSettings->get('chat_enabled') && $chatSettings->get('enable_osc') && $DIC->user() && !$DIC->user()->isAnonymous();
29  }
30 
35  protected static function getEmoticons(ilChatroomServerSettings $chatSettings)
36  {
37  $smileys = array();
38 
39  if($chatSettings->getSmiliesEnabled())
40  {
41  require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
42  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
43 
45 
46  $smileys_array = ilChatroomSmilies::_getSmilies();
47  foreach($smileys_array as $smiley_array)
48  {
49  $new_keys = array();
50  $new_val = '';
51  foreach($smiley_array as $key => $value)
52  {
53  if($key == 'smiley_keywords')
54  {
55  $new_keys = explode("\n", $value);
56  }
57 
58  if($key == 'smiley_fullpath')
59  {
60  $new_val = ilWACSignedPath::signFile($value);
61  }
62  }
63 
64  if(!$new_keys || !$new_val)
65  {
66  continue;
67  }
68 
69  foreach($new_keys as $new_key)
70  {
71  $smileys[$new_key] = $new_val;
72  }
73  }
74  }
75 
76  return $smileys;
77  }
78 
79  public function executeCommand()
80  {
81  global $DIC;
82 
83  $cmd = $DIC->ctrl()->getCmd();
84 
85  switch($cmd)
86  {
87  case 'getUserProfileImages':
88  $this->getUserProfileImages();
89  break;
90  case 'verifyLogin':
91  $this->verifyLogin();
92  break;
93  case 'getUserlist':
94  default:
95  $this->getUserList();
96  }
97  }
98 
105  public function verifyLogin()
106  {
107  global $DIC;
108 
109  require_once 'Services/Authentication/classes/class.ilSession.php';
111 
112  echo json_encode(array(
113  'loggedIn' => $DIC->user() && !$DIC->user()->isAnonymous()
114  ));
115  exit;
116  }
117 
118  public function getUserList()
119  {
120  global $DIC;
121 
122  if(!$DIC->user() || $DIC->user()->isAnonymous())
123  {
124  return;
125  }
126 
127  require_once 'Services/OnScreenChat/classes/class.ilOnScreenChatUserUserAutoComplete.php';
129  $auto->setUser($DIC->user());
131  if(($_REQUEST['fetchall']))
132  {
133  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
134  }
135  $auto->setMoreLinkAvailable(true);
136  $auto->setSearchFields(array('firstname', 'lastname'));
137  $auto->setResultField('login');
138  $auto->enableFieldSearchableCheck(true);
139  echo $auto->getList($_REQUEST['term']);
140  exit;
141  }
142 
143  public function getUserProfileImages()
144  {
145  global $DIC;
146 
147  $response = array();
148 
149  if(!$DIC->user() || $DIC->user()->isAnonymous())
150  {
151  echo json_encode($response);
152  exit();
153  }
154 
155  if(!isset($_GET['usr_ids']) || strlen($_GET['usr_ids']) == 0)
156  {
157  echo json_encode($response);
158  exit();
159  }
160 
161  $DIC['lng']->loadLanguageModule('user');
162 
163  require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
165 
166  $user_ids = array_filter(array_map('intval', array_map('trim', explode(',', $_GET['usr_ids']))));
167  require_once 'Services/User/classes/class.ilUserUtil.php';
168  $public_data = ilUserUtil::getNamePresentation($user_ids, true, false, '', false, true, false, true);
169  $public_names = ilUserUtil::getNamePresentation($user_ids, false, false, '', false, true, false, false);
170 
171  foreach($user_ids as $usr_id)
172  {
173  $public_image = isset($public_data[$usr_id]) && isset($public_data[$usr_id]['img']) ? $public_data[$usr_id]['img'] : '';
174 
175  $public_name = '';
176  if(isset($public_names[$usr_id]))
177  {
178  $public_name = $public_names[$usr_id];
179  if('unknown' == $public_name && isset($public_data[$usr_id]) && isset($public_data[$usr_id]['login']))
180  {
181  $public_name = $public_data[$usr_id]['login'];
182  }
183  }
184 
185  $response[$usr_id] = array(
186  'public_name' => $public_name,
187  'profile_image' => $public_image
188  );
189  }
190 
191  require_once 'Services/Authentication/classes/class.ilSession.php';
193 
194  echo json_encode($response);
195  exit();
196  }
197 
201  public static function initializeFrontend()
202  {
203  global $DIC;
204 
205  if(!self::$frontend_initialized)
206  {
207  $clientSettings = new ilSetting('chatroom');
208 
209  if(!self::isOnScreenChatAccessible($clientSettings))
210  {
211  self::$frontend_initialized = true;
212  return;
213  }
214 
215  require_once 'Services/JSON/classes/class.ilJsonUtil.php';
216 
217  $settings = self::loadServerSettings();
218 
219  $DIC->language()->loadLanguageModule('chatroom');
220 
221  $renderer = $DIC->ui()->renderer();
222  $factory = $DIC->ui()->factory();
223 
224  $chatWindowTemplate = new ilTemplate('tpl.chat-window.html', false, false, 'Services/OnScreenChat');
225  $chatWindowTemplate->setVariable('SUBMIT_ACTION', $renderer ->render(
226  $factory->button()->standard($DIC->language()->txt('chat_osc_send'), 'onscreenchat-submit')
227  ));
228  $chatWindowTemplate->setVariable('ADD_ACTION', $renderer ->render(
229  $factory->glyph()->add('addUser')
230  ));
231  $chatWindowTemplate->setVariable('CLOSE_ACTION', $renderer ->render(
232  $factory->button()->close()
233  ));
234  $chatWindowTemplate->setVariable('CONVERSATION_ICON', ilUtil::img(ilUtil::getImagePath('icon_chta.svg')));
235 
236  $guiConfig = array(
237  'chatWindowTemplate' => $chatWindowTemplate->get(),
238  'messageTemplate' => (new ilTemplate('tpl.chat-message.html', false, false, 'Services/OnScreenChat'))->get(),
239  'modalTemplate' => (new ilTemplate('tpl.chat-add-user.html', false, false, 'Services/OnScreenChat'))->get(),
240  'userId' => $DIC->user()->getId(),
241  'username' => $DIC->user()->getLogin(),
242  'userListURL' => $DIC->ctrl()->getLinkTargetByClass('ilonscreenchatgui', 'getUserList', '', true, false),
243  'userProfileDataURL' => $DIC->ctrl()->getLinkTargetByClass('ilonscreenchatgui', 'getUserProfileImages', '', true, false),
244  'verifyLoginURL' => $DIC->ctrl()->getLinkTargetByClass('ilonscreenchatgui', 'verifyLogin', '', true, false),
245  'loaderImg' => ilUtil::getImagePath('loader.svg'),
246  'emoticons' => self::getEmoticons($settings),
247  'locale' => $DIC->language()->getLangKey()
248  );
249 
250  $chatConfig = array(
251  'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
252  'subDirectory' => $settings->getSubDirectory() . '/socket.io',
253  'userId' => $DIC->user()->getId(),
254  'username' => $DIC->user()->getLogin()
255  );
256 
257  $DIC->language()->toJS(array(
258  'chat_osc_no_usr_found', 'chat_osc_emoticons', 'chat_osc_write_a_msg', 'autocomplete_more',
259  'close', 'chat_osc_invite_to_conversation', 'chat_osc_user', 'chat_osc_add_user', 'chat_osc_subs_rej_msgs',
260  'chat_osc_subs_rej_msgs_p', 'chat_osc_self_rej_msgs'
261  ));
262 
263  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
266 
267  require_once 'Services/Link/classes/class.ilLinkifyUtil.php';
269 
270  $DIC['tpl']->addJavaScript('./Services/jQuery/js/jquery.outside.events.min.js');
271  $DIC['tpl']->addJavaScript('./Services/jQuery/js/jquery.ui.touch-punch.min.js');
272  $DIC['tpl']->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
273  $DIC['tpl']->addJavascript('./libs/composer/components/moment/min/moment-with-locales.js');
274  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/moment.js');
275  $DIC['tpl']->addJavascript('./Modules/Chatroom/chat/node_modules/socket.io/node_modules/socket.io-client/socket.io.js');
276  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/chat.js');
277  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/onscreenchat.js');
278  $DIC['tpl']->addOnLoadCode("il.Chat.setConfig(".ilJsonUtil::encode($chatConfig).");");
279  $DIC['tpl']->addOnLoadCode("il.OnScreenChat.setConfig(".ilJsonUtil::encode($guiConfig).");");
280  $DIC['tpl']->addOnLoadCode("il.OnScreenChat.init();");
281 
282  self::$frontend_initialized = true;
283  }
284  }
285 
286  protected static function loadServerSettings()
287  {
288  require_once './Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
289  return ilChatroomServerSettings::loadDefault();
290  }
291 }
static enableWebAccessWithoutSession($enable_web_access_without_session)
static initjQueryUI()
Init jQuery UI (see included_components.txt for included components)
ILIAS Setting Class.
Class ilOnScreenChatUserUserAutoComplete.
static initializeFrontend()
Initialize frontend and delivers required javascript files and configuration to the global template...
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
static getEmoticons(ilChatroomServerSettings $chatSettings)
Class ilOnScreenChatGUI.
static getNamePresentation($a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false)
Default behaviour is:
static encode($mixed, $suppress_native=false)
static isOnScreenChatAccessible(ilSetting $chatSettings)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
static signFile($path_to_file)
Create styles array
The data for the language used.
get($a_keyword, $a_default_value=false)
get setting
Class ilChatroomServerSettings.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
verifyLogin()
Checks if a user is logged in.
static initjQuery($a_tpl=null)
Init jQuery.
global $DIC
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
static initLinkify($a_tpl=null)
Init Linkify.