5 Plugin URI: http://status.net/wiki/Feed_subscription
6 Description: FeedSub allows subscribing to real-time updates from external feeds supporting PubHubSubbub protocol.
8 Author: Brion Vibber <brion@status.net>
9 Author URI: http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * @package FeedSubPlugin
32 * @maintainer Brion Vibber <brion@status.net>
35 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
37 define('FEEDSUB_SERVICE', 100); // fixme -- avoid hardcoding these?
39 // We bundle the XML_Parse_Feed library...
40 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib');
42 class FeedSubException extends Exception
46 class OStatusPlugin extends Plugin
49 * Hook for RouterInitialized event.
51 * @param Net_URL_Mapper $m path-to-action mapper
52 * @return boolean hook return
54 function onRouterInitialized($m)
56 $m->connect('push/hub', array('action' => 'hub'));
58 $m->connect('feedsub/callback/:feed',
59 array('action' => 'feedsubcallback'),
60 array('feed' => '[0-9]+'));
61 $m->connect('settings/feedsub',
62 array('action' => 'feedsubsettings'));
67 * Set up queue handlers for outgoing hub pushes
68 * @param QueueManager $qm
69 * @return boolean hook return
71 function onEndInitializeQueueManager(QueueManager $qm)
73 $qm->connect('hubverify', 'HubVerifyQueueHandler');
74 $qm->connect('hubdistrib', 'HubDistribQueueHandler');
75 $qm->connect('hubout', 'HubOutQueueHandler');
80 * Put saved notices into the queue for pubsub distribution.
82 function onStartEnqueueNotice($notice, &$transports)
84 $transports[] = 'hubdistrib';
89 * Set up a PuSH hub link to our internal link for canonical timeline
90 * Atom feeds for users.
92 function onStartApiAtom(Action $action)
94 if ($action instanceof ApiTimelineUserAction) {
95 $id = $action->arg('id');
96 if (strval(intval($id)) === strval($id)) {
97 // Canonical form of id in URL?
98 // Updates will be handled for our internal PuSH hub.
99 $action->element('link', array('rel' => 'hub',
100 'href' => common_local_url('hub')));
107 * Add the feed settings page to the Connect Settings menu
109 * @param Action &$action The calling page
111 * @return boolean hook return
113 function onEndConnectSettingsNav(&$action)
115 $action_name = $action->trimmed('action');
117 $action->menuItem(common_local_url('feedsubsettings'),
119 _m('Feed subscription options'),
120 $action_name === 'feedsubsettings');
126 * Automatically load the actions and libraries used by the plugin
128 * @param Class $cls the class
130 * @return boolean hook return
133 function onAutoload($cls)
135 $base = dirname(__FILE__);
136 $lower = strtolower($cls);
137 $files = array("$base/classes/$cls.php",
138 "$base/lib/$lower.php");
139 if (substr($lower, -6) == 'action') {
140 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
142 foreach ($files as $file) {
143 if (file_exists($file)) {
151 function onCheckSchema() {
152 // warning: the autoincrement doesn't seem to set.
153 // alter table feedinfo change column id id int(11) not null auto_increment;
154 $schema = Schema::get();
155 $schema->ensureTable('feedinfo', Feedinfo::schemaDef());
156 $schema->ensureTable('hubsub', HubSub::schemaDef());