3 function mention_url_representative_hcard($url, $fn=null, $mf2=null) {
5 $request = HTTPClient::start();
8 $response = $request->get($url);
9 } catch(Exception $ex) {
13 $url = $response->getEffectiveUrl();
14 $mf2 = new Mf2\Parser($response->getBody(), $url);
20 if(!empty($mf2['items'])) {
22 foreach($mf2['items'] as $item) {
23 if(!in_array('h-card', $item['type'])) {
27 // We found a match, return it immediately
28 if(isset($item['properties']['url']) && in_array($url, $item['properties']['url'])) {
29 $hcard = $item['properties'];
33 // Let's keep all the hcards for later, to return one of them at least
34 $hcards[] = $item['properties'];
37 // No match immediately for the url we expected, but there were h-cards found
38 if (count($hcards) > 0) {
44 $hcard = array('name' => array($fn));
47 if(!$hcard && $response) {
48 preg_match('/<title>([^<]+)/', $response->getBody(), $match);
49 $hcard = array('name' => array($match[1]));
52 if($hcard && !$hcard['url']) {
53 $hcard['url'] = array($url);