]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into public-redir
authorMichael <heluecht@pirati.ca>
Fri, 1 Jun 2018 12:32:51 +0000 (12:32 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 1 Jun 2018 12:32:51 +0000 (12:32 +0000)
include/conversation.php
mod/redir.php
src/Model/Contact.php
src/Object/Post.php

index 60fa0e4ecd71cb7dee293f320fe14de2ab51d238..5f56723e2e361e47b84b15e7dc10439fc3e043ba 100644 (file)
@@ -347,16 +347,7 @@ function localize_item(&$item) {
        }
 
        // add sparkle links to appropriate permalinks
-
-       $x = stristr($item['plink'],'/display/');
-       if ($x) {
-               $sparkle = false;
-               $y = best_link_url($item, $sparkle);
-
-               if (strstr($y, '/redir/')) {
-                       $item['plink'] = $y . '?f=&url=' . $item['plink'];
-               }
-       }
+       $item['plink'] = Contact::magicLink($item['author-link'], $item['plink']);
 }
 
 /**
@@ -674,16 +665,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
 
                                $tags = \Friendica\Model\Term::populateTagsFromItem($item);
 
-                               $sp = false;
-                               $profile_link = best_link_url($item, $sp);
-                               if ($profile_link === 'mailbox') {
-                                       $profile_link = '';
-                               }
+                               $profile_link = Contact::magicLink($item['author-link']);
 
-                               if ($sp) {
+                               if (strpos($profile_link, 'redir/') === 0) {
                                        $sparkle = ' sparkle';
-                               } else {
-                                       $profile_link = Profile::zrl($profile_link);
                                }
 
                                if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
@@ -978,11 +963,8 @@ function item_photo_menu($item) {
                $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
        }
 
-       $sparkle = false;
-       $profile_link = best_link_url($item, $sparkle);
-       if ($profile_link === 'mailbox') {
-               $profile_link = '';
-       }
+       $profile_link = Contact::magicLink($item['author-link']);
+       $sparkle = (strpos($profile_link, 'redir/') === 0);
 
        $cid = 0;
        $network = '';
@@ -1088,12 +1070,9 @@ function builtin_activity_puller($item, &$conv_responses) {
                }
 
                if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
-                       $url = $item['author-link'];
-                       if (local_user() && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && !$item['self'] && link_compare($item['author-link'], $item['url'])) {
-                               $url = 'redir/' . $item['contact-id'];
+                       $url = Contact::MagicLink($item['author-link']);
+                       if (strpos($url, 'redir/') === 0) {
                                $sparkle = ' class="sparkle" ';
-                       } else {
-                               $url = Profile::zrl($url);
                        }
 
                        $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
index b7292384268a4bc21f94e62b4c242701e54bd4f9..e290a29da78a4f322fd038f7567c66c9182408c7 100644 (file)
@@ -1,89 +1,94 @@
 <?php
 
 use Friendica\App;
+use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Model\Contact;
+use Friendica\Model\Profile;
 
 function redir_init(App $a) {
 
-       $url = ((x($_GET,'url')) ? $_GET['url'] : '');
-       $quiet = ((x($_GET,'quiet')) ? '&quiet=1' : '');
-       $con_url = ((x($_GET,'conurl')) ? $_GET['conurl'] : '');
+       $url = defaults($_GET, 'url', '');
+       $quiet = !empty($_GET['quiet']) ? '&quiet=1' : '';
+       $con_url = defaults($_GET, 'conurl', '');
 
-       // traditional DFRN
+       if (local_user() && ($a->argc > 1) && intval($a->argv[1])) {
+               $cid = intval($a->argv[1]);
+       } elseif (local_user() && !empty($con_url)) {
+               $cid = Contact::getIdForURL($con_url, local_user());
+       } else {
+               $cid = 0;
+       }
 
-       if ($con_url || (local_user() && $a->argc > 1 && intval($a->argv[1]))) {
+       if (!empty($cid)) {
+               $fields = ['id', 'uid', 'nurl', 'url', 'name', 'network', 'poll', 'issued-id', 'dfrn-id', 'duplex'];
+               $contact = dba::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, local_user()]]);
+               if (!DBM::is_result($contact)) {
+                       notice(L10n::t('Contact not found.'));
+                       goaway(System::baseUrl());
+               }
 
-               if ($con_url) {
-                       $con_url = str_replace('https', 'http', $con_url);
+               if ($contact['network'] !== NETWORK_DFRN) {
+                       goaway(($url != '' ? $url : $contact['url']));
+               }
 
-                       $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc($con_url),
-                               intval(local_user())
-                       );
+               if ($contact['uid'] == 0) {
+                       $contact_url = $contact['url'];
+                       $contact = dba::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => local_user()]);
+                       if (!DBM::is_result($contact)) {
+                               $target_url = ($url != '' ? $url : $contact_url);
 
-                       if (!DBM::is_result($r)) {
-                               goaway(System::baseUrl());
-                       }
-                       if ($r[0]['network'] !== NETWORK_DFRN) {
-                               goaway(($url != '' ? $url : $r[0]['url']));
-                       }
-                       $cid = $r[0]['id'];
-               } else {
-                       $cid = $a->argv[1];
+                               $my_profile = Profile::getMyURL();
 
-                       $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                               intval($cid),
-                               intval(local_user())
-                       );
+                               if (!empty($my_profile) && !link_compare($my_profile, $target_url)) {
+                                       $separator = strpos($target_url, '?') ? '&' : '?';
 
-                       if (!DBM::is_result($r)) {
-                               goaway(System::baseUrl());
-                       }
-                       if ($r[0]['network'] !== NETWORK_DFRN) {
-                               goaway(($url != '' ? $url : $r[0]['url']));
+                                       $target_url .= $separator . 'zrl=' . urlencode($my_profile);
+                               }
+                               goaway($target_url);
+                       } else {
+                               $cid = $contact['id'];
                        }
                }
 
-               $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
+               $dfrn_id = $orig_id = (($contact['issued-id']) ? $contact['issued-id'] : $contact['dfrn-id']);
 
-               if ($r[0]['duplex'] && $r[0]['issued-id']) {
-                       $orig_id = $r[0]['issued-id'];
+               if ($contact['duplex'] && $contact['issued-id']) {
+                       $orig_id = $contact['issued-id'];
                        $dfrn_id = '1:' . $orig_id;
                }
-               if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
-                       $orig_id = $r[0]['dfrn-id'];
+               if ($contact['duplex'] && $contact['dfrn-id']) {
+                       $orig_id = $contact['dfrn-id'];
                        $dfrn_id = '0:' . $orig_id;
                }
 
                $sec = random_string();
 
-               q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
-                       VALUES( %d, %s, '%s', '%s', %d )",
-                       intval(local_user()),
-                       intval($cid),
-                       dbesc($dfrn_id),
-                       dbesc($sec),
-                       intval(time() + 45)
-               );
-
-               logger('mod_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
-               $dest = (($url) ? '&destination_url=' . $url : '');
-               goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
+               $fields = ['uid' => local_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id,
+                       'sec' => $sec, 'expire' => time() + 45];
+               dba::insert('profile_check', $fields);
+
+               logger('mod_redir: ' . $contact['name'] . ' ' . $sec, LOGGER_DEBUG);
+
+               $dest = (!empty($url) ? '&destination_url=' . $url : '');
+
+               goaway($contact['poll'] . '?dfrn_id=' . $dfrn_id
                        . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet);
        }
 
        if (local_user()) {
-               $handle = $a->user['nickname'] . '@' . substr(System::baseUrl(),strpos(System::baseUrl(),'://')+3);
+               $handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
        }
        if (remote_user()) {
                $handle = $_SESSION['handle'];
        }
 
-       if ($url) {
-               $url = str_replace('{zid}','&zid=' . $handle,$url);
+       if (!empty($url)) {
+               $url = str_replace('{zid}', '&zid=' . $handle, $url);
                goaway($url);
        }
 
+       notice(L10n::t('Contact not found.'));
        goaway(System::baseUrl());
 }
index bbfb399238df47f38b8c69ad5b9ae2c91430b00a..4a6ddd52dbabdfbf6a7ef941859fa22861904ad0 100644 (file)
@@ -1686,4 +1686,49 @@ class Contact extends BaseObject
 
                $contact_ids = $return;
        }
+
+       /**
+        * @brief Returns a magic link to authenticate remote visitors
+        *
+        * @param string $contact_url The address of the target contact profile
+        * @param integer $url An url that we will be redirected to after the authentication
+        *
+        * @return string with "redir" link
+        */
+       public static function magicLink($contact_url, $url = '')
+       {
+               $cid = self::getIdForURL($contact_url);
+               if (empty($cid)) {
+                       return ($url != '') ? $url : $contact_url;
+               }
+
+               return self::magicLinkbyId($cid, $url);
+       }
+
+       /**
+        * @brief Returns a magic link to authenticate remote visitors
+        *
+        * @param integer $cid The contact id of the target contact profile
+        * @param integer $url An url that we will be redirected to after the authentication
+        *
+        * @return string with "redir" link
+        */
+       public static function magicLinkbyId($cid, $url = '')
+       {
+               // Direkt auf die URL verweisen, wenn die Host-Angaben unterschiedlich sind
+
+               $contact = dba::selectFirst('contact', ['network', 'url'], ['id' => $cid]);
+
+               if ($contact['network'] != NETWORK_DFRN) {
+                       return ($url != '') ? $url : $contact['url'];
+               }
+
+               $redirect = 'redir/' . $cid;
+
+               if ($url != '') {
+                       $redirect .= '?url=' . $url;
+               }
+
+               return $redirect;
+        }
 }
index b47bbd69fe866556f3016785ab724d097e51d244..86fe2fa999817764e4799fe2da951a889b8b5ce6 100644 (file)
@@ -205,16 +205,9 @@ class Post extends BaseObject
                        $profile_name = $item['author-link'];
                }
 
-               $sp = false;
-               $profile_link = best_link_url($item, $sp);
-               if ($profile_link === 'mailbox') {
-                       $profile_link = '';
-               }
-
-               if ($sp) {
+               $profile_link = Contact::magicLink($item['author-link']);
+               if (strpos($profile_link, 'redir/') === 0) {
                        $sparkle = ' sparkle';
-               } else {
-                       $profile_link = Profile::zrl($profile_link);
                }
 
                if (($item['network'] == NETWORK_FEED) || empty($item['author-thumb'])) {