*
* @return array Ordered data
*/
- private function rearrangeData($data) {
+ private static function rearrangeData($data) {
$fields = array("name", "nick", "guid", "url", "addr", "alias",
"photo", "community", "keywords", "location", "about",
"batch", "notify", "poll", "request", "confirm", "poco",
*
* @return bool Does the testes hostname belongs to the own server?
*/
- private function ownHost($host) {
+ private static function ownHost($host) {
$own_host = get_app()->get_hostname();
$parts = parse_url($host);
* 'lrdd-xml' => Link to LRDD endpoint in XML format
* 'lrdd-json' => Link to LRDD endpoint in JSON format
*/
- private function xrd($host) {
+ private static function xrd($host) {
// Reset the static variable
self::$baseurl = '';
*
* @return string profile link
*/
-
public static function webfingerDfrn($webbie, &$hcard_url) {
$profile_link = '';
return $data;
}
+ /**
+ * @brief Switch the scheme of an url between http and https
+ *
+ * @param string $url URL
+ *
+ * @return string switched URL
+ */
+ private static function switchScheme($url) {
+ $parts = parse_url($url);
+
+ if (!isset($parts['scheme'])) {
+ return $url;
+ }
+
+ if ($parts['scheme'] == 'http') {
+ $url = str_replace('http://', 'https://', $url);
+ } elseif ($parts['scheme'] == 'https') {
+ $url = str_replace('https://', 'http://', $url);
+ }
+
+ return $url;
+ }
+
+ /**
+ * @brief Checks if a profile url should be OStatus but only provides partial information
+ *
+ * @param array $webfinger Webfinger data
+ * @param string $lrdd Path template for webfinger request
+ *
+ * @return array fixed webfinger data
+ */
+ private static function fixOstatus($webfinger, $lrdd) {
+ if (empty($webfinger['links']) || empty($webfinger['subject'])) {
+ return $webfinger;
+ }
+
+ $is_ostatus = false;
+ $has_key = false;
+
+ foreach ($webfinger['links'] as $link) {
+ if ($link['rel'] == NAMESPACE_OSTATUSSUB) {
+ $is_ostatus = true;
+ }
+ if ($link['rel'] == 'magic-public-key') {
+ $has_key = true;
+ }
+ }
+
+ if (!$is_ostatus || $has_key) {
+ return $webfinger;
+ }
+
+ $url = self::switchScheme($webfinger['subject']);
+ $path = str_replace('{uri}', urlencode($url), $lrdd);
+ $webfinger2 = self::webfinger($path);
+
+ // Is the new webfinger detectable as OStatus?
+ if (self::ostatus($webfinger2, true)) {
+ $webfinger = $webfinger2;
+ }
+
+ return $webfinger;
+ }
+
/**
* @brief Fetch information (protocol endpoints and user information) about a given uri
*
*
* @return array uri data
*/
- private function detect($uri, $network, $uid) {
+ private static function detect($uri, $network, $uid) {
$parts = parse_url($uri);
if (isset($parts["scheme"]) && isset($parts["host"]) && isset($parts["path"])) {
$path = str_replace('{uri}', urlencode($uri), $link);
$webfinger = self::webfinger($path);
+ // Fix possible problems with GNU Social probing to wrong scheme
+ $webfinger = self::fixOstatus($webfinger, $link);
+
// We cannot be sure that the detected address was correct, so we don't use the values
if ($webfinger && ($uri != $addr)) {
$nick = "";
*
* @return array webfinger data
*/
- private function webfinger($url) {
+ private static function webfinger($url) {
$xrd_timeout = Config::get('system', 'xrd_timeout', 20);
$redirects = 0;
*
* @return array noscrape data
*/
- private function pollNoscrape($noscrape_url, $data) {
+ private static function pollNoscrape($noscrape_url, $data) {
$ret = z_fetch_url($noscrape_url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
*
* @return array DFRN data
*/
- private function dfrn($webfinger) {
+ private static function dfrn($webfinger) {
$hcard_url = "";
$data = array();
}
}
+ if (is_array($webfinger["aliases"])) {
+ foreach ($webfinger["aliases"] as $alias) {
+ if (substr($alias, 0, 5) == 'acct:') {
+ $data["addr"] = substr($alias, 5);
+ }
+ }
+ }
+
if (!isset($data["network"]) || ($hcard_url == "")) {
return false;
}
*
* @return array hcard data
*/
- private function pollHcard($hcard_url, $data, $dfrn = false) {
+ private static function pollHcard($hcard_url, $data, $dfrn = false) {
$ret = z_fetch_url($hcard_url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
*
* @return array Diaspora data
*/
- private function diaspora($webfinger) {
+ private static function diaspora($webfinger) {
$hcard_url = "";
$data = array();
* @brief Check for OStatus contact
*
* @param array $webfinger Webfinger data
+ * @param bool $short Short detection mode
*
- * @return array OStatus data
+ * @return array|bool OStatus data or "false" on error or "true" on short mode
*/
- private function ostatus($webfinger) {
+ private static function ostatus($webfinger, $short = false) {
$data = array();
if (is_array($webfinger["aliases"])) {
foreach ($webfinger["aliases"] as $alias) {
} else {
return false;
}
+
+ if ($short) {
+ return true;
+ }
+
// Fetch all additional data from the feed
$ret = z_fetch_url($data["poll"]);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
*
* @return array profile data
*/
- private function pumpioProfileData($profile_link) {
+ private static function pumpioProfileData($profile_link) {
$doc = new DOMDocument();
if (!@$doc->loadHTMLFile($profile_link)) {
*
* @return array pump.io data
*/
- private function pumpio($webfinger) {
+ private static function pumpio($webfinger) {
$data = array();
foreach ($webfinger["links"] as $link) {
*
* @return string feed link
*/
- private function getFeedLink($url) {
+ private static function getFeedLink($url) {
$doc = new DOMDocument();
if (!@$doc->loadHTMLFile($url)) {
*
* @return array feed data
*/
- private function feed($url, $probe = true) {
+ private static function feed($url, $probe = true) {
$ret = z_fetch_url($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
*
* @return array mail data
*/
- private function mail($uri, $uid) {
+ private static function mail($uri, $uid) {
if (!validate_email($uri)) {
return false;