]> git.mxchange.org Git - friendica.git/blob - mod/xrd.php
Merge remote-tracking branch 'upstream/develop' into rewrites/coding-convention
[friendica.git] / mod / xrd.php
1 <?php
2
3 require_once('include/crypto.php');
4
5 function xrd_init(App $a) {
6
7         $uri = urldecode(notags(trim($_GET['uri'])));
8
9         if (substr($uri,0,4) === 'http') {
10                 $acct = false;
11                 $name = basename($uri);
12         } else {
13                 $acct = true;
14                 $local = str_replace('acct:', '', $uri);
15                 if (substr($local,0,2) == '//') {
16                         $local = substr($local,2);
17                 }
18
19                 $name = substr($local,0,strpos($local,'@'));
20         }
21
22         $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
23                 dbesc($name)
24         );
25         if (! dbm::is_result($r)) {
26                 killme();
27         }
28
29         $salmon_key = salmon_key($r[0]['spubkey']);
30
31         header('Access-Control-Allow-Origin: *');
32         header("Content-type: text/xml");
33
34         $tpl = get_markup_template('xrd_diaspora.tpl');
35         $dspr = replace_macros($tpl,array(
36                 '$baseurl' => App::get_baseurl(),
37                 '$dspr_guid' => $r[0]['guid'],
38                 '$dspr_key' => base64_encode(pemtorsa($r[0]['pubkey']))
39         ));
40
41         $tpl = get_markup_template('xrd_person.tpl');
42
43         $profile_url = App::get_baseurl().'/profile/'.$r[0]['nickname'];
44
45         if ($acct) {
46                 $alias = $profile_url;
47         }
48         else {
49                 $alias = 'acct:'.$r[0]['nickname'].'@'.$a->get_hostname();
50
51                 if ($a->get_path()) {
52                         $alias .= '/'.$a->get_path();
53                 }
54         }
55
56         $o = replace_macros($tpl, array(
57                 '$nick'        => $r[0]['nickname'],
58                 '$accturi'     => $uri,
59                 '$alias'       => $alias,
60                 '$profile_url' => $profile_url,
61                 '$hcard_url'   => App::get_baseurl() . '/hcard/'         . $r[0]['nickname'],
62                 '$atom'        => App::get_baseurl() . '/dfrn_poll/'     . $r[0]['nickname'],
63                 '$zot_post'    => App::get_baseurl() . '/post/'          . $r[0]['nickname'],
64                 '$poco_url'    => App::get_baseurl() . '/poco/'          . $r[0]['nickname'],
65                 '$photo'       => App::get_baseurl() . '/photo/profile/' . $r[0]['uid']      . '.jpg',
66                 '$dspr'        => $dspr,
67                 '$salmon'      => App::get_baseurl() . '/salmon/'        . $r[0]['nickname'],
68                 '$salmen'      => App::get_baseurl() . '/salmon/'        . $r[0]['nickname'] . '/mention',
69                 '$subscribe'   => App::get_baseurl() . '/follow?url={uri}',
70                 '$modexp'      => 'data:application/magic-public-key,'  . $salmon_key,
71                 '$bigkey'      => salmon_key($r[0]['pubkey']),
72         ));
73
74
75         $arr = array('user' => $r[0], 'xml' => $o);
76         call_hooks('personal_xrd', $arr);
77
78         echo $arr['xml'];
79         killme();
80
81 }