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')) {
35 * Plugin class for adding RSSCloud capabilities to StatusNet
39 * @author Zach Copley <zach@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/
44 class RSSCloudPlugin extends Plugin
47 * Our friend, the constructor
51 function __construct()
53 parent::__construct();
57 * Setup the info for the subscription handler. Allow overriding
58 * 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
106 function onRouterInitialized(&$m)
108 $m->connect('/main/rsscloud/request_notify',
109 array('action' => 'RSSCloudRequestNotify'));
111 // XXX: This is just for end-to-end testing. Uncomment if you need to pretend
112 // to be a cloud hub for some reason.
113 //$m->connect('/main/rsscloud/notify',
114 // array('action' => 'LoggingAggregator'));
120 * Automatically load the actions and libraries used by
121 * the RSSCloud plugin
123 * @param Class $cls the class
125 * @return boolean hook return
129 function onAutoload($cls)
133 case 'RSSCloudSubscription':
134 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudSubscription.php';
136 case 'RSSCloudNotifier':
137 include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php';
139 case 'RSSCloudRequestNotifyAction':
140 case 'LoggingAggregatorAction':
141 include_once INSTALLDIR . '/plugins/RSSCloud/' .
142 mb_substr($cls, 0, -6) . '.php';
150 * Add a <cloud> element to the RSS feed (after the rss <channel>
151 * element is started).
153 * @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 array_push($transports, 'rsscloud');
195 * broadcast the message when not using queuehandler
197 * @param Notice &$notice the notice
198 * @param array $queue destination queue
200 * @return boolean hook return
203 function onUnqueueHandleNotice(&$notice, $queue)
205 if (($queue == 'rsscloud') && ($this->_isLocal($notice))) {
207 common_debug('broadcasting rssCloud bound notice ' . $notice->id);
209 $profile = $notice->getProfile();
211 $notifier = new RSSCloudNotifier();
212 $notifier->notify($profile);
221 * Determine whether the notice was locally created
223 * @param Notice $notice the notice in question
225 * @return boolean locality
228 function _isLocal($notice)
230 return ($notice->is_local == Notice::LOCAL_PUBLIC ||
231 $notice->is_local == Notice::LOCAL_NONPUBLIC);
235 * Create the rsscloud_subscription table if it's not
238 * @return boolean hook return
241 function onCheckSchema()
243 $schema = Schema::get();
244 $schema->ensureTable('rsscloud_subscription',
245 array(new ColumnDef('subscribed', 'integer',
247 new ColumnDef('url', 'varchar',
248 '255', false, 'PRI'),
249 new ColumnDef('failures', 'integer',
250 null, false, null, 0),
251 new ColumnDef('created', 'datetime',
253 new ColumnDef('modified', 'timestamp',
256 'on update CURRENT_TIMESTAMP')
262 * Add RSSCloudQueueHandler to the list of valid daemons to
265 * @param array $daemons the list of daemons to run
267 * @return boolean hook return
271 function onGetValidDaemons($daemons)
273 array_push($daemons, INSTALLDIR .
274 '/plugins/RSSCloud/RSSCloudQueueHandler.php');