3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to support RSSCloud
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.
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.
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/>.
24 * @author Zach Copley <zach@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/
30 if (!defined('STATUSNET')) {
34 define('RSSCLOUDPLUGIN_VERSION', '0.1');
37 * Plugin class for adding RSSCloud capabilities to StatusNet
41 * @author Zach Copley <zach@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/
45 class RSSCloudPlugin extends Plugin
48 * Our friend, the constructor
52 function __construct()
54 parent::__construct();
58 * Setup the info for the subscription handler. Allow overriding
59 * to point at another cloud hub (not currently used).
63 function onInitializePlugin()
65 $this->domain = common_config('rsscloud', 'domain');
66 $this->port = common_config('rsscloud', 'port');
67 $this->path = common_config('rsscloud', 'path');
68 $this->funct = common_config('rsscloud', 'function');
69 $this->protocol = common_config('rsscloud', 'protocol');
73 $local_server = parse_url(common_path('main/rsscloud/request_notify'));
75 if (empty($this->domain)) {
76 $this->domain = $local_server['host'];
79 if (empty($this->port)) {
83 if (empty($this->path)) {
84 $this->path = $local_server['path'];
87 if (empty($this->funct)) {
91 if (empty($this->protocol)) {
92 $this->protocol = 'http-post';
97 * Add RSSCloud-related paths to the router table
99 * Hook for RouterInitialized event.
101 * @param Mapper $m URL parser and mapper
103 * @return boolean hook return
105 function onRouterInitialized($m)
107 $m->connect('/main/rsscloud/request_notify',
108 array('action' => 'RSSCloudRequestNotify'));
110 // XXX: This is just for end-to-end testing. Uncomment if you need to pretend
111 // to be a cloud hub for some reason.
112 //$m->connect('/main/rsscloud/notify',
113 // array('action' => 'LoggingAggregator'));
119 * Add a <cloud> element to the RSS feed (after the rss <channel>
120 * element is started).
122 * @param Action $action the ApiAction
126 function onStartApiRss($action)
128 if (get_class($action) == 'ApiTimelineUserAction') {
130 $attrs = array('domain' => $this->domain,
131 'port' => $this->port,
132 'path' => $this->path,
133 'registerProcedure' => $this->funct,
134 'protocol' => $this->protocol);
136 // Dipping into XMLWriter to avoid a full end element (</cloud>).
138 $action->xw->startElement('cloud');
139 foreach ($attrs as $name => $value) {
140 $action->xw->writeAttribute($name, $value);
143 $action->xw->endElement();
148 * Add an RSSCloud queue item for each notice
150 * @param Notice $notice the notice
151 * @param array &$transports the list of transports (queues)
153 * @return boolean hook return
156 function onStartEnqueueNotice($notice, &$transports)
158 if ($notice->isLocal()) {
159 array_push($transports, 'rsscloud');
165 * Create the rsscloud_subscription table if it's not
168 * @return boolean hook return
171 function onCheckSchema()
173 $schema = Schema::get();
174 $schema->ensureTable('rsscloud_subscription',
177 'subscribed' => array('type' => 'int', 'not null' => true),
178 'url' => array('type' => 'varchar', 'length' => '191', 'not null' => true),
179 'failures' => array('type' => 'int', 'not null' => true, 'default' => 0),
180 'created' => array('type' => 'datetime', 'not null' => true),
181 'modified' => array('type' => 'timestamp', 'not null' => true),
183 'primary key' => array('subscribed', 'url'),
189 * Register RSSCloud notice queue handler
191 * @param QueueManager $manager
193 * @return boolean hook return
195 function onEndInitializeQueueManager($manager)
197 $manager->connect('rsscloud', 'RSSCloudQueueHandler');
201 function onPluginVersion(array &$versions)
203 $versions[] = array('name' => 'RSSCloud',
204 'version' => RSSCLOUDPLUGIN_VERSION,
205 'author' => 'Zach Copley',
206 'homepage' => 'http://status.net/wiki/Plugin:RSSCloud',
208 // TRANS: Plugin description.
209 _m('The RSSCloud plugin enables your StatusNet instance to publish ' .
210 'real-time updates for profile RSS feeds using the ' .
211 '<a href="http://rsscloud.org/">RSSCloud protocol</a>.'));