]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Magic.php
Merge pull request #12895 from HankG/mastodon-status-edit-fix-deleting-all-images
[friendica.git] / src / Module / Magic.php
index c47a7a4d504dffce50bf9e1acd7647692c8accf3..1012dc72baffdbb57fddcb6e69b2ae50e32b7e19 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -24,13 +24,16 @@ namespace Friendica\Module;
 use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Model\Contact;
 use Friendica\Model\User;
 use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
+use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Util\HTTPSignature;
+use Friendica\Util\Profiler;
 use Friendica\Util\Strings;
 use Psr\Log\LoggerInterface;
 
@@ -43,26 +46,24 @@ class Magic extends BaseModule
 {
        /** @var App */
        protected $app;
-       /** @var LoggerInterface */
-       protected $logger;
        /** @var Database */
        protected $dba;
        /** @var ICanSendHttpRequests */
        protected $httpClient;
-       protected $baseUrl;
+       /** @var IHandleUserSessions */
+       protected $userSession;
 
-       public function __construct(App $app, App\BaseURL $baseUrl, LoggerInterface $logger, Database $dba, ICanSendHttpRequests $httpClient, L10n $l10n, array $parameters = [])
+       public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = [])
        {
-               parent::__construct($l10n, $parameters);
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               $this->app        = $app;
-               $this->logger     = $logger;
-               $this->dba        = $dba;
-               $this->httpClient = $httpClient;
-               $this->baseUrl    = $baseUrl;
+               $this->app         = $app;
+               $this->dba         = $dba;
+               $this->httpClient  = $httpClient;
+               $this->userSession = $userSession;
        }
 
-       public function rawContent()
+       protected function rawContent(array $request = [])
        {
                $this->logger->info('magic module: invoked');
 
@@ -87,14 +88,14 @@ class Magic extends BaseModule
                $contact = $this->dba->selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
 
                // Redirect if the contact is already authenticated on this site.
-               if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl->get())) !== false) {
+               if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) {
                        $this->logger->info('Contact is already authenticated');
                        System::externalRedirect($dest);
                }
 
                // OpenWebAuth
-               if (local_user() && $owa) {
-                       $user = User::getById(local_user());
+               if ($this->userSession->getLocalUserId() && $owa) {
+                       $user = User::getById($this->userSession->getLocalUserId());
 
                        // Extract the basepath
                        // NOTE: we need another solution because this does only work
@@ -112,11 +113,11 @@ class Magic extends BaseModule
                        $header = HTTPSignature::createSig(
                                $header,
                                $user['prvkey'],
-                               'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHostname() . ($this->baseUrl->getUrlPath() ? '/' . $this->baseUrl->getUrlPath() : '')
+                               'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHost() . ($this->baseUrl->getPath() ? '/' . $this->baseUrl->getPath() : '')
                        );
 
                        // Try to get an authentication token from the other instance.
-                       $curlResult = $this->httpClient->get($basepath . '/owa', [HttpClientOptions::HEADERS => $header]);
+                       $curlResult = $this->httpClient->get($basepath . '/owa', HttpClientAccept::DEFAULT, [HttpClientOptions::HEADERS => $header]);
 
                        if ($curlResult->isSuccess()) {
                                $j = json_decode($curlResult->getBody(), true);