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('api',array('apiaction' => 'statuses','method' => 'public_timeline.rss'));
69 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'public_timeline.atom'));
72 $user = User::staticGet('id',$notice->profile_id);
73 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.rss'));
74 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.atom'));
77 $tag = new Notice_tag();
78 $tag->notice_id = $notice->id;
80 while ($tag->fetch()) {
81 $feeds[]=common_local_url('api',array('apiaction' => 'tags','method' => 'timeline', 'argument'=>$tag->tag.'.atom'));
82 $feeds[]=common_local_url('api',array('apiaction' => 'tags','method' => 'timeline', 'argument'=>$tag->tag.'.rss'));
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('api',array('apiaction' => 'groups','method' => 'timeline','argument' => $group->nickname.'.rss'));
93 $feeds[]=common_local_url('api',array('apiaction' => 'groups','method' => 'timeline','argument' => $group->nickname.'.atom'));
97 //feed of each user that subscribes to the notice's author
98 $notice_inbox = new Notice_inbox();
99 $notice_inbox->notice_id = $notice->id;
100 if ($notice_inbox->find()) {
101 while ($notice_inbox->fetch()) {
102 $user = User::staticGet('id',$notice_inbox->user_id);
103 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.rss'));
104 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.atom'));
108 /* TODO: when the reply page gets RSS and ATOM feeds, implement this
109 //feed of user replied to
110 if($notice->reply_to){
111 $user = User::staticGet('id',$notice->reply_to);
112 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.rss'));
113 $feeds[]=common_local_url('api',array('apiaction' => 'statuses','method' => 'user_timeline','argument' => $user->nickname.'.atom'));
116 foreach(array_unique($feeds) as $feed){
117 if(! $publisher->publish_update($feed)){
118 common_log_line(LOG_WARNING,$feed.' was not published to hub at '.$this->hub.':'.$publisher->last_response());