ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilChatroomServerConnector Class Reference

Class ilChatroomServerConnector. More...

+ Inheritance diagram for ilChatroomServerConnector:
+ Collaboration diagram for ilChatroomServerConnector:

Public Member Functions

 __construct (ilChatroomServerSettings $settings)
 Constructor Sets $this->settings using given $settings. More...
 
 isServerAlive ()
 
 connect ($scope, $userId)
 Returns connect URL Creates connect URL using given $scope and $userId and returns it. More...
 
 sendCreatePrivateRoom ($scope, $subScope, $user, $title)
 
 sendDeletePrivateRoom ($scope, $subScope, $user)
 
 enterPrivateRoom ($scope, $subScope, $user)
 
 sendEnterPrivateRoom ($scope, $subScope, $user)
 
 sendClearMessages ($scope, $subScope, $user)
 
 leavePrivateRoom ($scope, $subScope, $user)
 
 sendLeavePrivateRoom ($scope, $subScope, $user)
 
 sendKick ($scope, $subScope, $user)
 
 kick ($scope, $subScope, $user)
 Returns kick URL Creates kick URL using given $scope and $query and returns it. More...
 
 sendBan ($scope, $subScope, $user)
 
 getSettings ()
 Returns $this->settings. More...
 
 sendMessage ($scope, $message, $options=array())
 Returns if given message is sucessfully sent. More...
 
 post ($scope, $query)
 Returns post URL Creates post URL using given $scope and $query and returns it. More...
 
 sendInviteToPrivateRoom ($scope, $subScope, $user, $invited_id)
 
 createUniqueScopeId ($roomId, $pRoomId=null)
 
 sendUserConfigChange ($message)
 

Static Public Member Functions

static checkServerConnection ($use_cache=true)
 

Protected Member Functions

 file_get_contents ($url, array $stream_context_params=null)
 

Static Protected Attributes

static $connection_status = null
 

Private Attributes

 $settings
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilChatroomServerConnector::__construct ( ilChatroomServerSettings  $settings)

Constructor Sets $this->settings using given $settings.

Parameters
ilChatroomServerSettings$settings

Definition at line 27 of file class.ilChatroomServerConnector.php.

References $settings, and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkServerConnection()

static ilChatroomServerConnector::checkServerConnection (   $use_cache = true)
static
Parameters
bool | true$use_cache
Returns
bool

Definition at line 36 of file class.ilChatroomServerConnector.php.

37 {
38 if ($use_cache && self::$connection_status !== null) {
40 }
41
42 require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
43 $connector = new self(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
44 self::$connection_status = (bool) $connector->isServerAlive();
45
47 }
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.

References $connection_status, and ilChatroomAdmin\getDefaultConfiguration().

Referenced by ilChatroomAdminViewGUI\checkServerConnection(), and ilChatroomBlockGUI\getHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect()

ilChatroomServerConnector::connect (   $scope,
  $userId 
)

Returns connect URL Creates connect URL using given $scope and $userId and returns it.

Parameters
string$scope
integer$userId
Returns
mixed

Definition at line 78 of file class.ilChatroomServerConnector.php.

79 {
80 return $this->file_get_contents(
81 $this->settings->getURL('Connect', $scope) . '/' . $userId
82 );
83 }
file_get_contents($url, array $stream_context_params=null)

References file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ createUniqueScopeId()

ilChatroomServerConnector::createUniqueScopeId (   $roomId,
  $pRoomId = null 
)
Parameters
string$roomId
string | null$pRoomId
Returns
string

Definition at line 315 of file class.ilChatroomServerConnector.php.

316 {
317 if ($pRoomId != null) {
318 $roomId .= '-' . $pRoomId;
319 }
320
321 return $roomId;
322 }

◆ enterPrivateRoom()

ilChatroomServerConnector::enterPrivateRoom (   $scope,
  $subScope,
  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
mixed
Deprecated:
Please use sendEnterPrivateRoom instead

Definition at line 162 of file class.ilChatroomServerConnector.php.

163 {
164 return $this->sendEnterPrivateRoom($scope, $subScope, $user);
165 }
sendEnterPrivateRoom($scope, $subScope, $user)
$user
Definition: migrateto20.php:57

References $user, and sendEnterPrivateRoom().

+ Here is the call graph for this function:

◆ file_get_contents()

ilChatroomServerConnector::file_get_contents (   $url,
array  $stream_context_params = null 
)
protected
Parameters
string$url
array$stream_context_params
Returns
string|false

Definition at line 90 of file class.ilChatroomServerConnector.php.

91 {
92 $credentials = $this->settings->getAuthKey() . ':' . $this->settings->getAuthSecret();
93 $header =
94 "Connection: close\r\n" .
95 "Content-Type: application/json; charset=utf-8\r\n" .
96 "Authorization: Basic " . base64_encode($credentials);
97
98 $ctx = array(
99 'http' => array(
100 'method' => 'GET',
101 'header' => $header
102 ),
103 'https' => array(
104 'method' => 'GET',
105 'header' => $header
106 )
107 );
108
109 if (is_array($stream_context_params)) {
110 $ctx = array_merge_recursive($ctx, $stream_context_params);
111 }
112
113 set_error_handler(function ($severity, $message, $file, $line) {
114 throw new ErrorException($message, $severity, $severity, $file, $line);
115 });
116
117 try {
118 $response = file_get_contents($url, null, stream_context_create($ctx));
119 restore_error_handler();
120 return $response;
121 } catch (Exception $e) {
122 restore_error_handler();
123 ilLoggerFactory::getLogger('chatroom')->alert($e->getMessage());
124 }
125
126 return false;
127 }
static getLogger($a_component_id)
Get component logger.
catch(Exception $e) $message
$url
$response

References $header, $message, $response, $url, file_get_contents(), ilLoggerFactory\getLogger(), and settings().

Referenced by connect(), file_get_contents(), isServerAlive(), kick(), post(), sendBan(), sendClearMessages(), sendCreatePrivateRoom(), sendDeletePrivateRoom(), sendEnterPrivateRoom(), sendInviteToPrivateRoom(), sendLeavePrivateRoom(), and sendUserConfigChange().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings()

ilChatroomServerConnector::getSettings ( )

Returns $this->settings.

Returns
ilChatroomServerSettings

Definition at line 261 of file class.ilChatroomServerConnector.php.

262 {
263 return $this->settings;
264 }

References $settings.

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )
Returns
bool

Definition at line 52 of file class.ilChatroomServerConnector.php.

53 {
55 $this->settings->getURL('Heartbeat'),
56 array(
57 'http' => array(
58 'timeout' => 2
59 ),
60 'https' => array(
61 'timeout' => 2
62 )
63 )
64 );
65
66 $responseObject = json_decode($response);
67
68 return $responseObject->status == 200;
69 }

References $response, file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ kick()

ilChatroomServerConnector::kick (   $scope,
  $subScope,
  $user 
)

Returns kick URL Creates kick URL using given $scope and $query and returns it.

Parameters
string$scope
string$subScope
int$user
Returns
mixed

Definition at line 237 of file class.ilChatroomServerConnector.php.

238 {
239 return $this->file_get_contents(
240 $this->settings->getURL('Kick', $scope) . '/' . $subScope . '/' . $user
241 );
242 }

References $user, file_get_contents(), and settings().

Referenced by sendKick().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ leavePrivateRoom()

ilChatroomServerConnector::leavePrivateRoom (   $scope,
  $subScope,
  $user 
)
Parameters
string$scope
int$subScope
int$user
Returns
mixed
Deprecated:
; Use sendLeavePrivateRoom instead

Definition at line 200 of file class.ilChatroomServerConnector.php.

201 {
202 return $this->sendLeavePrivateRoom($scope, $subScope, $user);
203 }
sendLeavePrivateRoom($scope, $subScope, $user)

References $user, and sendLeavePrivateRoom().

+ Here is the call graph for this function:

◆ post()

ilChatroomServerConnector::post (   $scope,
  $query 
)

Returns post URL Creates post URL using given $scope and $query and returns it.

Parameters
string$scope
string$query
Returns
mixed

Definition at line 289 of file class.ilChatroomServerConnector.php.

290 {
291 return $this->file_get_contents(
292 $this->settings->getURL('Post', $scope) . '?' . $query
293 );
294 }
$query

References $query, file_get_contents(), and settings().

Referenced by sendMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendBan()

ilChatroomServerConnector::sendBan (   $scope,
  $subScope,
  $user 
)
Parameters
string$scope
string$subScope
int$user
Returns
false|string

Definition at line 250 of file class.ilChatroomServerConnector.php.

251 {
252 return $this->file_get_contents(
253 $this->settings->getURL('Ban', $scope) . '/' . $subScope . '/' . $user
254 );
255 }

References $user, file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ sendClearMessages()

ilChatroomServerConnector::sendClearMessages (   $scope,
  $subScope,
  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string

Definition at line 186 of file class.ilChatroomServerConnector.php.

187 {
188 return $this->file_get_contents(
189 $this->settings->getURL('ClearMessages', $scope) . '/' . $subScope . '/' . $user
190 );
191 }

References $user, file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ sendCreatePrivateRoom()

ilChatroomServerConnector::sendCreatePrivateRoom (   $scope,
  $subScope,
  $user,
  $title 
)
Parameters
int$scope
int$subScope
int$user
Returns
mixed

Definition at line 135 of file class.ilChatroomServerConnector.php.

136 {
137 return $this->file_get_contents(
138 $this->settings->getURL('CreatePrivateRoom', $scope) . '/' . $subScope . '/' . $user . '/' . rawurlencode($title)
139 );
140 }

References $title, $user, file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ sendDeletePrivateRoom()

ilChatroomServerConnector::sendDeletePrivateRoom (   $scope,
  $subScope,
  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
mixed

Definition at line 148 of file class.ilChatroomServerConnector.php.

149 {
150 return $this->file_get_contents(
151 $this->settings->getURL('DeletePrivateRoom', $scope) . '/' . $subScope . '/' . $user
152 );
153 }

References $user, file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ sendEnterPrivateRoom()

ilChatroomServerConnector::sendEnterPrivateRoom (   $scope,
  $subScope,
  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
mixed

Definition at line 173 of file class.ilChatroomServerConnector.php.

174 {
175 return $this->file_get_contents(
176 $this->settings->getURL('EnterPrivateRoom', $scope) . '/' . $subScope . '/' . $user
177 );
178 }

References $user, file_get_contents(), and settings().

Referenced by enterPrivateRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendInviteToPrivateRoom()

ilChatroomServerConnector::sendInviteToPrivateRoom (   $scope,
  $subScope,
  $user,
  $invited_id 
)
Parameters
int$scope
int$subScope
int$user
int$invited_id
Returns
mixed

Definition at line 303 of file class.ilChatroomServerConnector.php.

304 {
305 return $this->file_get_contents(
306 $this->settings->getURL('InvitePrivateRoom', $scope) . '/' . $subScope . '/' . $user . '/' . $invited_id
307 );
308 }

References $user, file_get_contents(), and settings().

+ Here is the call graph for this function:

◆ sendKick()

ilChatroomServerConnector::sendKick (   $scope,
  $subScope,
  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
string

Definition at line 224 of file class.ilChatroomServerConnector.php.

225 {
226 return $this->kick($scope, $subScope, $user);
227 }
kick($scope, $subScope, $user)
Returns kick URL Creates kick URL using given $scope and $query and returns it.

References $user, and kick().

+ Here is the call graph for this function:

◆ sendLeavePrivateRoom()

ilChatroomServerConnector::sendLeavePrivateRoom (   $scope,
  $subScope,
  $user 
)
Parameters
int$scope
int$subScope
int$user
Returns
mixed

Definition at line 211 of file class.ilChatroomServerConnector.php.

212 {
213 return $this->file_get_contents(
214 $this->settings->getURL('LeavePrivateRoom', $scope) . '/' . $subScope . '/' . $user
215 );
216 }

References $user, file_get_contents(), and settings().

Referenced by leavePrivateRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMessage()

ilChatroomServerConnector::sendMessage (   $scope,
  $message,
  $options = array() 
)

Returns if given message is sucessfully sent.

Calls $this->post using given $scope and $query built by http_build_query with given $message and returns if message was sent sucessfully.

Parameters
string$scope
string$message
Returns
stdClass

Definition at line 275 of file class.ilChatroomServerConnector.php.

276 {
277 $query = http_build_query(array('message' => $message) + $options);
278 $response = $this->post($scope, $query);
279 return @json_decode($response);
280 }
post($scope, $query)
Returns post URL Creates post URL using given $scope and $query and returns it.

References $message, PHPMailer\PHPMailer\$options, $query, $response, and post().

+ Here is the call graph for this function:

◆ sendUserConfigChange()

ilChatroomServerConnector::sendUserConfigChange (   $message)
Parameters
string$message
Returns
bool

Definition at line 328 of file class.ilChatroomServerConnector.php.

329 {
330 $query = http_build_query(array('message' => $message));
331 return $this->file_get_contents(
332 $this->settings->getURL('UserConfigChange', null) . '?' . $query
333 );
334 }

References $message, $query, file_get_contents(), and settings().

+ Here is the call graph for this function:

Field Documentation

◆ $connection_status

ilChatroomServerConnector::$connection_status = null
staticprotected

Definition at line 15 of file class.ilChatroomServerConnector.php.

Referenced by checkServerConnection().

◆ $settings

ilChatroomServerConnector::$settings
private

The documentation for this class was generated from the following file: