Support for noscrape when probing.
This commit is contained in:
parent
99f94edc9c
commit
b124b94288
1 changed files with 74 additions and 11 deletions
|
@ -12,9 +12,10 @@ require_once("include/feed.php");
|
||||||
class Probe {
|
class Probe {
|
||||||
|
|
||||||
private function rearrange_data($data) {
|
private function rearrange_data($data) {
|
||||||
$fields = array("name", "nick", "guid", "url", "addr", "batch",
|
$fields = array("name", "nick", "guid", "url", "addr", "alias",
|
||||||
"notify", "poll", "request", "confirm", "poco",
|
"photo", "community", "keywords", "location", "about",
|
||||||
"photo", "priority", "network", "alias", "pubkey", "baseurl");
|
"batch", "notify", "poll", "request", "confirm", "poco",
|
||||||
|
"priority", "network", "pubkey", "baseurl");
|
||||||
|
|
||||||
$newdata = array();
|
$newdata = array();
|
||||||
foreach ($fields AS $field)
|
foreach ($fields AS $field)
|
||||||
|
@ -80,8 +81,8 @@ class Probe {
|
||||||
return $xrd_data;
|
return $xrd_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function uri($uri) {
|
public static function uri($uri, $network = "") {
|
||||||
$data = self::detect($uri);
|
$data = self::detect($uri, $network);
|
||||||
|
|
||||||
//if (!data)
|
//if (!data)
|
||||||
// return false;
|
// return false;
|
||||||
|
@ -108,7 +109,7 @@ class Probe {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function detect($uri) {
|
private function detect($uri, $network) {
|
||||||
if (strstr($uri, '@')) {
|
if (strstr($uri, '@')) {
|
||||||
// If the URI starts with "mailto:" then jum directly to the mail detection
|
// If the URI starts with "mailto:" then jum directly to the mail detection
|
||||||
if (strpos($url,'mailto:') !== false) {
|
if (strpos($url,'mailto:') !== false) {
|
||||||
|
@ -116,6 +117,9 @@ class Probe {
|
||||||
return self::mail($uri);
|
return self::mail($uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($network == NETWORK_MAIL)
|
||||||
|
return self::mail($uri);
|
||||||
|
|
||||||
// Remove "acct:" from the URI
|
// Remove "acct:" from the URI
|
||||||
$uri = str_replace('acct:', '', $uri);
|
$uri = str_replace('acct:', '', $uri);
|
||||||
|
|
||||||
|
@ -171,15 +175,15 @@ class Probe {
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
if (!$result)
|
if (in_array($network, array("", NETWORK_DFRN)))
|
||||||
$result = self::dfrn($webfinger);
|
$result = self::dfrn($webfinger);
|
||||||
if (!$result)
|
if ((!$result AND ($network == "")) OR ($network == NETWORK_DIASPORA))
|
||||||
$result = self::diaspora($webfinger);
|
$result = self::diaspora($webfinger);
|
||||||
if (!$result)
|
if ((!$result AND ($network == "")) OR ($network == NETWORK_OSTATUS))
|
||||||
$result = self::ostatus($webfinger);
|
$result = self::ostatus($webfinger);
|
||||||
if (!$result)
|
if ((!$result AND ($network == "")) OR ($network == NETWORK_PUMPIO))
|
||||||
$result = self::pumpio($webfinger);
|
$result = self::pumpio($webfinger);
|
||||||
if (!$result)
|
if ((!$result AND ($network == "")) OR ($network == NETWORK_FEED))
|
||||||
$result = self::feed($uri);
|
$result = self::feed($uri);
|
||||||
else {
|
else {
|
||||||
// We overwrite the detected nick with our try if the previois routines hadn't detected it.
|
// We overwrite the detected nick with our try if the previois routines hadn't detected it.
|
||||||
|
@ -245,6 +249,57 @@ class Probe {
|
||||||
return $webfinger;
|
return $webfinger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function poll_noscrape($noscrape, $data) {
|
||||||
|
$content = fetch_url($noscrape);
|
||||||
|
|
||||||
|
$json = json_decode($content, true);
|
||||||
|
|
||||||
|
if (isset($json["fn"]))
|
||||||
|
$data["name"] = $json["fn"];
|
||||||
|
|
||||||
|
if (isset($json["addr"]))
|
||||||
|
$data["addr"] = $json["addr"];
|
||||||
|
|
||||||
|
if (isset($json["nick"]))
|
||||||
|
$data["nick"] = $json["nick"];
|
||||||
|
|
||||||
|
if (isset($json["comm"]))
|
||||||
|
$data["community"] = $json["comm"];
|
||||||
|
|
||||||
|
if (isset($json["tags"])) {
|
||||||
|
$keywords = implode(" ", $json["tags"]);
|
||||||
|
if ($keywords != "")
|
||||||
|
$data["keywords"] = $keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
$location = formatted_location($json);
|
||||||
|
if ($location)
|
||||||
|
$data["location"] = $location;
|
||||||
|
|
||||||
|
if (isset($json["about"]))
|
||||||
|
$data["about"] = $json["about"];
|
||||||
|
|
||||||
|
if (isset($json["key"]))
|
||||||
|
$data["pubkey"] = $json["key"];
|
||||||
|
|
||||||
|
if (isset($json["photo"]))
|
||||||
|
$data["photo"] = $json["photo"];
|
||||||
|
|
||||||
|
if (isset($json["dfrn-request"]))
|
||||||
|
$data["request"] = $json["dfrn-request"];
|
||||||
|
|
||||||
|
if (isset($json["dfrn-confirm"]))
|
||||||
|
$data["confirm"] = $json["dfrn-confirm"];
|
||||||
|
|
||||||
|
if (isset($json["dfrn-notify"]))
|
||||||
|
$data["notify"] = $json["dfrn-notify"];
|
||||||
|
|
||||||
|
if (isset($json["dfrn-poll"]))
|
||||||
|
$data["poll"] = $json["dfrn-poll"];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
private function dfrn($webfinger) {
|
private function dfrn($webfinger) {
|
||||||
|
|
||||||
$hcard = "";
|
$hcard = "";
|
||||||
|
@ -279,6 +334,14 @@ class Probe {
|
||||||
if (!isset($data["network"]) OR ($hcard == ""))
|
if (!isset($data["network"]) OR ($hcard == ""))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Fetch data via noscrape - this is faster
|
||||||
|
$noscrape = str_replace("/hcard/", "/noscrape/", $hcard);
|
||||||
|
$data = self::poll_noscrape($noscrape, $data);
|
||||||
|
|
||||||
|
if (isset($data["notify"]) AND isset($data["confirm"]) AND isset($data["request"]) AND
|
||||||
|
isset($data["poll"]) AND isset($data["name"]) AND isset($data["photo"]))
|
||||||
|
return $data;
|
||||||
|
|
||||||
$data = self::poll_hcard($hcard, $data, true);
|
$data = self::poll_hcard($hcard, $data, true);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
Loading…
Reference in a new issue