ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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().

28  {
29  $this->settings = $settings;
30  }
settings()
Definition: settings.php:2
+ 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.

References ilChatroomAdmin\getDefaultConfiguration().

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

37  {
38  if ($use_cache && self::$connection_status !== null) {
39  return self::$connection_status;
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 
46  return self::$connection_status;
47  }
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
+ 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.

References file_get_contents(), and settings().

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)
settings()
Definition: settings.php:2
+ 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.

References sendEnterPrivateRoom().

163  {
164  return $this->sendEnterPrivateRoom($scope, $subScope, $user);
165  }
sendEnterPrivateRoom($scope, $subScope, $user)
+ 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.

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

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

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  }
catch(Exception $e) $message
file_get_contents($url, array $stream_context_params=null)
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
static getLogger($a_component_id)
Get component logger.
$url
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
$response
+ 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.

References $settings.

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )
Returns
bool

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

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

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  }
file_get_contents($url, array $stream_context_params=null)
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
$response
+ 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.

References file_get_contents(), and settings().

Referenced by sendKick().

238  {
239  return $this->file_get_contents(
240  $this->settings->getURL('Kick', $scope) . '/' . $subScope . '/' . $user
241  );
242  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

References sendLeavePrivateRoom().

201  {
202  return $this->sendLeavePrivateRoom($scope, $subScope, $user);
203  }
sendLeavePrivateRoom($scope, $subScope, $user)
+ 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.

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

Referenced by sendMessage().

290  {
291  return $this->file_get_contents(
292  $this->settings->getURL('Post', $scope) . '?' . $query
293  );
294  }
file_get_contents($url, array $stream_context_params=null)
$query
settings()
Definition: settings.php:2
+ 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.

References file_get_contents(), and settings().

251  {
252  return $this->file_get_contents(
253  $this->settings->getURL('Ban', $scope) . '/' . $subScope . '/' . $user
254  );
255  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

References file_get_contents(), and settings().

187  {
188  return $this->file_get_contents(
189  $this->settings->getURL('ClearMessages', $scope) . '/' . $subScope . '/' . $user
190  );
191  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

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

136  {
137  return $this->file_get_contents(
138  $this->settings->getURL('CreatePrivateRoom', $scope) . '/' . $subScope . '/' . $user . '/' . rawurlencode($title)
139  );
140  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

References file_get_contents(), and settings().

149  {
150  return $this->file_get_contents(
151  $this->settings->getURL('DeletePrivateRoom', $scope) . '/' . $subScope . '/' . $user
152  );
153  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

References file_get_contents(), and settings().

Referenced by enterPrivateRoom().

174  {
175  return $this->file_get_contents(
176  $this->settings->getURL('EnterPrivateRoom', $scope) . '/' . $subScope . '/' . $user
177  );
178  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

References file_get_contents(), and settings().

304  {
305  return $this->file_get_contents(
306  $this->settings->getURL('InvitePrivateRoom', $scope) . '/' . $subScope . '/' . $user . '/' . $invited_id
307  );
308  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

References kick().

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.
+ 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.

References file_get_contents(), and settings().

Referenced by leavePrivateRoom().

212  {
213  return $this->file_get_contents(
214  $this->settings->getURL('LeavePrivateRoom', $scope) . '/' . $subScope . '/' . $user
215  );
216  }
file_get_contents($url, array $stream_context_params=null)
settings()
Definition: settings.php:2
+ 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.

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

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.
catch(Exception $e) $message
$query
Create styles array
The data for the language used.
$response
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ 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.

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

329  {
330  $query = http_build_query(array('message' => $message));
331  return $this->file_get_contents(
332  $this->settings->getURL('UserConfigChange', null) . '?' . $query
333  );
334  }
catch(Exception $e) $message
file_get_contents($url, array $stream_context_params=null)
$query
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
+ 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.

◆ $settings

ilChatroomServerConnector::$settings
private

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