Merge pull request #5161 from annando/public-redir

"redir" is now centralized
This commit is contained in:
Hypolite Petovan 2018-06-02 09:18:10 -04:00 committed by GitHub
commit 541f8634c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 168 additions and 246 deletions

View file

@ -197,10 +197,10 @@ function localize_item(&$item) {
} }
} }
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]'; $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]'; $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto != "") { if ($Bphoto != "") {
$Bphoto = '[url=' . Profile::zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]'; $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img]' . $Bphoto . '[/img][/url]';
} }
$item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto; $item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
@ -234,10 +234,10 @@ function localize_item(&$item) {
} }
} }
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]'; $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]'; $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto != "") { if ($Bphoto != "") {
$Bphoto = '[url=' . Profile::zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]'; $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
} }
/* /*
@ -269,8 +269,8 @@ function localize_item(&$item) {
$obj = $r[0]; $obj = $r[0];
$author = '[url=' . Profile::zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]'; $author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . Profile::zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]'; $objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
switch ($obj['verb']) { switch ($obj['verb']) {
case ACTIVITY_POST: case ACTIVITY_POST:
@ -323,8 +323,8 @@ function localize_item(&$item) {
$target = $r[0]; $target = $r[0];
$Bname = $target['author-name']; $Bname = $target['author-name'];
$Blink = $target['author-link']; $Blink = $target['author-link'];
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]'; $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]'; $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
$P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]'; $P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
$item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n"; $item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
} }
@ -334,7 +334,7 @@ function localize_item(&$item) {
if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) { if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
foreach ($matches as $mtch) { foreach ($matches as $mtch) {
if (!strpos($mtch[1], 'zrl=')) { if (!strpos($mtch[1], 'zrl=')) {
$item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']); $item['body'] = str_replace($mtch[0], '@[url=' . Contact::magicLink($mtch[1]) . ']', $item['body']);
} }
} }
} }
@ -347,16 +347,7 @@ function localize_item(&$item) {
} }
// add sparkle links to appropriate permalinks // add sparkle links to appropriate permalinks
$item['plink'] = Contact::magicLinkById($item['author-id'], $item['plink']);
$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'];
}
}
} }
/** /**
@ -674,16 +665,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
$tags = \Friendica\Model\Term::populateTagsFromItem($item); $tags = \Friendica\Model\Term::populateTagsFromItem($item);
$sp = false; $profile_link = Contact::magicLinkbyId($item['author-id']);
$profile_link = best_link_url($item, $sp);
if ($profile_link === 'mailbox') {
$profile_link = '';
}
if ($sp) { if (strpos($profile_link, 'redir/') === 0) {
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} else {
$profile_link = Profile::zrl($profile_link);
} }
if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) { if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
@ -923,48 +908,6 @@ function conversation_add_children($parents, $block_authors, $order, $uid) {
return $items; return $items;
} }
function best_link_url($item, &$sparkle, $url = '') {
$best_url = '';
$sparkle = false;
$clean_url = normalise_link($item['author-link']);
if (local_user()) {
$condition = [
'network' => NETWORK_DFRN,
'uid' => local_user(),
'nurl' => normalise_link($clean_url),
'pending' => false
];
$contact = dba::selectFirst('contact', ['id'], $condition);
if (DBM::is_result($contact)) {
$best_url = 'redir/' . $contact['id'];
$sparkle = true;
if ($url != '') {
$hostname = get_app()->get_hostname();
if (!strstr($url, $hostname)) {
$best_url .= "?url=".$url;
} else {
$best_url = $url;
}
}
}
}
if (!$best_url) {
if ($url != '') {
$best_url = $url;
} elseif (strlen($item['author-link'])) {
$best_url = $item['author-link'];
} else {
$best_url = $item['url'];
}
}
return $best_url;
}
function item_photo_menu($item) { function item_photo_menu($item) {
$sub_link = ''; $sub_link = '';
$poke_link = ''; $poke_link = '';
@ -978,11 +921,8 @@ function item_photo_menu($item) {
$sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
} }
$sparkle = false; $profile_link = Contact::magicLinkById($item['author-id']);
$profile_link = best_link_url($item, $sparkle); $sparkle = (strpos($profile_link, 'redir/') === 0);
if ($profile_link === 'mailbox') {
$profile_link = '';
}
$cid = 0; $cid = 0;
$network = ''; $network = '';
@ -1000,7 +940,7 @@ function item_photo_menu($item) {
$photos_link = $profile_link . '?url=photos'; $photos_link = $profile_link . '?url=photos';
$profile_link = $profile_link . '?url=profile'; $profile_link = $profile_link . '?url=profile';
} else { } else {
$profile_link = Profile::zrl($profile_link); $profile_link = Contact::magicLink($profile_link);
} }
if ($cid && !$item['self']) { if ($cid && !$item['self']) {
@ -1088,12 +1028,9 @@ function builtin_activity_puller($item, &$conv_responses) {
} }
if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) { if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
$url = $item['author-link']; $url = Contact::MagicLinkbyId($item['author-id']);
if (local_user() && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && !$item['self'] && link_compare($item['author-link'], $item['url'])) { if (strpos($url, 'redir/') === 0) {
$url = 'redir/' . $item['contact-id'];
$sparkle = ' class="sparkle" '; $sparkle = ' class="sparkle" ';
} else {
$url = Profile::zrl($url);
} }
$url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>'; $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';

View file

@ -961,13 +961,9 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
$redir = false; $redir = false;
if ($redirect) { if ($redirect) {
$redirect_url = 'redir/' . $contact['id']; $url = Contact::magicLink($contact['url']);
if (local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) { if (strpos($url, 'redir/') === 0) {
$redir = true;
$url = $redirect_url;
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} else {
$url = Profile::zrl($url);
} }
} }
@ -1300,11 +1296,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
foreach ($matches as $mtch) { foreach ($matches as $mtch) {
$mime = $mtch[3]; $mime = $mtch[3];
if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) { $the_url = Contact::magicLinkById($item['author-id'], $mtch[1]);
$the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
} else {
$the_url = $mtch[1];
}
if (strpos($mime, 'video') !== false) { if (strpos($mime, 'video') !== false) {
if (!$vhead) { if (!$vhead) {

View file

@ -70,7 +70,7 @@ function allfriends_content(App $a)
} else { } else {
$connlnk = System::baseUrl() . '/follow/?url=' . $rr['url']; $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
$photo_menu = [ $photo_menu = [
'profile' => [L10n::t("View Profile"), Profile::zrl($rr['url'])], 'profile' => [L10n::t("View Profile"), Contact::magicLink($rr['url'])],
'follow' => [L10n::t("Connect/Follow"), $connlnk] 'follow' => [L10n::t("Connect/Follow"), $connlnk]
]; ];
} }

View file

@ -65,7 +65,7 @@ function contacts_init(App $a)
$vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [ $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
'$name' => htmlentities($a->data['contact']['name']), '$name' => htmlentities($a->data['contact']['name']),
'$photo' => $a->data['contact']['photo'], '$photo' => $a->data['contact']['photo'],
'$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/" . $a->data['contact']['id'] : $a->data['contact']['url'], '$url' => Contact::MagicLink($a->data['contact']['url']),
'$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""), '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
'$network_name' => $networkname, '$network_name' => $networkname,
'$network' => L10n::t('Network:'), '$network' => L10n::t('Network:'),
@ -536,11 +536,10 @@ function contacts_content(App $a)
$relation_text = sprintf($relation_text, htmlentities($contact['name'])); $relation_text = sprintf($relation_text, htmlentities($contact['name']));
if (($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) { $url = Contact::magicLink($contact['url']);
$url = "redir/{$contact['id']}"; if (strpos($url, 'redir/') === 0) {
$sparkle = ' class="sparkle" '; $sparkle = ' class="sparkle" ';
} else { } else {
$url = $contact['url'];
$sparkle = ''; $sparkle = '';
} }
@ -940,11 +939,11 @@ function _contact_detail_for_template($rr)
default: default:
break; break;
} }
if (($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
$url = "redir/{$rr['id']}"; $url = Contact::magicLink($rr['url']);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' class="sparkle" '; $sparkle = ' class="sparkle" ';
} else { } else {
$url = $rr['url'];
$sparkle = ''; $sparkle = '';
} }

View file

@ -189,7 +189,6 @@ function dfrn_request_post(App $a)
} }
// (ignore reply, nothing we can do it failed) // (ignore reply, nothing we can do it failed)
// Old: goaway(Profile::zrl($dfrn_url));
goaway($forwardurl); goaway($forwardurl);
return; // NOTREACHED return; // NOTREACHED
} }

View file

@ -156,7 +156,7 @@ function directory_content(App $a)
$location_e = $location; $location_e = $location;
$photo_menu = [ $photo_menu = [
'profile' => [L10n::t("View Profile"), Profile::zrl($profile_link)] 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
]; ];
$entry = [ $entry = [

View file

@ -11,7 +11,6 @@ use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Network; use Friendica\Util\Network;
@ -214,7 +213,7 @@ function dirfind_content(App $a, $prefix = "") {
$connlnk = System::baseUrl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url); $connlnk = System::baseUrl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
$conntxt = L10n::t('Connect'); $conntxt = L10n::t('Connect');
$photo_menu = [ $photo_menu = [
'profile' => [L10n::t("View Profile"), Profile::zrl($jj->url)], 'profile' => [L10n::t("View Profile"), Contact::magicLink($jj->url)],
'follow' => [L10n::t("Connect/Follow"), $connlnk] 'follow' => [L10n::t("Connect/Follow"), $connlnk]
]; ];
} }
@ -223,7 +222,7 @@ function dirfind_content(App $a, $prefix = "") {
$entry = [ $entry = [
'alt_text' => $alt_text, 'alt_text' => $alt_text,
'url' => Profile::magicLink($jj->url), 'url' => Contact::magicLink($jj->url),
'itemurl' => $itemurl, 'itemurl' => $itemurl,
'name' => htmlentities($jj->name), 'name' => htmlentities($jj->name),
'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB), 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),

View file

@ -72,7 +72,7 @@ function hovercard_content()
'nick' => $contact['nick'], 'nick' => $contact['nick'],
'addr' => defaults($contact, 'addr', $contact['url']), 'addr' => defaults($contact, 'addr', $contact['url']),
'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB), 'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
'url' => $cid ? ('redir/' . $cid) : Profile::zrl($contact['url']), 'url' => Contact::magicLink($contact['url']),
'nurl' => $contact['nurl'], // We additionally store the nurl as identifier 'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
'location' => $contact['location'], 'location' => $contact['location'],
'gender' => $contact['gender'], 'gender' => $contact['gender'],

View file

@ -86,14 +86,14 @@ function match_content(App $a)
$jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo); $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
$connlnk = System::baseUrl() . '/follow/?url=' . $jj->url; $connlnk = System::baseUrl() . '/follow/?url=' . $jj->url;
$photo_menu = [ $photo_menu = [
'profile' => [L10n::t("View Profile"), Profile::zrl($jj->url)], 'profile' => [L10n::t("View Profile"), Contact::magicLink($jj->url)],
'follow' => [L10n::t("Connect/Follow"), $connlnk] 'follow' => [L10n::t("Connect/Follow"), $connlnk]
]; ];
$contact_details = Contact::getDetailsByURL($jj->url, local_user()); $contact_details = Contact::getDetailsByURL($jj->url, local_user());
$entry = [ $entry = [
'url' => Profile::zrl($jj->url), 'url' => Contact::magicLink($jj->url),
'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $jj->url), 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $jj->url),
'name' => $jj->name, 'name' => $jj->name,
'details' => $contact_details['location'], 'details' => $contact_details['location'],

View file

@ -341,11 +341,8 @@ function message_content(App $a)
if ($message['from-url'] == $myprofile) { if ($message['from-url'] == $myprofile) {
$from_url = $myprofile; $from_url = $myprofile;
$sparkle = ''; $sparkle = '';
} elseif ($message['contact-id'] != 0) {
$from_url = 'redir/' . $message['contact-id'];
$sparkle = ' sparkle';
} else { } else {
$from_url = $message['from-url'] . "?zrl=" . urlencode($myprofile); $from_url = Contact::magicLink($message['from-url']);
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} }
@ -470,7 +467,7 @@ function render_messages(array $msg, $t)
$rslt .= replace_macros($tpl, [ $rslt .= replace_macros($tpl, [
'$id' => $rr['id'], '$id' => $rr['id'],
'$from_name' => $participants, '$from_name' => $participants,
'$from_url' => (($rr['network'] === NETWORK_DFRN) ? 'redir/' . $rr['contact-id'] : $rr['url']), '$from_url' => Contact::magicLink($rr['url']),
'$from_addr' => $contact['addr'], '$from_addr' => $contact['addr'],
'$sparkle' => ' sparkle', '$sparkle' => ' sparkle',
'$from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB), '$from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB),

View file

@ -1538,14 +1538,10 @@ function photos_content(App $a)
continue; continue;
} }
$redirect_url = 'redir/' . $item['cid']; $profile_url = Contact::MagicLinkById($item['cid']);
if (strpos($profile_url, 'redir/') === 0) {
if (local_user() && ($item['contact-uid'] == local_user())
&& ($item['network'] == NETWORK_DFRN) && !$item['self']) {
$profile_url = $redirect_url;
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} else { } else {
$profile_url = $item['url'];
$sparkle = ''; $sparkle = '';
} }

View file

@ -4,6 +4,7 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
@ -12,7 +13,7 @@ function randprof_init(App $a)
$x = GContact::getRandomUrl(); $x = GContact::getRandomUrl();
if ($x) { if ($x) {
goaway(Profile::zrl($x)); goaway(Contact::magicLink($x));
} }
goaway(System::baseUrl() . '/profile'); goaway(System::baseUrl() . '/profile');

View file

@ -1,89 +1,94 @@
<?php <?php
use Friendica\App; use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
function redir_init(App $a) { function redir_init(App $a) {
$url = ((x($_GET,'url')) ? $_GET['url'] : ''); $url = defaults($_GET, 'url', '');
$quiet = ((x($_GET,'quiet')) ? '&quiet=1' : ''); $quiet = !empty($_GET['quiet']) ? '&quiet=1' : '';
$con_url = ((x($_GET,'conurl')) ? $_GET['conurl'] : ''); $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) { if ($contact['network'] !== NETWORK_DFRN) {
$con_url = str_replace('https', 'http', $con_url); goaway(($url != '' ? $url : $contact['url']));
}
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", if ($contact['uid'] == 0) {
dbesc($con_url), $contact_url = $contact['url'];
intval(local_user()) $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)) { $my_profile = Profile::getMyURL();
goaway(System::baseUrl());
}
if ($r[0]['network'] !== NETWORK_DFRN) {
goaway(($url != '' ? $url : $r[0]['url']));
}
$cid = $r[0]['id'];
} else {
$cid = $a->argv[1];
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", if (!empty($my_profile) && !link_compare($my_profile, $target_url)) {
intval($cid), $separator = strpos($target_url, '?') ? '&' : '?';
intval(local_user())
);
if (!DBM::is_result($r)) { $target_url .= $separator . 'zrl=' . urlencode($my_profile);
goaway(System::baseUrl()); }
} goaway($target_url);
if ($r[0]['network'] !== NETWORK_DFRN) { } else {
goaway(($url != '' ? $url : $r[0]['url'])); $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']) { if ($contact['duplex'] && $contact['issued-id']) {
$orig_id = $r[0]['issued-id']; $orig_id = $contact['issued-id'];
$dfrn_id = '1:' . $orig_id; $dfrn_id = '1:' . $orig_id;
} }
if ($r[0]['duplex'] && $r[0]['dfrn-id']) { if ($contact['duplex'] && $contact['dfrn-id']) {
$orig_id = $r[0]['dfrn-id']; $orig_id = $contact['dfrn-id'];
$dfrn_id = '0:' . $orig_id; $dfrn_id = '0:' . $orig_id;
} }
$sec = random_string(); $sec = random_string();
q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`) $fields = ['uid' => local_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id,
VALUES( %d, %s, '%s', '%s', %d )", 'sec' => $sec, 'expire' => time() + 45];
intval(local_user()), dba::insert('profile_check', $fields);
intval($cid),
dbesc($dfrn_id),
dbesc($sec),
intval(time() + 45)
);
logger('mod_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG); logger('mod_redir: ' . $contact['name'] . ' ' . $sec, LOGGER_DEBUG);
$dest = (($url) ? '&destination_url=' . $url : '');
goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id $dest = (!empty($url) ? '&destination_url=' . $url : '');
goaway($contact['poll'] . '?dfrn_id=' . $dfrn_id
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet); . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet);
} }
if (local_user()) { 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()) { if (remote_user()) {
$handle = $_SESSION['handle']; $handle = $_SESSION['handle'];
} }
if ($url) { if (!empty($url)) {
$url = str_replace('{zid}','&zid=' . $handle,$url); $url = str_replace('{zid}', '&zid=' . $handle, $url);
goaway($url); goaway($url);
} }
notice(L10n::t('Contact not found.'));
goaway(System::baseUrl()); goaway(System::baseUrl());
} }

View file

@ -79,7 +79,7 @@ function suggest_content(App $a) {
$connlnk = System::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']); $connlnk = System::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']);
$ignlnk = System::baseUrl() . '/suggest?ignore=' . $rr['id']; $ignlnk = System::baseUrl() . '/suggest?ignore=' . $rr['id'];
$photo_menu = [ $photo_menu = [
'profile' => [L10n::t("View Profile"), Profile::zrl($rr["url"])], 'profile' => [L10n::t("View Profile"), Contact::magicLink($rr["url"])],
'follow' => [L10n::t("Connect/Follow"), $connlnk], 'follow' => [L10n::t("Connect/Follow"), $connlnk],
'hide' => [L10n::t('Ignore/Hide'), $ignlnk] 'hide' => [L10n::t('Ignore/Hide'), $ignlnk]
]; ];
@ -87,7 +87,7 @@ function suggest_content(App $a) {
$contact_details = Contact::getDetailsByURL($rr["url"], local_user(), $rr); $contact_details = Contact::getDetailsByURL($rr["url"], local_user(), $rr);
$entry = [ $entry = [
'url' => Profile::zrl($rr['url']), 'url' => Contact::magicLink($rr['url']),
'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
'img_hover' => $rr['url'], 'img_hover' => $rr['url'],
'name' => $contact_details['name'], 'name' => $contact_details['name'],

View file

@ -118,7 +118,7 @@ function unfollow_content(App $a)
'$nickname' => "", '$nickname' => "",
'$name' => $contact["name"], '$name' => $contact["name"],
'$url' => $contact["url"], '$url' => $contact["url"],
'$zrl' => Profile::zrl($contact["url"]), '$zrl' => Contact::magicLink($contact["url"]),
'$url_label' => L10n::t("Profile URL"), '$url_label' => L10n::t("Profile URL"),
'$myaddr' => $myaddr, '$myaddr' => $myaddr,
'$request' => $request, '$request' => $request,

View file

@ -96,15 +96,6 @@ function viewcontacts_content(App $a)
continue; continue;
} }
$url = $rr['url'];
// route DFRN profiles through the redirect
if ($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
$url = 'redir/' . $rr['id'];
} else {
$url = Profile::zrl($url);
}
$contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr); $contact_details = Contact::getDetailsByURL($rr['url'], $a->profile['uid'], $rr);
$contacts[] = [ $contacts[] = [
@ -118,7 +109,7 @@ function viewcontacts_content(App $a)
'tags' => $contact_details['keywords'], 'tags' => $contact_details['keywords'],
'about' => $contact_details['about'], 'about' => $contact_details['about'],
'account_type' => Contact::getAccountType($contact_details), 'account_type' => Contact::getAccountType($contact_details),
'url' => $url, 'url' => Contact::magicLink($rr['url']),
'sparkle' => '', 'sparkle' => '',
'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
'network' => ContactSelector::networkToName($rr['network'], $rr['url']), 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),

View file

@ -9,6 +9,7 @@ use Friendica\App;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use dba; use dba;
@ -107,7 +108,7 @@ class ForumManager
$entry = [ $entry = [
'url' => 'network?f=&cid=' . $contact['id'], 'url' => 'network?f=&cid=' . $contact['id'],
'external_url' => 'redir/' . $contact['id'], 'external_url' => Contact::magicLink($contact['url']),
'name' => $contact['name'], 'name' => $contact['name'],
'cid' => $contact['id'], 'cid' => $contact['id'],
'selected' => $selected, 'selected' => $selected,

View file

@ -828,7 +828,7 @@ class NotificationsManager extends BaseObject
'contact_id' => $it['contact-id'], 'contact_id' => $it['contact-id'],
'photo' => ((x($it, 'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"), 'photo' => ((x($it, 'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
'name' => $it['fname'], 'name' => $it['fname'],
'url' => Profile::zrl($it['furl']), 'url' => Contact::magicLink($it['furl']),
'hidden' => $it['hidden'] == 1, 'hidden' => $it['hidden'] == 1,
'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0), 'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
'knowyou' => $knowyou, 'knowyou' => $knowyou,
@ -862,7 +862,7 @@ class NotificationsManager extends BaseObject
'hidden' => $it['hidden'] == 1, 'hidden' => $it['hidden'] == 1,
'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0), 'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
'url' => $it['url'], 'url' => $it['url'],
'zrl' => Profile::zrl($it['url']), 'zrl' => Contact::magicLink($it['url']),
'addr' => $it['gaddr'], 'addr' => $it['gaddr'],
'network' => $it['gnetwork'], 'network' => $it['gnetwork'],
'knowyou' => $it['knowyou'], 'knowyou' => $it['knowyou'],

View file

@ -598,7 +598,7 @@ class Contact extends BaseObject
if ($contact['uid'] != $uid) { if ($contact['uid'] != $uid) {
if ($uid == 0) { if ($uid == 0) {
$profile_link = Profile::zrl($contact['url']); $profile_link = self::magicLink($contact['url']);
$menu = ['profile' => [L10n::t('View Profile'), $profile_link, true]]; $menu = ['profile' => [L10n::t('View Profile'), $profile_link, true]];
return $menu; return $menu;
@ -609,7 +609,7 @@ class Contact extends BaseObject
if (DBM::is_result($contact_own)) { if (DBM::is_result($contact_own)) {
return self::photoMenu($contact_own, $uid); return self::photoMenu($contact_own, $uid);
} else { } else {
$profile_link = Profile::zrl($contact['url']); $profile_link = self::magicLink($contact['url']);
$connlnk = 'follow/?url=' . $contact['url']; $connlnk = 'follow/?url=' . $contact['url'];
$menu = [ $menu = [
'profile' => [L10n::t('View Profile'), $profile_link, true], 'profile' => [L10n::t('View Profile'), $profile_link, true],
@ -1686,4 +1686,56 @@ class Contact extends BaseObject
$contact_ids = $return; $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, 0, true);
if (empty($cid)) {
return $url ?: $contact_url; // Equivalent to: ($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 = '')
{
$contact = dba::selectFirst('contact', ['network', 'url', 'uid'], ['id' => $cid]);
if ($contact['network'] != NETWORK_DFRN) {
return $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
}
// Only redirections to the same host do make sense
if (($url != '') && (parse_url($url, PHP_URL_HOST) != parse_url($contact['url'], PHP_URL_HOST))) {
return $url;
}
if ($contact['uid'] != 0) {
return self::magicLink($contact['url'], $url);
}
$redirect = 'redir/' . $cid;
if ($url != '') {
$redirect .= '?url=' . $url;
}
return $redirect;
}
} }

View file

@ -868,12 +868,7 @@ class Event extends BaseObject
$location = self::locationToArray($item['event-location']); $location = self::locationToArray($item['event-location']);
// Construct the profile link (magic-auth). // Construct the profile link (magic-auth).
$sp = false; $profile_link = Contact::magicLinkById($item['author-id']);
$profile_link = best_link_url($item, $sp);
if (!$sp) {
$profile_link = Profile::zrl($profile_link);
}
$tpl = get_markup_template('event_stream_item.tpl'); $tpl = get_markup_template('event_stream_item.tpl');
$return = replace_macros($tpl, [ $return = replace_macros($tpl, [

View file

@ -496,7 +496,7 @@ class Profile
$p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL); $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
} }
$p['url'] = self::magicLink($p['url']); $p['url'] = Contact::magicLink($p['url']);
$tpl = get_markup_template('profile_vcard.tpl'); $tpl = get_markup_template('profile_vcard.tpl');
$o .= replace_macros($tpl, [ $o .= replace_macros($tpl, [
@ -594,12 +594,8 @@ class Profile
$cids[] = $rr['cid']; $cids[] = $rr['cid'];
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false); $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
$url = $rr['url'];
if ($rr['network'] === NETWORK_DFRN) {
$url = System::baseUrl() . '/redir/' . $rr['cid'];
}
$rr['link'] = $url; $rr['link'] = Contact::magicLink($rr['url']);
$rr['title'] = $rr['name']; $rr['title'] = $rr['name'];
$rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : ''); $rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
$rr['startime'] = null; $rr['startime'] = null;
@ -1003,29 +999,6 @@ class Profile
} }
} }
/**
* @brief Returns a magic link to authenticate remote visitors
*
* @param string $contact_url The address of the contact profile
* @param integer $uid The user id, "local_user" is the default
*
* @return string with "redir" link
*/
public static function magicLink($contact_url, $uid = -1)
{
if ($uid == -1) {
$uid = local_user();
}
$condition = ['pending' => false, 'uid' => $uid,
'nurl' => normalise_link($contact_url),
'network' => NETWORK_DFRN, 'self' => false];
$contact = dba::selectFirst('contact', ['id'], $condition);
if (DBM::is_result($contact)) {
return System::baseUrl() . '/redir/' . $contact['id'];
}
return self::zrl($contact_url);
}
public static function zrl($s, $force = false) public static function zrl($s, $force = false)
{ {
if (!strlen($s)) { if (!strlen($s)) {

View file

@ -196,7 +196,7 @@ class Term
$orig_tag = $tag["url"]; $orig_tag = $tag["url"];
$tag["url"] = best_link_url($item, $sp, $tag["url"]); $tag["url"] = Contact::magicLinkById($item['author-id'], $tag['url']);
if ($tag["type"] == TERM_HASHTAG) { if ($tag["type"] == TERM_HASHTAG) {
if ($orig_tag != $tag["url"]) { if ($orig_tag != $tag["url"]) {

View file

@ -13,7 +13,6 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
use dba; use dba;
@ -71,7 +70,7 @@ class Post extends BaseObject
} }
$this->writable = $this->getDataValue('writable') || $this->getDataValue('self'); $this->writable = $this->getDataValue('writable') || $this->getDataValue('self');
$this->redirect_url = 'redir/' . $this->getDataValue('cid'); $this->redirect_url = Contact::magicLinkById($this->getDataValue('cid'));
if (!$this->isToplevel()) { if (!$this->isToplevel()) {
$this->threaded = true; $this->threaded = true;
@ -205,16 +204,9 @@ class Post extends BaseObject
$profile_name = $item['author-link']; $profile_name = $item['author-link'];
} }
$sp = false; $profile_link = Contact::magicLinkById($item['author-id']);
$profile_link = best_link_url($item, $sp); if (strpos($profile_link, 'redir/') === 0) {
if ($profile_link === 'mailbox') {
$profile_link = '';
}
if ($sp) {
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} else {
$profile_link = Profile::zrl($profile_link);
} }
if (($item['network'] == NETWORK_FEED) || empty($item['author-thumb'])) { if (($item['network'] == NETWORK_FEED) || empty($item['author-thumb'])) {
@ -847,7 +839,7 @@ class Post extends BaseObject
// This will have been stored in $a->page_contact by our calling page. // This will have been stored in $a->page_contact by our calling page.
// Put this person as the wall owner of the wall-to-wall notice. // Put this person as the wall owner of the wall-to-wall notice.
$this->owner_url = Profile::zrl($a->page_contact['url']); $this->owner_url = Contact::magicLink($a->page_contact['url']);
$this->owner_photo = $a->page_contact['thumb']; $this->owner_photo = $a->page_contact['thumb'];
$this->owner_name = $a->page_contact['name']; $this->owner_name = $a->page_contact['name'];
$this->wall_to_wall = true; $this->wall_to_wall = true;
@ -869,14 +861,7 @@ class Post extends BaseObject
$this->owner_photo = $this->getDataValue('owner-avatar'); $this->owner_photo = $this->getDataValue('owner-avatar');
$this->owner_name = $this->getDataValue('owner-name'); $this->owner_name = $this->getDataValue('owner-name');
$this->wall_to_wall = true; $this->wall_to_wall = true;
// If it is our contact, use a friendly redirect link $this->owner_url = Contact::magicLinkById($this->getDataValue('owner-id'));
if ($this->getDataValue('network') === NETWORK_DFRN
&& link_compare($this->getDataValue('owner-link'), $this->getDataValue('url'))
) {
$this->owner_url = $this->getRedirectUrl();
} else {
$this->owner_url = Profile::zrl($this->getDataValue('owner-link'));
}
} }
} }
} }

View file

@ -17,6 +17,7 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
@ -153,7 +154,6 @@ function vier_community_info()
foreach ($r as $rr) { foreach ($r as $rr) {
$entry = replace_macros($tpl, [ $entry = replace_macros($tpl, [
'$id' => $rr['id'], '$id' => $rr['id'],
//'$profile_link' => Profile::zrl($rr['url']),
'$profile_link' => 'follow/?url='.urlencode($rr['url']), '$profile_link' => 'follow/?url='.urlencode($rr['url']),
'$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO), '$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO),
'$alt_text' => $rr['name'], '$alt_text' => $rr['name'],
@ -234,7 +234,7 @@ function vier_community_info()
$entry = [ $entry = [
'url' => 'network?f=&cid=' . $contact['id'], 'url' => 'network?f=&cid=' . $contact['id'],
'external_url' => 'redir/' . $contact['id'], 'external_url' => Contact::magicLink($contact['url']),
'name' => $contact['name'], 'name' => $contact['name'],
'cid' => $contact['id'], 'cid' => $contact['id'],
'selected' => $selected, 'selected' => $selected,
@ -285,7 +285,7 @@ function vier_community_info()
} }
foreach ($r as $index => $helper) { foreach ($r as $index => $helper) {
$r[$index]["url"] = Profile::zrl($helper["url"]); $r[$index]["url"] = Contact::magicLink($helper["url"]);
} }
$r[] = ["url" => "help/Quick-Start-guide", "name" => L10n::t("Quick Start")]; $r[] = ["url" => "help/Quick-Start-guide", "name" => L10n::t("Quick Start")];