3 require_once('library/HTML5/Parser.php');
5 if(! function_exists('scrape_dfrn')) {
6 function scrape_dfrn($url) {
12 logger('scrape_dfrn: url=' . $url);
19 $headers = $a->get_curl_headers();
20 logger('scrape_dfrn: headers=' . $headers, LOGGER_DEBUG);
23 $lines = explode("\n",$headers);
25 foreach($lines as $line) {
26 // don't try and run feeds through the html5 parser
27 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
33 $dom = HTML5_Parser::parse($s);
38 $items = $dom->getElementsByTagName('link');
40 // get DFRN link elements
42 foreach($items as $item) {
43 $x = $item->getAttribute('rel');
44 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
45 $ret['feed_atom'] = $item->getAttribute('href');
46 if(substr($x,0,5) == "dfrn-")
47 $ret[$x] = $item->getAttribute('href');
49 $decoded = urldecode($item->getAttribute('href'));
50 if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
51 $ret['nick'] = $matches[1];
55 // Pull out hCard profile elements
57 $items = $dom->getElementsByTagName('*');
58 foreach($items as $item) {
59 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
60 $level2 = $item->getElementsByTagName('*');
61 foreach($level2 as $x) {
62 if(attribute_contains($x->getAttribute('class'),'fn'))
63 $ret['fn'] = $x->textContent;
64 if(attribute_contains($x->getAttribute('class'),'photo'))
65 $ret['photo'] = $x->getAttribute('src');
66 if(attribute_contains($x->getAttribute('class'),'key'))
67 $ret['key'] = $x->textContent;
80 if(! function_exists('validate_dfrn')) {
81 function validate_dfrn($a) {
85 if(! x($a,'dfrn-request'))
87 if(! x($a,'dfrn-confirm'))
89 if(! x($a,'dfrn-notify'))
91 if(! x($a,'dfrn-poll'))
96 if(! function_exists('scrape_meta')) {
97 function scrape_meta($url) {
103 logger('scrape_meta: url=' . $url);
105 $s = fetch_url($url);
110 $headers = $a->get_curl_headers();
111 logger('scrape_meta: headers=' . $headers, LOGGER_DEBUG);
113 $lines = explode("\n",$headers);
115 foreach($lines as $line) {
116 // don't try and run feeds through the html5 parser
117 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
124 $dom = HTML5_Parser::parse($s);
129 $items = $dom->getElementsByTagName('meta');
131 // get DFRN link elements
133 foreach($items as $item) {
134 $x = $item->getAttribute('name');
135 if(substr($x,0,5) == "dfrn-")
136 $ret[$x] = $item->getAttribute('content');
143 if(! function_exists('scrape_vcard')) {
144 function scrape_vcard($url) {
150 logger('scrape_vcard: url=' . $url);
152 $s = fetch_url($url);
157 $headers = $a->get_curl_headers();
158 $lines = explode("\n",$headers);
160 foreach($lines as $line) {
161 // don't try and run feeds through the html5 parser
162 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
167 $dom = HTML5_Parser::parse($s);
172 // Pull out hCard profile elements
174 $items = $dom->getElementsByTagName('*');
175 foreach($items as $item) {
176 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
177 $level2 = $item->getElementsByTagName('*');
178 foreach($level2 as $x) {
179 if(attribute_contains($x->getAttribute('class'),'fn'))
180 $ret['fn'] = $x->textContent;
181 if((attribute_contains($x->getAttribute('class'),'photo'))
182 || (attribute_contains($x->getAttribute('class'),'avatar')))
183 $ret['photo'] = $x->getAttribute('src');
184 if((attribute_contains($x->getAttribute('class'),'nickname'))
185 || (attribute_contains($x->getAttribute('class'),'uid')))
186 $ret['nick'] = $x->textContent;
195 if(! function_exists('scrape_feed')) {
196 function scrape_feed($url) {
201 $s = fetch_url($url);
206 $headers = $a->get_curl_headers();
207 logger('scrape_feed: headers=' . $headers, LOGGER_DEBUG);
209 $lines = explode("\n",$headers);
211 foreach($lines as $line) {
212 if(stristr($line,'content-type:')) {
213 if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) {
214 $ret['feed_atom'] = $url;
217 if(stristr($line,'application/rss+xml') || stristr($s,'<rss')) {
218 $ret['feed_rss'] = $url;
225 $dom = HTML5_Parser::parse($s);
231 $items = $dom->getElementsByTagName('img');
233 // get img elements (twitter)
236 foreach($items as $item) {
237 $x = $item->getAttribute('id');
238 if($x === 'profile-image') {
239 $ret['photo'] = $item->getAttribute('src');
244 $items = $dom->getElementsByTagName('link');
246 // get Atom/RSS link elements, take the first one of either.
249 foreach($items as $item) {
250 $x = $item->getAttribute('rel');
251 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml')) {
252 if(! x($ret,'feed_atom'))
253 $ret['feed_atom'] = $item->getAttribute('href');
255 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml')) {
256 if(! x($ret,'feed_rss'))
257 $ret['feed_rss'] = $item->getAttribute('href');