X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FScrape.php;h=bc6aebbdcfdee7b388c57f6905e2f008dc258647;hb=f496af08bb71080d11f9d76377605bbd16cb9090;hp=64a930bfdaedebfccbf46acb9f37a03085174cbe;hpb=e146b42d156fbe68b22b7799bd0d7a462ab89d64;p=friendica.git diff --git a/include/Scrape.php b/include/Scrape.php index 64a930bfda..bc6aebbdcf 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -12,15 +12,29 @@ function scrape_dfrn($url, $dont_probe = false) { logger('scrape_dfrn: url=' . $url); + // Try to fetch the data from noscrape. This is faster than parsing the HTML + $noscrape = str_replace("/hcard/", "/noscrape/", $url); + $noscrapejson = fetch_url($noscrape); + $noscrapedata = array(); + if ($noscrapejson) { + $noscrapedata = json_decode($noscrapejson, true); + + if (is_array($noscrapedata)) + if ($noscrapedata["nick"] != "") + return($noscrapedata); + } + $s = fetch_url($url); if(! $s) return $ret; - $probe = probe_url($url); + if (!$dont_probe) { + $probe = probe_url($url); - if (isset($probe["addr"])) - $ret["addr"] = $probe["addr"]; + if (isset($probe["addr"])) + $ret["addr"] = $probe["addr"]; + } $headers = $a->get_curl_headers(); logger('scrape_dfrn: headers=' . $headers, LOGGER_DEBUG); @@ -89,8 +103,7 @@ function scrape_dfrn($url, $dont_probe = false) { } } } - - return $ret; + return array_merge($ret, $noscrapedata); }} @@ -233,7 +246,9 @@ function scrape_feed($url) { $a = get_app(); $ret = array(); - $s = fetch_url($url); + $cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-'); + $s = fetch_url($url, false, $redirects, 0, Null, $cookiejar); + unlink($cookiejar); $headers = $a->get_curl_headers(); $code = $a->get_curl_code(); @@ -545,9 +560,23 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) { } } + // Scrape the public key from the hcard. + // Diaspora will remove it from the webfinger somewhere in the future. + if (($hcard != "") AND ($pubkey == "")) { + $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn, true); + if (isset($ret["key"])) { + $hcard_key = $ret["key"]; + if(strstr($hcard_key,'RSA ')) + $pubkey = rsatopem($hcard_key); + else + $pubkey = $hcard_key; + } + } if($diaspora && $diaspora_base && $diaspora_guid) { - if($mode == PROBE_DIASPORA || ! $notify) { - $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; + $diaspora_notify = $diaspora_base.'receive/users/'.$diaspora_guid; + + if($mode == PROBE_DIASPORA || ! $notify || ($notify == $diaspora_notify)) { + $notify = $diaspora_notify; $batch = $diaspora_base . 'receive/public' ; } if(strpos($url,'@')) @@ -646,7 +675,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) { $vcard['photo'] = $feedret['photo']; require_once('library/simplepie/simplepie.inc'); $feed = new SimplePie(); - $xml = fetch_url($poll); + $cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-'); + $xml = fetch_url($poll, false, $redirects, 0, Null, $cookiejar); + unlink($cookiejar); logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA); $a = get_app(); @@ -724,6 +755,45 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) { } } + // Workaround for misconfigured Friendica servers + if (($network == "") AND (strstr($url, "/profile/"))) { + $noscrape = str_replace("/profile/", "/noscrape/", $url); + $noscrapejson = fetch_url($noscrape); + if ($noscrapejson) { + + $network = NETWORK_DFRN; + + $poco = str_replace("/profile/", "/poco/", $url); + + $noscrapedata = json_decode($noscrapejson, true); + + if (isset($noscrapedata["addr"])) + $addr = $noscrapedata["addr"]; + + if (isset($noscrapedata["fn"])) + $vcard["fn"] = $noscrapedata["fn"]; + + if (isset($noscrapedata["key"])) + $pubkey = $noscrapedata["key"]; + + if (isset($noscrapedata["photo"])) + $vcard["photo"] = $noscrapedata["photo"]; + + if (isset($noscrapedata["dfrn-request"])) + $request = $noscrapedata["dfrn-request"]; + + if (isset($noscrapedata["dfrn-confirm"])) + $confirm = $noscrapedata["dfrn-confirm"]; + + if (isset($noscrapedata["dfrn-notify"])) + $notify = $noscrapedata["dfrn-notify"]; + + if (isset($noscrapedata["dfrn-poll"])) + $poll = $noscrapedata["dfrn-poll"]; + + } + } + if((! $vcard['photo']) && strlen($email)) $vcard['photo'] = avatar_img($email); if($poll === $profile) @@ -829,7 +899,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) { } // Only store into the cache if the value seems to be valid - if ($result['network'] != NETWORK_FEED) + if ($result['network'] != NETWORK_PHANTOM) Cache::set("probe_url:".$mode.":".$url,serialize($result), CACHE_DAY); return $result;