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 * Automatically load the actions and libraries used by
120 * the RSSCloud plugin
122 * @param Class $cls the class
124 * @return boolean hook return
127 function onAutoload($cls)
131 case 'RSSCloudSubscription':
132 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudSubscription.php';
134 case 'RSSCloudNotifier':
135 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php';
137 case 'RSSCloudQueueHandler':
138 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudQueueHandler.php';
140 case 'RSSCloudRequestNotifyAction':
141 case 'LoggingAggregatorAction':
142 include_once INSTALLDIR . '/plugins/RSSCloud/' .
143 mb_substr($cls, 0, -6) . '.php';
151 * Add a <cloud> element to the RSS feed (after the rss <channel>
152 * element is started).
154 * @param Action $action the ApiAction
158 function onStartApiRss($action)
160 if (get_class($action) == 'ApiTimelineUserAction') {
162 $attrs = array('domain' => $this->domain,
163 'port' => $this->port,
164 'path' => $this->path,
165 'registerProcedure' => $this->funct,
166 'protocol' => $this->protocol);
168 // Dipping into XMLWriter to avoid a full end element (</cloud>).
170 $action->xw->startElement('cloud');
171 foreach ($attrs as $name => $value) {
172 $action->xw->writeAttribute($name, $value);
175 $action->xw->endElement();
180 * Add an RSSCloud queue item for each notice
182 * @param Notice $notice the notice
183 * @param array &$transports the list of transports (queues)
185 * @return boolean hook return
188 function onStartEnqueueNotice($notice, &$transports)
190 if ($notice->isLocal()) {
191 array_push($transports, 'rsscloud');
197 * Create the rsscloud_subscription table if it's not
200 * @return boolean hook return
203 function onCheckSchema()
205 $schema = Schema::get();
206 $schema->ensureTable('rsscloud_subscription',
209 'subscribed' => array('type' => 'int', 'not null' => true),
210 'url' => array('type' => 'varchar', 'length' => '255', 'not null' => true),
211 'failures' => array('type' => 'int', 'not null' => true, 'default' => 0),
212 'created' => array('type' => 'datetime', 'not null' => true),
213 'modified' => array('type' => 'timestamp', 'not null' => true),
215 'primary key' => array('subscribed', 'url'),
221 * Register RSSCloud notice queue handler
223 * @param QueueManager $manager
225 * @return boolean hook return
227 function onEndInitializeQueueManager($manager)
229 $manager->connect('rsscloud', 'RSSCloudQueueHandler');
233 function onPluginVersion(&$versions)
235 $versions[] = array('name' => 'RSSCloud',
236 'version' => RSSCLOUDPLUGIN_VERSION,
237 'author' => 'Zach Copley',
238 'homepage' => 'http://status.net/wiki/Plugin:RSSCloud',
240 // TRANS: Plugin description.
241 _m('The RSSCloud plugin enables your StatusNet instance to publish ' .
242 'real-time updates for profile RSS feeds using the ' .
243 '<a href="http://rsscloud.org/">RSSCloud protocol</a>.'));