[REALTIME] Reviewed both the superclass and its dist plugins
This commit is contained in:
@@ -31,7 +31,7 @@ if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once INSTALLDIR.'/plugins/Realtime/RealtimePlugin.php';
|
||||
require_once INSTALLDIR . DIRECTORY_SEPARATOR . 'lib/modules/Realtime/RealtimePlugin.php';
|
||||
|
||||
/**
|
||||
* Plugin to do realtime updates using Comet
|
||||
@@ -52,8 +52,12 @@ class CometPlugin extends RealtimePlugin
|
||||
public $prefix = null;
|
||||
protected $bay = null;
|
||||
|
||||
function __construct($server=null, $username=null, $password=null, $prefix=null)
|
||||
{
|
||||
public function __construct(
|
||||
?string $server = null,
|
||||
?string $username = null,
|
||||
?string $password = null,
|
||||
?string $prefix = null
|
||||
) {
|
||||
$this->server = $server;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
@@ -62,11 +66,11 @@ class CometPlugin extends RealtimePlugin
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function _getScripts()
|
||||
public function _getScripts(): array
|
||||
{
|
||||
$scripts = parent::_getScripts();
|
||||
|
||||
$ours = array('js/jquery.comet.js', 'js/cometupdate.js');
|
||||
$ours = ['js/jquery.comet.js', 'js/cometupdate.js'];
|
||||
|
||||
foreach ($ours as $script) {
|
||||
$scripts[] = $this->path($script);
|
||||
@@ -75,30 +79,30 @@ class CometPlugin extends RealtimePlugin
|
||||
return $scripts;
|
||||
}
|
||||
|
||||
function _updateInitialize($timeline, $user_id)
|
||||
public function _updateInitialize($timeline, int $user_id)
|
||||
{
|
||||
$script = parent::_updateInitialize($timeline, $user_id);
|
||||
return $script." CometUpdate.init(\"$this->server\", \"$timeline\", $user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->deleteurl\");";
|
||||
}
|
||||
|
||||
function _connect()
|
||||
public function _connect(): void
|
||||
{
|
||||
require_once INSTALLDIR.'/plugins/Comet/extlib/Bayeux/Bayeux.class.php';
|
||||
require_once __DIR__. DIRECTORY_SEPARATOR . 'extlib/Bayeux/Bayeux.class.php';
|
||||
// Bayeux? Comet? Huh? These terms confuse me
|
||||
$this->bay = new Bayeux($this->server, $this->user, $this->password);
|
||||
}
|
||||
|
||||
function _publish($timeline, $json)
|
||||
public function _publish($timeline, $json): void
|
||||
{
|
||||
$this->bay->publish($timeline, $json);
|
||||
}
|
||||
|
||||
function _disconnect()
|
||||
public function _disconnect(): void
|
||||
{
|
||||
unset($this->bay);
|
||||
}
|
||||
|
||||
function _pathToChannel($path)
|
||||
public function _pathToChannel(array $path): string
|
||||
{
|
||||
if (!empty($this->prefix)) {
|
||||
array_unshift($path, $this->prefix);
|
||||
@@ -108,14 +112,16 @@ class CometPlugin extends RealtimePlugin
|
||||
|
||||
public function onPluginVersion(array &$versions): bool
|
||||
{
|
||||
$versions[] = array('name' => 'Comet',
|
||||
'version' => self::PLUGIN_VERSION,
|
||||
'author' => 'Evan Prodromou',
|
||||
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Comet',
|
||||
'rawdescription' =>
|
||||
// TRANS: Plugin description message. Bayeux is a protocol for transporting asynchronous messages
|
||||
// TRANS: and Comet is a web application model.
|
||||
_m('Plugin to make updates using Comet and Bayeux.'));
|
||||
$versions[] = [
|
||||
'name' => 'Comet',
|
||||
'version' => self::PLUGIN_VERSION,
|
||||
'author' => 'Evan Prodromou',
|
||||
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Comet',
|
||||
'rawdescription' =>
|
||||
// TRANS: Plugin description message. Bayeux is a protocol for transporting asynchronous messages
|
||||
// TRANS: and Comet is a web application model.
|
||||
_m('Plugin to make updates using Comet and Bayeux.')
|
||||
];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -30,36 +30,36 @@ class Bayeux
|
||||
|
||||
public $sUrl = '';
|
||||
|
||||
function __construct($sUrl, $sUser='', $sPassword='')
|
||||
public function __construct($sUrl, $sUser='', $sPassword='')
|
||||
{
|
||||
$this->sUrl = $sUrl;
|
||||
|
||||
$this->oCurl = curl_init();
|
||||
|
||||
$aHeaders = array();
|
||||
$aHeaders = [];
|
||||
$aHeaders[] = 'Connection: Keep-Alive';
|
||||
|
||||
curl_setopt($this->oCurl, CURLOPT_URL, $sUrl);
|
||||
curl_setopt($this->oCurl, CURLOPT_HTTPHEADER, $aHeaders);
|
||||
curl_setopt($this->oCurl, CURLOPT_HEADER, 0);
|
||||
curl_setopt($this->oCurl, CURLOPT_POST, 1);
|
||||
curl_setopt($this->oCurl, CURLOPT_RETURNTRANSFER,1);
|
||||
curl_setopt($this->oCurl, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
if (!is_null($sUser) && mb_strlen($sUser) > 0) {
|
||||
curl_setopt($this->oCurl, CURLOPT_USERPWD,"$sUser:$sPassword");
|
||||
curl_setopt($this->oCurl, CURLOPT_USERPWD, "$sUser:$sPassword");
|
||||
}
|
||||
|
||||
$this->handShake();
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
public function __destruct()
|
||||
{
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
function handShake()
|
||||
public function handShake()
|
||||
{
|
||||
$msgHandshake = array();
|
||||
$msgHandshake = [];
|
||||
$msgHandshake['channel'] = '/meta/handshake';
|
||||
$msgHandshake['version'] = "1.0";
|
||||
$msgHandshake['minimumVersion'] = "0.9";
|
||||
@@ -70,8 +70,9 @@ class Bayeux
|
||||
|
||||
$data = curl_exec($this->oCurl);
|
||||
|
||||
if(curl_errno($this->oCurl))
|
||||
die("Error: " . curl_error($this->oCurl));
|
||||
if (curl_errno($this->oCurl)) {
|
||||
die("Error: " . curl_error($this->oCurl));
|
||||
}
|
||||
|
||||
$oReturn = json_decode($data);
|
||||
|
||||
@@ -81,8 +82,7 @@ class Bayeux
|
||||
|
||||
$bSuccessful = ($oReturn->successful) ? true : false;
|
||||
|
||||
if($bSuccessful)
|
||||
{
|
||||
if ($bSuccessful) {
|
||||
$this->clientId = $oReturn->clientId;
|
||||
|
||||
$this->connect();
|
||||
@@ -101,9 +101,9 @@ class Bayeux
|
||||
$data = curl_exec($this->oCurl);
|
||||
}
|
||||
|
||||
function disconnect()
|
||||
public function disconnect()
|
||||
{
|
||||
$msgHandshake = array();
|
||||
$msgHandshake = [];
|
||||
$msgHandshake['channel'] = '/meta/disconnect';
|
||||
$msgHandshake['id'] = $this->nNextId++;
|
||||
$msgHandshake['clientId'] = $this->clientId;
|
||||
@@ -115,10 +115,11 @@ class Bayeux
|
||||
|
||||
public function publish($sChannel, $oData)
|
||||
{
|
||||
if(!$sChannel || !$oData)
|
||||
return;
|
||||
if (!$sChannel || !$oData) {
|
||||
return;
|
||||
}
|
||||
|
||||
$aMsg = array();
|
||||
$aMsg = [];
|
||||
|
||||
$aMsg['channel'] = $sChannel;
|
||||
$aMsg['id'] = $this->nNextId++;
|
||||
|
Reference in New Issue
Block a user