3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to push RSS/Atom updates to a PubSubHubBub hub
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 Craig Andrews <candrews@integralblue.com>
25 * @copyright 2009 Craig Andrews http://candrews.integralblue.com
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('DEFAULT_HUB', 'http://pubsubhubbub.appspot.com');
36 require_once INSTALLDIR.'/plugins/PubSubHubBub/publisher.php';
39 * Plugin to provide publisher side of PubSubHubBub (PuSH)
42 * PuSH is a real-time or near-real-time protocol for Atom
43 * and RSS feeds. More information here:
45 * http://code.google.com/p/pubsubhubbub/
47 * To enable, add the following line to your config.php:
49 * addPlugin('PubSubHubBub');
51 * This will use the Google default hub. If you'd like to use
54 * addPlugin('PubSubHubBub',
55 * array('hub' => 'http://yourhub.example.net/'));
59 * @author Craig Andrews <candrews@integralblue.com>
60 * @copyright 2009 Craig Andrews http://candrews.integralblue.com
61 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
62 * @link http://status.net/
65 class PubSubHubBubPlugin extends Plugin
68 * URL of the hub to advertise and publish to.
71 public $hub = DEFAULT_HUB;
74 * Default constructor.
77 function __construct()
79 parent::__construct();
83 * Hooks the StartApiAtom event
85 * Adds the necessary bits to advertise PubSubHubBub
88 * @param Action $action The API action being shown.
90 * @return boolean hook value
93 function onStartApiAtom($action)
95 $action->element('link', array('rel' => 'hub', 'href' => $this->hub), null);
101 * Hooks the StartApiRss event
103 * Adds the necessary bits to advertise PubSubHubBub
104 * for the RSS 2.0 feeds.
106 * @param Action $action The API action being shown.
108 * @return boolean hook value
111 function onStartApiRss($action)
113 $action->element('atom:link', array('rel' => 'hub',
114 'href' => $this->hub),
120 * Hook for a queued notice.
122 * When a notice has been queued, will ping the
123 * PuSH hub for each Atom and RSS feed in which
124 * the notice appears.
126 * @param Notice $notice The notice that's been queued
128 * @return boolean hook value
131 function onHandleQueuedNotice($notice)
133 $publisher = new Publisher($this->hub);
137 //public timeline feeds
138 $feeds[] = common_local_url('ApiTimelinePublic', array('format' => 'rss'));
139 $feeds[] = common_local_url('ApiTimelinePublic', array('format' => 'atom'));
142 $user = User::staticGet('id', $notice->profile_id);
144 $feeds[] = common_local_url('ApiTimelineUser',
145 array('id' => $user->nickname,
147 $feeds[] = common_local_url('ApiTimelineUser',
148 array('id' => $user->nickname,
149 'format' => 'atom'));
152 $tag = new Notice_tag();
154 $tag->notice_id = $notice->id;
156 while ($tag->fetch()) {
157 $feeds[] = common_local_url('ApiTimelineTag',
158 array('tag' => $tag->tag,
160 $feeds[] = common_local_url('ApiTimelineTag',
161 array('tag' => $tag->tag,
162 'format' => 'atom'));
167 $group_inbox = new Group_inbox();
169 $group_inbox->notice_id = $notice->id;
170 if ($group_inbox->find()) {
171 while ($group_inbox->fetch()) {
172 $group = User_group::staticGet('id', $group_inbox->group_id);
174 $feeds[] = common_local_url('ApiTimelineGroup',
175 array('id' => $group->nickname,
177 $feeds[] = common_local_url('ApiTimelineGroup',
178 array('id' => $group->nickname,
179 'format' => 'atom'));
183 //feed of each user that subscribes to the notice's author
185 $ni = $notice->whoGets();
187 foreach (array_keys($ni) as $user_id) {
188 $user = User::staticGet('id', $user_id);
192 $feeds[] = common_local_url('ApiTimelineFriends',
193 array('id' => $user->nickname,
195 $feeds[] = common_local_url('ApiTimelineFriends',
196 array('id' => $user->nickname,
197 'format' => 'atom'));
200 $replies = $notice->getReplies();
202 //feed of user replied to
203 foreach ($replies as $recipient) {
204 $user = User::staticGet('id', $recipient);
206 $feeds[] = common_local_url('ApiTimelineMentions',
207 array('id' => $user->nickname,
209 $feeds[] = common_local_url('ApiTimelineMentions',
210 array('id' => $user->nickname,
211 'format' => 'atom'));
215 foreach (array_unique($feeds) as $feed) {
216 if (!$publisher->publish_update($feed)) {
217 common_log_line(LOG_WARNING,
218 $feed.' was not published to hub at '.
219 $this->hub.':'.$publisher->last_response());
227 * Provide version information
229 * Adds this plugin's version data to the global
230 * version array, for e.g. displaying on the version page.
232 * @param array &$versions array of array of versions
234 * @return boolean hook value
237 function onPluginVersion(&$versions)
239 $versions[] = array('name' => 'PubSubHubBub',
240 'version' => STATUSNET_VERSION,
241 'author' => 'Craig Andrews',
243 'http://status.net/wiki/Plugin:PubSubHubBub',
245 _m('The PubSubHubBub plugin pushes RSS/Atom updates '.
247 'http://pubsubhubbub.googlecode.com/'.
248 '">PubSubHubBub</a> hub.'));