]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/PubSubHubBub/PubSubHubBubPlugin.php
96500404bc85b5cdfe2ca8c3b71faed1d9cb2530
[quix0rs-gnu-social.git] / plugins / PubSubHubBub / PubSubHubBubPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to push RSS/Atom updates to a PubSubHubBub hub
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 define('DEFAULT_HUB','http://pubsubhubbub.appspot.com');
35
36 require_once(INSTALLDIR.'/plugins/PubSubHubBub/publisher.php');
37
38 class PubSubHubBubPlugin extends Plugin
39 {
40     public $hub = DEFAULT_HUB;
41
42     function __construct()
43     {
44         parent::__construct();
45     }
46
47     function onStartApiAtom($action){
48         $action->element('link',array('rel'=>'hub','href'=>$this->hub),null);
49     }
50
51     function onStartApiRss($action){
52         $action->element('atom:link',array('rel'=>'hub','href'=>$this->hub),null);
53     }
54
55     function onHandleQueuedNotice($notice){
56         $publisher = new Publisher($this->hub);
57
58         $feeds = array();
59
60         //public timeline feeds
61         $feeds[]=common_local_url('ApiTimelinePublic',array('format' => 'rss'));
62         $feeds[]=common_local_url('ApiTimelinePublic',array('format' => 'atom'));
63
64         //author's own feeds
65         $user = User::staticGet('id',$notice->profile_id);
66         $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'rss'));
67         $feeds[]=common_local_url('ApiTimelineUser',array('id' => $user->nickname, 'format'=>'atom'));
68
69         //tag feeds
70         $tag = new Notice_tag();
71         $tag->notice_id = $notice->id;
72         if ($tag->find()) {
73             while ($tag->fetch()) {
74                 $feeds[]=common_local_url('ApiTimelineTag',array('tag'=>$tag->tag, 'format'=>'rss'));
75                 $feeds[]=common_local_url('ApiTimelineTag',array('tag'=>$tag->tag, 'format'=>'atom'));
76             }
77         }
78
79         //group feeds
80         $group_inbox = new Group_inbox();
81         $group_inbox->notice_id = $notice->id;
82         if ($group_inbox->find()) {
83             while ($group_inbox->fetch()) {
84                 $group = User_group::staticGet('id',$group_inbox->group_id);
85                 $feeds[]=common_local_url('ApiTimelineGroup',array('id' => $group->nickname,'format'=>'rss'));
86                 $feeds[]=common_local_url('ApiTimelineGroup',array('id' => $group->nickname,'format'=>'atom'));
87             }
88         }
89
90         //feed of each user that subscribes to the notice's author
91
92         $ni = $notice->whoGets();
93
94         foreach (array_keys($ni) as $user_id) {
95             $user = User::staticGet('id', $user_id);
96             if (empty($user)) {
97                 continue;
98             }
99             $feeds[]=common_local_url('ApiTimelineFriends', array('id' => $user->nickname, 'format'=>'rss'));
100             $feeds[]=common_local_url('ApiTimelineFriends', array('id' => $user->nickname, 'format'=>'atom'));
101         }
102
103         $replies = $notice->getReplies();
104
105         //feed of user replied to
106         foreach ($replies as $recipient) {
107                 $user = User::staticGet('id',$recipient);
108             if (!empty($user)) {
109                 $feeds[]=common_local_url('ApiTimelineMentions',array('id' => $user->nickname,'format'=>'rss'));
110                 $feeds[]=common_local_url('ApiTimelineMentions',array('id' => $user->nickname,'format'=>'atom'));
111             }
112         }
113
114         foreach(array_unique($feeds) as $feed){
115             if(! $publisher->publish_update($feed)){
116                 common_log_line(LOG_WARNING,$feed.' was not published to hub at '.$this->hub.':'.$publisher->last_response());
117             }
118         }
119     }
120
121     function onPluginVersion(&$versions)
122     {
123         $versions[] = array('name' => 'PubSubHubBub',
124                             'version' => STATUSNET_VERSION,
125                             'author' => 'Craig Andrews',
126                             'homepage' => 'http://status.net/wiki/Plugin:PubSubHubBub',
127                             'rawdescription' =>
128                             _m('The PubSubHubBub plugin pushes RSS/Atom updates to a <a href="http://pubsubhubbub.googlecode.com/">PubSubHubBub</a> hub.'));
129
130         return true;
131     }
132 }