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 'RSSCloudRequestNotifyAction':
142 case 'LoggingAggregatorAction':
143 include_once INSTALLDIR . '/plugins/RSSCloud/' .
144 mb_substr($cls, 0, -6) . '.php';
152 * Add a <cloud> element to the RSS feed (after the rss <channel>
153 * element is started).
155 * @param Action $action the ApiAction
160 function onStartApiRss($action)
162 if (get_class($action) == 'ApiTimelineUserAction') {
164 $attrs = array('domain' => $this->domain,
165 'port' => $this->port,
166 'path' => $this->path,
167 'registerProcedure' => $this->funct,
168 'protocol' => $this->protocol);
170 // Dipping into XMLWriter to avoid a full end element (</cloud>).
172 $action->xw->startElement('cloud');
173 foreach ($attrs as $name => $value) {
174 $action->xw->writeAttribute($name, $value);
177 $action->xw->endElement();
182 * Add an RSSCloud queue item for each notice
184 * @param Notice $notice the notice
185 * @param array &$transports the list of transports (queues)
187 * @return boolean hook return
190 function onStartEnqueueNotice($notice, &$transports)
192 array_push($transports, 'rsscloud');
197 * broadcast the message when not using queuehandler
199 * @param Notice &$notice the notice
200 * @param array $queue destination queue
202 * @return boolean hook return
205 function onUnqueueHandleNotice(&$notice, $queue)
207 if (($queue == 'rsscloud') && ($this->_isLocal($notice))) {
209 common_debug('broadcasting rssCloud bound notice ' . $notice->id);
211 $profile = $notice->getProfile();
213 $notifier = new RSSCloudNotifier();
214 $notifier->notify($profile);
223 * Determine whether the notice was locally created
225 * @param Notice $notice the notice in question
227 * @return boolean locality
230 function _isLocal($notice)
232 return ($notice->is_local == Notice::LOCAL_PUBLIC ||
233 $notice->is_local == Notice::LOCAL_NONPUBLIC);
237 * Create the rsscloud_subscription table if it's not
240 * @return boolean hook return
243 function onCheckSchema()
245 $schema = Schema::get();
246 $schema->ensureTable('rsscloud_subscription',
247 array(new ColumnDef('subscribed', 'integer',
249 new ColumnDef('url', 'varchar',
250 '255', false, 'PRI'),
251 new ColumnDef('failures', 'integer',
252 null, false, null, 0),
253 new ColumnDef('created', 'datetime',
255 new ColumnDef('modified', 'timestamp',
258 'on update CURRENT_TIMESTAMP')
264 * Add RSSCloudQueueHandler to the list of valid daemons to
267 * @param array $daemons the list of daemons to run
269 * @return boolean hook return
273 function onGetValidDaemons($daemons)
275 array_push($daemons, INSTALLDIR .
276 '/plugins/RSSCloud/RSSCloudQueueHandler.php');
280 function onPluginVersion(&$versions)
282 $versions[] = array('name' => 'RSSCloud',
283 'version' => RSSCLOUDPLUGIN_VERSION,
284 'author' => 'Zach Copley',
285 'homepage' => 'http://status.net/wiki/Plugin:RSSCloud',
287 _m('The RSSCloud plugin enables your StatusNet instance to publish ' .
288 'real-time updates for profile RSS feeds using the ' .
289 '<a href="http://rsscloud.org/">RSSCloud protocol</a>".'));