123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
- exit(1);
- }
- require_once INSTALLDIR.'/plugins/Realtime/RealtimePlugin.php';
- class OrbitedPlugin extends RealtimePlugin
- {
- const PLUGIN_VERSION = '2.0.0';
- public $webserver = null;
- public $webport = null;
- public $channelbase = null;
- public $stompserver = null;
- public $stompport = null;
- public $username = null;
- public $password = null;
- public $webuser = null;
- public $webpass = null;
- protected $con = null;
- function onStartShowHeadElements($action)
- {
-
- $action->element('script', null, ' document.domain = document.domain; ');
- }
- function _getScripts()
- {
- $scripts = parent::_getScripts();
- $port = (is_null($this->webport)) ? 8000 : $this->webport;
- $server = (is_null($this->webserver)) ? common_config('site', 'server') : $this->webserver;
- $root = 'http://'.$server.(($port == 80) ? '':':'.$port);
- $scripts[] = $root.'/static/Orbited.js';
- $scripts[] = $this->path('js/orbitedextra.js');
- $scripts[] = $root.'/static/protocols/stomp/stomp.js';
- $scripts[] = $this->path('js/orbitedupdater.js');
- return $scripts;
- }
- function _updateInitialize($timeline, $user_id)
- {
- $script = parent::_updateInitialize($timeline, $user_id);
- $server = $this->_getStompServer();
- $port = $this->_getStompPort();
- return $script." OrbitedUpdater.init(\"$server\", $port, ".
- "\"{$timeline}\", \"{$this->webuser}\", \"{$this->webpass}\");";
- }
- function _connect()
- {
- require_once(INSTALLDIR.'/extlib/Stomp.php');
- $url = $this->_getStompUrl();
- $this->con = new Stomp($url);
- if ($this->con->connect($this->username, $this->password)) {
- $this->log(LOG_INFO, "Connected.");
- } else {
- $this->log(LOG_ERR, 'Failed to connect to queue server');
-
- throw new ServerException(_m('Failed to connect to queue server.'));
- }
- }
- function _publish($channel, $message)
- {
- $result = $this->con->send($channel,
- json_encode($message));
- return $result;
-
- }
- function _disconnect()
- {
- $this->con->disconnect();
- }
- function _pathToChannel($path)
- {
- if (!empty($this->channelbase)) {
- array_unshift($path, $this->channelbase);
- }
- return '/' . implode('/', $path);
- }
- function _getStompServer()
- {
- return (!is_null($this->stompserver)) ? $this->stompserver :
- (!is_null($this->webserver)) ? $this->webserver :
- common_config('site', 'server');
- }
- function _getStompPort()
- {
- return (!is_null($this->stompport)) ? $this->stompport : 61613;
- }
- function _getStompUrl()
- {
- $server = $this->_getStompServer();
- $port = $this->_getStompPort();
- return "tcp://$server:$port/";
- }
-
- function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'Orbited',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Evan Prodromou',
- 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Orbited',
- 'rawdescription' =>
-
- _m('Plugin to make updates using Orbited and STOMP.'));
- return true;
- }
- }
|