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 * Check if plugin should be active; may be mass-enabled.
89 if (common_config('site', 'private')) {
90 // PuSH relies on public feeds
93 // @fixme check for being on a private network?
98 * Hooks the StartApiAtom event
100 * Adds the necessary bits to advertise PubSubHubBub
103 * @param Action $action The API action being shown.
105 * @return boolean hook value
108 function onStartApiAtom($action)
110 if ($this->enabled()) {
111 $action->element('link', array('rel' => 'hub', 'href' => $this->hub), null);
117 * Hooks the StartApiRss event
119 * Adds the necessary bits to advertise PubSubHubBub
120 * for the RSS 2.0 feeds.
122 * @param Action $action The API action being shown.
124 * @return boolean hook value
127 function onStartApiRss($action)
129 if ($this->enabled()) {
130 $action->element('atom:link', array('rel' => 'hub',
131 'href' => $this->hub),
138 * Hook for a queued notice.
140 * When a notice has been queued, will ping the
141 * PuSH hub for each Atom and RSS feed in which
142 * the notice appears.
144 * @param Notice $notice The notice that's been queued
146 * @return boolean hook value
149 function onHandleQueuedNotice($notice)
151 if (!$this->enabled()) {
154 $publisher = new Publisher($this->hub);
158 //public timeline feeds
159 $feeds[] = common_local_url('ApiTimelinePublic', array('format' => 'rss'));
160 $feeds[] = common_local_url('ApiTimelinePublic', array('format' => 'atom'));
163 $user = User::staticGet('id', $notice->profile_id);
165 $feeds[] = common_local_url('ApiTimelineUser',
166 array('id' => $user->nickname,
168 $feeds[] = common_local_url('ApiTimelineUser',
169 array('id' => $user->nickname,
170 'format' => 'atom'));
173 $tag = new Notice_tag();
175 $tag->notice_id = $notice->id;
177 while ($tag->fetch()) {
178 $feeds[] = common_local_url('ApiTimelineTag',
179 array('tag' => $tag->tag,
181 $feeds[] = common_local_url('ApiTimelineTag',
182 array('tag' => $tag->tag,
183 'format' => 'atom'));
188 $group_inbox = new Group_inbox();
190 $group_inbox->notice_id = $notice->id;
191 if ($group_inbox->find()) {
192 while ($group_inbox->fetch()) {
193 $group = User_group::staticGet('id', $group_inbox->group_id);
195 $feeds[] = common_local_url('ApiTimelineGroup',
196 array('id' => $group->nickname,
198 $feeds[] = common_local_url('ApiTimelineGroup',
199 array('id' => $group->nickname,
200 'format' => 'atom'));
204 //feed of each user that subscribes to the notice's author
206 $ni = $notice->whoGets();
208 foreach (array_keys($ni) as $user_id) {
209 $user = User::staticGet('id', $user_id);
213 $feeds[] = common_local_url('ApiTimelineFriends',
214 array('id' => $user->nickname,
216 $feeds[] = common_local_url('ApiTimelineFriends',
217 array('id' => $user->nickname,
218 'format' => 'atom'));
221 $replies = $notice->getReplies();
223 //feed of user replied to
224 foreach ($replies as $recipient) {
225 $user = User::staticGet('id', $recipient);
227 $feeds[] = common_local_url('ApiTimelineMentions',
228 array('id' => $user->nickname,
230 $feeds[] = common_local_url('ApiTimelineMentions',
231 array('id' => $user->nickname,
232 'format' => 'atom'));
235 $feeds = array_unique($feeds);
238 $ok = $publisher->publish_update($feeds);
239 $push_last_response = ob_get_clean();
242 common_log(LOG_WARNING,
243 'Failure publishing ' . count($feeds) . ' feeds to hub at '.
244 $this->hub.': '.$push_last_response);
247 'Published ' . count($feeds) . ' feeds to hub at '.
248 $this->hub.': '.$push_last_response);
255 * Provide version information
257 * Adds this plugin's version data to the global
258 * version array, for e.g. displaying on the version page.
260 * @param array &$versions array of array of versions
262 * @return boolean hook value
265 function onPluginVersion(&$versions)
267 $about = _m('The PubSubHubBub plugin pushes RSS/Atom updates '.
269 'http://pubsubhubbub.googlecode.com/'.
270 '">PubSubHubBub</a> hub.');
271 if (!$this->enabled()) {
272 $about = '<span class="disabled" style="color:gray">' . $about . '</span> ' .
273 _m('(inactive on private site)');
275 $versions[] = array('name' => 'PubSubHubBub',
276 'version' => STATUSNET_VERSION,
277 'author' => 'Craig Andrews',
279 'http://status.net/wiki/Plugin:PubSubHubBub',