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/
46 class RSSCloudPlugin extends Plugin
49 * Our friend, the constructor
53 function __construct()
55 parent::__construct();
59 * Setup the info for the subscription handler. Allow overriding
60 * to point at another cloud hub (not currently used).
65 function onInitializePlugin()
67 $this->domain = common_config('rsscloud', 'domain');
68 $this->port = common_config('rsscloud', 'port');
69 $this->path = common_config('rsscloud', 'path');
70 $this->funct = common_config('rsscloud', 'function');
71 $this->protocol = common_config('rsscloud', 'protocol');
75 $local_server = parse_url(common_path('main/rsscloud/request_notify'));
77 if (empty($this->domain)) {
78 $this->domain = $local_server['host'];
81 if (empty($this->port)) {
85 if (empty($this->path)) {
86 $this->path = $local_server['path'];
89 if (empty($this->funct)) {
93 if (empty($this->protocol)) {
94 $this->protocol = 'http-post';
99 * Add RSSCloud-related paths to the router table
101 * Hook for RouterInitialized event.
103 * @param Mapper &$m URL parser and mapper
105 * @return boolean hook return
108 function onRouterInitialized(&$m)
110 $m->connect('/main/rsscloud/request_notify',
111 array('action' => 'RSSCloudRequestNotify'));
113 // XXX: This is just for end-to-end testing. Uncomment if you need to pretend
114 // to be a cloud hub for some reason.
115 //$m->connect('/main/rsscloud/notify',
116 // array('action' => 'LoggingAggregator'));
122 * Automatically load the actions and libraries used by
123 * the RSSCloud plugin
125 * @param Class $cls the class
127 * @return boolean hook return
131 function onAutoload($cls)
135 case 'RSSCloudSubscription':
136 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudSubscription.php';
138 case 'RSSCloudNotifier':
139 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php';
141 case 'RSSCloudQueueHandler':
142 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudQueueHandler.php';
144 case 'RSSCloudRequestNotifyAction':
145 case 'LoggingAggregatorAction':
146 include_once INSTALLDIR . '/plugins/RSSCloud/' .
147 mb_substr($cls, 0, -6) . '.php';
155 * Add a <cloud> element to the RSS feed (after the rss <channel>
156 * element is started).
158 * @param Action $action the ApiAction
163 function onStartApiRss($action)
165 if (get_class($action) == 'ApiTimelineUserAction') {
167 $attrs = array('domain' => $this->domain,
168 'port' => $this->port,
169 'path' => $this->path,
170 'registerProcedure' => $this->funct,
171 'protocol' => $this->protocol);
173 // Dipping into XMLWriter to avoid a full end element (</cloud>).
175 $action->xw->startElement('cloud');
176 foreach ($attrs as $name => $value) {
177 $action->xw->writeAttribute($name, $value);
180 $action->xw->endElement();
185 * Add an RSSCloud queue item for each notice
187 * @param Notice $notice the notice
188 * @param array &$transports the list of transports (queues)
190 * @return boolean hook return
193 function onStartEnqueueNotice($notice, &$transports)
195 array_push($transports, 'rsscloud');
200 * Determine whether the notice was locally created
202 * @param Notice $notice the notice in question
204 * @return boolean locality
207 function _isLocal($notice)
209 return ($notice->is_local == Notice::LOCAL_PUBLIC ||
210 $notice->is_local == Notice::LOCAL_NONPUBLIC);
214 * Create the rsscloud_subscription table if it's not
217 * @return boolean hook return
220 function onCheckSchema()
222 $schema = Schema::get();
223 $schema->ensureTable('rsscloud_subscription',
224 array(new ColumnDef('subscribed', 'integer',
226 new ColumnDef('url', 'varchar',
227 '255', false, 'PRI'),
228 new ColumnDef('failures', 'integer',
229 null, false, null, 0),
230 new ColumnDef('created', 'datetime',
232 new ColumnDef('modified', 'timestamp',
235 'on update CURRENT_TIMESTAMP')
241 * Register RSSCloud notice queue handler
243 * @param QueueManager $manager
245 * @return boolean hook return
247 function onEndInitializeQueueManager($manager)
249 $manager->connect('rsscloud', 'RSSCloudQueueHandler');
253 function onPluginVersion(&$versions)
255 $versions[] = array('name' => 'RSSCloud',
256 'version' => RSSCLOUDPLUGIN_VERSION,
257 'author' => 'Zach Copley',
258 'homepage' => 'http://status.net/wiki/Plugin:RSSCloud',
260 _m('The RSSCloud plugin enables your StatusNet instance to publish ' .
261 'real-time updates for profile RSS feeds using the ' .
262 '<a href="http://rsscloud.org/">RSSCloud protocol</a>".'));