]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Magic.php
Merge pull request #7848 from annando/mail-hooks
[friendica.git] / src / Module / Magic.php
index 491ed31cbd4a4bd0c24036ea45a398325d078251..0f610d123c3c0b7a1a2dc9795f9f2c96ddc3b2f4 100644 (file)
@@ -20,7 +20,7 @@ use Friendica\Util\Strings;
  */
 class Magic extends BaseModule
 {
-       public static function init()
+       public static function init(array $parameters = [])
        {
                $a = self::getApp();
                $ret = ['success' => false, 'url' => '', 'message' => ''];
@@ -28,22 +28,20 @@ class Magic extends BaseModule
 
                Logger::log('args: ' . print_r($_REQUEST, true), Logger::DATA);
 
-               $addr = defaults($_REQUEST, 'addr', '');
-               $dest = defaults($_REQUEST, 'dest', '');
+               $addr = $_REQUEST['addr'] ?? '';
+               $dest = $_REQUEST['dest'] ?? '';
                $test = (!empty($_REQUEST['test']) ? intval($_REQUEST['test']) : 0);
                $owa  = (!empty($_REQUEST['owa'])  ? intval($_REQUEST['owa'])  : 0);
+               $cid  = 0;
 
-               // NOTE: I guess $dest isn't just the profile url (could be also
-               // other profile pages e.g. photo). We need to find a solution
-               // to be able to redirct to other pages than the contact profile.
-               $cid = Contact::getIdForURL($dest);
-
-               if (!$cid && !empty($addr)) {
+               if (!empty($addr)) {
                        $cid = Contact::getIdForURL($addr);
+               } elseif (!empty($dest)) {
+                       $cid = Contact::getIdForURL($dest);
                }
 
                if (!$cid) {
-                       Logger::log('No contact record found: ' . json_encode($_REQUEST), Logger::DEBUG);
+                       Logger::info('No contact record found', $_REQUEST);
                        // @TODO Finding a more elegant possibility to redirect to either internal or external URL
                        $a->redirect($dest);
                }
@@ -85,7 +83,7 @@ class Magic extends BaseModule
                                );
 
                                // Try to get an authentication token from the other instance.
-                               $curlResult = Network::curl($basepath . '/owa', false, $redirects, ['headers' => $headers]);
+                               $curlResult = Network::curl($basepath . '/owa', false, ['headers' => $headers]);
 
                                if ($curlResult->isSuccess()) {
                                        $j = json_decode($curlResult->getBody(), true);
@@ -99,9 +97,9 @@ class Magic extends BaseModule
                                                } else {
                                                        $token = $j['token'];
                                                }
-                                               $x = strpbrk($dest, '?&');
-                                               $args = (($x) ? '&owt=' . $token : '?f=&owt=' . $token);
+                                               $args = (strpbrk($dest, '?&') ? '&' : '?') . 'owt=' . $token;
 
+                                               Logger::info('Redirecting', ['path' => $dest . $args]);
                                                System::externalRedirect($dest . $args);
                                        }
                                }