diff options
Diffstat (limited to 'lib/private/URLGenerator.php')
-rw-r--r-- | lib/private/URLGenerator.php | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index b432b0b69ca..e90d8cf1d1c 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -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 $parameters = []): string { + public function linkToRoute(string $routeName, array $arguments = []): string { // TODO: mock router - return \OC::$server->getRouter()->generate($route, $parameters); + return \OC::$server->getRouter()->generate($routeName, $arguments); } /** @@ -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 $image): string { + public function imagePath(string $appName, string $file): string { $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-'); - $cacheKey = $app.'-'.$image; + $cacheKey = $appName.'-'.$file; 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($image),0,-4); + $basename = substr(basename($file),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, $image); + $themingImagePath = $themingDefaults->replaceImagePath($appName, $file); } } - if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; - } 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/$image")) { - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; - } 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/$image")) { - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; + if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$appName/img/$file")) { + $path = \OC::$WEBROOT . "/themes/$theme/apps/$appName/img/$file"; + } 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/$file")) { + $path = \OC::$WEBROOT . "/themes/$theme/$appName/img/$file"; + } 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/$file")) { + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$file"; } 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/$image")) { - $path = \OC_App::getAppWebPath($app) . "/img/$image"; + } elseif ($appPath && file_exists($appPath . "/img/$file")) { + $path = \OC_App::getAppWebPath($appName) . "/img/$file"; } 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/$image")) { - $path = \OC::$WEBROOT . "/$app/img/$image"; - } 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/$image")) { - $path = \OC::$WEBROOT . "/core/img/$image"; + $path = \OC_App::getAppWebPath($appName) . "/img/$basename.png"; + } elseif (!empty($appName) and file_exists(\OC::$SERVERROOT . "/$appName/img/$file")) { + $path = \OC::$WEBROOT . "/$appName/img/$file"; + } 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/$file")) { + $path = \OC::$WEBROOT . "/core/img/$file"; } 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:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); + throw new RuntimeException('image not found: image:' . $file . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); } |