]> git.mxchange.org Git - friendica.git/blob - include/Scrape.php
Mail: New options for actions after importing mails.
[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 Friendica 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
452                                                                         $personal = imap_mime_header_decode($feadr->personal);
453                                                                         $vcard['fn'] = "";
454                                                                         foreach($personal as $perspart)
455                                                                                 if ($perspart->charset != "default")
456                                                                                         $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
457                                                                                 else
458                                                                                         $vcard['fn'] .= $perspart->text;
459
460                                                                         $vcard['fn'] = notags($vcard['fn']);
461                                                                 }
462                                                         }
463                                                 }
464                                         }
465                                         imap_close($mbox);
466                                 }
467                         }
468                 }
469         }       
470
471         if($mode == PROBE_NORMAL) {
472                 if(strlen($zot)) {
473                         $s = fetch_url($zot);
474                         if($s) {
475                                 $j = json_decode($s);
476                                 if($j) {
477                                         $network = NETWORK_ZOT;
478                                         $vcard   = array(
479                                                 'fn'    => $j->fullname, 
480                                                 'nick'  => $j->nickname, 
481                                                 'photo' => $j->photo
482                                         );
483                                         $profile  = $j->url;
484                                         $notify   = $j->post;
485                                         $pubkey   = $j->pubkey;
486                                         $poll     = 'N/A';
487                                 }
488                         }
489                 }
490
491                 if(strlen($dfrn)) {
492                         $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn);
493                         if(is_array($ret) && x($ret,'dfrn-request')) {
494                                 $network = NETWORK_DFRN;
495                                 $request = $ret['dfrn-request'];
496                                 $confirm = $ret['dfrn-confirm'];
497                                 $notify  = $ret['dfrn-notify'];
498                                 $poll    = $ret['dfrn-poll'];
499
500                                 $vcard = array();
501                                 $vcard['fn'] = $ret['fn'];
502                                 $vcard['nick'] = $ret['nick'];
503                                 $vcard['photo'] = $ret['photo'];
504                         }
505                 }
506         }
507
508         if($diaspora && $diaspora_base && $diaspora_guid) {
509                 if($mode == PROBE_DIASPORA || ! $notify) {
510                         $notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
511                         $batch  = $diaspora_base . 'receive/public' ;
512                 }
513                 if(strpos($url,'@'))
514                         $addr = str_replace('acct:', '', $url);
515         }                       
516
517         if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
518                 if($diaspora)
519                         $network = NETWORK_DIASPORA;
520                 elseif($has_lrdd)
521                         $network  = NETWORK_OSTATUS;
522                 $priority = 0;
523
524                 if($hcard && ! $vcard) {
525                         $vcard = scrape_vcard($hcard);
526
527                         // Google doesn't use absolute url in profile photos
528         
529                         if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
530                                 $h = @parse_url($hcard);
531                                 if($h)
532                                         $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
533                         }
534                 
535                         logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
536                 }
537
538                 if($twitter) {          
539                         logger('twitter: setup');
540                         $tid = basename($url);
541                         $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
542                         if(intval($tid))
543                                 $poll = $tapi . '?user_id=' . $tid;
544                         else
545                                 $poll = $tapi . '?screen_name=' . $tid;
546                         $profile = 'http://twitter.com/#!/' . $tid;
547                         $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
548                         $vcard['nick'] = $tid;
549                         $vcard['fn'] = $tid . '@twitter';
550                 }
551
552                 if(! x($vcard,'fn'))
553                         if(x($vcard,'nick'))
554                                 $vcard['fn'] = $vcard['nick'];
555
556                 $check_feed = false;
557
558                 if($twitter || ! $poll)
559                         $check_feed = true;
560                 if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile))
561                         $check_feed = true;
562                 if(($at_addr) && (! count($links)))
563                         $check_feed = false;
564
565                 if($check_feed) {
566
567                         $feedret = scrape_feed(($poll) ? $poll : $url);
568                         logger('probe_url: scrape_feed returns: ' . print_r($feedret,true), LOGGER_DATA);
569                         if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
570                                 $poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']));
571                                 if(! x($vcard)) 
572                                         $vcard = array();
573                         }
574
575                         if(x($feedret,'photo') && (! x($vcard,'photo')))
576                                 $vcard['photo'] = $feedret['photo'];
577                         require_once('library/simplepie/simplepie.inc');
578                     $feed = new SimplePie();
579                         $xml = fetch_url($poll);
580
581                         logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
582                         $a = get_app();
583
584                         logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), $LOGGER_DATA);
585
586                         $feed->set_raw_data($xml);
587
588                     $feed->init();
589                         if($feed->error())
590                                 logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
591
592
593                         if(! x($vcard,'photo'))
594                                 $vcard['photo'] = $feed->get_image_url();
595                         $author = $feed->get_author();
596
597                         if($author) {                   
598                                 $vcard['fn'] = unxmlify(trim($author->get_name()));
599                                 if(! $vcard['fn'])
600                                         $vcard['fn'] = trim(unxmlify($author->get_email()));
601                                 if(strpos($vcard['fn'],'@') !== false)
602                                         $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
603                                 $email = unxmlify($author->get_email());
604                                 if(! $profile && $author->get_link())
605                                         $profile = trim(unxmlify($author->get_link()));
606                                 if(! $vcard['photo']) {
607                                         $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
608                                 if($rawtags) {
609                                                 $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
610                                                 if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
611                                                         $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
612                                 }
613                                 }
614                         }
615                         else {
616                                 $item = $feed->get_item(0);
617                                 if($item) {
618                                         $author = $item->get_author();
619                                         if($author) {                   
620                                                 $vcard['fn'] = trim(unxmlify($author->get_name()));
621                                                 if(! $vcard['fn'])
622                                                         $vcard['fn'] = trim(unxmlify($author->get_email()));
623                                                 if(strpos($vcard['fn'],'@') !== false)
624                                                         $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
625                                                 $email = unxmlify($author->get_email());
626                                                 if(! $profile && $author->get_link())
627                                                         $profile = trim(unxmlify($author->get_link()));
628                                         }
629                                         if(! $vcard['photo']) {
630                                                 $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
631                                                 if($rawmedia && $rawmedia[0]['attribs']['']['url'])
632                                                         $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
633                                         }
634                                         if(! $vcard['photo']) {
635                                                 $rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
636                                         if($rawtags) {
637                                                         $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
638                                                         if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
639                                                                 $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
640                                         }
641                                         }
642                                 }
643                         }
644
645                         if((! $vcard['photo']) && strlen($email))
646                                 $vcard['photo'] = gravatar_img($email);
647                         if($poll === $profile)
648                                 $lnk = $feed->get_permalink();
649                         if(isset($lnk) && strlen($lnk))
650                                 $profile = $lnk;        
651
652                         if(! (x($vcard,'fn')))
653                                 $vcard['fn'] = notags($feed->get_title());
654                         if(! (x($vcard,'fn')))
655                                 $vcard['fn'] = notags($feed->get_description());
656
657                         if(strpos($vcard['fn'],'Twitter / ') !== false) {
658                                 $vcard['fn'] = substr($vcard['fn'],strpos($vcard['fn'],'/')+1);
659                                 $vcard['fn'] = trim($vcard['fn']);
660                         }
661                         if(! x($vcard,'nick')) {
662                                 $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
663                                 if(strpos($vcard['nick'],' '))
664                                         $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
665                         }
666                         if(! $network)
667                                 $network = NETWORK_FEED;
668                         if(! $priority)
669                                 $priority = 2;
670                 }
671         }
672
673         if(! x($vcard,'photo')) {
674                 $a = get_app();
675                 $vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ; 
676         }
677
678         if(! $profile)
679                 $profile = $url;
680
681         // No human could be associated with this link, use the URL as the contact name
682
683         if(($network === NETWORK_FEED) && ($poll) && (! x($vcard,'fn')))
684                 $vcard['fn'] = $url;
685
686         $vcard['fn'] = notags($vcard['fn']);
687         $vcard['nick'] = str_replace(' ','',notags($vcard['nick']));
688                 
689         $result['name'] = $vcard['fn'];
690         $result['nick'] = $vcard['nick'];
691         $result['url'] = $profile;
692         $result['addr'] = $addr;
693         $result['batch'] = $batch;
694         $result['notify'] = $notify;
695         $result['poll'] = $poll;
696         $result['request'] = $request;
697         $result['confirm'] = $confirm;
698         $result['poco'] = $poco;
699         $result['photo'] = $vcard['photo'];
700         $result['priority'] = $priority;
701         $result['network'] = $network;
702         $result['alias'] = $alias;
703         $result['pubkey'] = $pubkey;
704
705         logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG);
706
707         return $result;
708 }