Skip to content

Commit

Permalink
Fix url generator for index.php frontend and linkToRoute
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Dec 7, 2020
1 parent 342355d commit 9d641d3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/private/URLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ public function __construct(IConfig $config,
* Returns a url to the given route.
*/
public function linkToRoute(string $routeName, array $arguments = []): string {
return $this->router->generate($routeName, $arguments);
$frontControllerActive = $this->isFrontControllerActive();
$url = $this->router->generate($routeName, $arguments);

if (strpos($url, '/index.php/') !== false || $frontControllerActive) {
return $url;
}

return 'index.php/' . $url;
}

/**
Expand Down Expand Up @@ -121,7 +128,7 @@ public function linkToOCSRouteAbsolute(string $routeName, array $arguments = [])
* Returns a url to the given app and file.
*/
public function linkTo(string $appName, string $file, array $args = []): string {
$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
$frontControllerActive = $this->isFrontControllerActive();

if ($appName !== '') {
$app_path = \OC_App::getAppPath($appName);
Expand Down Expand Up @@ -271,4 +278,13 @@ public function linkToDocs(string $key): string {
public function getBaseUrl(): string {
return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT;
}

/**
* is index.php needed ?
* @return bool
*/
protected function isFrontControllerActive() {
return $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true
|| getenv('front_controller_active') === 'true';
}
}

0 comments on commit 9d641d3

Please sign in to comment.