ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOnScreenChatGUI.php
Go to the documentation of this file.
1 <?php
2 
10 {
16  protected static $frontend_initialized = false;
17 
22  protected static function isOnScreenChatAccessible(ilSetting $chatSettings)
23  {
24  global $DIC;
25 
26  return $chatSettings->get('chat_enabled') && $chatSettings->get('enable_osc') && $DIC->user() && !$DIC->user()->isAnonymous();
27  }
28 
33  protected static function getEmoticons(ilChatroomServerSettings $chatSettings)
34  {
35  $smileys = array();
36 
37  if ($chatSettings->getSmiliesEnabled()) {
38  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
39  ;
40 
41  $smileys_array = ilChatroomSmilies::_getSmilies();
42  foreach ($smileys_array as $smiley_array) {
43  $new_keys = array();
44  $new_val = '';
45  foreach ($smiley_array as $key => $value) {
46  if ($key == 'smiley_keywords') {
47  $new_keys = explode("\n", $value);
48  }
49 
50  if ($key == 'smiley_fullpath') {
51  $new_val = $value;
52  }
53  }
54 
55  if (!$new_keys || !$new_val) {
56  continue;
57  }
58 
59  foreach ($new_keys as $new_key) {
60  $smileys[$new_key] = $new_val;
61  }
62  }
63  }
64 
65  return $smileys;
66  }
67 
68  public function executeCommand()
69  {
70  global $DIC;
71 
72  $cmd = $DIC->ctrl()->getCmd();
73 
74  switch ($cmd) {
75  case 'getUserProfileData':
76  $this->getUserProfileData();
77  break;
78  case 'verifyLogin':
79  $this->verifyLogin();
80  break;
81  case 'getUserlist':
82  default:
83  $this->getUserList();
84  }
85  }
86 
93  public function verifyLogin()
94  {
95  global $DIC;
96 
97  require_once 'Services/Authentication/classes/class.ilSession.php';
99 
100  echo json_encode(array(
101  'loggedIn' => $DIC->user() && !$DIC->user()->isAnonymous()
102  ));
103  exit;
104  }
105 
106  public function getUserList()
107  {
108  global $DIC;
109 
110  if (!$DIC->user() || $DIC->user()->isAnonymous()) {
111  return;
112  }
113 
114  require_once 'Services/OnScreenChat/classes/class.ilOnScreenChatUserUserAutoComplete.php';
116  $auto->setUser($DIC->user());
118  if (($_REQUEST['fetchall'])) {
119  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
120  }
121  $auto->setMoreLinkAvailable(true);
122  $auto->setSearchFields(array('firstname', 'lastname'));
123  $auto->setResultField('login');
124  $auto->enableFieldSearchableCheck(true);
125  echo $auto->getList($_REQUEST['term']);
126  exit;
127  }
128 
129  public function getUserProfileData()
130  {
131  global $DIC;
132 
133  if (!$DIC->user() || $DIC->user()->isAnonymous()) {
134  echo json_encode([]);
135  exit();
136  }
137 
138  if (!isset($_GET['usr_ids']) || strlen($_GET['usr_ids']) == 0) {
139  echo json_encode([]);
140  exit();
141  }
142 
143  $DIC['lng']->loadLanguageModule('user');
144 
145  $userProvider = new \ilOnScreenChatUserDataProvider($DIC->database(), $DIC->user());
146  $data = $userProvider->getDataByUserIds(explode(',', $_GET['usr_ids']));
147 
148  require_once 'Services/Authentication/classes/class.ilSession.php';
150 
151  echo json_encode($data);
152  exit();
153  }
154 
158  public static function initializeFrontend()
159  {
160  global $DIC;
161 
162  if (!self::$frontend_initialized) {
163  $clientSettings = new ilSetting('chatroom');
164 
165  if (!self::isOnScreenChatAccessible($clientSettings)) {
166  self::$frontend_initialized = true;
167  return;
168  }
169 
170  require_once 'Services/JSON/classes/class.ilJsonUtil.php';
171 
172  $settings = self::loadServerSettings();
173 
174  $DIC->language()->loadLanguageModule('chatroom');
175  $DIC->language()->loadLanguageModule('user');
176 
177  $renderer = $DIC->ui()->renderer();
178  $factory = $DIC->ui()->factory();
179 
180  $chatWindowTemplate = new ilTemplate('tpl.chat-window.html', false, false, 'Services/OnScreenChat');
181  $chatWindowTemplate->setVariable('SUBMIT_ACTION', $renderer ->render(
182  $factory->button()->standard($DIC->language()->txt('chat_osc_send'), 'onscreenchat-submit')
183  ));
184  $chatWindowTemplate->setVariable('ADD_ACTION', $renderer ->render(
185  $factory->glyph()->add('addUser')
186  ));
187  $chatWindowTemplate->setVariable('CLOSE_ACTION', $renderer ->render(
188  $factory->button()->close()
189  ));
190  $chatWindowTemplate->setVariable('CONVERSATION_ICON', ilUtil::img(ilUtil::getImagePath('icon_chta.svg')));
191 
192  $userProvider = new \ilOnScreenChatUserDataProvider($DIC->database(), $DIC->user());
193 
194  $guiConfig = array(
195  'chatWindowTemplate' => $chatWindowTemplate->get(),
196  'messageTemplate' => (new ilTemplate('tpl.chat-message.html', false, false, 'Services/OnScreenChat'))->get(),
197  'modalTemplate' => (new ilTemplate('tpl.chat-add-user.html', false, false, 'Services/OnScreenChat'))->get(),
198  'userId' => $DIC->user()->getId(),
199  'username' => $DIC->user()->getLogin(),
200  'userListURL' => $DIC->ctrl()->getLinkTargetByClass('ilonscreenchatgui', 'getUserList', '', true, false),
201  'userProfileDataURL' => $DIC->ctrl()->getLinkTargetByClass('ilonscreenchatgui', 'getUserProfileData', '', true, false),
202  'verifyLoginURL' => $DIC->ctrl()->getLinkTargetByClass('ilonscreenchatgui', 'verifyLogin', '', true, false),
203  'loaderImg' => ilUtil::getImagePath('loader.svg'),
204  'emoticons' => self::getEmoticons($settings),
205  'locale' => $DIC->language()->getLangKey(),
206  'initialUserData' => $userProvider->getInitialUserProfileData(),
207  );
208 
209  $chatConfig = array(
210  'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
211  'subDirectory' => $settings->getSubDirectory() . '/socket.io',
212  'userId' => $DIC->user()->getId(),
213  'username' => $DIC->user()->getLogin(),
214  );
215 
216  $DIC->language()->toJS(array(
217  'chat_osc_no_usr_found', 'chat_osc_emoticons', 'chat_osc_write_a_msg', 'autocomplete_more',
218  'close', 'chat_osc_invite_to_conversation', 'chat_osc_user', 'chat_osc_add_user', 'chat_osc_subs_rej_msgs',
219  'chat_osc_subs_rej_msgs_p', 'chat_osc_self_rej_msgs', 'chat_osc_search_modal_info',
220  'chat_osc_head_grp_x_persons'
221  ));
222 
223  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
226 
227  require_once 'Services/Link/classes/class.ilLinkifyUtil.php';
229 
230  $DIC['tpl']->addJavaScript('./libs/bower/bower_components/jquery-outside-events/jquery.ba-outside-events.min.js');
231  $DIC['tpl']->addJavaScript('./libs/bower/bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
232  $DIC['tpl']->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
233  $DIC['tpl']->addJavascript('./libs/composer/components/moment/min/moment-with-locales.js');
234  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/moment.js');
235  $DIC['tpl']->addJavascript('./Modules/Chatroom/chat/node_modules/socket.io/node_modules/socket.io-client/socket.io.js');
236  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/chat.js');
237  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/onscreenchat.js');
238  $DIC['tpl']->addOnLoadCode("il.Chat.setConfig(" . json_encode($chatConfig) . ");");
239  $DIC['tpl']->addOnLoadCode("il.OnScreenChat.setConfig(" . json_encode($guiConfig) . ");");
240  $DIC['tpl']->addOnLoadCode("il.OnScreenChat.init();");
241 
242  self::$frontend_initialized = true;
243  }
244  }
245 
246  protected static function loadServerSettings()
247  {
248  require_once './Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
250  }
251 }
static enableWebAccessWithoutSession($enable_web_access_without_session)
Class ilOnScreenChatUserUserAutoComplete.
static initializeFrontend()
Initialize frontend and delivers required javascript files and configuration to the global template...
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$factory
Definition: metadata.php:47
static getEmoticons(ilChatroomServerSettings $chatSettings)
Class ilOnScreenChatGUI.
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
Create styles array
The data for the language used.
get($a_keyword, $a_default_value=false)
get setting
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
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)
inits and adds the jQuery JS-File to the global or a passed template
$key
Definition: croninfo.php:18
static initLinkify($a_tpl=null)
Init Linkify.