+
+ // get the host meta file
+
+ $host = @parse_url($uri);
+
+ if($host) {
+ $url = ((x($host,'scheme')) ? $host['scheme'] : 'http') . '://';
+ $url .= $host['host'] . '/.well-known/host-meta' ;
+ }
+ else
+ return array();
+
+ logger('lrdd: constructed url: ' . $url);
+
+ $xml = fetch_url($url);
+ $headers = $a->get_curl_headers();
+
+ if (! $xml)
+ return array();
+
+ logger('lrdd: host_meta: ' . $xml, LOGGER_DATA);
+
+ $h = parse_xml_string($xml);
+
+ $arr = convert_xml_element_to_array($h);
+
+ if(isset($arr['xrd']['property'])) {
+ $property = $arr['crd']['property'];
+ if(! isset($property[0]))
+ $properties = array($property);
+ else
+ $properties = $property;
+ foreach($properties as $prop)
+ if((string) $prop['@attributes'] === 'http://lrdd.net/priority/resource')
+ $priority = 'resource';
+ }
+
+ // save the links in case we need them
+
+ $links = array();
+
+ if(isset($arr['xrd']['link'])) {
+ $link = $arr['xrd']['link'];
+ if(! isset($link[0]))
+ $links = array($link);
+ else
+ $links = $link;
+ }
+
+ // do we have a template or href?
+
+ if(count($links)) {
+ foreach($links as $link) {
+ if($link['@attributes']['rel'] && attribute_contains($link['@attributes']['rel'],'lrdd')) {
+ if(x($link['@attributes'],'template'))
+ $tpl = $link['@attributes']['template'];
+ elseif(x($link['@attributes'],'href'))
+ $href = $link['@attributes']['href'];
+ }
+ }
+ }
+
+ if((! isset($tpl)) || (! strpos($tpl,'{uri}')))
+ $tpl = '';
+
+ if($priority === 'host') {
+ if(strlen($tpl))
+ $pxrd = str_replace('{uri}', urlencode($uri), $tpl);
+ elseif(isset($href))
+ $pxrd = $href;
+ if(isset($pxrd)) {
+ logger('lrdd: (host priority) pxrd: ' . $pxrd);
+ $links = fetch_xrd_links($pxrd);
+ return $links;
+ }
+