use Friendica\Network\HTTPException;
use Friendica\Object\Search\ContactResult;
use Friendica\Object\Search\ResultList;
+use Friendica\Util\Network;
/**
* Base class for search modules
$header = DI::l10n()->t('People Search - %s', $search);
if (strrpos($search, '@') > 0) {
- $results = Search::getContactsFromProbe($search);
+ $results = Search::getContactsFromProbe(Network::convertToIdn($search));
}
}
$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'));
use Friendica\Model\Tag;
use Friendica\Module\BaseSearch;
use Friendica\Network\HTTPException;
+use Friendica\Util\Network;
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) {
return;
}
+ $search = Network::convertToIdn($search);
+
if (local_user()) {
// Post URL search
$item_id = Item::fetchByLink($search, local_user());
*/
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");
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
*
(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