]> git.mxchange.org Git - friendica.git/blob - include/Scrape.php
some dspr fixes
[friendica.git] / include / Scrape.php
1 <?php
2
3 require_once('library/HTML5/Parser.php');
4 require_once('include/crypto.php');
5
6 if(! function_exists('scrape_dfrn')) {
7 function scrape_dfrn($url) {
8
9         $a = get_app();
10
11         $ret = array();
12
13         logger('scrape_dfrn: url=' . $url);
14
15         $s = fetch_url($url);
16
17         if(! $s) 
18                 return $ret;
19
20         $headers = $a->get_curl_headers();
21         logger('scrape_dfrn: headers=' . $headers, LOGGER_DEBUG);
22
23
24         $lines = explode("\n",$headers);
25         if(count($lines)) {
26                 foreach($lines as $line) {                              
27                         // don't try and run feeds through the html5 parser
28                         if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
29                                 return ret;
30                 }
31         }
32
33         try {
34                 $dom = HTML5_Parser::parse($s);
35         } catch (DOMException $e) {
36                 logger('scrape_dfrn: parse error: ' . $e);
37         }
38
39         if(! $dom)
40                 return $ret;
41
42         $items = $dom->getElementsByTagName('link');
43
44         // get DFRN link elements
45
46         foreach($items as $item) {
47                 $x = $item->getAttribute('rel');
48                 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
49                         $ret['feed_atom'] = $item->getAttribute('href');
50                 if(substr($x,0,5) == "dfrn-") {
51                         $ret[$x] = $item->getAttribute('href');
52                 }
53                 if($x === 'lrdd') {
54                         $decoded = urldecode($item->getAttribute('href'));
55                         if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
56                                 $ret['nick'] = $matches[1];
57                 }
58         }
59
60         // Pull out hCard profile elements
61
62         $largest_photo = 0;
63
64         $items = $dom->getElementsByTagName('*');
65         foreach($items as $item) {
66                 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
67                         $level2 = $item->getElementsByTagName('*');
68                         foreach($level2 as $x) {
69                                 if(attribute_contains($x->getAttribute('class'),'fn')) {
70                                         $ret['fn'] = $x->textContent;
71                                 }
72                                 if((attribute_contains($x->getAttribute('class'),'photo'))
73                                         || (attribute_contains($x->getAttribute('class'),'avatar'))) {
74                                         $size = intval($x->getAttribute('width'));
75                                         // dfrn prefers 175, so if we find this, we set largest_size so it can't be topped.
76                                         if(($size > $largest_photo) || ($size == 175) || (! $largest_photo)) {
77                                                 $ret['photo'] = $x->getAttribute('src');
78                                                 $largest_photo = (($size == 175) ? 9999 : $size);
79                                         }
80                                 }
81                                 if(attribute_contains($x->getAttribute('class'),'key')) {
82                                         $ret['key'] = $x->textContent;
83                                 }
84                         }
85                 }
86         }
87
88         return $ret;
89 }}
90
91
92
93
94
95
96 if(! function_exists('validate_dfrn')) {
97 function validate_dfrn($a) {
98         $errors = 0;
99         if(! x($a,'key'))
100                 $errors ++;
101         if(! x($a,'dfrn-request'))
102                 $errors ++;
103         if(! x($a,'dfrn-confirm'))
104                 $errors ++;
105         if(! x($a,'dfrn-notify'))
106                 $errors ++;
107         if(! x($a,'dfrn-poll'))
108                 $errors ++;
109         return $errors;
110 }}
111
112 if(! function_exists('scrape_meta')) {
113 function scrape_meta($url) {
114
115         $a = get_app();
116
117         $ret = array();
118
119         logger('scrape_meta: url=' . $url);
120
121         $s = fetch_url($url);
122
123         if(! $s) 
124                 return $ret;
125
126         $headers = $a->get_curl_headers();
127         logger('scrape_meta: headers=' . $headers, LOGGER_DEBUG);
128
129         $lines = explode("\n",$headers);
130         if(count($lines)) {
131                 foreach($lines as $line) {                              
132                         // don't try and run feeds through the html5 parser
133                         if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
134                                 return ret;
135                 }
136         }
137
138         try {
139                 $dom = HTML5_Parser::parse($s);
140         } catch (DOMException $e) {
141                 logger('scrape_meta: parse error: ' . $e);
142         }
143
144         if(! $dom)
145                 return $ret;
146
147         $items = $dom->getElementsByTagName('meta');
148
149         // get DFRN link elements
150
151         foreach($items as $item) {
152                 $x = $item->getAttribute('name');
153                 if(substr($x,0,5) == "dfrn-")
154                         $ret[$x] = $item->getAttribute('content');
155         }
156
157         return $ret;
158 }}
159
160
161 if(! function_exists('scrape_vcard')) {
162 function scrape_vcard($url) {
163
164         $a = get_app();
165
166         $ret = array();
167
168         logger('scrape_vcard: url=' . $url);
169
170         $s = fetch_url($url);
171
172         if(! $s) 
173                 return $ret;
174
175         $headers = $a->get_curl_headers();
176         $lines = explode("\n",$headers);
177         if(count($lines)) {
178                 foreach($lines as $line) {                              
179                         // don't try and run feeds through the html5 parser
180                         if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
181                                 return ret;
182                 }
183         }
184
185         try {
186                 $dom = HTML5_Parser::parse($s);
187         } catch (DOMException $e) {
188                 logger('scrape_vcard: parse error: ' . $e);
189         }
190
191         if(! $dom)
192                 return $ret;
193
194         // Pull out hCard profile elements
195
196         $largest_photo = 0;
197
198         $items = $dom->getElementsByTagName('*');
199         foreach($items as $item) {
200                 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
201                         $level2 = $item->getElementsByTagName('*');
202                         foreach($level2 as $x) {
203                                 if(attribute_contains($x->getAttribute('class'),'fn'))
204                                         $ret['fn'] = $x->textContent;
205                                 if((attribute_contains($x->getAttribute('class'),'photo'))
206                                         || (attribute_contains($x->getAttribute('class'),'avatar'))) {
207                                         $size = intval($x->getAttribute('width'));
208                                         if(($size > $largest_photo) || (! $largest_photo)) {
209                                                 $ret['photo'] = $x->getAttribute('src');
210                                                 $largest_photo = $size;
211                                         }
212                                 }
213                                 if((attribute_contains($x->getAttribute('class'),'nickname'))
214                                         || (attribute_contains($x->getAttribute('class'),'uid'))) {
215                                         $ret['nick'] = $x->textContent;
216                                 }
217                         }
218                 }
219         }
220
221         return $ret;
222 }}
223
224
225 if(! function_exists('scrape_feed')) {
226 function scrape_feed($url) {
227
228         $a = get_app();
229
230         $ret = array();
231         $s = fetch_url($url);
232
233         if(! $s) 
234                 return $ret;
235
236         $headers = $a->get_curl_headers();
237         logger('scrape_feed: headers=' . $headers, LOGGER_DEBUG);
238
239         $lines = explode("\n",$headers);
240         if(count($lines)) {
241                 foreach($lines as $line) {                              
242                         if(stristr($line,'content-type:')) {
243                                 if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) {
244                                         $ret['feed_atom'] = $url;
245                                         return $ret;
246                                 }
247                                 if(stristr($line,'application/rss+xml') || stristr($s,'<rss')) {
248                                         $ret['feed_rss'] = $url;
249                                         return $ret;
250                                 }
251                         }
252                 }
253         }
254
255         try {
256                 $dom = HTML5_Parser::parse($s);
257         } catch (DOMException $e) {
258                 logger('scrape_feed: parse error: ' . $e);
259         }
260
261         if(! $dom)
262                 return $ret;
263
264
265         $head = $dom->getElementsByTagName('base');
266         if($head) {
267                 foreach($head as $head0) {
268                         $basename = $head0->getAttribute('href');
269                         break;
270                 }
271         }
272         if(! $basename)
273                 $basename = substr($url,0,strrpos($url,'/')) . '/';
274
275         $items = $dom->getElementsByTagName('link');
276
277         // get Atom/RSS link elements, take the first one of either.
278
279         if($items) {
280                 foreach($items as $item) {
281                         $x = $item->getAttribute('rel');
282                         if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml')) {
283                                 if(! x($ret,'feed_atom'))
284                                         $ret['feed_atom'] = $item->getAttribute('href');
285                         }
286                         if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml')) {
287                                 if(! x($ret,'feed_rss'))
288                                         $ret['feed_rss'] = $item->getAttribute('href');
289                         }
290                 }       
291         }
292
293         // Drupal and perhaps others only provide relative URL's. Turn them into absolute.
294
295         if(x($ret,'feed_atom') && (! strstr($ret['feed_atom'],'://')))
296                 $ret['feed_atom'] = $basename . $ret['feed_atom'];
297         if(x($ret,'feed_rss') && (! strstr($ret['feed_rss'],'://')))
298                 $ret['feed_rss'] = $basename . $ret['feed_rss'];
299
300         return $ret;
301 }}
302
303
304 /**
305  *
306  * Probe a network address to discover what kind of protocols we need to communicate with it.
307  *
308  * Warning: this function is a bit touchy and there are some subtle dependencies within the logic flow.
309  * Edit with care.
310  *
311  */
312
313 /**
314  *
315  * PROBE_DIASPORA has a bias towards returning Diaspora information
316  * while PROBE_NORMAL has a bias towards dfrn/zot - in the case where
317  * an address (such as a Friendika address) supports more than one type
318  * of network. 
319  *
320  */
321
322
323 define ( 'PROBE_NORMAL',   0);
324 define ( 'PROBE_DIASPORA', 1);
325
326 function probe_url($url, $mode = PROBE_NORMAL) {
327         require_once('include/email.php');
328
329         $result = array();
330
331         if(! $url)
332                 return $result;
333
334         $network = null;
335         $diaspora = false;
336         $diaspora_base = '';
337         $diaspora_guid = '';    
338         $diaspora_key = '';
339         $has_lrdd = false;
340         $email_conversant = false;
341
342         $twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
343
344         $at_addr = ((strpos($url,'@') !== false) ? true : false);
345
346         if(! $twitter) {
347
348                 if(strpos($url,'mailto:') !== false && $at_addr) {
349                         $url = str_replace('mailto:','',$url);
350                         $links = array();
351                 }
352                 else
353                         $links = lrdd($url);
354
355                 if(count($links)) {
356                         $has_lrdd = true;
357
358                         logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA);
359                         foreach($links as $link) {
360                                 if($link['@attributes']['rel'] === NAMESPACE_ZOT)
361                                         $zot = unamp($link['@attributes']['href']);
362                                 if($link['@attributes']['rel'] === NAMESPACE_DFRN)
363                                         $dfrn = unamp($link['@attributes']['href']);
364                                 if($link['@attributes']['rel'] === 'salmon')
365                                         $notify = unamp($link['@attributes']['href']);
366                                 if($link['@attributes']['rel'] === NAMESPACE_FEED)
367                                         $poll = unamp($link['@attributes']['href']);
368                                 if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard')
369                                         $hcard = unamp($link['@attributes']['href']);
370                                 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
371                                         $profile = unamp($link['@attributes']['href']);
372                                 if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
373                                         $diaspora_base = unamp($link['@attributes']['href']);
374                                         $diaspora = true;
375                                 }
376                                 if($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') {
377                                         $diaspora_guid = unamp($link['@attributes']['href']);
378                                         $diaspora = true;
379                                 }
380                                 if($link['@attributes']['rel'] === 'diaspora-public-key') {
381                                         $diaspora_key = base64_decode(unamp($link['@attributes']['href']));
382                                         $pubkey = rsatopem($diaspora_key);
383                                         $diaspora = true;
384                                 }
385                         }
386
387                         // Status.Net can have more than one profile URL. We need to match the profile URL
388                         // to a contact on incoming messages to prevent spam, and we won't know which one
389                         // to match. So in case of two, one of them is stored as an alias. Only store URL's
390                         // and not webfinger user@host aliases. If they've got more than two non-email style
391                         // aliases, let's hope we're lucky and get one that matches the feed author-uri because 
392                         // otherwise we're screwed.
393
394                         foreach($links as $link) {
395                                 if($link['@attributes']['rel'] === 'alias') {
396                                         if(strpos($link['@attributes']['href'],'@') === false) {
397                                                 if(isset($profile)) {
398                                                         if($link['@attributes']['href'] !== $profile)
399                                                                 $alias = unamp($link['@attributes']['href']);
400                                                 }
401                                                 else
402                                                         $profile = unamp($link['@attributes']['href']);
403                                         }
404                                 }
405                         }
406                 }
407                 elseif($mode == PROBE_NORMAL) {
408
409                         // Check email
410
411                         $orig_url = $url;
412                         if((strpos($orig_url,'@')) && validate_email($orig_url)) {
413                                 $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
414                                         intval(local_user())
415                                 );
416                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
417                                         intval(local_user())
418                                 );
419                                 if(count($x) && count($r)) {
420                                     $mailbox = construct_mailbox_name($r[0]);
421                                         $password = '';
422                                         openssl_private_decrypt(hex2bin($r[0]['pass']),$password,$x[0]['prvkey']);
423                                         $mbox = email_connect($mailbox,$r[0]['user'],$password);
424                                         unset($password);
425                                 }
426                                 if($mbox) {
427                                         $msgs = email_poll($mbox,$orig_url);
428                                         if(count($msgs)) {
429                                                 $addr = $orig_url;
430                                                 $network = NETWORK_MAIL;
431                                                 $name = substr($url,0,strpos($url,'@'));
432                                                 $phost = substr($url,strpos($url,'@')+1);
433                                                 $profile = 'http://' . $phost;
434                                                 // fix nick character range
435                                                 $vcard = array('fn' => $name, 'nick' => $name, 'photo' => gravatar_img($url));
436                                                 $notify = 'smtp ' . random_string();
437                                                 $poll = 'email ' . random_string();
438                                                 $priority = 0;
439                                                 $x = email_msg_meta($mbox,$msgs[0]);
440                                                 if(stristr($x->from,$orig_url))
441                                                         $adr = imap_rfc822_parse_adrlist($x->from,'');
442                                                 elseif(stristr($x->to,$orig_url))
443                                                         $adr = imap_rfc822_parse_adrlist($x->to,'');
444                                                 if(isset($adr)) {
445                                                         foreach($adr as $feadr) {
446                                                                 if((strcasecmp($feadr->mailbox,$name) == 0) 
447                                                                         &&(strcasecmp($feadr->host,$phost) == 0) 
448                                                                         && (strlen($feadr->personal))) {
449                                                                         $vcard['fn'] = notags($feadr->personal);
450                                                                 }
451                                                         }
452                                                 }
453                                         }
454                                         imap_close($mbox);
455                                 }
456                         }
457                 }
458         }       
459
460         if($mode == PROBE_NORMAL) {
461                 if(strlen($zot)) {
462                         $s = fetch_url($zot);
463                         if($s) {
464                                 $j = json_decode($s);
465                                 if($j) {
466                                         $network = NETWORK_ZOT;
467                                         $vcard   = array(
468                                                 'fn'    => $j->fullname, 
469                                                 'nick'  => $j->nickname, 
470                                                 'photo' => $j->photo
471                                         );
472                                         $profile  = $j->url;
473                                         $notify   = $j->post;
474                                         $pubkey   = $j->pubkey;
475                                         $poll     = 'N/A';
476                                 }
477                         }
478                 }
479
480                 if(strlen($dfrn)) {
481                         $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn);
482                         if(is_array($ret) && x($ret,'dfrn-request')) {
483                                 $network = NETWORK_DFRN;
484                                 $request = $ret['dfrn-request'];
485                                 $confirm = $ret['dfrn-confirm'];
486                                 $notify  = $ret['dfrn-notify'];
487                                 $poll    = $ret['dfrn-poll'];
488
489                                 $vcard = array();
490                                 $vcard['fn'] = $ret['fn'];
491                                 $vcard['nick'] = $ret['nick'];
492                                 $vcard['photo'] = $ret['photo'];
493                         }
494                 }
495         }
496
497         if($diaspora && $diaspora_base && $diaspora_guid) {
498                 if($mode == PROBE_DIASPORA || ! $notify) {
499                         $notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
500                         $batch  = $diaspora_base . 'receive/public' ;
501                 }
502                 if(strpos($url,'@'))
503                         $addr = str_replace('acct:', '', $url);
504         }                       
505
506         if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
507                 if($diaspora)
508                         $network = NETWORK_DIASPORA;
509                 elseif($has_lrdd)
510                         $network  = NETWORK_OSTATUS;
511                 $priority = 0;
512
513                 if($hcard && ! $vcard) {
514                         $vcard = scrape_vcard($hcard);
515
516                         // Google doesn't use absolute url in profile photos
517         
518                         if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
519                                 $h = @parse_url($hcard);
520                                 if($h)
521                                         $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
522                         }
523                 
524                         logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
525                 }
526
527                 if($twitter) {          
528                         logger('twitter: setup');
529                         $tid = basename($url);
530                         $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
531                         if(intval($tid))
532                                 $poll = $tapi . '?user_id=' . $tid;
533                         else
534                                 $poll = $tapi . '?screen_name=' . $tid;
535                         $profile = 'http://twitter.com/#!/' . $tid;
536                         $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
537                         $vcard['nick'] = $tid;
538                         $vcard['fn'] = $tid . '@twitter';
539                 }
540
541                 if(! x($vcard,'fn'))
542                         if(x($vcard,'nick'))
543                                 $vcard['fn'] = $vcard['nick'];
544
545                 $check_feed = false;
546
547                 if($twitter || ! $poll)
548                         $check_feed = true;
549                 if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile))
550                         $check_feed = true;
551                 if(($at_addr) && (! count($links)))
552                         $check_feed = false;
553
554                 if($check_feed) {
555
556                         $feedret = scrape_feed(($poll) ? $poll : $url);
557                         logger('probe_url: scrape_feed returns: ' . print_r($feedret,true), LOGGER_DATA);
558                         if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
559                                 $poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']));
560                                 if(! x($vcard)) 
561                                         $vcard = array();
562                         }
563
564                         if(x($feedret,'photo') && (! x($vcard,'photo')))
565                                 $vcard['photo'] = $feedret['photo'];
566                         require_once('library/simplepie/simplepie.inc');
567                     $feed = new SimplePie();
568                         $xml = fetch_url($poll);
569
570                         logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
571                         $a = get_app();
572
573                         logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), $LOGGER_DATA);
574
575                         $feed->set_raw_data($xml);
576
577                     $feed->init();
578                         if($feed->error())
579                                 logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
580
581
582                         if(! x($vcard,'photo'))
583                                 $vcard['photo'] = $feed->get_image_url();
584                         $author = $feed->get_author();
585
586                         if($author) {                   
587                                 $vcard['fn'] = unxmlify(trim($author->get_name()));
588                                 if(! $vcard['fn'])
589                                         $vcard['fn'] = trim(unxmlify($author->get_email()));
590                                 if(strpos($vcard['fn'],'@') !== false)
591                                         $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
592                                 $email = unxmlify($author->get_email());
593                                 if(! $profile && $author->get_link())
594                                         $profile = trim(unxmlify($author->get_link()));
595                                 if(! $vcard['photo']) {
596                                         $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
597                                 if($rawtags) {
598                                                 $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
599                                                 if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
600                                                         $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
601                                 }
602                                 }
603                         }
604                         else {
605                                 $item = $feed->get_item(0);
606                                 if($item) {
607                                         $author = $item->get_author();
608                                         if($author) {                   
609                                                 $vcard['fn'] = trim(unxmlify($author->get_name()));
610                                                 if(! $vcard['fn'])
611                                                         $vcard['fn'] = trim(unxmlify($author->get_email()));
612                                                 if(strpos($vcard['fn'],'@') !== false)
613                                                         $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
614                                                 $email = unxmlify($author->get_email());
615                                                 if(! $profile && $author->get_link())
616                                                         $profile = trim(unxmlify($author->get_link()));
617                                         }
618                                         if(! $vcard['photo']) {
619                                                 $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
620                                                 if($rawmedia && $rawmedia[0]['attribs']['']['url'])
621                                                         $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
622                                         }
623                                         if(! $vcard['photo']) {
624                                                 $rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
625                                         if($rawtags) {
626                                                         $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
627                                                         if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
628                                                                 $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
629                                         }
630                                         }
631                                 }
632                         }
633
634                         if((! $vcard['photo']) && strlen($email))
635                                 $vcard['photo'] = gravatar_img($email);
636                         if($poll === $profile)
637                                 $lnk = $feed->get_permalink();
638                         if(isset($lnk) && strlen($lnk))
639                                 $profile = $lnk;        
640
641                         if(! (x($vcard,'fn')))
642                                 $vcard['fn'] = notags($feed->get_title());
643                         if(! (x($vcard,'fn')))
644                                 $vcard['fn'] = notags($feed->get_description());
645
646                         if(strpos($vcard['fn'],'Twitter / ') !== false) {
647                                 $vcard['fn'] = substr($vcard['fn'],strpos($vcard['fn'],'/')+1);
648                                 $vcard['fn'] = trim($vcard['fn']);
649                         }
650                         if(! x($vcard,'nick')) {
651                                 $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
652                                 if(strpos($vcard['nick'],' '))
653                                         $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
654                         }
655                         if(! $network)
656                                 $network = NETWORK_FEED;
657                         if(! $priority)
658                                 $priority = 2;
659                 }
660         }
661
662         if(! x($vcard,'photo')) {
663                 $a = get_app();
664                 $vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ; 
665         }
666
667         if(! $profile)
668                 $profile = $url;
669
670         // No human could be associated with this link, use the URL as the contact name
671
672         if(($network === NETWORK_FEED) && ($poll) && (! x($vcard,'fn')))
673                 $vcard['fn'] = $url;
674
675         $vcard['fn'] = notags($vcard['fn']);
676         $vcard['nick'] = str_replace(' ','',notags($vcard['nick']));
677                 
678         $result['name'] = $vcard['fn'];
679         $result['nick'] = $vcard['nick'];
680         $result['url'] = $profile;
681         $result['addr'] = $addr;
682         $result['batch'] = $batch;
683         $result['notify'] = $notify;
684         $result['poll'] = $poll;
685         $result['request'] = $request;
686         $result['confirm'] = $confirm;
687         $result['photo'] = $vcard['photo'];
688         $result['priority'] = $priority;
689         $result['network'] = $network;
690         $result['alias'] = $alias;
691         $result['pubkey'] = $pubkey;
692
693         logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG);
694
695         return $result;
696 }