<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Contact;
+use Friendica\Network\HTTPException\NotModifiedException;
+use GuzzleHttp\Psr7\Uri;
class Network
{
return false;
}
+ /**
+ * Checks if the provided url is on the list of domains where redirects are blocked.
+ * Returns true if it is or malformed URL, false if not.
+ *
+ * @param string $url The url to check the domain from
+ *
+ * @return boolean
+ */
+ public static function isRedirectBlocked(string $url)
+ {
+ $host = @parse_url($url, PHP_URL_HOST);
+ if (!$host) {
+ return false;
+ }
+
+ $no_redirect_list = DI::config()->get('system', 'no_redirect_list', []);
+ if (!$no_redirect_list) {
+ return false;
+ }
+
+ foreach ($no_redirect_list as $no_redirect) {
+ if (fnmatch(strtolower($no_redirect), strtolower($host))) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/**
* Check if email address is allowed to register here.
*
$avatar['url'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
}
- Logger::log('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], Logger::DEBUG);
+ Logger::info('Avatar: ' . $avatar['email'] . ' ' . $avatar['url']);
return $avatar['url'];
}
*
* @param array $parsed URL parts
*
- * @return string The glued URL
+ * @return string The glued URL.
+ * @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead
*/
public static function unparseURL(array $parsed)
{
(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 = Uri::fromParts($parts);
+ } else {
+ $parts = explode('@', $uri);
+ if (count($parts) == 2) {
+ $uri = $parts[0] . '@' . idn_to_ascii($parts[1]);
+ } else {
+ $uri = idn_to_ascii($uri);
+ }
+ }
+
+ return $uri;
+ }
/**
* Switch the scheme of an url between http and https
header('Last-Modified: ' . $last_modified);
if ($flag_not_modified) {
- header("HTTP/1.1 304 Not Modified");
- exit;
+ throw new NotModifiedException();
}
}
+
+ /**
+ * Check if the given URL is a local link
+ *
+ * @param string $url
+ * @return bool
+ */
+ public static function isLocalLink(string $url)
+ {
+ return (strpos(Strings::normaliseLink($url), Strings::normaliseLink(DI::baseUrl())) !== false);
+ }
+
+ /**
+ * Check if the given URL is a valid HTTP/HTTPS URL
+ *
+ * @param string $url
+ * @return bool
+ */
+ public static function isValidHttpUrl(string $url)
+ {
+ $scheme = parse_url($url, PHP_URL_SCHEME);
+ return !empty($scheme) && in_array($scheme, ['http', 'https']) && parse_url($url, PHP_URL_HOST);
+ }
}