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');
38 class PubSubHubBubPlugin extends Plugin
42 function __construct()
44 parent::__construct();
47 function onInitializePlugin(){
48 $this->hub = common_config('PubSubHubBub', 'hub');
49 if(empty($this->hub)){
50 $this->hub = DEFAULT_HUB;
54 function onStartApiAtom($action){
55 $action->element('link',array('rel'=>'hub','href'=>$this->hub),null);
58 function onStartApiRss($action){
59 $action->element('atom:link',array('rel'=>'hub','href'=>$this->hub),null);
62 function onHandleQueuedNotice($notice){
63 $publisher = new Publisher($this->hub);
67 //public timeline feeds
68 $feeds[]=common_local_url('ApiTimelinePublic',array('format' => 'rss'));
69 $feeds[]=common_local_url('ApiTimelinePublic',array('format' => 'atom'));
72 $user = User::staticGet('id',$notice->profile_id);
73 $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'rss'));
74 $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'atom'));
77 $tag = new Notice_tag();
78 $tag->notice_id = $notice->id;
80 while ($tag->fetch()) {
81 $feeds[]=common_local_url('ApiTimelineTag',array('tag'=>$tag->tag, 'format'=>'rss'));
82 $feeds[]=common_local_url('ApiTimelineTag',array('tag'=>$tag->tag, 'format'=>'atom'));
87 $group_inbox = new Group_inbox();
88 $group_inbox->notice_id = $notice->id;
89 if ($group_inbox->find()) {
90 while ($group_inbox->fetch()) {
91 $group = User_group::staticGet('id',$group_inbox->group_id);
92 $feeds[]=common_local_url('ApiTimelineGroup',array('id' => $group->nickname,'format'=>'rss'));
93 $feeds[]=common_local_url('ApiTimelineGroup',array('id' => $group->nickname,'format'=>'atom'));
97 //feed of each user that subscribes to the notice's author
99 $ni = $notice->whoGets();
101 foreach (array_keys($ni) as $user_id) {
102 $user = User::staticGet('id', $user_id);
106 $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'rss'));
107 $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'atom'));
110 //feed of user replied to
111 if($notice->reply_to){
112 $user = User::staticGet('id',$notice->reply_to);
113 $feeds[]=common_local_url('ApiTimelineMentions',array('id' => $user->nickname,'format'=>'rss'));
114 $feeds[]=common_local_url('ApiTimelineMentions',array('id' => $user->nickname,'format'=>'atom'));
117 foreach(array_unique($feeds) as $feed){
118 if(! $publisher->publish_update($feed)){
119 common_log_line(LOG_WARNING,$feed.' was not published to hub at '.$this->hub.':'.$publisher->last_response());
124 function onPluginVersion(&$versions)
126 $versions[] = array('name' => 'PubSubHubBub',
127 'version' => STATUSNET_VERSION,
128 'author' => 'Craig Andrews',
129 'homepage' => 'http://status.net/wiki/Plugin:PubSubHubBub',
131 _m('The PubSubHubBub plugin pushes RSS/Atom updates to a <a href="http://pubsubhubbub.googlecode.com/">PubSubHubBub</a> hub.'));