Renamed System::redirect() to $a->redirect()

This commit is contained in:
Philipp Holzer
2018-10-13 20:02:04 +02:00
parent c46caeb0d3
commit 2ef81108b3
62 changed files with 269 additions and 253 deletions
+18
View File
@@ -1999,4 +1999,22 @@ class App
/// @TODO Looks unsafe (remote-inclusion), is maybe not but Core\Theme::getPathForFile() uses file_exists() but does not escape anything
require_once $template;
}
/**
* Redirects to another URL and exits this process.
*
* @param string $toUrl The destination URL (Default is empty, which is the default page of the Friendica node)
* @param bool $ssl if true, base URL will try to get called with https:// (works just for relative paths)
*/
public function redirect($toUrl = '', $ssl = false)
{
if (strstr(normalise_link($toUrl), 'http://')) {
$redirectTo = $toUrl;
} else {
$redirectTo = self::getApp()->getBaseURL($ssl) . '/' . ltrim($toUrl, '/');
}
header("Location: $redirectTo");
exit();
}
}
+2 -1
View File
@@ -60,7 +60,8 @@ abstract class BaseModule extends BaseObject
*/
public static function post()
{
// goaway('module');
// $a = self::getApp();
// $a->redirect('module');
}
/**
-1
View File
@@ -239,7 +239,6 @@ class System extends BaseObject
/// @todo Move the following functions from boot.php
/*
function killme()
function goaway($s)
function local_user()
function public_contact()
function remote_user()
+1 -1
View File
@@ -272,6 +272,6 @@ class UserImport
Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $newuid);
info(L10n::t("Done. You can now login with your username and password"));
goaway(System::baseUrl() . "/login");
$a->redirect('login');
}
}
+1 -1
View File
@@ -1639,7 +1639,7 @@ class Contact extends BaseObject
$myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName());
}
goaway($ret['request'] . "&addr=$myaddr");
$a->redirect($ret['request'] . "&addr=$myaddr");
// NOTREACHED
}
+3 -3
View File
@@ -1047,7 +1047,7 @@ class Profile
// Try to avoid recursion - but send them home to do a proper magic auth.
$query = str_replace(array('?zrl=', '&zid='), array('?rzrl=', '&rzrl='), $a->query_string);
// The other instance needs to know where to redirect.
$dest = urlencode(System::baseUrl() . '/' . $query);
$dest = urlencode($a->getBaseURL() . '/' . $query);
// We need to extract the basebath from the profile url
// to redirect the visitors '/magic' module.
@@ -1055,14 +1055,14 @@ class Profile
$urlarr = explode('/profile/', $contact['url']);
$basepath = $urlarr[0];
if ($basepath != System::baseUrl() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
if ($basepath != $a->getBaseURL() && !strstr($dest, '/magic') && !strstr($dest, '/rmagic')) {
$magic_path = $basepath . '/magic' . '?f=&owa=1&dest=' . $dest;
// We have to check if the remote server does understand /magic without invoking something
$serverret = Network::curl($basepath . '/magic');
if ($serverret->isSuccess()) {
logger('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path, LOGGER_DEBUG);
goaway($magic_path);
$a->redirect($magic_path);
}
}
}
+4 -2
View File
@@ -450,7 +450,7 @@ class User
} catch (Exception $e) {
throw new Exception(L10n::t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . EOL . EOL . L10n::t('The error message was:') . $e->getMessage(), 0, $e);
}
goaway($authurl);
$a->redirect($authurl);
// NOTREACHED
}
@@ -783,6 +783,8 @@ class User
return;
}
$a = get_app();
logger('Removing user: ' . $uid);
$user = DBA::selectFirst('user', [], ['uid' => $uid]);
@@ -807,7 +809,7 @@ class User
if ($uid == local_user()) {
unset($_SESSION['authenticated']);
unset($_SESSION['uid']);
goaway();;
$a->redirect();
}
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ class Acctlink extends BaseModule
$url = defaults(Probe::uri(trim($addr)), 'url', false);
if ($url) {
goaway($url);
self::getApp()->redirect($url);
exit();
}
}
+12 -12
View File
@@ -66,9 +66,9 @@ class Contact extends BaseModule
if (DBA::isResult($contact)) {
if ($contact['self']) {
if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
goaway('profile/' . $contact['nick']);
$a->redirect('profile/' . $contact['nick']);
} else {
goaway('profile/' . $contact['nick'] . '?tab=profile');
$a->redirect('profile/' . $contact['nick'] . '?tab=profile');
}
}
@@ -168,7 +168,7 @@ class Contact extends BaseModule
info(L10n::tt('%d contact edited.', '%d contacts edited.', $count_actions));
}
goaway('contact');
$a->redirect('contact');
}
public static function post()
@@ -191,7 +191,7 @@ class Contact extends BaseModule
if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
notice(L10n::t('Could not access contact record.') . EOL);
goaway('contact');
$a->redirect('contact');
return; // NOTREACHED
}
@@ -374,19 +374,19 @@ class Contact extends BaseModule
$orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
if (!DBA::isResult($orig_record)) {
notice(L10n::t('Could not access contact record.') . EOL);
goaway('contact');
$a->redirect('contact');
return; // NOTREACHED
}
if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
self::updateContactFromPoll($contact_id);
goaway('contact/' . $contact_id);
$a->redirect('contact/' . $contact_id);
// NOTREACHED
}
if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
self::updateContactFromProbe($contact_id);
goaway('crepair/' . $contact_id);
$a->redirect('crepair/' . $contact_id);
// NOTREACHED
}
@@ -396,7 +396,7 @@ class Contact extends BaseModule
$blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
goaway('contact/' . $contact_id);
$a->redirect('contact/' . $contact_id);
return; // NOTREACHED
}
@@ -406,7 +406,7 @@ class Contact extends BaseModule
$ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
goaway('contact/' . $contact_id);
$a->redirect('contact/' . $contact_id);
return; // NOTREACHED
}
@@ -417,7 +417,7 @@ class Contact extends BaseModule
info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
}
goaway('contact/' . $contact_id);
$a->redirect('contact/' . $contact_id);
return; // NOTREACHED
}
@@ -451,13 +451,13 @@ class Contact extends BaseModule
}
// Now check how the user responded to the confirmation query
if (!empty($_REQUEST['canceled'])) {
goaway('contact');
$a->redirect('contact');
}
self::dropContact($orig_record);
info(L10n::t('Contact has been removed.') . EOL);
goaway('contact');
$a->redirect('contact');
return; // NOTREACHED
}
if ($cmd === 'posts') {
+15 -8
View File
@@ -10,6 +10,7 @@ use Friendica\Core\Addon;
use Friendica\Core\Authentication;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
@@ -39,7 +40,7 @@ class Login extends BaseModule
}
if (local_user()) {
goaway(self::getApp()->getBaseURL());
$a->redirect();
}
return self::form($_SESSION['return_url'], intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
@@ -83,10 +84,12 @@ class Login extends BaseModule
{
$noid = Config::get('system', 'no_openid');
$a = self::getApp();
// if it's an email address or doesn't resolve to a URL, fail.
if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) {
notice(L10n::t('Login failed.') . EOL);
goaway(self::getApp()->getBaseURL());
$a->redirect();
// NOTREACHED
}
@@ -98,7 +101,7 @@ class Login extends BaseModule
$_SESSION['openid'] = $openid_url;
$_SESSION['remember'] = $remember;
$openid->returnUrl = self::getApp()->getBaseURL(true) . '/openid';
goaway($openid->authUrl());
$a->redirect($openid->authUrl());
} catch (Exception $e) {
notice(L10n::t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . '<br /><br >' . L10n::t('The error message was:') . ' ' . $e->getMessage());
}
@@ -122,6 +125,8 @@ class Login extends BaseModule
'user_record' => null
];
$a = self::getApp();
/*
* An addon indicates successful login by setting 'authenticated' to non-zero value and returning a user record
* Addons should never set 'authenticated' except to indicate success - as hooks may be chained
@@ -144,7 +149,7 @@ class Login extends BaseModule
} catch (Exception $e) {
logger('authenticate: failed login attempt: ' . notags($username) . ' from IP ' . $_SERVER['REMOTE_ADDR']);
info('Login failed. Please check your credentials.' . EOL);
goaway('/');
$a->redirect();
}
if (!$remember) {
@@ -163,7 +168,7 @@ class Login extends BaseModule
$return_url = '';
}
goaway($return_url);
$a->redirect($return_url);
}
/**
@@ -173,6 +178,8 @@ class Login extends BaseModule
*/
public static function sessionAuth()
{
$a = self::getApp();
// When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.
if (isset($_COOKIE["Friendica"])) {
$data = json_decode($_COOKIE["Friendica"]);
@@ -191,7 +198,7 @@ class Login extends BaseModule
if ($data->hash != Authentication::getCookieHashForUser($user)) {
logger("Hash for user " . $data->uid . " doesn't fit.");
Authentication::deleteSession();
goaway(self::getApp()->getBaseURL());
$a->redirect();
}
// Renew the cookie
@@ -228,7 +235,7 @@ class Login extends BaseModule
logger('Session address changed. Paranoid setting in effect, blocking session. ' .
$_SESSION['addr'] . ' != ' . $_SERVER['REMOTE_ADDR']);
Authentication::deleteSession();
goaway(self::getApp()->getBaseURL());
$a->redirect();
}
$user = DBA::selectFirst('user', [],
@@ -242,7 +249,7 @@ class Login extends BaseModule
);
if (!DBA::isResult($user)) {
Authentication::deleteSession();
goaway(self::getApp()->getBaseURL());
$a->redirect();
}
// Make sure to refresh the last login time for the user if the user
+2 -1
View File
@@ -8,6 +8,7 @@ use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Authentication;
use Friendica\Core\L10n;
use Friendica\Core\System;
require_once 'boot.php';
@@ -26,6 +27,6 @@ class Logout extends BaseModule
Addon::callHooks("logging_out");
Authentication::deleteSession();
info(L10n::t('Logged out.') . EOL);
goaway(self::getApp()->getBaseURL());
self::getApp()->redirect();
}
}
+6 -5
View File
@@ -5,6 +5,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Util\HTTPSignature;
@@ -41,7 +42,7 @@ class Magic extends BaseModule
if (!$cid) {
logger('No contact record found: ' . print_r($_REQUEST, true), LOGGER_DEBUG);
goaway($dest);
$a->redirect($dest);
}
$contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
@@ -55,7 +56,7 @@ class Magic extends BaseModule
}
logger('Contact is already authenticated', LOGGER_DEBUG);
goaway($dest);
$a->redirect($dest);
}
if (local_user()) {
@@ -99,10 +100,10 @@ class Magic extends BaseModule
$x = strpbrk($dest, '?&');
$args = (($x) ? '&owt=' . $token : '?f=&owt=' . $token);
goaway($dest . $args);
$a->redirect($dest . $args);
}
}
goaway($dest);
$a->redirect($dest);
}
}
@@ -111,6 +112,6 @@ class Magic extends BaseModule
return $ret;
}
goaway($dest);
$a->redirect($dest);
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ class Objects extends BaseModule
}
if (!ActivityPub::isRequest()) {
goaway(str_replace('objects/', 'display/', $a->query_string));
$a->redirect(str_replace('objects/', 'display/', $a->query_string));
}
$item = Item::selectFirst(['id'], ['guid' => $a->argv[1], 'wall' => true, 'private' => false]);
+1 -1
View File
@@ -49,7 +49,7 @@ class Tos extends BaseModule
public static function init()
{
if (strlen(Config::get('system','singleuser'))) {
goaway(System::baseUrl()."/profile/" . Config::get('system','singleuser'));
self::getApp()->redirect('profile/' . Config::get('system','singleuser'));
}
}
/**
+1 -1
View File
@@ -3037,7 +3037,7 @@ class DFRN
logger('auto_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
$dest = (($url) ? '&destination_url=' . $url : '');
goaway($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
$a->redirect($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest);
}