3 require_once('library/HTML5/Parser.php');
5 if(! function_exists('attribute_contains')) {
6 function attribute_contains($attr,$s) {
7 $a = explode(' ', $attr);
8 if(count($a) && in_array($s,$a))
14 if(! function_exists('scrape_dfrn')) {
15 function scrape_dfrn($url) {
23 $dom = HTML5_Parser::parse($s);
28 $items = $dom->getElementsByTagName('link');
30 // get DFRN link elements
32 foreach($items as $item) {
33 $x = $item->getAttribute('rel');
34 if(substr($x,0,5) == "dfrn-")
35 $ret[$x] = $item->getAttribute('href');
37 $decoded = urldecode($item->getAttribute('href'));
38 if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
39 $ret['nick'] = $matches[1];
43 // Pull out hCard profile elements
45 $items = $dom->getElementsByTagName('*');
46 foreach($items as $item) {
47 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
48 $level2 = $item->getElementsByTagName('*');
49 foreach($level2 as $x) {
50 if(attribute_contains($x->getAttribute('class'),'fn'))
51 $ret['fn'] = $x->textContent;
52 if(attribute_contains($x->getAttribute('class'),'photo'))
53 $ret['photo'] = $x->getAttribute('src');
54 if(attribute_contains($x->getAttribute('class'),'key'))
55 $ret['key'] = $x->textContent;
68 if(! function_exists('validate_dfrn')) {
69 function validate_dfrn($a) {
73 if(! x($a,'dfrn-request'))
75 if(! x($a,'dfrn-confirm'))
77 if(! x($a,'dfrn-notify'))
79 if(! x($a,'dfrn-poll'))
84 if(! function_exists('scrape_meta')) {
85 function scrape_meta($url) {
93 $dom = HTML5_Parser::parse($s);
98 $items = $dom->getElementsByTagName('meta');
100 // get DFRN link elements
102 foreach($items as $item) {
103 $x = $item->getAttribute('name');
104 if(substr($x,0,5) == "dfrn-")
105 $ret[$x] = $item->getAttribute('content');