*/
class Probe {
+ private static $baseurl;
+
/**
* @brief Rearrange the array so that it always has the same order
*
*/
private function xrd($host) {
+ // Reset the static variable
+ self::$baseurl = '';
+
$ssl_url = "https://".$host."/.well-known/host-meta";
$url = "http://".$host."/.well-known/host-meta";
elseif ($attributes["rel"] == "lrdd")
$xrd_data["lrdd"] = $attributes["template"];
}
+
+ self::$baseurl = "http://".$host;
+
return $xrd_data;
}
$path_parts = explode("/", trim($parts["path"], "/"));
+ $nick = array_pop($path_parts);
+
do {
$lrdd = self::xrd($host);
$host .= "/".array_shift($path_parts);
$path = str_replace('{uri}', urlencode("acct:".$uri), $link);
$webfinger = self::webfinger($path);
}
+
+ // Special treatment for Mastodon
+ // Problem is that Mastodon uses an URL format like http://domain.tld/@nick
+ // But the webfinger for this format fails.
+ if (!$webfinger AND isset($nick)) {
+ // Mastodon uses a "@" as prefix for usernames in their url format
+ $nick = ltrim($nick, '@');
+
+ $addr = $nick."@".$host;
+
+ $path = str_replace('{uri}', urlencode("acct:".$addr), $link);
+ $webfinger = self::webfinger($path);
+ }
}
if (!is_array($webfinger["links"]))
$data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
}
- if (!isset($data["network"]))
+ if (self::$baseurl != "") {
+ $data["baseurl"] = self::$baseurl;
+ }
+
+ if (!isset($data["network"])) {
$data["network"] = NETWORK_PHANTOM;
+ }
$data = self::rearrange_data($data);
dbesc(normalise_link($data['url']))
);
}
+
return $data;
}
* @return array uri data
*/
private function detect($uri, $network, $uid) {
- if (strstr($uri, '@')) {
+ $parts = parse_url($uri);
+
+ if (isset($parts["scheme"]) AND isset($parts["host"]) AND isset($parts["path"])) {
+
+ /// @todo: Ports?
+ $host = $parts["host"];
+
+ if ($host == 'twitter.com') {
+ return array("network" => NETWORK_TWITTER);
+ }
+ $lrdd = self::xrd($host);
+
+ $path_parts = explode("/", trim($parts["path"], "/"));
+
+ while (!$lrdd AND (sizeof($path_parts) > 1)) {
+ $host .= "/".array_shift($path_parts);
+ $lrdd = self::xrd($host);
+ }
+ if (!$lrdd) {
+ return self::feed($uri);
+ }
+ $nick = array_pop($path_parts);
+
+ // Mastodon uses a "@" as prefix for usernames in their url format
+ $nick = ltrim($nick, '@');
+
+ $addr = $nick."@".$host;
+ } elseif (strstr($uri, '@')) {
// If the URI starts with "mailto:" then jump directly to the mail detection
if (strpos($url,'mailto:') !== false) {
$uri = str_replace('mailto:', '', $url);
$host = substr($uri,strpos($uri, '@') + 1);
$nick = substr($uri,0, strpos($uri, '@'));
- if (strpos($uri, '@twitter.com'))
+ if (strpos($uri, '@twitter.com')) {
return array("network" => NETWORK_TWITTER);
-
+ }
$lrdd = self::xrd($host);
- if (!$lrdd)
+ if (!$lrdd) {
return self::mail($uri, $uid);
-
+ }
$addr = $uri;
} else {
- $parts = parse_url($uri);
- if (!isset($parts["scheme"]) OR
- !isset($parts["host"]) OR
- !isset($parts["path"]))
- return false;
-
- /// @todo: Ports?
- $host = $parts["host"];
-
- if ($host == 'twitter.com')
- return array("network" => NETWORK_TWITTER);
-
- $lrdd = self::xrd($host);
-
- $path_parts = explode("/", trim($parts["path"], "/"));
-
- while (!$lrdd AND (sizeof($path_parts) > 1)) {
- $host .= "/".array_shift($path_parts);
- $lrdd = self::xrd($host);
- }
- if (!$lrdd)
- return self::feed($uri);
-
- $nick = array_pop($path_parts);
- $addr = $nick."@".$host;
+ return false;
}
+
$webfinger = false;
/// @todo Do we need the prefix "acct:" or "acct://"?
*/
public static function valid_dfrn($data) {
$errors = 0;
- if (!isset($data['key']))
+ if(!isset($data['key']))
$errors ++;
- if (!isset($data['dfrn-request']))
+ if(!isset($data['dfrn-request']))
$errors ++;
- if (!isset($data['dfrn-confirm']))
+ if(!isset($data['dfrn-confirm']))
$errors ++;
- if (!isset($data['dfrn-notify']))
+ if(!isset($data['dfrn-notify']))
$errors ++;
- if (!isset($data['dfrn-poll']))
+ if(!isset($data['dfrn-poll']))
$errors ++;
return $errors;
}
* @return array OStatus data
*/
private function ostatus($webfinger) {
-
$data = array();
- if (is_array($webfinger["aliases"]))
- foreach ($webfinger["aliases"] AS $alias)
- if (strstr($alias, "@"))
+ if (is_array($webfinger["aliases"])) {
+ foreach ($webfinger["aliases"] AS $alias) {
+ if (strstr($alias, "@")) {
$data["addr"] = str_replace('acct:', '', $alias);
+ }
+ }
+ }
- if (is_string($webfinger["subject"]) AND strstr($webfinger["subject"], "@"))
+ if (is_string($webfinger["subject"]) AND strstr($webfinger["subject"], "@")) {
$data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
-
+ }
$pubkey = "";
foreach ($webfinger["links"] AS $link) {
if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
- ($link["type"] == "text/html") AND ($link["href"] != ""))
+ ($link["type"] == "text/html") AND ($link["href"] != "")) {
$data["url"] = $link["href"];
- elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
+ } elseif (($link["rel"] == "salmon") AND ($link["href"] != "")) {
$data["notify"] = $link["href"];
- elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
+ } elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != "")) {
$data["poll"] = $link["href"];
- elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
+ } elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
$pubkey = $link["href"];
if (substr($pubkey, 0, 5) === 'data:') {
- if (strstr($pubkey, ','))
+ if (strstr($pubkey, ',')) {
$pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
- else
+ } else {
$pubkey = substr($pubkey, 5);
+ }
} elseif (normalise_link($pubkey) == 'http://') {
$ret = z_fetch_url($pubkey);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
$e = base64url_decode($key[2]);
$data["pubkey"] = metopem($m,$e);
}
-
}
}
if (isset($data["notify"]) AND isset($data["pubkey"]) AND
isset($data["poll"]) AND isset($data["url"])) {
$data["network"] = NETWORK_OSTATUS;
- } else
+ } else {
return false;
-
+ }
// Fetch all additional data from the feed
$ret = z_fetch_url($data["poll"]);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
}
$feed = $ret['body'];
$feed_data = feed_import($feed,$dummy1,$dummy2, $dummy3, true);
- if (!$feed_data)
+ if (!$feed_data) {
return false;
-
- if ($feed_data["header"]["author-name"] != "")
+ }
+ if ($feed_data["header"]["author-name"] != "") {
$data["name"] = $feed_data["header"]["author-name"];
-
- if ($feed_data["header"]["author-nick"] != "")
+ }
+ if ($feed_data["header"]["author-nick"] != "") {
$data["nick"] = $feed_data["header"]["author-nick"];
-
- if ($feed_data["header"]["author-avatar"] != "")
- $data["photo"] = $feed_data["header"]["author-avatar"];
-
- if ($feed_data["header"]["author-id"] != "")
+ }
+ if ($feed_data["header"]["author-avatar"] != "") {
+ $data["photo"] = ostatus::fix_avatar($feed_data["header"]["author-avatar"], $data["url"]);
+ }
+ if ($feed_data["header"]["author-id"] != "") {
$data["alias"] = $feed_data["header"]["author-id"];
-
- if ($feed_data["header"]["author-location"] != "")
+ }
+ if ($feed_data["header"]["author-location"] != "") {
$data["location"] = $feed_data["header"]["author-location"];
-
- if ($feed_data["header"]["author-about"] != "")
+ }
+ if ($feed_data["header"]["author-about"] != "") {
$data["about"] = $feed_data["header"]["author-about"];
-
+ }
// OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
// So we take the value that we just fetched, although the other one worked as well
- if ($feed_data["header"]["author-link"] != "")
+ if ($feed_data["header"]["author-link"] != "") {
$data["url"] = $feed_data["header"]["author-link"];
-
+ }
/// @todo Fetch location and "about" from the feed as well
return $data;
}
$password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']), $password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$r[0]['user'], $password);
- if (!$mbox) {
+ if(!mbox)
return false;
- }
}
$msgs = email_poll($mbox, $uri);
logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
- if (!count($msgs)) {
+ if (!count($msgs))
return false;
- }
$data = array();
$data["poll"] = 'email '.random_string();
$x = email_msg_meta($mbox, $msgs[0]);
- if (stristr($x[0]->from, $uri)) {
+ if(stristr($x[0]->from, $uri))
$adr = imap_rfc822_parse_adrlist($x[0]->from, '');
- } elseif (stristr($x[0]->to, $uri)) {
+ elseif(stristr($x[0]->to, $uri))
$adr = imap_rfc822_parse_adrlist($x[0]->to, '');
- }
- if (isset($adr)) {
- foreach ($adr as $feadr) {
- if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)
+ if(isset($adr)) {
+ foreach($adr as $feadr) {
+ if((strcasecmp($feadr->mailbox, $data["name"]) == 0)
&&(strcasecmp($feadr->host, $phost) == 0)
&& (strlen($feadr->personal))) {
$personal = imap_mime_header_decode($feadr->personal);
$data["name"] = "";
- foreach ($personal as $perspart) {
- if ($perspart->charset != "default") {
+ foreach($personal as $perspart)
+ if ($perspart->charset != "default")
$data["name"] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
- } else {
+ else
$data["name"] .= $perspart->text;
- }
- }
$data["name"] = notags($data["name"]);
}