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