]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Comet/CometPlugin.php
Preparing plugins for no-minify-in-core-policy
[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 /**
35  * Plugin to do realtime updates using Comet
36  *
37  * @category Plugin
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class CometPlugin extends RealtimePlugin
44 {
45     public $server   = null;
46     public $username = null;
47     public $password = null;
48     public $prefix   = null;
49     protected $bay   = null;
50
51     function __construct($server=null, $username=null, $password=null, $prefix=null)
52     {
53         $this->server   = $server;
54         $this->username = $username;
55         $this->password = $password;
56         $this->prefix   = $prefix;
57
58         parent::__construct();
59     }
60
61     function _getScripts()
62     {
63         $scripts = parent::_getScripts();
64
65         $ours = array('js/jquery.comet.js', 'js/cometupdate.js');
66
67         foreach ($ours as $script) {
68             $scripts[] = $this->path($script);
69         }
70
71         return $scripts;
72     }
73
74     function _updateInitialize($timeline, $user_id)
75     {
76         $script = parent::_updateInitialize($timeline, $user_id);
77         return $script." CometUpdate.init(\"$this->server\", \"$timeline\", $user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->deleteurl\");";
78     }
79
80     function _connect()
81     {
82         require_once INSTALLDIR.'/plugins/Comet/extlib/Bayeux/Bayeux.class.php';
83         // Bayeux? Comet? Huh? These terms confuse me
84         $this->bay = new Bayeux($this->server, $this->user, $this->password);
85     }
86
87     function _publish($timeline, $json)
88     {
89         $this->bay->publish($timeline, $json);
90     }
91
92     function _disconnect()
93     {
94         unset($this->bay);
95     }
96
97     function _pathToChannel($path)
98     {
99         if (!empty($this->prefix)) {
100             array_unshift($path, $this->prefix);
101         }
102         return '/' . implode('/', $path);
103     }
104
105     function onPluginVersion(&$versions)
106     {
107         $versions[] = array('name' => 'Comet',
108                             'version' => GNUSOCIAL_VERSION,
109                             'author' => 'Evan Prodromou',
110                             'homepage' => 'http://status.net/wiki/Plugin:Comet',
111                             'rawdescription' =>
112                             // TRANS: Plugin description message. Bayeux is a protocol for transporting asynchronous messages
113                             // TRANS: and Comet is a web application model.
114                             _m('Plugin to make updates using Comet and Bayeux.'));
115         return true;
116     }
117 }