From: Michael Date: Wed, 11 May 2022 06:34:25 +0000 (+0000) Subject: Issue 11487: IDN support added X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=47808ab0e9416a465093075a086aa6a41f385592;p=friendica.git Issue 11487: IDN support added --- diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index ca5bb76127..3497ad9b1d 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -30,6 +30,7 @@ use Friendica\Model; use Friendica\Network\HTTPException; use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ResultList; +use Friendica\Util\Network; /** * Base class for search modules @@ -68,7 +69,7 @@ class BaseSearch extends BaseModule $header = DI::l10n()->t('People Search - %s', $search); if (strrpos($search, '@') > 0) { - $results = Search::getContactsFromProbe($search); + $results = Search::getContactsFromProbe(Network::convertToIdn($search)); } } @@ -78,6 +79,8 @@ class BaseSearch extends BaseModule $header = DI::l10n()->t('Forum Search - %s', $search); } + $search = Network::convertToIdn($search); + if (DI::mode()->isMobile()) { $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', DI::config()->get('system', 'itemspage_network_mobile')); diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 93c1af7aa6..4b161e39ce 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -38,6 +38,7 @@ use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Module\BaseSearch; use Friendica\Network\HTTPException; +use Friendica\Util\Network; class Index extends BaseSearch { @@ -226,7 +227,8 @@ class Index extends BaseSearch */ private static function tryRedirectToProfile(string $search) { - $isUrl = !empty(parse_url($search, PHP_URL_SCHEME)); + $search = Network::convertToIdn($search); + $isUrl = !empty(parse_url($search, PHP_URL_SCHEME)); $isAddr = (bool)preg_match('/^@?([a-z0-9.-_]+@[a-z0-9.-_:]+)$/i', trim($search), $matches); if (!$isUrl && !$isAddr) { @@ -274,6 +276,8 @@ class Index extends BaseSearch return; } + $search = Network::convertToIdn($search); + if (local_user()) { // Post URL search $item_id = Item::fetchByLink($search, local_user()); diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 82d608f2c4..70ab396fed 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -65,6 +65,8 @@ class Probe */ public static function cleanURI(string $rawUri): string { + $rawUri = Network::convertToIdn($rawUri); + // At first remove leading and trailing junk $rawUri = trim($rawUri, "@#?:/ \t\n\r\0\x0B"); @@ -243,49 +245,6 @@ class Probe return $lrdd; } - /** - * 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 - * is located, returns an OStatus subscription template (prefixed - * with the string 'stat:' to identify it as on OStatus template). - * If this isn't an email style address just return $webbie. - * Return an empty string if email-style addresses but webfinger fails, - * or if the resultant personal XRD doesn't contain a supported - * subscription/friend-request attribute. - * - * amended 7/9/2011 to return an hcard which could save potentially loading - * a lengthy content page to scrape dfrn attributes - * - * @param string $webbie Address that should be probed - * @param string $hcard_url Link to the hcard - is returned by reference - * - * @return string profile link - * @throws HTTPException\InternalServerErrorException - */ - public static function webfingerDfrn(string $webbie, string &$hcard_url) - { - $profile_link = ''; - - $links = self::lrdd($webbie); - Logger::debug('Result', ['url' => $webbie, 'links' => $links]); - if (!empty($links) && is_array($links)) { - foreach ($links as $link) { - if ($link['@attributes']['rel'] === ActivityNamespace::DFRN) { - $profile_link = $link['@attributes']['href']; - } - if (($link['@attributes']['rel'] === ActivityNamespace::OSTATUSSUB) && ($profile_link == "")) { - $profile_link = 'stat:'.$link['@attributes']['template']; - } - if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') { - $hcard_url = $link['@attributes']['href']; - } - } - } - return $profile_link; - } - /** * Check an URI for LRDD data * diff --git a/src/Util/Network.php b/src/Util/Network.php index 7e72404287..bc374c2bcc 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -462,6 +462,27 @@ class Network (strlen($fragment) ? "#".$fragment : ''); } + /** + * Convert an URI to an IDN compatible URI + * + * @param string $uri + * @return string + */ + public static function convertToIdn(string $uri): string + { + $parts = parse_url($uri); + if (!empty($parts['scheme']) && !empty($parts['host'])) { + $parts['host'] = idn_to_ascii($parts['host']); + $uri = self::unparseURL($parts); + } elseif (strstr($uri, '@')) { + $host = idn_to_ascii(substr($uri, strpos($uri, '@') + 1)); + $nick = substr($uri, 0, strpos($uri, '@')); + + $uri = $nick . '@' . $host; + } + + return $uri; + } /** * Switch the scheme of an url between http and https