3 require_once('library/HTML5/Parser.php');
5 if(! function_exists('scrape_dfrn')) {
6 function scrape_dfrn($url) {
16 $headers = $a->get_curl_headers();
17 $lines = explode("\n",$headers);
19 foreach($lines as $line) {
20 // don't try and run feeds through the html5 parser
21 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
27 $dom = HTML5_Parser::parse($s);
32 $items = $dom->getElementsByTagName('link');
34 // get DFRN link elements
36 foreach($items as $item) {
37 $x = $item->getAttribute('rel');
38 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
39 $ret['feed_atom'] = $item->getAttribute('href');
40 if(substr($x,0,5) == "dfrn-")
41 $ret[$x] = $item->getAttribute('href');
43 $decoded = urldecode($item->getAttribute('href'));
44 if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
45 $ret['nick'] = $matches[1];
49 // Pull out hCard profile elements
51 $items = $dom->getElementsByTagName('*');
52 foreach($items as $item) {
53 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
54 $level2 = $item->getElementsByTagName('*');
55 foreach($level2 as $x) {
56 if(attribute_contains($x->getAttribute('class'),'fn'))
57 $ret['fn'] = $x->textContent;
58 if(attribute_contains($x->getAttribute('class'),'photo'))
59 $ret['photo'] = $x->getAttribute('src');
60 if(attribute_contains($x->getAttribute('class'),'key'))
61 $ret['key'] = $x->textContent;
74 if(! function_exists('validate_dfrn')) {
75 function validate_dfrn($a) {
79 if(! x($a,'dfrn-request'))
81 if(! x($a,'dfrn-confirm'))
83 if(! x($a,'dfrn-notify'))
85 if(! x($a,'dfrn-poll'))
90 if(! function_exists('scrape_meta')) {
91 function scrape_meta($url) {
101 $headers = $a->get_curl_headers();
102 $lines = explode("\n",$headers);
104 foreach($lines as $line) {
105 // don't try and run feeds through the html5 parser
106 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
113 $dom = HTML5_Parser::parse($s);
118 $items = $dom->getElementsByTagName('meta');
120 // get DFRN link elements
122 foreach($items as $item) {
123 $x = $item->getAttribute('name');
124 if(substr($x,0,5) == "dfrn-")
125 $ret[$x] = $item->getAttribute('content');
132 if(! function_exists('scrape_vcard')) {
133 function scrape_vcard($url) {
138 $s = fetch_url($url);
143 $headers = $a->get_curl_headers();
144 $lines = explode("\n",$headers);
146 foreach($lines as $line) {
147 // don't try and run feeds through the html5 parser
148 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
153 $dom = HTML5_Parser::parse($s);
158 // Pull out hCard profile elements
160 $items = $dom->getElementsByTagName('*');
161 foreach($items as $item) {
162 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
163 $level2 = $item->getElementsByTagName('*');
164 foreach($level2 as $x) {
165 if(attribute_contains($x->getAttribute('class'),'fn'))
166 $ret['fn'] = $x->textContent;
167 if((attribute_contains($x->getAttribute('class'),'photo'))
168 || (attribute_contains($x->getAttribute('class'),'avatar')))
169 $ret['photo'] = $x->getAttribute('src');
170 if((attribute_contains($x->getAttribute('class'),'nickname'))
171 || (attribute_contains($x->getAttribute('class'),'uid')))
172 $ret['nick'] = $x->textContent;
181 if(! function_exists('scrape_feed')) {
182 function scrape_feed($url) {
187 $s = fetch_url($url);
192 $headers = $a->get_curl_headers();
193 $lines = explode("\n",$headers);
195 foreach($lines as $line) {
196 if(stristr($line,'content-type:')) {
197 if(stristr($line,'application/atom+xml')) {
198 $ret['feed_atom'] = $url;
201 if(stristr($line,'application/rss+xml')) {
202 $ret['feed_rss'] = $url;
209 $dom = HTML5_Parser::parse($s);
214 $items = $dom->getElementsByTagName('link');
216 // get Atom link elements
218 foreach($items as $item) {
219 $x = $item->getAttribute('rel');
220 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
221 $ret['feed_atom'] = $item->getAttribute('href');
222 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml'))
223 $ret['feed_rss'] = $item->getAttribute('href');