@ -72,15 +72,16 @@ class URLGenerator implements IURLGenerator {
/**
* Creates an url using a defined route
* @param string $route
* @param array $parameters args with param=>value, will be appended to the returned url
*
* @param string $routeName
* @param array $arguments args with param=>value, will be appended to the returned url
* @return string the url
*
* Returns a url to the given route.
*/
public function linkToRoute(string $route, array $parameter s = []): string {
public function linkToRoute(string $routeName, array $argument s = []): string {
// TODO: mock router
return \OC::$server->getRouter()->generate($route, $parameter s);
return \OC::$server->getRouter()->generate($routeName, $argument s);
}
/**
@ -111,7 +112,8 @@ class URLGenerator implements IURLGenerator {
/**
* Creates an url
* @param string $app app
*
* @param string $appName app
* @param string $file file
* @param array $args array with param=>value, will be appended to the returned url
* The value of $args will be urlencoded
@ -119,24 +121,24 @@ class URLGenerator implements IURLGenerator {
*
* Returns a url to the given app and file.
*/
public function linkTo(string $app, string $file, array $args = []): string {
public function linkTo(string $appName , string $file, array $args = []): string {
$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
if ($app !== '') {
$app_path = \OC_App::getAppPath($app);
if ($appName !== '') {
$app_path = \OC_App::getAppPath($appName );
// Check if the app is in the app folder
if ($app_path & & file_exists($app_path . '/' . $file)) {
if (substr($file, -3) === 'php') {
$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $appName ;
if ($frontControllerActive) {
$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
$urlLinkTo = \OC::$WEBROOT . '/apps/' . $appName ;
}
$urlLinkTo .= ($file !== 'index.php') ? '/' . $file : '';
} else {
$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
$urlLinkTo = \OC_App::getAppWebPath($appName ) . '/' . $file;
}
} else {
$urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
$urlLinkTo = \OC::$WEBROOT . '/' . $appName . '/' . $file;
}
} else {
if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
@ -159,16 +161,17 @@ class URLGenerator implements IURLGenerator {
/**
* Creates path to an image
* @param string $app app
* @param string $image image name
*
* @param string $appName app
* @param string $file image name
* @throws \RuntimeException If the image does not exist
* @return string the url
*
* Returns the path to the image.
*/
public function imagePath(string $app, string $imag e): string {
public function imagePath(string $appName, string $fil e): string {
$cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-');
$cacheKey = $app.'-'.$imag e;
$cacheKey = $appName.'-'.$fil e;
if ($key = $cache->get($cacheKey)) {
return $key;
}
@ -177,9 +180,9 @@ class URLGenerator implements IURLGenerator {
$theme = \OC_Util::getTheme();
//if a theme has a png but not an svg always use the png
$basename = substr(basename($imag e),0,-4);
$basename = substr(basename($fil e),0,-4);
$appPath = \OC_App::getAppPath($app);
$appPath = \OC_App::getAppPath($appName );
// Check if the app is in the app folder
$path = '';
@ -188,39 +191,39 @@ class URLGenerator implements IURLGenerator {
if ($themingEnabled) {
$themingDefaults = \OC::$server->getThemingDefaults();
if ($themingDefaults instanceof ThemingDefaults) {
$themingImagePath = $themingDefaults->replaceImagePath($app, $imag e);
$themingImagePath = $themingDefaults->replaceImagePath($appName, $fil e);
}
}
if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$imag e")) {
$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$imag e";
} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$imag e")) {
$path = \OC::$WEBROOT . "/themes/$theme/$app/img/$imag e";
} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
$path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
} elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$imag e")) {
$path = \OC::$WEBROOT . "/themes/$theme/core/img/$imag e";
if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$appName/img/$fil e")) {
$path = \OC::$WEBROOT . "/themes/$theme/apps/$appName/img/$fil e";
} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$appName /img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$appName /img/$basename.png")) {
$path = \OC::$WEBROOT . "/themes/$theme/apps/$appName /img/$basename.png";
} elseif (!empty($appName ) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$appName/img/$fil e")) {
$path = \OC::$WEBROOT . "/themes/$theme/$appName/img/$fil e";
} elseif (!empty($appName ) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$appName /img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/themes/$theme/$appName /img/$basename.png"))) {
$path = \OC::$WEBROOT . "/themes/$theme/$appName /img/$basename.png";
} elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$fil e")) {
$path = \OC::$WEBROOT . "/themes/$theme/core/img/$fil e";
} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
$path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
} elseif ($themingEnabled & & $themingImagePath) {
$path = $themingImagePath;
} elseif ($appPath & & file_exists($appPath . "/img/$imag e")) {
$path = \OC_App::getAppWebPath($app) . "/img/$imag e";
} elseif ($appPath & & file_exists($appPath . "/img/$fil e")) {
$path = \OC_App::getAppWebPath($appName) . "/img/$fil e";
} elseif ($appPath & & !file_exists($appPath . "/img/$basename.svg")
& & file_exists($appPath . "/img/$basename.png")) {
$path = \OC_App::getAppWebPath($app) . "/img/$basename.png";
} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$imag e")) {
$path = \OC::$WEBROOT . "/$app/img/$imag e";
} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
$path = \OC::$WEBROOT . "/$app/img/$basename.png";
} elseif (file_exists(\OC::$SERVERROOT . "/core/img/$imag e")) {
$path = \OC::$WEBROOT . "/core/img/$imag e";
$path = \OC_App::getAppWebPath($appName ) . "/img/$basename.png";
} elseif (!empty($appName) and file_exists(\OC::$SERVERROOT . "/$appName/img/$fil e")) {
$path = \OC::$WEBROOT . "/$appName/img/$fil e";
} elseif (!empty($appName ) and (!file_exists(\OC::$SERVERROOT . "/$appName /img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/$appName /img/$basename.png"))) {
$path = \OC::$WEBROOT . "/$appName /img/$basename.png";
} elseif (file_exists(\OC::$SERVERROOT . "/core/img/$fil e")) {
$path = \OC::$WEBROOT . "/core/img/$fil e";
} elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg")
& & file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) {
$path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
@ -231,7 +234,7 @@ class URLGenerator implements IURLGenerator {
return $path;
}
throw new RuntimeException('image not found: image:' . $imag e . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
throw new RuntimeException('image not found: image:' . $fil e . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
}