Merge pull request #11489 from annando/issue-11487
Issue 11487: IDN support added
This commit is contained in:
commit
b5129eb4ed
4 changed files with 32 additions and 45 deletions
|
@ -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'));
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue