1
0
Fork 0

Bugfixing redirects

- Adding App->redirect if both redirects are possible
This commit is contained in:
Philipp Holzer 2018-10-24 20:16:14 +02:00
commit 48535c0959
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
4 changed files with 25 additions and 19 deletions

View file

@ -8,6 +8,7 @@ use Detection\MobileDetect;
use DOMDocument;
use DOMXPath;
use Exception;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Network\HTTPException\InternalServerErrorException;
@ -2006,4 +2007,21 @@ class App
$redirectTo = $this->getBaseURL($ssl) . '/' . ltrim($toUrl, '/');
Core\System::externalRedirect($redirectTo);
}
/**
* Redirects to another URL in case
* Should only be used if it isn't clear if the URL is either internal or external
*
* @param string $toUrl The target URL
*
*/
public function redirect($toUrl)
{
if (filter_var($toUrl, FILTER_VALIDATE_URL))
{
System::externalRedirect($toUrl);
} else {
$this->internalRedirect($toUrl);
}
}
}

View file

@ -43,11 +43,7 @@ class Magic extends BaseModule
if (!$cid) {
logger('No contact record found: ' . print_r($_REQUEST, true), LOGGER_DEBUG);
// @TODO Finding a more elegant possibility to redirect to either internal or external URL
if (filter_var($dest, FILTER_VALIDATE_URL)) {
System::externalRedirect($dest);
} else {
$a->internalRedirect($dest);
}
$a->redirect($dest);
}
$contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
@ -117,10 +113,6 @@ class Magic extends BaseModule
}
// @TODO Finding a more elegant possibility to redirect to either internal or external URL
if (filter_var($dest, FILTER_VALIDATE_URL)) {
System::externalRedirect($dest);
} else {
$a->internalRedirect($dest);
}
$a->redirect($dest);
}
}