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('.well-known/host-meta',
57 array('action' => 'hostmeta'));
58 $m->connect('main/webfinger',
59 array('action' => 'webfinger'));
60 $m->connect('main/ostatus',
61 array('action' => 'ostatusinit'));
62 $m->connect('main/ostatus?nickname=:nickname',
63 array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+'));
64 $m->connect('main/ostatussub',
65 array('action' => 'ostatussub'));
66 $m->connect('main/ostatussub',
67 array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+'));
69 $m->connect('main/push/hub', array('action' => 'pushhub'));
71 $m->connect('main/push/callback/:feed',
72 array('action' => 'pushcallback'),
73 array('feed' => '[0-9]+'));
74 $m->connect('settings/feedsub',
75 array('action' => 'feedsubsettings'));
80 * Set up queue handlers for outgoing hub pushes
81 * @param QueueManager $qm
82 * @return boolean hook return
84 function onEndInitializeQueueManager(QueueManager $qm)
86 $qm->connect('hubverify', 'HubVerifyQueueHandler');
87 $qm->connect('hubdistrib', 'HubDistribQueueHandler');
88 $qm->connect('hubout', 'HubOutQueueHandler');
93 * Put saved notices into the queue for pubsub distribution.
95 function onStartEnqueueNotice($notice, &$transports)
97 $transports[] = 'hubdistrib';
102 * Set up a PuSH hub link to our internal link for canonical timeline
103 * Atom feeds for users.
105 function onStartApiAtom(Action $action)
107 if ($action instanceof ApiTimelineUserAction) {
108 $id = $action->arg('id');
109 if (strval(intval($id)) === strval($id)) {
110 // Canonical form of id in URL?
111 // Updates will be handled for our internal PuSH hub.
112 $action->element('link', array('rel' => 'hub',
113 'href' => common_local_url('pushhub')));
120 * Add the feed settings page to the Connect Settings menu
122 * @param Action &$action The calling page
124 * @return boolean hook return
126 function onEndConnectSettingsNav(&$action)
128 $action_name = $action->trimmed('action');
130 $action->menuItem(common_local_url('feedsubsettings'),
132 _m('Feed subscription options'),
133 $action_name === 'feedsubsettings');
139 * Automatically load the actions and libraries used by the plugin
141 * @param Class $cls the class
143 * @return boolean hook return
146 function onAutoload($cls)
148 $base = dirname(__FILE__);
149 $lower = strtolower($cls);
150 $files = array("$base/classes/$cls.php",
151 "$base/lib/$lower.php");
152 if (substr($lower, -6) == 'action') {
153 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
155 foreach ($files as $file) {
156 if (file_exists($file)) {
165 * Add in an OStatus subscribe button
167 function onStartProfilePageActionsElements($output, $profile)
169 $cur = common_current_user();
172 // Add an OStatus subscribe
173 $output->elementStart('li', 'entity_subscribe');
174 $url = common_local_url('ostatusinit',
175 array('nickname' => $profile->nickname));
176 $output->element('a', array('href' => $url,
177 'class' => 'entity_remote_subscribe'),
180 $output->elementEnd('li');
186 function onCheckSchema() {
187 // warning: the autoincrement doesn't seem to set.
188 // alter table feedinfo change column id id int(11) not null auto_increment;
189 $schema = Schema::get();
190 $schema->ensureTable('feedinfo', Feedinfo::schemaDef());
191 $schema->ensureTable('hubsub', HubSub::schemaDef());