ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

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

37  {
38  if($use_cache && self::$connection_status !== null)
39  {
40  return self::$connection_status;
41  }
42 
43  require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
44  $connector = new self(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
45  self::$connection_status = (bool)$connector->isServerAlive();
46 
47  return self::$connection_status;
48  }
+ 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 79 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

80  {
81  return $this->file_get_contents(
82  $this->settings->getURL('Connect', $scope) . '/' . $userId
83  );
84  }
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 321 of file class.ilChatroomServerConnector.php.

322  {
323  if($pRoomId != null)
324  {
325  $roomId .= '-' . $pRoomId;
326  }
327 
328  return $roomId;
329  }

◆ enterPrivateRoom()

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

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

References sendEnterPrivateRoom().

169  {
170  return $this->sendEnterPrivateRoom($scope, $subScope, $user);
171  }
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 91 of file class.ilChatroomServerConnector.php.

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

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

92  {
93  $credentials = $this->settings->getAuthKey() . ':' . $this->settings->getAuthSecret();
94  $header =
95  "Connection: close\r\n" .
96  "Content-Type: application/json; charset=utf-8\r\n" .
97  "Authorization: Basic " . base64_encode($credentials);
98 
99  $ctx = array(
100  'http' => array(
101  'method' => 'GET',
102  'header' => $header
103  ),
104  'https' => array(
105  'method' => 'GET',
106  'header' => $header
107  )
108  );
109 
110  if(is_array($stream_context_params))
111  {
112  $ctx = array_merge_recursive($ctx, $stream_context_params);
113  }
114 
115  set_error_handler(function ($severity, $message, $file, $line)
116  {
117  throw new ErrorException($message, $severity, $severity, $file, $line);
118  });
119 
120  try
121  {
122  $response = file_get_contents($url, null, stream_context_create($ctx));
123  restore_error_handler();
124  return $response;
125  }
126  catch(Exception $e)
127  {
128  restore_error_handler();
129  ilLoggerFactory::getLogger('chatroom')->alert($e->getMessage());
130  }
131 
132  return false;
133  }
$url
Definition: shib_logout.php:72
$header
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.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ 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 267 of file class.ilChatroomServerConnector.php.

References $settings.

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )
Returns
bool

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

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

54  {
55  $response = $this->file_get_contents(
56  $this->settings->getURL('Heartbeat'),
57  array(
58  'http' => array(
59  'timeout' => 2
60  ),
61  'https' => array(
62  'timeout' => 2
63  )
64  )
65  );
66 
67  $responseObject = json_decode($response);
68 
69  return $responseObject->status == 200;
70  }
file_get_contents($url, array $stream_context_params=null)
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
+ 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 243 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

Referenced by sendKick().

244  {
245  return $this->file_get_contents(
246  $this->settings->getURL('Kick', $scope) . '/' . $subScope . '/' . $user
247  );
248  }
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 206 of file class.ilChatroomServerConnector.php.

References sendLeavePrivateRoom().

207  {
208  return $this->sendLeavePrivateRoom($scope, $subScope, $user);
209  }
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 295 of file class.ilChatroomServerConnector.php.

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

Referenced by sendMessage().

296  {
297  return $this->file_get_contents(
298  $this->settings->getURL('Post', $scope) . '?' . $query
299  );
300  }
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:

◆ sendBan()

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

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

References file_get_contents(), and settings().

257  {
258  return $this->file_get_contents(
259  $this->settings->getURL('Ban', $scope) . '/' . $subScope . '/' . $user
260  );
261  }
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 192 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

193  {
194  return $this->file_get_contents(
195  $this->settings->getURL('ClearMessages', $scope) . '/' . $subScope . '/' . $user
196  );
197  }
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 141 of file class.ilChatroomServerConnector.php.

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

142  {
143  return $this->file_get_contents(
144  $this->settings->getURL('CreatePrivateRoom', $scope) . '/' . $subScope . '/' . $user . '/' . rawurlencode($title)
145  );
146  }
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 154 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

155  {
156  return $this->file_get_contents(
157  $this->settings->getURL('DeletePrivateRoom', $scope) . '/' . $subScope . '/' . $user
158  );
159  }
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 179 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

Referenced by enterPrivateRoom().

180  {
181  return $this->file_get_contents(
182  $this->settings->getURL('EnterPrivateRoom', $scope) . '/' . $subScope . '/' . $user
183  );
184  }
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 309 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

310  {
311  return $this->file_get_contents(
312  $this->settings->getURL('InvitePrivateRoom', $scope) . '/' . $subScope . '/' . $user . '/' . $invited_id
313  );
314  }
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 230 of file class.ilChatroomServerConnector.php.

References kick().

231  {
232  return $this->kick($scope, $subScope, $user);
233  }
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 217 of file class.ilChatroomServerConnector.php.

References file_get_contents(), and settings().

Referenced by leavePrivateRoom().

218  {
219  return $this->file_get_contents(
220  $this->settings->getURL('LeavePrivateRoom', $scope) . '/' . $subScope . '/' . $user
221  );
222  }
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 281 of file class.ilChatroomServerConnector.php.

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

282  {
283  $query = http_build_query(array('message' => $message) + $options);
284  $response = $this->post($scope, $query);
285  return @json_decode($response);
286  }
post($scope, $query)
Returns post URL Creates post URL using given $scope and $query and returns it.
if(!is_array($argv)) $options
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ sendUserConfigChange()

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

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

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

336  {
337  $query = http_build_query(array('message' => $message));
338  return $this->file_get_contents(
339  $this->settings->getURL('UserConfigChange', null) . '?' . $query);
340  }
file_get_contents($url, array $stream_context_params=null)
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: