]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/xrdaction.php
Move user xrd action to core and use hooks to extend
[quix0rs-gnu-social.git] / lib / xrdaction.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * @package OStatusPlugin
22  * @maintainer James Walker <james@status.net>
23  */
24
25 if (!defined('STATUSNET')) {
26     exit(1);
27 }
28
29 class XrdAction extends Action
30 {
31     public $uri;
32
33     public $user;
34
35     public $xrd;
36
37     function handle()
38     {
39         $nick    = $this->user->nickname;
40         $profile = $this->user->getProfile();
41
42         if (empty($this->xrd)) {
43             $xrd = new XRD();
44         } else {
45             $xrd = $this->xrd;
46         }
47
48         if (empty($xrd->subject)) {
49             $xrd->subject = Discovery::normalize($this->uri);
50         }
51
52         if (Event::handle('StartXrdActionAliases', array(&$xrd, $this->user))) {
53             
54             // Possible aliases for the user
55             
56             $uris = array($this->user->uri, $profile->profileurl);
57             
58             // FIXME: Webfinger generation code should live somewhere on its own
59             
60             $path = common_config('site', 'path');
61             
62             if (empty($path)) {
63                 $uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server'));
64             }
65             
66             foreach ($uris as $uri) {
67                 if ($uri != $xrd->subject) {
68                     $xrd->alias[] = $uri;
69                 }
70             }
71             
72             Event::handle('EndXrdActionAliases', array(&$xrd, $this->user));
73         }
74
75         if (Event::handle('StartXrdActionLinks', array(&$xrd, $this->user))) {
76             
77             $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
78                                   'type' => 'text/html',
79                                   'href' => $profile->profileurl);
80             
81             // hCard
82             $xrd->links[] = array('rel' => Discovery::HCARD,
83                                   'type' => 'text/html',
84                                   'href' => common_local_url('hcard', array('nickname' => $nick)));
85             
86             // XFN
87             $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
88                                   'type' => 'text/html',
89                                   'href' => $profile->profileurl);
90             // FOAF
91             $xrd->links[] = array('rel' => 'describedby',
92                                   'type' => 'application/rdf+xml',
93                                   'href' => common_local_url('foaf',
94                                                              array('nickname' => $nick)));
95             
96             $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
97                                   'href' => common_local_url('ApiTimelineUser',
98                                                              array('id' => $this->user->id,
99                                                                    'format' => 'atom')),
100                                   'type' => 'application/atom+xml');
101             
102             Event::handle('EndXrdActionLinks', array(&$xrd, $this->user));
103         }
104             
105
106         header('Content-type: application/xrd+xml');
107         print $xrd->toXML();
108     }
109 }