]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LRDD/lib/lrddmethod/linkheader.php
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
[quix0rs-gnu-social.git] / plugins / LRDD / lib / lrddmethod / linkheader.php
1 <?php
2 /**
3  * Implementation of discovery using HTTP Link header
4  *
5  * Discovers XRD file for a user by fetching the URL and reading any
6  * Link: headers in the HTTP response.
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_LinkHeader extends LRDDMethod
16 {
17     /**
18      * For HTTP IDs fetch the URL and look for Link headers.
19      *
20      * @todo fail out of WebFinger URIs faster
21      */
22     public function discover($uri)
23     {
24         $response = self::fetchUrl($uri, HTTPClient::METHOD_HEAD);
25
26         $link_header = $response->getHeader('Link');
27         if (empty($link_header)) {
28             throw new Exception('No Link header found');
29         }
30         common_debug('LRDD LinkHeader found: '.var_export($link_header,true));
31
32         return self::parseHeader($link_header);
33     }
34
35     /**
36      * Given a string or array of headers, returns JRD-like assoc array
37      *
38      * @param string|array $header string or array of strings for headers
39      *
40      * @return array of associative arrays in JRD-like array format
41      */
42     protected static function parseHeader($header)
43     {
44         $lh = new LinkHeader($header);
45
46         $link = new XML_XRD_Element_Link($lh->rel, $lh->href, $lh->type);
47
48         return array($link);
49     }
50 }