]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11487: IDN support added
authorMichael <heluecht@pirati.ca>
Wed, 11 May 2022 06:34:25 +0000 (06:34 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 11 May 2022 06:34:25 +0000 (06:34 +0000)
src/Module/BaseSearch.php
src/Module/Search/Index.php
src/Network/Probe.php
src/Util/Network.php

index ca5bb761275688fd927a36774f05ddb3ea0b43af..3497ad9b1d945365bee0e9bbc3bf2cfb355d2422 100644 (file)
@@ -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'));
index 93c1af7aa6d5874afb82f08d744ae4392969c893..4b161e39ce6d97ad9901342410c690a5eac0efcc 100644 (file)
@@ -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());
index 82d608f2c4f7190575b0e753bef545ec77eddc44..70ab396fede8be897481020cc591fbc7f91886f4 100644 (file)
@@ -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
         *
index 7e72404287471eb815e2f8f68241f223a1833d1b..bc374c2bcc348a43834017046d5583be978dd814 100644 (file)
@@ -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