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(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
26 $ret['feed_atom'] = $item->getAttribute('href');
27 if(substr($x,0,5) == "dfrn-")
28 $ret[$x] = $item->getAttribute('href');
30 $decoded = urldecode($item->getAttribute('href'));
31 if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
32 $ret['nick'] = $matches[1];
36 // Pull out hCard profile elements
38 $items = $dom->getElementsByTagName('*');
39 foreach($items as $item) {
40 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
41 $level2 = $item->getElementsByTagName('*');
42 foreach($level2 as $x) {
43 if(attribute_contains($x->getAttribute('class'),'fn'))
44 $ret['fn'] = $x->textContent;
45 if(attribute_contains($x->getAttribute('class'),'photo'))
46 $ret['photo'] = $x->getAttribute('src');
47 if(attribute_contains($x->getAttribute('class'),'key'))
48 $ret['key'] = $x->textContent;
61 if(! function_exists('validate_dfrn')) {
62 function validate_dfrn($a) {
66 if(! x($a,'dfrn-request'))
68 if(! x($a,'dfrn-confirm'))
70 if(! x($a,'dfrn-notify'))
72 if(! x($a,'dfrn-poll'))
77 if(! function_exists('scrape_meta')) {
78 function scrape_meta($url) {
86 $dom = HTML5_Parser::parse($s);
91 $items = $dom->getElementsByTagName('meta');
93 // get DFRN link elements
95 foreach($items as $item) {
96 $x = $item->getAttribute('name');
97 if(substr($x,0,5) == "dfrn-")
98 $ret[$x] = $item->getAttribute('content');
105 if(! function_exists('scrape_vcard')) {
106 function scrape_vcard($url) {
109 $s = fetch_url($url);
114 $dom = HTML5_Parser::parse($s);
119 // Pull out hCard profile elements
121 $items = $dom->getElementsByTagName('*');
122 foreach($items as $item) {
123 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
124 $level2 = $item->getElementsByTagName('*');
125 foreach($level2 as $x) {
126 if(attribute_contains($x->getAttribute('class'),'fn'))
127 $ret['fn'] = $x->textContent;
128 if((attribute_contains($x->getAttribute('class'),'photo'))
129 || (attribute_contains($x->getAttribute('class'),'avatar')))
130 $ret['photo'] = $x->getAttribute('src');
131 if((attribute_contains($x->getAttribute('class'),'nickname'))
132 || (attribute_contains($x->getAttribute('class'),'uid')))
133 $ret['nick'] = $x->textContent;
142 if(! function_exists('scrape_feed')) {
143 function scrape_feed($url) {
146 $s = fetch_url($url);
151 $dom = HTML5_Parser::parse($s);
156 $items = $dom->getElementsByTagName('link');
158 // get Atom link elements
160 foreach($items as $item) {
161 $x = $item->getAttribute('rel');
162 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
163 $ret['feed_atom'] = $item->getAttribute('href');