]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/lib/xrdaction.php
syntax error in exception string in discovery.php
[quix0rs-gnu-social.git] / plugins / OStatus / 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') && !defined('LACONICA')) { exit(1); }
26
27 class XrdAction extends Action
28 {
29     public $uri;
30
31     public $user;
32
33     public $xrd;
34
35     function handle()
36     {
37         $nick =  $this->user->nickname;
38
39         if (empty($this->xrd)) {
40             $xrd = new XRD();
41         } else {
42             $xrd = $this->xrd;
43         }
44
45         if (empty($xrd->subject)) {
46             $xrd->subject = Discovery::normalize($this->uri);
47         }
48         $xrd->alias[] = $this->user->uri;
49         $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
50                               'type' => 'text/html',
51                               'href' => $this->user->uri);
52
53         $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
54                               'href' => common_local_url('ApiTimelineUser',
55                                                          array('id' => $this->user->id,
56                                                                'format' => 'atom')),
57                               'type' => 'application/atom+xml');
58
59         // hCard
60         $xrd->links[] = array('rel' => Discovery::HCARD,
61                               'type' => 'text/html',
62                               'href' => common_local_url('hcard', array('nickname' => $nick)));
63
64         // XFN
65         $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
66                               'type' => 'text/html',
67                               'href' => $this->user->uri);
68         // FOAF
69         $xrd->links[] = array('rel' => 'describedby',
70                               'type' => 'application/rdf+xml',
71                               'href' => common_local_url('foaf',
72                                                          array('nickname' => $nick)));
73
74         // Salmon
75         $salmon_url = common_local_url('usersalmon',
76                                        array('id' => $this->user->id));
77
78         $xrd->links[] = array('rel' => Salmon::REL_SALMON,
79                               'href' => $salmon_url);
80         // XXX : Deprecated - to be removed.
81         $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
82                               'href' => $salmon_url);
83
84         $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
85                               'href' => $salmon_url);
86
87         // Get this user's keypair
88         $magickey = Magicsig::staticGet('user_id', $this->user->id);
89         if (!$magickey) {
90             // No keypair yet, let's generate one.
91             $magickey = new Magicsig();
92             $magickey->generate($this->user->id);
93         }
94
95         $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
96                               'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
97
98         // TODO - finalize where the redirect should go on the publisher
99         $url = common_local_url('ostatussub') . '?profile={uri}';
100         $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
101                               'template' => $url );
102
103         header('Content-type: application/xrd+xml');
104         print $xrd->toXML();
105     }
106
107 }