a0e107f17f
New plugins: * LRDD LRDD implements client-side RFC6415 and RFC7033 resource descriptor discovery procedures. I.e. LRDD, host-meta and WebFinger stuff. OStatus and OpenID now depend on the LRDD plugin (XML_XRD). * WebFinger This plugin implements the server-side of RFC6415 and RFC7033. Note: WebFinger technically doesn't handle XRD, but we serve both that and JRD (JSON Resource Descriptor), depending on Accept header and one ugly hack to check for old StatusNet installations. WebFinger depends on LRDD. We might make this even prettier by using Net_WebFinger, but it is not currently RFC7033 compliant (no /.well-known/webfinger resource GETs). Disabling the WebFinger plugin would effectively render your site non- federated (which might be desired on a private site). Disabling the LRDD plugin would make your site unable to do modern web URI lookups (making life just a little bit harder).
80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Implementation of discovery using HTML <link> element
|
|
*
|
|
* Discovers XRD file for a user by fetching the URL and reading any
|
|
* <link> elements in the HTML response.
|
|
*
|
|
* @category Discovery
|
|
* @package StatusNet
|
|
* @author James Walker <james@status.net>
|
|
* @copyright 2010 StatusNet, Inc.
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
* @link http://status.net/
|
|
*/
|
|
class LRDDMethod_LinkHTML extends LRDDMethod
|
|
{
|
|
/**
|
|
* For HTTP IDs, fetch the URL and look for <link> elements
|
|
* in the HTML response.
|
|
*
|
|
* @todo fail out of WebFinger URIs faster
|
|
*/
|
|
public function discover($uri)
|
|
{
|
|
$response = self::fetchUrl($uri);
|
|
|
|
return self::parse($response->getBody());
|
|
}
|
|
|
|
/**
|
|
* Parse HTML and return <link> elements
|
|
*
|
|
* Given an HTML string, scans the string for <link> elements
|
|
*
|
|
* @param string $html HTML to scan
|
|
*
|
|
* @return array array of associative arrays in JRD-ish array format
|
|
*/
|
|
public function parse($html)
|
|
{
|
|
$links = array();
|
|
|
|
preg_match('/<head(\s[^>]*)?>(.*?)<\/head>/is', $html, $head_matches);
|
|
$head_html = $head_matches[2];
|
|
|
|
preg_match_all('/<link\s[^>]*>/i', $head_html, $link_matches);
|
|
|
|
foreach ($link_matches[0] as $link_html) {
|
|
$link_url = null;
|
|
$link_rel = null;
|
|
$link_type = null;
|
|
|
|
preg_match('/\srel=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $rel_matches);
|
|
if ( isset($rel_matches[3]) ) {
|
|
$link_rel = $rel_matches[3];
|
|
} else if ( isset($rel_matches[1]) ) {
|
|
$link_rel = $rel_matches[1];
|
|
}
|
|
|
|
preg_match('/\shref=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $href_matches);
|
|
if ( isset($href_matches[3]) ) {
|
|
$link_uri = $href_matches[3];
|
|
} else if ( isset($href_matches[1]) ) {
|
|
$link_uri = $href_matches[1];
|
|
}
|
|
|
|
preg_match('/\stype=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $type_matches);
|
|
if ( isset($type_matches[3]) ) {
|
|
$link_type = $type_matches[3];
|
|
} else if ( isset($type_matches[1]) ) {
|
|
$link_type = $type_matches[1];
|
|
}
|
|
|
|
$links[] = new XML_XRD_Element_Link($link_rel, $link_uri, $link_type);
|
|
}
|
|
|
|
return $links;
|
|
}
|
|
}
|