1
0
Fork 0

Merge pull request #12802 from nupplaphil/feat/system_url_handling

Transform BaseURL to URIInterface conform class with less business logic
This commit is contained in:
Hypolite Petovan 2023-02-20 08:43:00 -05:00 committed by GitHub
commit ee5acc29c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 829 additions and 1471 deletions

View file

@ -570,7 +570,7 @@ class Contact
{
if (!parse_url($url, PHP_URL_SCHEME)) {
$addr_parts = explode('@', $url);
return (count($addr_parts) == 2) && ($addr_parts[1] == DI::baseUrl()->getHostname());
return (count($addr_parts) == 2) && ($addr_parts[1] == DI::baseUrl()->getHost());
}
return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl());

View file

@ -408,7 +408,7 @@ class Item
if ($notify) {
// We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri.
// We add the hash of our own host because our host is the original creator of the post.
$prefix_host = DI::baseUrl()->getHostname();
$prefix_host = DI::baseUrl()->getHost();
} else {
$prefix_host = '';
@ -2048,7 +2048,7 @@ class Item
$guid = System::createUUID();
}
return DI::baseUrl()->get() . '/objects/' . $guid;
return DI::baseUrl() . '/objects/' . $guid;
}
/**
@ -2288,7 +2288,7 @@ class Item
}
// Prevent to forward already forwarded posts
if ($datarray['app'] == DI::baseUrl()->getHostname()) {
if ($datarray['app'] == DI::baseUrl()->getHost()) {
Logger::info('Already forwarded (second test)');
return false;
}

View file

@ -171,7 +171,7 @@ class Nodeinfo
return [
'name' => $administrator['username'] ?? null,
'contact' => $administrator['email'] ?? null,
'account' => $administrator['nickname'] ?? '' ? DI::baseUrl()->get() . '/profile/' . $administrator['nickname'] : null,
'account' => $administrator['nickname'] ?? '' ? DI::baseUrl() . '/profile/' . $administrator['nickname'] : null,
];
}
}

View file

@ -918,7 +918,7 @@ class Photo
*/
public static function getResourceData(string $name): array
{
$base = DI::baseUrl()->get();
$base = DI::baseUrl();
$guid = str_replace([Strings::normaliseLink($base), '/photo/'], '', Strings::normaliseLink($name));
@ -982,7 +982,7 @@ class Photo
*/
public static function isLocalPage(string $name): bool
{
$base = DI::baseUrl()->get();
$base = DI::baseUrl();
$guid = str_replace(Strings::normaliseLink($base), '', Strings::normaliseLink($name));
$guid = preg_replace("=/photos/.*/image/(.*)=ism", '$1', $guid);

View file

@ -334,7 +334,7 @@ class Profile
if (!$local_user_is_self) {
if (!$visitor_is_authenticated) {
// Remote follow is only available for local profiles
if (!empty($profile['nickname']) && strpos($profile_url, DI::baseUrl()->get()) === 0) {
if (!empty($profile['nickname']) && strpos($profile_url, DI::baseUrl()) === 0) {
$follow_link = 'profile/' . $profile['nickname'] . '/remote_follow';
}
} else {
@ -756,13 +756,13 @@ class Profile
$query = rtrim(str_replace($addr_request, '', DI::args()->getQueryString()), '?&');
// The other instance needs to know where to redirect.
$dest = urlencode(DI::baseUrl()->get() . '/' . $query);
$dest = urlencode(DI::baseUrl() . '/' . $query);
// We need to extract the basebath from the profile url
// to redirect the visitors '/magic' module.
$basepath = Contact::getBasepath($contact['url']);
if ($basepath != DI::baseUrl()->get() && !strstr($dest, '/magic')) {
if ($basepath != DI::baseUrl() && !strstr($dest, '/magic')) {
$magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
// We have to check if the remote server does understand /magic without invoking something
@ -870,7 +870,7 @@ class Profile
$a->setContactId($arr['visitor']['id']);
DI::sysmsg()->addInfo(DI::l10n()->t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHostname(), $visitor['name']));
DI::sysmsg()->addInfo(DI::l10n()->t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHost(), $visitor['name']));
Logger::info('OpenWebAuth: auth success from ' . $visitor['addr']);
}

View file

@ -166,7 +166,7 @@ class User
$system['region'] = '';
$system['postal-code'] = '';
$system['country-name'] = '';
$system['homepage'] = DI::baseUrl()->get();
$system['homepage'] = DI::baseUrl();
$system['dob'] = '0000-00-00';
// Ensure that the user contains data
@ -219,7 +219,7 @@ class User
'self' => true,
'network' => Protocol::ACTIVITYPUB,
'name' => 'System Account',
'addr' => $system_actor_name . '@' . DI::baseUrl()->getHostname(),
'addr' => $system_actor_name . '@' . DI::baseUrl()->getHost(),
'nick' => $system_actor_name,
'url' => DI::baseUrl() . '/friendica',
'pubkey' => $keys['pubkey'],
@ -1023,7 +1023,7 @@ class User
$_SESSION['register'] = 1;
$_SESSION['openid'] = $openid_url;
$openid = new LightOpenID(DI::baseUrl()->getHostname());
$openid = new LightOpenID(DI::baseUrl()->getHost());
$openid->identity = $openid_url;
$openid->returnUrl = DI::baseUrl() . '/openid';
$openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
@ -1360,7 +1360,7 @@ class User
$l10n,
$user,
DI::config()->get('config', 'sitename'),
DI::baseUrl()->get(),
DI::baseUrl(),
($register['password'] ?? '') ?: 'Sent in a previous email'
);
}
@ -1457,7 +1457,7 @@ class User
Thank you and welcome to %4$s.'));
$preamble = sprintf($preamble, $user['username'], DI::config()->get('config', 'sitename'));
$body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
$body = sprintf($body, DI::baseUrl(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
$email = DI::emailer()
->newSystemMail()

View file

@ -59,7 +59,7 @@ class Cookie
*/
public function __construct(App\Request $request, IManageConfigValues $config, App\BaseURL $baseURL, array $COOKIE = [])
{
$this->sslEnabled = $baseURL->getSSLPolicy() === App\BaseURL::SSL_POLICY_FULL;
$this->sslEnabled = $baseURL->getScheme() === 'https';
$this->sitePrivateKey = $config->get('system', 'site_prvkey');
$authCookieDays = $config->get('system', 'auth_cookie_lifetime',