friendica_2021-01/mod/redir.php

95 lines
2.7 KiB
PHP
Raw Normal View History

2010-07-02 01:48:07 +02:00
<?php
use Friendica\App;
use Friendica\Core\L10n;
2017-08-26 08:04:21 +02:00
use Friendica\Core\System;
2017-11-08 04:57:46 +01:00
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
function redir_init(App $a) {
2010-07-02 01:48:07 +02:00
$url = defaults($_GET, 'url', '');
$quiet = !empty($_GET['quiet']) ? '&quiet=1' : '';
$con_url = defaults($_GET, 'conurl', '');
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 (!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());
}
2010-09-02 09:31:11 +02:00
if ($contact['network'] !== NETWORK_DFRN) {
goaway(($url != '' ? $url : $contact['url']));
}
2010-09-02 09:31:11 +02:00
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);
2012-01-30 00:47:25 +01:00
$my_profile = Profile::getMyURL();
if (!empty($my_profile) && !link_compare($my_profile, $target_url)) {
$separator = strpos($target_url, '?') ? '&' : '?';
$target_url .= $separator . 'zrl=' . urlencode($my_profile);
}
goaway($target_url);
} else {
$cid = $contact['id'];
}
}
2012-01-30 00:47:25 +01:00
$dfrn_id = $orig_id = (($contact['issued-id']) ? $contact['issued-id'] : $contact['dfrn-id']);
2012-01-30 00:47:25 +01:00
if ($contact['duplex'] && $contact['issued-id']) {
$orig_id = $contact['issued-id'];
2012-01-30 00:47:25 +01:00
$dfrn_id = '1:' . $orig_id;
}
if ($contact['duplex'] && $contact['dfrn-id']) {
$orig_id = $contact['dfrn-id'];
2012-01-30 00:47:25 +01:00
$dfrn_id = '0:' . $orig_id;
}
$sec = random_string();
$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);
2010-09-13 06:25:37 +02:00
}
2012-01-30 00:47:25 +01:00
if (local_user()) {
$handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
}
if (remote_user()) {
2012-01-30 00:47:25 +01:00
$handle = $_SESSION['handle'];
}
2012-01-30 00:47:25 +01:00
if (!empty($url)) {
$url = str_replace('{zid}', '&zid=' . $handle, $url);
2012-01-30 00:47:25 +01:00
goaway($url);
2010-09-13 06:25:37 +02:00
}
notice(L10n::t('Contact not found.'));
goaway(System::baseUrl());
2010-10-13 11:47:32 +02:00
}