Use magicLink whenever possible

This commit is contained in:
Michael 2018-06-02 08:05:06 +00:00
parent 885f2b52d1
commit 8a34895a23
23 changed files with 61 additions and 165 deletions

View file

@ -598,7 +598,7 @@ class Contact extends BaseObject
if ($contact['uid'] != $uid) {
if ($uid == 0) {
$profile_link = Profile::zrl($contact['url']);
$profile_link = self::magicLink($contact['url']);
$menu = ['profile' => [L10n::t('View Profile'), $profile_link, true]];
return $menu;
@ -609,7 +609,7 @@ class Contact extends BaseObject
if (DBM::is_result($contact_own)) {
return self::photoMenu($contact_own, $uid);
} else {
$profile_link = Profile::zrl($contact['url']);
$profile_link = self::magicLink($contact['url']);
$connlnk = 'follow/?url=' . $contact['url'];
$menu = [
'profile' => [L10n::t('View Profile'), $profile_link, true],
@ -1697,7 +1697,7 @@ class Contact extends BaseObject
*/
public static function magicLink($contact_url, $url = '')
{
$cid = self::getIdForURL($contact_url);
$cid = self::getIdForURL($contact_url, 0, true);
if (empty($cid)) {
return ($url != '') ? $url : $contact_url;
}
@ -1717,12 +1717,16 @@ class Contact extends BaseObject
{
// Direkt auf die URL verweisen, wenn die Host-Angaben unterschiedlich sind
$contact = dba::selectFirst('contact', ['network', 'url'], ['id' => $cid]);
$contact = dba::selectFirst('contact', ['network', 'url', 'uid'], ['id' => $cid]);
if ($contact['network'] != NETWORK_DFRN) {
return ($url != '') ? $url : $contact['url'];
}
if ($contact['uid'] != 0) {
return self::magicLink($contact['url'], $url);
}
$redirect = 'redir/' . $cid;
if ($url != '') {

View file

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

View file

@ -496,7 +496,7 @@ class Profile
$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');
$o .= replace_macros($tpl, [
@ -594,12 +594,8 @@ class Profile
$cids[] = $rr['cid'];
$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['date'] = day_translate(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
$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)
{
if (!strlen($s)) {

View file

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