X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FProbe.php;h=771312f6ec8498b3d64712d41d9052e86fa3328f;hb=357c0072bda29e9838eaedf1d157c534c596f2dd;hp=497fd3c51704bd4f468e708da9ac5f0a1f1153f3;hpb=4e3849c18b5acd27da14de2ee0abb9607b00a219;p=friendica.git diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 497fd3c517..771312f6ec 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -1,18 +1,29 @@ . + * */ -namespace Friendica\Network; -/** - * @file src/Network/Probe.php - * @brief Functions for probing URL - */ +namespace Friendica\Network; use DOMDocument; use DomXPath; -use Friendica\Core\Cache\Cache; -use Friendica\Core\Config; +use Friendica\Core\Cache\Duration; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Database\DBA; @@ -29,8 +40,7 @@ use Friendica\Util\Strings; use Friendica\Util\XML; /** - * @brief This class contain functions for probing URL - * + * This class contain functions for probing URL */ class Probe { @@ -38,7 +48,32 @@ class Probe private static $istimeout; /** - * @brief Rearrange the array so that it always has the same order + * Remove stuff from an URI that doesn't belong there + * + * @param string $URI + * @return string Cleaned URI + */ + public static function cleanURI(string $URI) + { + // At first remove leading and trailing junk + $URI = trim($URI, "@#?:/ \t\n\r\0\x0B"); + + $parts = parse_url($URI); + + if (empty($parts['scheme'])) { + return $URI; + } + + // Remove the URL fragment, since these shouldn't be part of any profile URL + unset($parts['fragment']); + + $URI = Network::unparseURL($parts); + + return $URI; + } + + /** + * Rearrange the array so that it always has the same order * * @param array $data Unordered data * @@ -47,7 +82,7 @@ class Probe private static function rearrangeData($data) { $fields = ["name", "nick", "guid", "url", "addr", "alias", "photo", "account-type", - "community", "keywords", "location", "about", "gender", "hide", + "community", "keywords", "location", "about", "hide", "batch", "notify", "poll", "request", "confirm", "poco", "following", "followers", "inbox", "outbox", "sharedinbox", "priority", "network", "pubkey", "baseurl"]; @@ -68,7 +103,7 @@ class Probe } /** - * @brief Check if the hostname belongs to the own server + * Check if the hostname belongs to the own server * * @param string $host The hostname that is to be checked * @@ -91,7 +126,7 @@ class Probe } /** - * @brief Probes for webfinger path via "host-meta" + * Probes for webfinger path via "host-meta" * * We have to check if the servers in the future still will offer this. * It seems as if it was dropped from the standard. @@ -109,7 +144,7 @@ class Probe $ssl_url = "https://".$host."/.well-known/host-meta"; $url = "http://".$host."/.well-known/host-meta"; - $xrd_timeout = Config::get('system', 'xrd_timeout', 20); + $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20); Logger::log("Probing for ".$host, Logger::DEBUG); $xrd = null; @@ -179,7 +214,7 @@ class Probe } /** - * @brief Perform Webfinger lookup and return DFRN data + * Perform Webfinger lookup and return DFRN data * * Given an email style address, perform webfinger lookup and * return the resulting DFRN profile URL, or if no DFRN profile URL @@ -222,7 +257,29 @@ class Probe } /** - * @brief Check an URI for LRDD data + * Get the link for the remote follow page for a given profile link + * + * @param sting $profile + * @return string Remote follow page link + */ + public static function getRemoteFollowLink(string $profile) + { + $follow_link = ''; + + $links = self::lrdd($profile); + + if (!empty($links) && is_array($links)) { + foreach ($links as $link) { + if ($link['@attributes']['rel'] === ActivityNamespace::OSTATUSSUB) { + $follow_link = $link['@attributes']['template']; + } + } + } + return $follow_link; + } + + /** + * Check an URI for LRDD data * * this is a replacement for the "lrdd" function. * It isn't used in this class and has some redundancies in the code. @@ -318,7 +375,7 @@ class Probe } /** - * @brief Fetch information (protocol endpoints and user information) about a given uri + * Fetch information (protocol endpoints and user information) about a given uri * * @param string $uri Address that should be probed * @param string $network Test for this specific network @@ -401,6 +458,11 @@ class Probe $data['network'] = Protocol::PHANTOM; } + // Ensure that local connections always are DFRN + if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) { + $data['network'] = Protocol::DFRN; + } + if (!isset($data['hide']) && in_array($data['network'], Protocol::FEDERATED)) { $data['hide'] = self::getHideStatus($data['url']); } @@ -409,7 +471,7 @@ class Probe // Only store into the cache if the value seems to be valid if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) { - DI::cache()->set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY); + DI::cache()->set('Probe::uri:' . $network . ':' . $uri, $data, Duration::DAY); } return $data; @@ -480,7 +542,7 @@ class Probe } /** - * @brief Checks if a profile url should be OStatus but only provides partial information + * 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 @@ -524,7 +586,7 @@ class Probe } /** - * @brief Fetch information (protocol endpoints and user information) about a given uri + * Fetch information (protocol endpoints and user information) about a given uri * * This function is only called by the "uri" function that adds caching and rearranging of data. * @@ -812,9 +874,6 @@ class Probe if (!empty($profile['description'])) { $data['about'] = $profile['description']; } - if (!empty($profile['gender'])) { - $data['gender'] = $profile['gender']; - } if (!empty($profile['keywords'])) { $keywords = implode(', ', $profile['keywords']); if (!empty($keywords)) { @@ -829,9 +888,6 @@ class Probe if (!empty($profile['country'])) { $loc['country-name'] = $profile['country']; } - if (!empty($profile['hometown'])) { - $loc['locality'] = $profile['hometown']; - } $location = Profile::formatLocation($loc); if (!empty($location)) { $data['location'] = $location; @@ -842,7 +898,7 @@ class Probe } /** - * @brief Perform a webfinger request. + * Perform a webfinger request. * * For details see RFC 7033: * @@ -854,7 +910,7 @@ class Probe */ private static function webfinger($url, $type) { - $xrd_timeout = Config::get('system', 'xrd_timeout', 20); + $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20); $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($curlResult->isTimeout()) { @@ -912,7 +968,7 @@ class Probe } /** - * @brief Poll the Friendica specific noscrape page. + * Poll the Friendica specific noscrape page. * * "noscrape" is a faster alternative to fetch the data from the hcard. * This functionality was originally created for the directory. @@ -978,10 +1034,6 @@ class Probe $data["about"] = $json["about"]; } - if (!empty($json["gender"])) { - $data["gender"] = $json["gender"]; - } - if (!empty($json["key"])) { $data["pubkey"] = $json["key"]; } @@ -1016,7 +1068,7 @@ class Probe } /** - * @brief Check for valid DFRN data + * Check for valid DFRN data * * @param array $data DFRN data * @@ -1044,7 +1096,7 @@ class Probe } /** - * @brief Fetch data from a DFRN profile page and via "noscrape" + * Fetch data from a DFRN profile page and via "noscrape" * * @param string $profile_link Link to the profile page * @@ -1096,7 +1148,7 @@ class Probe } /** - * @brief Check for DFRN contact + * Check for DFRN contact * * @param array $webfinger Webfinger data * @@ -1176,7 +1228,7 @@ class Probe } /** - * @brief Poll the hcard page (Diaspora and Friendica specific) + * Poll the hcard page (Diaspora and Friendica specific) * * @param string $hcard_url Link to the hcard page * @param array $data The already fetched data @@ -1304,7 +1356,7 @@ class Probe } /** - * @brief Check for Diaspora contact + * Check for Diaspora contact * * @param array $webfinger Webfinger data * @@ -1392,7 +1444,7 @@ class Probe } /** - * @brief Check for OStatus contact + * Check for OStatus contact * * @param array $webfinger Webfinger data * @param bool $short Short detection mode @@ -1519,7 +1571,7 @@ class Probe } /** - * @brief Fetch data from a pump.io profile page + * Fetch data from a pump.io profile page * * @param string $profile_link Link to the profile page * @@ -1580,7 +1632,7 @@ class Probe } /** - * @brief Check for pump.io contact + * Check for pump.io contact * * @param array $webfinger Webfinger data * @param string $addr @@ -1637,7 +1689,7 @@ class Probe } /** - * @brief Check for twitter contact + * Check for twitter contact * * @param string $uri * @@ -1697,7 +1749,7 @@ class Probe } /** - * @brief Check page for feed link + * Check page for feed link * * @param string $url Page link * @@ -1744,7 +1796,7 @@ class Probe } /** - * @brief Check for feed contact + * Check for feed contact * * @param string $url Profile link * @param boolean $probe Do a probe if the page contains a feed link @@ -1807,7 +1859,7 @@ class Probe } /** - * @brief Check for mail contact + * Check for mail contact * * @param string $uri Profile link * @param integer $uid User ID @@ -1895,7 +1947,7 @@ class Probe } /** - * @brief Mix two paths together to possibly fix missing parts + * Mix two paths together to possibly fix missing parts * * @param string $avatar Path to the avatar * @param string $base Another path that is hopefully complete