]> git.mxchange.org Git - friendica.git/blobdiff - mod/redir.php
Move mod/follow to src/Modules
[friendica.git] / mod / redir.php
index e96a58b63a965f50ef70016481be5b38c46f3571..903c6b2a354f074b7f5de0caa039c167b14f2e22 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 use Friendica\App;
 use Friendica\Core\Logger;
-use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
+use Friendica\Network\HTTPClient\Client\HttpClientAccept;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Util\Strings;
 
 function redir_init(App $a) {
-       if (!Session::isAuthenticated()) {
+       if (!DI::userSession()->isAuthenticated()) {
                throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
        }
 
@@ -50,7 +51,7 @@ function redir_init(App $a) {
        }
 
        $fields = ['id', 'uid', 'nurl', 'url', 'addr', 'name'];
-       $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, local_user()]]);
+       $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, DI::userSession()->getLocalUserId()]]);
        if (!DBA::isResult($contact)) {
                throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
        }
@@ -63,10 +64,10 @@ function redir_init(App $a) {
                $a->redirect($url ?: $contact_url);
        }
 
-       if ($contact['uid'] == 0 && local_user()) {
+       if ($contact['uid'] == 0 && DI::userSession()->getLocalUserId()) {
                // Let's have a look if there is an established connection
                // between the public contact we have found and the local user.
-               $contact = DBA::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => local_user()]);
+               $contact = DBA::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => DI::userSession()->getLocalUserId()]);
 
                if (DBA::isResult($contact)) {
                        $cid = $contact['id'];
@@ -81,7 +82,7 @@ function redir_init(App $a) {
                }
        }
 
-       if (remote_user()) {
+       if (DI::userSession()->getRemoteUserId()) {
                $host = substr(DI::baseUrl()->getUrlPath() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''), strpos(DI::baseUrl()->getUrlPath(), '://') + 3);
                $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1);
 
@@ -89,7 +90,7 @@ function redir_init(App $a) {
                // with the local contact. Otherwise the local user would ask the local contact
                // for authentification everytime he/she is visiting a profile page of the local
                // contact.
-               if (($host == $remotehost) && (Session::getRemoteContactID(Session::get('visitor_visiting')) == Session::get('visitor_id'))) {
+               if (($host == $remotehost) && (DI::userSession()->getRemoteContactID(DI::session()->get('visitor_visiting')) == DI::session()->get('visitor_id'))) {
                        // Remote user is already authenticated.
                        redir_check_url($contact_url, $url);
                        $target_url = $url ?: $contact_url;
@@ -142,7 +143,7 @@ function redir_magic($a, $cid, $url)
        }
 
        // Test for magic auth on the target system
-       $serverret = DI::httpClient()->get($basepath . '/magic');
+       $serverret = DI::httpClient()->head($basepath . '/magic', [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::HTML]);
        if ($serverret->isSuccess()) {
                $separator = strpos($target_url, '?') ? '&' : '?';
                $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);