]> git.mxchange.org Git - friendica.git/blobdiff - mod/redir.php
Ensure *toArray returns an array
[friendica.git] / mod / redir.php
index f8dfa3ab9fe8e115191b42d29758c8ce87b06da2..c99e1823c76c84f05de01e5a7a3adbe622909e34 100644 (file)
@@ -3,13 +3,13 @@
 use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
-use Friendica\Core\Protocol;
+use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
-use Friendica\Util\Strings;
 use Friendica\Util\Network;
+use Friendica\Util\Strings;
 
 function redir_init(App $a) {
 
@@ -71,7 +71,9 @@ function redir_init(App $a) {
                                && is_array($_SESSION['remote']))
                        {
                                foreach ($_SESSION['remote'] as $v) {
-                                       if ($v['uid'] == $_SESSION['visitor_visiting'] && $v['cid'] == $_SESSION['visitor_id']) {
+                                       if (!empty($v['uid']) && !empty($v['cid']) &&
+                                           $v['uid'] == Session::get('visitor_visiting') &&
+                                           $v['cid'] == Session::get('visitor_id')) {
                                                // Remote user is already authenticated.
                                                $target_url = defaults($url, $contact_url);
                                                Logger::log($contact['name'] . " is already authenticated. Redirecting to " . $target_url, Logger::DEBUG);
@@ -83,14 +85,15 @@ function redir_init(App $a) {
 
                // When the remote page does support OWA, then we enforce the use of it
                $basepath = Contact::getBasepath($contact_url);
-               $serverret = Network::curl($basepath . '/magic');
-               if ($serverret->isSuccess()) {
-                       $contact['issued-id'] = '';
-                       $contact['dfrn-id'] = '';
+               if (Strings::compareLink($basepath, System::baseUrl())) {
+                       $use_magic = true;
+               } else {
+                       $serverret = Network::curl($basepath . '/magic');
+                       $use_magic = $serverret->isSuccess();
                }
 
                // Doing remote auth with dfrn.
-               if (local_user() && (!empty($contact['dfrn-id']) || !empty($contact['issued-id'])) && empty($contact['pending'])) {
+               if (local_user() && !$use_magic && (!empty($contact['dfrn-id']) || !empty($contact['issued-id'])) && empty($contact['pending'])) {
                        $dfrn_id = $orig_id = (($contact['issued-id']) ? $contact['issued-id'] : $contact['dfrn-id']);
 
                        if ($contact['duplex'] && $contact['issued-id']) {