new config parameter 'front_controller_active' which will instruct the url generator to generate urls without index.php

This commit is contained in:
Thomas Müller 2013-12-31 14:36:02 +01:00
parent 988710b0fc
commit ae5671d281
2 changed files with 27 additions and 3 deletions

View File

@ -120,7 +120,8 @@ class Server extends SimpleContainer implements IServerContainer {
return new \OC\L10N\Factory(); return new \OC\L10N\Factory();
}); });
$this->registerService('URLGenerator', function($c) { $this->registerService('URLGenerator', function($c) {
return new \OC\URLGenerator(); $config = $this->getConfig();
return new \OC\URLGenerator($config);
}); });
$this->registerService('AppHelper', function($c) { $this->registerService('AppHelper', function($c) {
return new \OC\AppHelper(); return new \OC\AppHelper();
@ -249,7 +250,7 @@ class Server extends SimpleContainer implements IServerContainer {
} }
/** /**
* @return \OC\Config * @return \OCP\IConfig
*/ */
function getConfig() { function getConfig() {
return $this->query('AllConfig'); return $this->query('AllConfig');

View File

@ -15,6 +15,19 @@ use RuntimeException;
* Class to generate URLs * Class to generate URLs
*/ */
class URLGenerator implements IURLGenerator { class URLGenerator implements IURLGenerator {
/**
* @var \OCP\IConfig
*/
private $config;
/**
* @param \OCP\IConfig $config
*/
public function __construct($config) {
$this->config = $config;
}
/** /**
* @brief Creates an url using a defined route * @brief Creates an url using a defined route
* @param $route * @param $route
@ -41,12 +54,18 @@ class URLGenerator implements IURLGenerator {
* Returns a url to the given app and file. * Returns a url to the given app and file.
*/ */
public function linkTo( $app, $file, $args = array() ) { public function linkTo( $app, $file, $args = array() ) {
$frontControllerActive=($this->config->getSystemValue('front_controller_active', 'false') == 'true');
if( $app != '' ) { if( $app != '' ) {
$app_path = \OC_App::getAppPath($app); $app_path = \OC_App::getAppPath($app);
// Check if the app is in the app folder // Check if the app is in the app folder
if ($app_path && file_exists($app_path . '/' . $file)) { if ($app_path && file_exists($app_path . '/' . $file)) {
if (substr($file, -3) == 'php' || substr($file, -3) == 'css') { if (substr($file, -3) == 'php' || substr($file, -3) == 'css') {
$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
if ($frontControllerActive) {
$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
}
$urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; $urlLinkTo .= ($file != 'index.php') ? '/' . $file : '';
} else { } else {
$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
@ -57,10 +76,14 @@ class URLGenerator implements IURLGenerator {
} else { } else {
if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
$urlLinkTo = \OC::$WEBROOT . '/core/' . $file; $urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
} else {
if ($frontControllerActive && $file === 'index.php') {
$urlLinkTo = \OC::$WEBROOT;
} else { } else {
$urlLinkTo = \OC::$WEBROOT . '/' . $file; $urlLinkTo = \OC::$WEBROOT . '/' . $file;
} }
} }
}
if ($args && $query = http_build_query($args, '', '&')) { if ($args && $query = http_build_query($args, '', '&')) {
$urlLinkTo .= '?' . $query; $urlLinkTo .= '?' . $query;