]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LRDD/lib/lrddmethod/hostmeta.php
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
[quix0rs-gnu-social.git] / plugins / LRDD / lib / lrddmethod / hostmeta.php
1 <?php
2 /**
3  * Implementation of discovery using host-meta file
4  *
5  * Discovers resource descriptor file for a user by going to the
6  * organization's host-meta file and trying to find a template for LRDD.
7  *
8  * @category  Discovery
9  * @package   StatusNet
10  * @author    James Walker <james@status.net>
11  * @copyright 2010 StatusNet, Inc.
12  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
13  * @link      http://status.net/
14  */
15 class LRDDMethod_HostMeta extends LRDDMethod
16 {
17     /**
18      * For RFC6415 and HTTP URIs, fetch the host-meta file
19      * and look for LRDD templates
20      */
21     public function discover($uri)
22     {
23         // This is allowed for RFC6415 but not the 'WebFinger' RFC7033.
24         $try_schemes = array('https', 'http');
25
26         $scheme = mb_strtolower(parse_url($uri, PHP_URL_SCHEME));
27         switch ($scheme) {
28         case 'acct':
29             if (!Discovery::isAcct($uri)) {
30                 throw new Exception('Bad resource URI: '.$uri);
31             }
32             // We can't use parse_url data for this, since the 'host'
33             // entry is only set if the scheme has '://' after it.
34             list($user, $domain) = explode('@', parse_url($uri, PHP_URL_PATH));
35             break;
36         case 'http':
37         case 'https':
38             $domain = mb_strtolower(parse_url($uri, PHP_URL_HOST));
39             $try_schemes = array($scheme);
40             break;
41         default:
42             throw new Exception('Unable to discover resource descriptor endpoint.');
43         }
44
45         foreach ($try_schemes as $scheme) {
46             $url = $scheme . '://' . $domain . '/.well-known/host-meta';
47             
48             try {
49                 $response = self::fetchUrl($url);
50                 $this->xrd->loadString($response->getBody());
51             } catch (Exception $e) {
52                 common_debug('LRDD could not load resource descriptor: '.$url.' ('.$e->getMessage().')');
53                 continue;
54             }
55             return $this->xrd->links;
56         }
57
58         throw new Exception('Unable to retrieve resource descriptor links.');
59     }
60 }