]> git.mxchange.org Git - friendica.git/blobdiff - mod/xrd.php
Review updates
[friendica.git] / mod / xrd.php
index 49fdde25448a215881883802971c00d64dc529ca..05b07dc162505a1bc76248a90ab686081f253123 100644 (file)
@@ -1,12 +1,14 @@
 <?php
-
+/**
+ * @file mod/xrd.php
+ */
 use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Protocol\Salmon;
 
-require_once('include/crypto.php');
-
-function xrd_init(App $a) {
+function xrd_init(App $a)
+{
        if ($a->argv[0] == 'xrd') {
                $uri = urldecode(notags(trim($_GET['uri'])));
                if ($_SERVER['HTTP_ACCEPT'] == 'application/jrd+json') {
@@ -27,35 +29,37 @@ function xrd_init(App $a) {
                $name = ltrim(basename($uri), '~');
        } else {
                $local = str_replace('acct:', '', $uri);
-               if (substr($local, 0, 2) == '//')
+               if (substr($local, 0, 2) == '//') {
                        $local = substr($local, 2);
+               }
 
                $name = substr($local, 0, strpos($local, '@'));
        }
 
-       $r = dba::select('user', array(), array('nickname' => $name), array('limit' => 1));
-       if (!DBM::is_result($r)) {
+       $user = dba::selectFirst('user', [], ['nickname' => $name]);
+       if (!DBM::is_result($user)) {
                killme();
        }
 
-       $profile_url = System::baseUrl().'/profile/'.$r['nickname'];
+       $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
 
        $alias = str_replace('/profile/', '/~', $profile_url);
 
-       $addr = 'acct:'.$r['nickname'].'@'.$a->get_hostname();
+       $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
        if ($a->get_path()) {
                $addr .= '/'.$a->get_path();
        }
 
        if ($mode == 'xml') {
-               xrd_xml($a, $addr, $alias, $profile_url, $r);
+               xrd_xml($a, $addr, $alias, $profile_url, $user);
        } else {
-               xrd_json($a, $addr, $alias, $profile_url, $r);
+               xrd_json($a, $addr, $alias, $profile_url, $user);
        }
 }
 
-function xrd_json($a, $uri, $alias, $profile_url, $r) {
-       $salmon_key = salmon_key($r['spubkey']);
+function xrd_json($a, $uri, $alias, $profile_url, $r)
+{
+       $salmon_key = Salmon::salmonKey($r['spubkey']);
 
        header('Access-Control-Allow-Origin: *');
        header("Content-type: application/json; charset=utf-8");
@@ -79,8 +83,9 @@ function xrd_json($a, $uri, $alias, $profile_url, $r) {
        killme();
 }
 
-function xrd_xml($a, $uri, $alias, $profile_url, $r) {
-       $salmon_key = salmon_key($r['spubkey']);
+function xrd_xml($a, $uri, $alias, $profile_url, $r)
+{
+       $salmon_key = Salmon::salmonKey($r['spubkey']);
 
        header('Access-Control-Allow-Origin: *');
        header("Content-type: text/xml");
@@ -100,8 +105,8 @@ function xrd_xml($a, $uri, $alias, $profile_url, $r) {
                '$salmon'      => System::baseUrl() . '/salmon/'        . $r['nickname'],
                '$salmen'      => System::baseUrl() . '/salmon/'        . $r['nickname'] . '/mention',
                '$subscribe'   => System::baseUrl() . '/follow?url={uri}',
-               '$modexp'      => 'data:application/magic-public-key,'  . $salmon_key,
-       ));
+               '$modexp'      => 'data:application/magic-public-key,'  . $salmon_key)
+       );
 
        $arr = array('user' => $r, 'xml' => $o);
        call_hooks('personal_xrd', $arr);