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');
38 // Pull out hCard profile elements
40 $items = $dom->getElementsByTagName('*');
41 foreach($items as $item) {
42 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
43 $level2 = $item->getElementsByTagName('*');
44 foreach($level2 as $x) {
45 if(attribute_contains($x->getAttribute('class'),'fn'))
46 $ret['fn'] = $x->textContent;
47 if(attribute_contains($x->getAttribute('class'),'photo'))
48 $ret['photo'] = $x->getAttribute('src');
49 if(attribute_contains($x->getAttribute('class'),'key'))
50 $ret['key'] = $x->textContent;
63 if(! function_exists('validate_dfrn')) {
64 function validate_dfrn($a) {
68 if(! x($a,'dfrn-request'))
70 if(! x($a,'dfrn-confirm'))
72 if(! x($a,'dfrn-notify'))
74 if(! x($a,'dfrn-poll'))
79 if(! function_exists('scrape_meta')) {
80 function scrape_meta($url) {
88 $dom = HTML5_Parser::parse($s);
93 $items = $dom->getElementsByTagName('meta');
95 // get DFRN link elements
97 foreach($items as $item) {
98 $x = $item->getAttribute('name');
99 if(substr($x,0,5) == "dfrn-")
100 $ret[$x] = $item->getAttribute('content');