]> git.mxchange.org Git - friendica.git/blob - include/Scrape.php
string update
[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://portablecontacts.net/spec/1.0')
373                                         $poco = unamp($link['@attributes']['href']);
374                                 if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
375                                         $diaspora_base = unamp($link['@attributes']['href']);
376                                         $diaspora = true;
377                                 }
378                                 if($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') {
379                                         $diaspora_guid = unamp($link['@attributes']['href']);
380                                         $diaspora = true;
381                                 }
382                                 if($link['@attributes']['rel'] === 'diaspora-public-key') {
383                                         $diaspora_key = base64_decode(unamp($link['@attributes']['href']));
384                                         $pubkey = rsatopem($diaspora_key);
385                                         $diaspora = true;
386                                 }
387                         }
388
389                         // Status.Net can have more than one profile URL. We need to match the profile URL
390                         // to a contact on incoming messages to prevent spam, and we won't know which one
391                         // to match. So in case of two, one of them is stored as an alias. Only store URL's
392                         // and not webfinger user@host aliases. If they've got more than two non-email style
393                         // aliases, let's hope we're lucky and get one that matches the feed author-uri because 
394                         // otherwise we're screwed.
395
396                         foreach($links as $link) {
397                                 if($link['@attributes']['rel'] === 'alias') {
398                                         if(strpos($link['@attributes']['href'],'@') === false) {
399                                                 if(isset($profile)) {
400                                                         if($link['@attributes']['href'] !== $profile)
401                                                                 $alias = unamp($link['@attributes']['href']);
402                                                 }
403                                                 else
404                                                         $profile = unamp($link['@attributes']['href']);
405                                         }
406                                 }
407                         }
408                 }
409                 elseif($mode == PROBE_NORMAL) {
410
411                         // Check email
412
413                         $orig_url = $url;
414                         if((strpos($orig_url,'@')) && validate_email($orig_url)) {
415                                 $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
416                                         intval(local_user())
417                                 );
418                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
419                                         intval(local_user())
420                                 );
421                                 if(count($x) && count($r)) {
422                                     $mailbox = construct_mailbox_name($r[0]);
423                                         $password = '';
424                                         openssl_private_decrypt(hex2bin($r[0]['pass']),$password,$x[0]['prvkey']);
425                                         $mbox = email_connect($mailbox,$r[0]['user'],$password);
426                                         unset($password);
427                                 }
428                                 if($mbox) {
429                                         $msgs = email_poll($mbox,$orig_url);
430                                         if(count($msgs)) {
431                                                 $addr = $orig_url;
432                                                 $network = NETWORK_MAIL;
433                                                 $name = substr($url,0,strpos($url,'@'));
434                                                 $phost = substr($url,strpos($url,'@')+1);
435                                                 $profile = 'http://' . $phost;
436                                                 // fix nick character range
437                                                 $vcard = array('fn' => $name, 'nick' => $name, 'photo' => gravatar_img($url));
438                                                 $notify = 'smtp ' . random_string();
439                                                 $poll = 'email ' . random_string();
440                                                 $priority = 0;
441                                                 $x = email_msg_meta($mbox,$msgs[0]);
442                                                 if(stristr($x->from,$orig_url))
443                                                         $adr = imap_rfc822_parse_adrlist($x->from,'');
444                                                 elseif(stristr($x->to,$orig_url))
445                                                         $adr = imap_rfc822_parse_adrlist($x->to,'');
446                                                 if(isset($adr)) {
447                                                         foreach($adr as $feadr) {
448                                                                 if((strcasecmp($feadr->mailbox,$name) == 0) 
449                                                                         &&(strcasecmp($feadr->host,$phost) == 0) 
450                                                                         && (strlen($feadr->personal))) {
451                                                                         $vcard['fn'] = notags($feadr->personal);
452                                                                 }
453                                                         }
454                                                 }
455                                         }
456                                         imap_close($mbox);
457                                 }
458                         }
459                 }
460         }       
461
462         if($mode == PROBE_NORMAL) {
463                 if(strlen($zot)) {
464                         $s = fetch_url($zot);
465                         if($s) {
466                                 $j = json_decode($s);
467                                 if($j) {
468                                         $network = NETWORK_ZOT;
469                                         $vcard   = array(
470                                                 'fn'    => $j->fullname, 
471                                                 'nick'  => $j->nickname, 
472                                                 'photo' => $j->photo
473                                         );
474                                         $profile  = $j->url;
475                                         $notify   = $j->post;
476                                         $pubkey   = $j->pubkey;
477                                         $poll     = 'N/A';
478                                 }
479                         }
480                 }
481
482                 if(strlen($dfrn)) {
483                         $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn);
484                         if(is_array($ret) && x($ret,'dfrn-request')) {
485                                 $network = NETWORK_DFRN;
486                                 $request = $ret['dfrn-request'];
487                                 $confirm = $ret['dfrn-confirm'];
488                                 $notify  = $ret['dfrn-notify'];
489                                 $poll    = $ret['dfrn-poll'];
490
491                                 $vcard = array();
492                                 $vcard['fn'] = $ret['fn'];
493                                 $vcard['nick'] = $ret['nick'];
494                                 $vcard['photo'] = $ret['photo'];
495                         }
496                 }
497         }
498
499         if($diaspora && $diaspora_base && $diaspora_guid) {
500                 if($mode == PROBE_DIASPORA || ! $notify) {
501                         $notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
502                         $batch  = $diaspora_base . 'receive/public' ;
503                 }
504                 if(strpos($url,'@'))
505                         $addr = str_replace('acct:', '', $url);
506         }                       
507
508         if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
509                 if($diaspora)
510                         $network = NETWORK_DIASPORA;
511                 elseif($has_lrdd)
512                         $network  = NETWORK_OSTATUS;
513                 $priority = 0;
514
515                 if($hcard && ! $vcard) {
516                         $vcard = scrape_vcard($hcard);
517
518                         // Google doesn't use absolute url in profile photos
519         
520                         if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
521                                 $h = @parse_url($hcard);
522                                 if($h)
523                                         $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
524                         }
525                 
526                         logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
527                 }
528
529                 if($twitter) {          
530                         logger('twitter: setup');
531                         $tid = basename($url);
532                         $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
533                         if(intval($tid))
534                                 $poll = $tapi . '?user_id=' . $tid;
535                         else
536                                 $poll = $tapi . '?screen_name=' . $tid;
537                         $profile = 'http://twitter.com/#!/' . $tid;
538                         $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
539                         $vcard['nick'] = $tid;
540                         $vcard['fn'] = $tid . '@twitter';
541                 }
542
543                 if(! x($vcard,'fn'))
544                         if(x($vcard,'nick'))
545                                 $vcard['fn'] = $vcard['nick'];
546
547                 $check_feed = false;
548
549                 if($twitter || ! $poll)
550                         $check_feed = true;
551                 if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile))
552                         $check_feed = true;
553                 if(($at_addr) && (! count($links)))
554                         $check_feed = false;
555
556                 if($check_feed) {
557
558                         $feedret = scrape_feed(($poll) ? $poll : $url);
559                         logger('probe_url: scrape_feed returns: ' . print_r($feedret,true), LOGGER_DATA);
560                         if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
561                                 $poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']));
562                                 if(! x($vcard)) 
563                                         $vcard = array();
564                         }
565
566                         if(x($feedret,'photo') && (! x($vcard,'photo')))
567                                 $vcard['photo'] = $feedret['photo'];
568                         require_once('library/simplepie/simplepie.inc');
569                     $feed = new SimplePie();
570                         $xml = fetch_url($poll);
571
572                         logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
573                         $a = get_app();
574
575                         logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), $LOGGER_DATA);
576
577                         $feed->set_raw_data($xml);
578
579                     $feed->init();
580                         if($feed->error())
581                                 logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
582
583
584                         if(! x($vcard,'photo'))
585                                 $vcard['photo'] = $feed->get_image_url();
586                         $author = $feed->get_author();
587
588                         if($author) {                   
589                                 $vcard['fn'] = unxmlify(trim($author->get_name()));
590                                 if(! $vcard['fn'])
591                                         $vcard['fn'] = trim(unxmlify($author->get_email()));
592                                 if(strpos($vcard['fn'],'@') !== false)
593                                         $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
594                                 $email = unxmlify($author->get_email());
595                                 if(! $profile && $author->get_link())
596                                         $profile = trim(unxmlify($author->get_link()));
597                                 if(! $vcard['photo']) {
598                                         $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
599                                 if($rawtags) {
600                                                 $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
601                                                 if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
602                                                         $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
603                                 }
604                                 }
605                         }
606                         else {
607                                 $item = $feed->get_item(0);
608                                 if($item) {
609                                         $author = $item->get_author();
610                                         if($author) {                   
611                                                 $vcard['fn'] = trim(unxmlify($author->get_name()));
612                                                 if(! $vcard['fn'])
613                                                         $vcard['fn'] = trim(unxmlify($author->get_email()));
614                                                 if(strpos($vcard['fn'],'@') !== false)
615                                                         $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
616                                                 $email = unxmlify($author->get_email());
617                                                 if(! $profile && $author->get_link())
618                                                         $profile = trim(unxmlify($author->get_link()));
619                                         }
620                                         if(! $vcard['photo']) {
621                                                 $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
622                                                 if($rawmedia && $rawmedia[0]['attribs']['']['url'])
623                                                         $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
624                                         }
625                                         if(! $vcard['photo']) {
626                                                 $rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
627                                         if($rawtags) {
628                                                         $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
629                                                         if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
630                                                                 $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
631                                         }
632                                         }
633                                 }
634                         }
635
636                         if((! $vcard['photo']) && strlen($email))
637                                 $vcard['photo'] = gravatar_img($email);
638                         if($poll === $profile)
639                                 $lnk = $feed->get_permalink();
640                         if(isset($lnk) && strlen($lnk))
641                                 $profile = $lnk;        
642
643                         if(! (x($vcard,'fn')))
644                                 $vcard['fn'] = notags($feed->get_title());
645                         if(! (x($vcard,'fn')))
646                                 $vcard['fn'] = notags($feed->get_description());
647
648                         if(strpos($vcard['fn'],'Twitter / ') !== false) {
649                                 $vcard['fn'] = substr($vcard['fn'],strpos($vcard['fn'],'/')+1);
650                                 $vcard['fn'] = trim($vcard['fn']);
651                         }
652                         if(! x($vcard,'nick')) {
653                                 $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
654                                 if(strpos($vcard['nick'],' '))
655                                         $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
656                         }
657                         if(! $network)
658                                 $network = NETWORK_FEED;
659                         if(! $priority)
660                                 $priority = 2;
661                 }
662         }
663
664         if(! x($vcard,'photo')) {
665                 $a = get_app();
666                 $vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ; 
667         }
668
669         if(! $profile)
670                 $profile = $url;
671
672         // No human could be associated with this link, use the URL as the contact name
673
674         if(($network === NETWORK_FEED) && ($poll) && (! x($vcard,'fn')))
675                 $vcard['fn'] = $url;
676
677         $vcard['fn'] = notags($vcard['fn']);
678         $vcard['nick'] = str_replace(' ','',notags($vcard['nick']));
679                 
680         $result['name'] = $vcard['fn'];
681         $result['nick'] = $vcard['nick'];
682         $result['url'] = $profile;
683         $result['addr'] = $addr;
684         $result['batch'] = $batch;
685         $result['notify'] = $notify;
686         $result['poll'] = $poll;
687         $result['request'] = $request;
688         $result['confirm'] = $confirm;
689         $result['poco'] = $poco;
690         $result['photo'] = $vcard['photo'];
691         $result['priority'] = $priority;
692         $result['network'] = $network;
693         $result['alias'] = $alias;
694         $result['pubkey'] = $pubkey;
695
696         logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG);
697
698         return $result;
699 }