]> git.mxchange.org Git - friendica.git/blob - mod/xrd.php
Hubzilla doesn't return the handle in the hcard
[friendica.git] / mod / xrd.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5
6 require_once('include/crypto.php');
7
8 function xrd_init(App $a) {
9         if ($a->argv[0] == 'xrd') {
10                 $uri = urldecode(notags(trim($_GET['uri'])));
11                 if ($_SERVER['HTTP_ACCEPT'] == 'application/jrd+json') {
12                         $mode = 'json';
13                 } else {
14                         $mode = 'xml';
15                 }
16         } else {
17                 $uri = urldecode(notags(trim($_GET['resource'])));
18                 if ($_SERVER['HTTP_ACCEPT'] == 'application/xrd+xml') {
19                         $mode = 'xml';
20                 } else {
21                         $mode = 'json';
22                 }
23         }
24
25         if(substr($uri,0,4) === 'http') {
26                 $acct = false;
27                 $name = ltrim(basename($uri), '~');
28         } else {
29                 $acct = true;
30                 $local = str_replace('acct:', '', $uri);
31                 if(substr($local,0,2) == '//')
32                         $local = substr($local, 2);
33
34                 $name = substr($local, 0, strpos($local,'@'));
35         }
36
37         $r = dba::select('user', array(), array('nickname' => $name), array('limit' => 1));
38         if (!dbm::is_result($r)) {
39                 killme();
40         }
41
42         $profile_url = System::baseUrl().'/profile/'.$r['nickname'];
43
44         if ($acct) {
45                 $alias = $profile_url;
46         } else {
47                 $alias = 'acct:'.$r['nickname'].'@'.$a->get_hostname();
48
49                 if ($a->get_path()) {
50                         $alias .= '/'.$a->get_path();
51                 }
52         }
53
54         if ($mode == 'xml') {
55                 xrd_xml($a, $uri, $alias, $profile_url, $r);
56         } else {
57                 xrd_json($a, $uri, $alias, $profile_url, $r);
58         }
59 }
60
61 function xrd_json($a, $uri, $alias, $profile_url, $r) {
62         $salmon_key = salmon_key($r['spubkey']);
63
64         header('Access-Control-Allow-Origin: *');
65         header("Content-type: application/json; charset=utf-8");
66
67         $json = array('subject' => $uri,
68                         'aliases' => array($alias),
69                         'links' => array(array('rel' => NAMESPACE_DFRN, 'href' => $profile_url),
70                                         array('rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']),
71                                         array('rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url),
72                                         array('rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']),
73                                         array('rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']),
74                                         array('rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'),
75                                         array('rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()),
76                                         array('rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']),
77                                         array('rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']),
78                                         array('rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'),
79                                         array('rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'),
80                                         array('rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key)
81         ));
82         echo json_encode($json);
83         killme();
84 }
85
86 function xrd_xml($a, $uri, $alias, $profile_url, $r) {
87         $salmon_key = salmon_key($r['spubkey']);
88
89         header('Access-Control-Allow-Origin: *');
90         header("Content-type: text/xml");
91
92         $tpl = get_markup_template('xrd_person.tpl');
93
94         $o = replace_macros($tpl, array(
95                 '$nick'        => $r['nickname'],
96                 '$accturi'     => $uri,
97                 '$alias'       => $alias,
98                 '$profile_url' => $profile_url,
99                 '$hcard_url'   => System::baseUrl() . '/hcard/'         . $r['nickname'],
100                 '$atom'        => System::baseUrl() . '/dfrn_poll/'     . $r['nickname'],
101                 '$zot_post'    => System::baseUrl() . '/post/'          . $r['nickname'],
102                 '$poco_url'    => System::baseUrl() . '/poco/'          . $r['nickname'],
103                 '$photo'       => System::baseUrl() . '/photo/profile/' . $r['uid']      . '.jpg',
104                 '$baseurl' => System::baseUrl(),
105                 '$salmon'      => System::baseUrl() . '/salmon/'        . $r['nickname'],
106                 '$salmen'      => System::baseUrl() . '/salmon/'        . $r['nickname'] . '/mention',
107                 '$subscribe'   => System::baseUrl() . '/follow?url={uri}',
108                 '$modexp'      => 'data:application/magic-public-key,'  . $salmon_key,
109         ));
110
111         $arr = array('user' => $r, 'xml' => $o);
112         call_hooks('personal_xrd', $arr);
113
114         echo $arr['xml'];
115         killme();
116 }