]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Comet/CometPlugin.php
Added type-hint for RedirectToLogin hooks. Please note that User $user=null
[quix0rs-gnu-social.git] / plugins / Comet / CometPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to do "real time" updates using Comet/Bayeux
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/plugins/Realtime/RealtimePlugin.php';
35
36 /**
37  * Plugin to do realtime updates using Comet
38  *
39  * @category Plugin
40  * @package  StatusNet
41  * @author   Evan Prodromou <evan@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45 class CometPlugin extends RealtimePlugin
46 {
47     public $server   = null;
48     public $username = null;
49     public $password = null;
50     public $prefix   = null;
51     protected $bay   = null;
52
53     function __construct($server=null, $username=null, $password=null, $prefix=null)
54     {
55         $this->server   = $server;
56         $this->username = $username;
57         $this->password = $password;
58         $this->prefix   = $prefix;
59
60         parent::__construct();
61     }
62
63     function _getScripts()
64     {
65         $scripts = parent::_getScripts();
66
67         $ours = array('js/jquery.comet.js', 'js/cometupdate.js');
68
69         foreach ($ours as $script) {
70             $scripts[] = $this->path($script);
71         }
72
73         return $scripts;
74     }
75
76     function _updateInitialize($timeline, $user_id)
77     {
78         $script = parent::_updateInitialize($timeline, $user_id);
79         return $script." CometUpdate.init(\"$this->server\", \"$timeline\", $user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->deleteurl\");";
80     }
81
82     function _connect()
83     {
84         require_once INSTALLDIR.'/plugins/Comet/extlib/Bayeux/Bayeux.class.php';
85         // Bayeux? Comet? Huh? These terms confuse me
86         $this->bay = new Bayeux($this->server, $this->user, $this->password);
87     }
88
89     function _publish($timeline, $json)
90     {
91         $this->bay->publish($timeline, $json);
92     }
93
94     function _disconnect()
95     {
96         unset($this->bay);
97     }
98
99     function _pathToChannel($path)
100     {
101         if (!empty($this->prefix)) {
102             array_unshift($path, $this->prefix);
103         }
104         return '/' . implode('/', $path);
105     }
106
107     function onPluginVersion(array &$versions)
108     {
109         $versions[] = array('name' => 'Comet',
110                             'version' => GNUSOCIAL_VERSION,
111                             'author' => 'Evan Prodromou',
112                             'homepage' => 'http://status.net/wiki/Plugin:Comet',
113                             'rawdescription' =>
114                             // TRANS: Plugin description message. Bayeux is a protocol for transporting asynchronous messages
115                             // TRANS: and Comet is a web application model.
116                             _m('Plugin to make updates using Comet and Bayeux.'));
117         return true;
118     }
119 }