3 require_once('library/HTML5/Parser.php');
5 if(! function_exists('scrape_dfrn')) {
6 function scrape_dfrn($url) {
14 $dom = HTML5_Parser::parse($s);
19 $items = $dom->getElementsByTagName('link');
21 // get DFRN link elements
23 foreach($items as $item) {
24 $x = $item->getAttribute('rel');
25 if(substr($x,0,5) == "dfrn-")
26 $ret[$x] = $item->getAttribute('href');
28 $decoded = urldecode($item->getAttribute('href'));
29 if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
30 $ret['nick'] = $matches[1];
34 // Pull out hCard profile elements
36 $items = $dom->getElementsByTagName('*');
37 foreach($items as $item) {
38 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
39 $level2 = $item->getElementsByTagName('*');
40 foreach($level2 as $x) {
41 if(attribute_contains($x->getAttribute('class'),'fn'))
42 $ret['fn'] = $x->textContent;
43 if(attribute_contains($x->getAttribute('class'),'photo'))
44 $ret['photo'] = $x->getAttribute('src');
45 if(attribute_contains($x->getAttribute('class'),'key'))
46 $ret['key'] = $x->textContent;
59 if(! function_exists('validate_dfrn')) {
60 function validate_dfrn($a) {
64 if(! x($a,'dfrn-request'))
66 if(! x($a,'dfrn-confirm'))
68 if(! x($a,'dfrn-notify'))
70 if(! x($a,'dfrn-poll'))
75 if(! function_exists('scrape_meta')) {
76 function scrape_meta($url) {
84 $dom = HTML5_Parser::parse($s);
89 $items = $dom->getElementsByTagName('meta');
91 // get DFRN link elements
93 foreach($items as $item) {
94 $x = $item->getAttribute('name');
95 if(substr($x,0,5) == "dfrn-")
96 $ret[$x] = $item->getAttribute('content');
103 if(! function_exists('scrape_vcard')) {
104 function scrape_vcard($url) {
107 $s = fetch_url($url);
112 $dom = HTML5_Parser::parse($s);
117 // Pull out hCard profile elements
119 $items = $dom->getElementsByTagName('*');
120 foreach($items as $item) {
121 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
122 $level2 = $item->getElementsByTagName('*');
123 foreach($level2 as $x) {
124 if(attribute_contains($x->getAttribute('class'),'fn'))
125 $ret['fn'] = $x->textContent;
126 if((attribute_contains($x->getAttribute('class'),'photo'))
127 || (attribute_contains($x->getAttribute('class'),'avatar')))
128 $ret['photo'] = $x->getAttribute('src');
129 if((attribute_contains($x->getAttribute('class'),'nickname'))
130 || (attribute_contains($x->getAttribute('class'),'uid')))
131 $ret['nick'] = $x->textContent;