3 require_once('library/HTML5/Parser.php');
4 require_once('include/crypto.php');
5 require_once('include/feed.php');
7 if(! function_exists('scrape_dfrn')) {
8 function scrape_dfrn($url, $dont_probe = false) {
14 logger('scrape_dfrn: url=' . $url);
16 // Try to fetch the data from noscrape. This is faster than parsing the HTML
17 $noscrape = str_replace("/hcard/", "/noscrape/", $url);
18 $noscrapejson = fetch_url($noscrape);
19 $noscrapedata = array();
21 $noscrapedata = json_decode($noscrapejson, true);
23 if (is_array($noscrapedata)) {
24 if ($noscrapedata["nick"] != "")
25 return($noscrapedata);
27 unset($noscrapedata["nick"]);
29 $noscrapedata = array();
38 $probe = probe_url($url);
40 if (isset($probe["addr"]))
41 $ret["addr"] = $probe["addr"];
44 $headers = $a->get_curl_headers();
45 logger('scrape_dfrn: headers=' . $headers, LOGGER_DEBUG);
48 $lines = explode("\n",$headers);
50 foreach($lines as $line) {
51 // don't try and run feeds through the html5 parser
52 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
58 $dom = HTML5_Parser::parse($s);
59 } catch (DOMException $e) {
60 logger('scrape_dfrn: parse error: ' . $e);
66 $items = $dom->getElementsByTagName('link');
68 // get DFRN link elements
70 foreach($items as $item) {
71 $x = $item->getAttribute('rel');
72 if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
73 $ret['feed_atom'] = $item->getAttribute('href');
74 if(substr($x,0,5) == "dfrn-") {
75 $ret[$x] = $item->getAttribute('href');
78 $decoded = urldecode($item->getAttribute('href'));
79 if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
80 $ret['nick'] = $matches[1];
84 // Pull out hCard profile elements
88 $items = $dom->getElementsByTagName('*');
89 foreach($items as $item) {
90 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
91 $level2 = $item->getElementsByTagName('*');
92 foreach($level2 as $x) {
93 if(attribute_contains($x->getAttribute('class'),'fn')) {
94 $ret['fn'] = $x->textContent;
96 if((attribute_contains($x->getAttribute('class'),'photo'))
97 || (attribute_contains($x->getAttribute('class'),'avatar'))) {
98 $size = intval($x->getAttribute('width'));
99 // dfrn prefers 175, so if we find this, we set largest_size so it can't be topped.
100 if(($size > $largest_photo) || ($size == 175) || (! $largest_photo)) {
101 $ret['photo'] = $x->getAttribute('src');
102 $largest_photo = (($size == 175) ? 9999 : $size);
105 if(attribute_contains($x->getAttribute('class'),'key')) {
106 $ret['key'] = $x->textContent;
111 return array_merge($ret, $noscrapedata);
119 if(! function_exists('validate_dfrn')) {
120 function validate_dfrn($a) {
124 if(! x($a,'dfrn-request'))
126 if(! x($a,'dfrn-confirm'))
128 if(! x($a,'dfrn-notify'))
130 if(! x($a,'dfrn-poll'))
135 if(! function_exists('scrape_meta')) {
136 function scrape_meta($url) {
142 logger('scrape_meta: url=' . $url);
144 $s = fetch_url($url);
149 $headers = $a->get_curl_headers();
150 logger('scrape_meta: headers=' . $headers, LOGGER_DEBUG);
152 $lines = explode("\n",$headers);
154 foreach($lines as $line) {
155 // don't try and run feeds through the html5 parser
156 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
162 $dom = HTML5_Parser::parse($s);
163 } catch (DOMException $e) {
164 logger('scrape_meta: parse error: ' . $e);
170 $items = $dom->getElementsByTagName('meta');
172 // get DFRN link elements
174 foreach($items as $item) {
175 $x = $item->getAttribute('name');
176 if(substr($x,0,5) == "dfrn-")
177 $ret[$x] = $item->getAttribute('content');
184 if(! function_exists('scrape_vcard')) {
185 function scrape_vcard($url) {
191 logger('scrape_vcard: url=' . $url);
193 $s = fetch_url($url);
198 $headers = $a->get_curl_headers();
199 $lines = explode("\n",$headers);
201 foreach($lines as $line) {
202 // don't try and run feeds through the html5 parser
203 if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
209 $dom = HTML5_Parser::parse($s);
210 } catch (DOMException $e) {
211 logger('scrape_vcard: parse error: ' . $e);
217 // Pull out hCard profile elements
221 $items = $dom->getElementsByTagName('*');
222 foreach($items as $item) {
223 if(attribute_contains($item->getAttribute('class'), 'vcard')) {
224 $level2 = $item->getElementsByTagName('*');
225 foreach($level2 as $x) {
226 if(attribute_contains($x->getAttribute('class'),'fn'))
227 $ret['fn'] = $x->textContent;
228 if((attribute_contains($x->getAttribute('class'),'photo'))
229 || (attribute_contains($x->getAttribute('class'),'avatar'))) {
230 $size = intval($x->getAttribute('width'));
231 if(($size > $largest_photo) || (! $largest_photo)) {
232 $ret['photo'] = $x->getAttribute('src');
233 $largest_photo = $size;
236 if((attribute_contains($x->getAttribute('class'),'nickname'))
237 || (attribute_contains($x->getAttribute('class'),'uid'))) {
238 $ret['nick'] = $x->textContent;
248 if(! function_exists('scrape_feed')) {
249 function scrape_feed($url) {
254 $cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
255 $s = fetch_url($url, false, $redirects, 0, Null, $cookiejar);
258 $headers = $a->get_curl_headers();
259 $code = $a->get_curl_code();
261 logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG);
264 logger('scrape_feed: no data returned for ' . $url);
269 $lines = explode("\n",$headers);
271 foreach($lines as $line) {
272 if(stristr($line,'content-type:')) {
273 if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) {
274 $ret['feed_atom'] = $url;
277 if(stristr($line,'application/rss+xml') || stristr($s,'<rss')) {
278 $ret['feed_rss'] = $url;
283 // perhaps an RSS version 1 feed with a generic or incorrect content-type?
284 if(stristr($s,'</item>')) {
285 $ret['feed_rss'] = $url;
290 $basename = implode('/', array_slice(explode('/',$url),0,3)) . '/';
292 $doc = new DOMDocument();
294 $xpath = new DomXPath($doc);
296 $base = $xpath->query("//base");
297 foreach ($base as $node) {
300 if ($node->attributes->length)
301 foreach ($node->attributes as $attribute)
302 $attr[$attribute->name] = $attribute->value;
304 if ($attr["href"] != "")
305 $basename = $attr["href"] ;
308 $list = $xpath->query("//link");
309 foreach ($list as $node) {
312 if ($node->attributes->length)
313 foreach ($node->attributes as $attribute)
314 $attr[$attribute->name] = $attribute->value;
316 if (($attr["rel"] == "alternate") AND ($attr["type"] == "application/atom+xml"))
317 $ret["feed_atom"] = $attr["href"];
319 if (($attr["rel"] == "alternate") AND ($attr["type"] == "application/rss+xml"))
320 $ret["feed_rss"] = $attr["href"];
323 // Drupal and perhaps others only provide relative URLs. Turn them into absolute.
325 if(x($ret,'feed_atom') && (! strstr($ret['feed_atom'],'://')))
326 $ret['feed_atom'] = $basename . $ret['feed_atom'];
327 if(x($ret,'feed_rss') && (! strstr($ret['feed_rss'],'://')))
328 $ret['feed_rss'] = $basename . $ret['feed_rss'];
336 * Probe a network address to discover what kind of protocols we need to communicate with it.
338 * Warning: this function is a bit touchy and there are some subtle dependencies within the logic flow.
345 * PROBE_DIASPORA has a bias towards returning Diaspora information
346 * while PROBE_NORMAL has a bias towards dfrn/zot - in the case where
347 * an address (such as a Friendica address) supports more than one type
353 define ( 'PROBE_NORMAL', 0);
354 define ( 'PROBE_DIASPORA', 1);
356 function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
357 require_once('include/email.php');
364 $result = Cache::get("probe_url:".$mode.":".$url);
365 if (!is_null($result)) {
366 $result = unserialize($result);
370 $original_url = $url;
377 $email_conversant = false;
378 $connectornetworks = false;
381 if (strpos($url,'twitter.com')) {
382 $connectornetworks = true;
383 $network = NETWORK_TWITTER;
386 $lastfm = ((strpos($url,'last.fm/user') !== false) ? true : false);
388 $at_addr = ((strpos($url,'@') !== false) ? true : false);
390 if((!$appnet) && (!$lastfm) && !$connectornetworks) {
392 if(strpos($url,'mailto:') !== false && $at_addr) {
393 $url = str_replace('mailto:','',$url);
399 if ((count($links) == 0) AND strstr($url, "/index.php")) {
400 $url = str_replace("/index.php", "", $url);
407 logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA);
408 foreach($links as $link) {
409 if($link['@attributes']['rel'] === NAMESPACE_ZOT)
410 $zot = unamp($link['@attributes']['href']);
411 if($link['@attributes']['rel'] === NAMESPACE_DFRN)
412 $dfrn = unamp($link['@attributes']['href']);
413 if($link['@attributes']['rel'] === 'salmon')
414 $notify = unamp($link['@attributes']['href']);
415 if($link['@attributes']['rel'] === NAMESPACE_FEED)
416 $poll = unamp($link['@attributes']['href']);
417 if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard')
418 $hcard = unamp($link['@attributes']['href']);
419 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
420 $profile = unamp($link['@attributes']['href']);
421 if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0')
422 $poco = unamp($link['@attributes']['href']);
423 if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
424 $diaspora_base = unamp($link['@attributes']['href']);
427 if($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') {
428 $diaspora_guid = unamp($link['@attributes']['href']);
431 if($link['@attributes']['rel'] === 'diaspora-public-key') {
432 $diaspora_key = base64_decode(unamp($link['@attributes']['href']));
433 if(strstr($diaspora_key,'RSA '))
434 $pubkey = rsatopem($diaspora_key);
436 $pubkey = $diaspora_key;
439 if(($link['@attributes']['rel'] === 'http://ostatus.org/schema/1.0/subscribe') AND ($mode == PROBE_NORMAL)) {
444 // Status.Net can have more than one profile URL. We need to match the profile URL
445 // to a contact on incoming messages to prevent spam, and we won't know which one
446 // to match. So in case of two, one of them is stored as an alias. Only store URL's
447 // and not webfinger user@host aliases. If they've got more than two non-email style
448 // aliases, let's hope we're lucky and get one that matches the feed author-uri because
449 // otherwise we're screwed.
453 foreach($links as $link) {
454 if($link['@attributes']['rel'] === 'alias') {
455 if(strpos($link['@attributes']['href'],'@') === false) {
456 if(isset($profile)) {
457 $alias_url = $link['@attributes']['href'];
459 if(($alias_url !== $profile) AND ($backup_alias == "") AND
460 ($alias_url !== str_replace("/index.php", "", $profile)))
461 $backup_alias = $alias_url;
463 if(($alias_url !== $profile) AND !strstr($alias_url, "index.php") AND
464 ($alias_url !== str_replace("/index.php", "", $profile)))
468 $profile = unamp($link['@attributes']['href']);
474 $alias = $backup_alias;
476 // If the profile is different from the url then the url is abviously an alias
477 if (($alias == "") AND ($profile != "") AND !$at_addr AND (normalise_link($profile) != normalise_link($url)))
480 elseif($mode == PROBE_NORMAL) {
485 if((strpos($orig_url,'@')) && validate_email($orig_url)) {
486 $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
489 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
492 if(count($x) && count($r)) {
493 $mailbox = construct_mailbox_name($r[0]);
495 openssl_private_decrypt(hex2bin($r[0]['pass']),$password,$x[0]['prvkey']);
496 $mbox = email_connect($mailbox,$r[0]['user'],$password);
498 logger('probe_url: email_connect failed.');
502 $msgs = email_poll($mbox,$orig_url);
503 logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG);
506 $network = NETWORK_MAIL;
507 $name = substr($url,0,strpos($url,'@'));
508 $phost = substr($url,strpos($url,'@')+1);
509 $profile = 'http://' . $phost;
510 // fix nick character range
511 $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url));
512 $notify = 'smtp ' . random_string();
513 $poll = 'email ' . random_string();
515 $x = email_msg_meta($mbox,$msgs[0]);
516 if(stristr($x[0]->from,$orig_url))
517 $adr = imap_rfc822_parse_adrlist($x[0]->from,'');
518 elseif(stristr($x[0]->to,$orig_url))
519 $adr = imap_rfc822_parse_adrlist($x[0]->to,'');
521 foreach($adr as $feadr) {
522 if((strcasecmp($feadr->mailbox,$name) == 0)
523 &&(strcasecmp($feadr->host,$phost) == 0)
524 && (strlen($feadr->personal))) {
526 $personal = imap_mime_header_decode($feadr->personal);
528 foreach($personal as $perspart)
529 if ($perspart->charset != "default")
530 $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
532 $vcard['fn'] .= $perspart->text;
534 $vcard['fn'] = notags($vcard['fn']);
545 if($mode == PROBE_NORMAL) {
548 $s = fetch_url($zot);
550 $j = json_decode($s);
552 $network = NETWORK_ZOT;
554 'fn' => $j->fullname,
555 'nick' => $j->nickname,
560 $pubkey = $j->pubkey;
568 $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn, true);
569 if(is_array($ret) && x($ret,'dfrn-request')) {
570 $network = NETWORK_DFRN;
571 $request = $ret['dfrn-request'];
572 $confirm = $ret['dfrn-confirm'];
573 $notify = $ret['dfrn-notify'];
574 $poll = $ret['dfrn-poll'];
577 $vcard['fn'] = $ret['fn'];
578 $vcard['nick'] = $ret['nick'];
579 $vcard['photo'] = $ret['photo'];
584 // Scrape the public key from the hcard.
585 // Diaspora will remove it from the webfinger somewhere in the future.
586 if (($hcard != "") AND ($pubkey == "")) {
587 $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn, true);
588 if (isset($ret["key"])) {
589 $hcard_key = $ret["key"];
590 if(strstr($hcard_key,'RSA '))
591 $pubkey = rsatopem($hcard_key);
593 $pubkey = $hcard_key;
596 if($diaspora && $diaspora_base && $diaspora_guid) {
597 $diaspora_notify = $diaspora_base.'receive/users/'.$diaspora_guid;
599 if($mode == PROBE_DIASPORA || !$notify || ($notify == $diaspora_notify)) {
600 $notify = $diaspora_notify;
601 $batch = $diaspora_base . 'receive/public' ;
604 $addr = str_replace('acct:', '', $url);
607 if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
609 $network = NETWORK_DIASPORA;
610 elseif($has_lrdd AND ($notify))
611 $network = NETWORK_OSTATUS;
614 $addr = str_replace('acct:', '', $url);
618 if($hcard && ! $vcard) {
619 $vcard = scrape_vcard($hcard);
621 // Google doesn't use absolute url in profile photos
623 if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
624 $h = @parse_url($hcard);
626 $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
629 logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
632 if($diaspora && $addr) {
633 // Diaspora returns the name as the nick. As the nick will never be updated,
634 // let's use the Diaspora nickname (the first part of the handle) as the nick instead
635 $addr_parts = explode('@', $addr);
636 $vcard['nick'] = $addr_parts[0];
641 $poll = str_replace(array('www.','last.fm/'),array('','ws.audioscrobbler.com/1.0/'),$url) . '/recenttracks.rss';
642 $vcard['nick'] = basename($url);
643 $vcard['fn'] = $vcard['nick'] . t(' on Last.fm');
644 $network = NETWORK_FEED;
649 $vcard['fn'] = $vcard['nick'];
653 if(stristr($url,'tumblr.com') && (! stristr($url,'/rss'))) {
654 $poll = $url . '/rss';
656 // Will leave it to others to figure out how to grab the avatar, which is on the $url page in the open graph meta links
659 if($appnet || ! $poll)
661 if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile))
663 if(($at_addr) && (! count($links)))
666 if ($connectornetworks)
671 $feedret = scrape_feed(($poll) ? $poll : $url);
673 logger('probe_url: scrape_feed ' . (($poll)? $poll : $url) . ' returns: ' . print_r($feedret,true), LOGGER_DATA);
674 if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
675 $poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']));
680 if(x($feedret,'photo') && (! x($vcard,'photo')))
681 $vcard['photo'] = $feedret['photo'];
683 $cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
684 $xml = fetch_url($poll, false, $redirects, 0, Null, $cookiejar);
687 logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
690 logger("scrape_feed: XML is empty for feed ".$poll);
691 $network = NETWORK_PHANTOM;
693 $data = feed_import($xml,$dummy1,$dummy2, $dummy3, true);
695 if (!is_array($data)) {
696 logger("scrape_feed: This doesn't seem to be a feed: ".$poll);
697 $network = NETWORK_PHANTOM;
699 if (($vcard["photo"] == "") AND ($data["header"]["author-avatar"] != ""))
700 $vcard["photo"] = $data["header"]["author-avatar"];
702 if (($vcard["fn"] == "") AND ($data["header"]["author-name"] != ""))
703 $vcard["fn"] = $data["header"]["author-name"];
705 if (($vcard["nick"] == "") AND ($data["header"]["author-nick"] != ""))
706 $vcard["nick"] = $data["header"]["author-nick"];
708 if ($network == NETWORK_OSTATUS) {
709 if ($data["header"]["author-id"] != "")
710 $alias = $data["header"]["author-id"];
712 if ($data["header"]["author-link"] != "")
713 $profile = $data["header"]["author-link"];
715 } elseif(!$profile AND ($data["header"]["author-link"] != "") AND !in_array($network, array("", NETWORK_FEED)))
716 $profile = $data["header"]["author-link"];
720 // Workaround for misconfigured Friendica servers
721 if (($network == "") AND (strstr($url, "/profile/"))) {
722 $noscrape = str_replace("/profile/", "/noscrape/", $url);
723 $noscrapejson = fetch_url($noscrape);
726 $network = NETWORK_DFRN;
728 $poco = str_replace("/profile/", "/poco/", $url);
730 $noscrapedata = json_decode($noscrapejson, true);
732 if (isset($noscrapedata["addr"]))
733 $addr = $noscrapedata["addr"];
735 if (isset($noscrapedata["fn"]))
736 $vcard["fn"] = $noscrapedata["fn"];
738 if (isset($noscrapedata["key"]))
739 $pubkey = $noscrapedata["key"];
741 if (isset($noscrapedata["photo"]))
742 $vcard["photo"] = $noscrapedata["photo"];
744 if (isset($noscrapedata["dfrn-request"]))
745 $request = $noscrapedata["dfrn-request"];
747 if (isset($noscrapedata["dfrn-confirm"]))
748 $confirm = $noscrapedata["dfrn-confirm"];
750 if (isset($noscrapedata["dfrn-notify"]))
751 $notify = $noscrapedata["dfrn-notify"];
753 if (isset($noscrapedata["dfrn-poll"]))
754 $poll = $noscrapedata["dfrn-poll"];
760 $network = NETWORK_FEED;
762 if(! x($vcard,'nick')) {
763 $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
764 if(strpos($vcard['nick'],' '))
765 $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
772 if(! x($vcard,'photo')) {
774 $vcard['photo'] = App::get_baseurl() . '/images/person-175.jpg' ;
780 // No human could be associated with this link, use the URL as the contact name
782 if(($network === NETWORK_FEED) && ($poll) && (! x($vcard,'fn')))
785 if (($notify != "") AND ($poll != "")) {
786 $baseurl = matching_url(normalise_link($notify), normalise_link($poll));
788 $baseurl2 = matching_url($baseurl, normalise_link($profile));
790 $baseurl = $baseurl2;
793 if (($baseurl == "") AND ($notify != ""))
794 $baseurl = matching_url(normalise_link($profile), normalise_link($notify));
796 if (($baseurl == "") AND ($poll != ""))
797 $baseurl = matching_url(normalise_link($profile), normalise_link($poll));
799 if (substr($baseurl, -10) == "/index.php")
800 $baseurl = str_replace("/index.php", "", $baseurl);
803 $network = NETWORK_PHANTOM;
805 $baseurl = rtrim($baseurl, "/");
807 if(strpos($url,'@') AND ($addr == "") AND ($network == NETWORK_DFRN))
808 $addr = str_replace('acct:', '', $url);
810 $vcard['fn'] = notags($vcard['fn']);
811 $vcard['nick'] = str_replace(' ','',notags($vcard['nick']));
813 $result['name'] = $vcard['fn'];
814 $result['nick'] = $vcard['nick'];
815 $result['url'] = $profile;
816 $result['addr'] = $addr;
817 $result['batch'] = $batch;
818 $result['notify'] = $notify;
819 $result['poll'] = $poll;
820 $result['request'] = $request;
821 $result['confirm'] = $confirm;
822 $result['poco'] = $poco;
823 $result['photo'] = $vcard['photo'];
824 $result['priority'] = $priority;
825 $result['network'] = $network;
826 $result['alias'] = $alias;
827 $result['pubkey'] = $pubkey;
828 $result['baseurl'] = $baseurl;
830 logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG);
833 // Trying if it maybe a diaspora account
834 if (($result['network'] == NETWORK_FEED) OR ($result['addr'] == "")) {
835 require_once('include/bbcode.php');
836 $address = GetProfileUsername($url, "", true);
837 $result2 = probe_url($address, $mode, ++$level);
838 if ($result2['network'] != "")
842 // Maybe it's some non standard GNU Social installation (Single user, subfolder or no uri rewrite)
843 if (($result['network'] == NETWORK_FEED) AND ($result['baseurl'] != "") AND ($result['nick'] != "")) {
844 $addr = $result['nick'].'@'.str_replace("http://", "", $result['baseurl']);
845 $result2 = probe_url($addr, $mode, ++$level);
846 if (($result2['network'] != "") AND ($result2['network'] != NETWORK_FEED))
850 // Quickfix for Hubzilla systems with enabled OStatus plugin
851 if (($result['network'] == NETWORK_DIASPORA) AND ($result["batch"] == "")) {
852 $result2 = probe_url($url, PROBE_DIASPORA, ++$level);
853 if ($result2['network'] == NETWORK_DIASPORA) {
854 $addr = $result["addr"];
857 if (($result["addr"] == "") AND ($addr != ""))
858 $result["addr"] = $addr;
863 // Only store into the cache if the value seems to be valid
864 if ($result['network'] != NETWORK_PHANTOM) {
865 Cache::set("probe_url:".$mode.":".$original_url,serialize($result), CACHE_DAY);
867 /// @todo temporary fix - we need a real contact update function that updates only changing fields
868 /// The biggest problem is the avatar picture that could have a reduced image size.
869 /// It should only be updated if the existing picture isn't existing anymore.
870 if (($result['network'] != NETWORK_FEED) AND ($mode == PROBE_NORMAL) AND
871 $result["name"] AND $result["nick"] AND $result["url"] AND $result["addr"] AND $result["poll"])
872 q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `addr` = '%s',
873 `notify` = '%s', `poll` = '%s', `alias` = '%s', `success_update` = '%s'
874 WHERE `nurl` = '%s' AND NOT `self` AND `uid` = 0",
875 dbesc($result["name"]),
876 dbesc($result["nick"]),
877 dbesc($result["url"]),
878 dbesc($result["addr"]),
879 dbesc($result["notify"]),
880 dbesc($result["poll"]),
881 dbesc($result["alias"]),
882 dbesc(datetime_convert()),
883 dbesc(normalise_link($result['url']))
891 * @brief Find the matching part between two url
893 * @param string $url1
894 * @param string $url2
895 * @return string The matching part
897 function matching_url($url1, $url2) {
899 if (($url1 == "") OR ($url2 == ""))
902 $url1 = normalise_link($url1);
903 $url2 = normalise_link($url2);
905 $parts1 = parse_url($url1);
906 $parts2 = parse_url($url2);
908 if (!isset($parts1["host"]) OR !isset($parts2["host"]))
911 if ($parts1["scheme"] != $parts2["scheme"])
914 if ($parts1["host"] != $parts2["host"])
917 if ($parts1["port"] != $parts2["port"])
920 $match = $parts1["scheme"]."://".$parts1["host"];
923 $match .= ":".$parts1["port"];
925 $pathparts1 = explode("/", $parts1["path"]);
926 $pathparts2 = explode("/", $parts2["path"]);
931 $path1 = $pathparts1[$i];
932 $path2 = $pathparts2[$i];
934 if ($path1 == $path2)
937 } while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
941 return normalise_link($match);