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 = '/main/rsscloud/request_notify';
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 * @return boolean hook return
104 function onRouterInitialized(&$m)
106 $m->connect('/main/rsscloud/request_notify', array('action' => 'RSSCloudRequestNotify'));
108 // XXX: This is just for end-to-end testing. Uncomment if you need to pretend
109 // to be a cloud hub for some reason.
110 // $m->connect('/main/rsscloud/notify', array('action' => 'LoggingAggregator'));
116 * Automatically load the actions and libraries used by
117 * the RSSCloud plugin
119 * @param Class $cls the class
121 * @return boolean hook return
125 function onAutoload($cls)
129 case 'RSSCloudSubscription':
130 include_once(INSTALLDIR . '/plugins/RSSCloud/RSSCloudSubscription.php');
132 case 'RSSCloudNotifier':
133 include_once(INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php');
135 case 'RSSCloudRequestNotifyAction':
136 case 'LoggingAggregatorAction':
137 include_once(INSTALLDIR . '/plugins/RSSCloud/' . mb_substr($cls, 0, -6) . '.php');
145 * Add a <cloud> element to the RSS feed (after the rss <channel>
146 * element is started).
148 * @param Action $action
153 function onStartApiRss($action)
155 if (get_class($action) == 'ApiTimelineUserAction') {
157 $attrs = array('domain' => $this->domain,
158 'port' => $this->port,
159 'path' => $this->path,
160 'registerProcedure' => $this->funct,
161 'protocol' => $this->protocol);
163 // Dipping into XMLWriter to avoid a full end element (</cloud>).
165 $action->xw->startElement('cloud');
166 foreach ($attrs as $name => $value) {
167 $action->xw->writeAttribute($name, $value);
170 $action->xw->endElement();
175 * Add an RSSCloud queue item for each notice
177 * @param Notice $notice the notice
178 * @param array &$transports the list of transports (queues)
180 * @return boolean hook return
183 function onStartEnqueueNotice($notice, &$transports)
185 array_push($transports, 'rsscloud');
190 * broadcast the message when not using queuehandler
192 * @param Notice &$notice the notice
193 * @param array $queue destination queue
195 * @return boolean hook return
198 function onUnqueueHandleNotice(&$notice, $queue)
200 if (($queue == 'rsscloud') && ($this->_isLocal($notice))) {
202 common_debug('broadcasting rssCloud bound notice ' . $notice->id);
204 $profile = $notice->getProfile();
206 $notifier = new RSSCloudNotifier();
207 $notifier->notify($profile);
216 * Determine whether the notice was locally created
218 * @param Notice $notice
220 * @return boolean locality
223 function _isLocal($notice)
225 return ($notice->is_local == Notice::LOCAL_PUBLIC ||
226 $notice->is_local == Notice::LOCAL_NONPUBLIC);
230 * Create the rsscloud_subscription table if it's not
233 * @return boolean hook return
236 function onCheckSchema() {
237 $schema = Schema::get();
238 $schema->ensureTable('rsscloud_subscription',
239 array(new ColumnDef('subscribed', 'integer',
241 new ColumnDef('url', 'varchar',
242 '255', false, 'PRI'),
243 new ColumnDef('failures', 'integer',
244 null, false, null, 0),
245 new ColumnDef('created', 'datetime',
247 new ColumnDef('modified', 'timestamp',
250 'on update CURRENT_TIMESTAMP')
257 * Add RSSCloudQueueHandler to the list of valid daemons to
260 * @param array $daemons the list of daemons to run
262 * @return boolean hook return
266 function onGetValidDaemons($daemons)
268 array_push($daemons, INSTALLDIR .
269 '/plugins/RSSCloud/RSSCloudQueueHandler.php');