]> git.mxchange.org Git - friendica.git/blob - mod/xrd.php
Merge pull request #2323 from annando/1601-dfrn-import
[friendica.git] / mod / xrd.php
1 <?php
2
3 require_once('include/crypto.php');
4
5 if(! function_exists('xrd_init')) {
6 function xrd_init(&$a) {
7
8         $uri = urldecode(notags(trim($_GET['uri'])));
9
10         if(substr($uri,0,4) === 'http') {
11                 $acct = false;
12                 $name = basename($uri);
13         } else {
14                 $acct = true;
15                 $local = str_replace('acct:', '', $uri);
16                 if(substr($local,0,2) == '//')
17                         $local = substr($local,2);
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(! count($r))
26                 killme();
27
28         $salmon_key = salmon_key($r[0]['spubkey']);
29
30         header('Access-Control-Allow-Origin: *');
31         header("Content-type: text/xml");
32
33         if(get_config('system','diaspora_enabled')) {
34                 $tpl = get_markup_template('xrd_diaspora.tpl');
35                 $dspr = replace_macros($tpl,array(
36                         '$baseurl' => $a->get_baseurl(),
37                         '$dspr_guid' => $r[0]['guid'],
38                         '$dspr_key' => base64_encode(pemtorsa($r[0]['pubkey']))
39                 ));
40         }
41         else
42                 $dspr = '';
43
44         $tpl = get_markup_template('xrd_person.tpl');
45
46         $profile_url = $a->get_baseurl().'/profile/'.$r[0]['nickname'];
47
48         if ($acct)
49                 $alias = $profile_url;
50         else {
51                 $alias = 'acct:'.$r[0]['nickname'].'@'.$a->get_hostname();
52
53                 if ($a->get_path())
54                         $alias .= '/'.$a->get_path();
55         }
56
57         $o = replace_macros($tpl, array(
58                 '$nick'        => $r[0]['nickname'],
59                 '$accturi'     => $uri,
60                 '$alias'       => $alias,
61                 '$profile_url' => $profile_url,
62                 '$hcard_url'   => $a->get_baseurl() . '/hcard/'         . $r[0]['nickname'],
63                 '$atom'        => $a->get_baseurl() . '/dfrn_poll/'     . $r[0]['nickname'],
64                 '$zot_post'    => $a->get_baseurl() . '/post/'          . $r[0]['nickname'],
65                 '$poco_url'    => $a->get_baseurl() . '/poco/'          . $r[0]['nickname'],
66                 '$photo'       => $a->get_baseurl() . '/photo/profile/' . $r[0]['uid']      . '.jpg',
67                 '$dspr'        => $dspr,
68                 '$salmon'      => $a->get_baseurl() . '/salmon/'        . $r[0]['nickname'],
69                 '$salmen'      => $a->get_baseurl() . '/salmon/'        . $r[0]['nickname'] . '/mention',
70                 '$subscribe'   => $a->get_baseurl() . '/follow?url={uri}',
71                 '$modexp'      => 'data:application/magic-public-key,'  . $salmon_key,
72                 '$bigkey'      =>  salmon_key($r[0]['pubkey'])
73         ));
74
75
76         $arr = array('user' => $r[0], 'xml' => $o);
77         call_hooks('personal_xrd', $arr);
78
79         echo $arr['xml'];
80         killme();
81 }
82 }