}
// 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']);
}
/**
$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'] == "")) {
$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 = '';
}
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>';
<?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());
}
$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;
+ }
}