Completed
Pull Request — master (#8557)
by Morris
17:26
created
lib/private/URLGenerator.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -46,210 +46,210 @@
 block discarded – undo
46 46
  * Class to generate URLs
47 47
  */
48 48
 class URLGenerator implements IURLGenerator {
49
-	/** @var IConfig */
50
-	private $config;
51
-	/** @var ICacheFactory */
52
-	private $cacheFactory;
53
-	/** @var IRequest */
54
-	private $request;
55
-
56
-	/**
57
-	 * @param IConfig $config
58
-	 * @param ICacheFactory $cacheFactory
59
-	 * @param IRequest $request
60
-	 */
61
-	public function __construct(IConfig $config,
62
-								ICacheFactory $cacheFactory,
63
-								IRequest $request) {
64
-		$this->config = $config;
65
-		$this->cacheFactory = $cacheFactory;
66
-		$this->request = $request;
67
-	}
68
-
69
-	/**
70
-	 * Creates an url using a defined route
71
-	 * @param string $route
72
-	 * @param array $parameters args with param=>value, will be appended to the returned url
73
-	 * @return string the url
74
-	 *
75
-	 * Returns a url to the given route.
76
-	 */
77
-	public function linkToRoute(string $route, array $parameters = array()): string {
78
-		// TODO: mock router
79
-		return \OC::$server->getRouter()->generate($route, $parameters);
80
-	}
81
-
82
-	/**
83
-	 * Creates an absolute url using a defined route
84
-	 * @param string $routeName
85
-	 * @param array $arguments args with param=>value, will be appended to the returned url
86
-	 * @return string the url
87
-	 *
88
-	 * Returns an absolute url to the given route.
89
-	 */
90
-	public function linkToRouteAbsolute(string $routeName, array $arguments = array()): string {
91
-		return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments));
92
-	}
93
-
94
-	/**
95
-	 * Creates an url
96
-	 * @param string $app app
97
-	 * @param string $file file
98
-	 * @param array $args array with param=>value, will be appended to the returned url
99
-	 *    The value of $args will be urlencoded
100
-	 * @return string the url
101
-	 *
102
-	 * Returns a url to the given app and file.
103
-	 */
104
-	public function linkTo(string $app, string $file, array $args = array()): string {
105
-		$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
106
-
107
-		if( $app !== '' ) {
108
-			$app_path = \OC_App::getAppPath($app);
109
-			// Check if the app is in the app folder
110
-			if ($app_path && file_exists($app_path . '/' . $file)) {
111
-				if (substr($file, -3) === 'php') {
112
-
113
-					$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
114
-					if ($frontControllerActive) {
115
-						$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
116
-					}
117
-					$urlLinkTo .= ($file !== 'index.php') ? '/' . $file : '';
118
-				} else {
119
-					$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
120
-				}
121
-			} else {
122
-				$urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
123
-			}
124
-		} else {
125
-			if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
126
-				$urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
127
-			} else {
128
-				if ($frontControllerActive && $file === 'index.php') {
129
-					$urlLinkTo = \OC::$WEBROOT . '/';
130
-				} else {
131
-					$urlLinkTo = \OC::$WEBROOT . '/' . $file;
132
-				}
133
-			}
134
-		}
135
-
136
-		if ($args && $query = http_build_query($args, '', '&')) {
137
-			$urlLinkTo .= '?' . $query;
138
-		}
139
-
140
-		return $urlLinkTo;
141
-	}
142
-
143
-	/**
144
-	 * Creates path to an image
145
-	 * @param string $app app
146
-	 * @param string $image image name
147
-	 * @throws \RuntimeException If the image does not exist
148
-	 * @return string the url
149
-	 *
150
-	 * Returns the path to the image.
151
-	 */
152
-	public function imagePath(string $app, string $image): string {
153
-		$cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-');
154
-		$cacheKey = $app.'-'.$image;
155
-		if($key = $cache->get($cacheKey)) {
156
-			return $key;
157
-		}
158
-
159
-		// Read the selected theme from the config file
160
-		$theme = \OC_Util::getTheme();
161
-
162
-		//if a theme has a png but not an svg always use the png
163
-		$basename = substr(basename($image),0,-4);
164
-
165
-		$appPath = \OC_App::getAppPath($app);
166
-
167
-		// Check if the app is in the app folder
168
-		$path = '';
169
-		$themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming');
170
-		$themingImagePath = false;
171
-		if($themingEnabled) {
172
-			$themingDefaults = \OC::$server->getThemingDefaults();
173
-			if ($themingDefaults instanceof ThemingDefaults) {
174
-				$themingImagePath = $themingDefaults->replaceImagePath($app, $image);
175
-			}
176
-		}
177
-
178
-		if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
179
-			$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
180
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
181
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
182
-			$path =  \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
183
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
184
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$image";
185
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
186
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
187
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
188
-		} elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
189
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$image";
190
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
191
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
192
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
193
-		} elseif($themingEnabled && $themingImagePath) {
194
-			$path = $themingImagePath;
195
-		} elseif ($appPath && file_exists($appPath . "/img/$image")) {
196
-			$path =  \OC_App::getAppWebPath($app) . "/img/$image";
197
-		} elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
198
-			&& file_exists($appPath . "/img/$basename.png")) {
199
-			$path =  \OC_App::getAppWebPath($app) . "/img/$basename.png";
200
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) {
201
-			$path =  \OC::$WEBROOT . "/$app/img/$image";
202
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
203
-				&& file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
204
-			$path =  \OC::$WEBROOT . "/$app/img/$basename.png";
205
-		} elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) {
206
-			$path =  \OC::$WEBROOT . "/core/img/$image";
207
-		} elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg")
208
-			&& file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) {
209
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
210
-		}
211
-
212
-		if($path !== '') {
213
-			$cache->set($cacheKey, $path);
214
-			return $path;
215
-		}
216
-
217
-		throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
218
-	}
219
-
220
-
221
-	/**
222
-	 * Makes an URL absolute
223
-	 * @param string $url the url in the ownCloud host
224
-	 * @return string the absolute version of the url
225
-	 */
226
-	public function getAbsoluteURL(string $url): string {
227
-		$separator = $url[0] === '/' ? '' : '/';
228
-
229
-		if (\OC::$CLI && !\defined('PHPUNIT_RUN')) {
230
-			return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
231
-		}
232
-		// The ownCloud web root can already be prepended.
233
-		if(substr($url, 0, \strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) {
234
-			$url = substr($url, \strlen(\OC::$WEBROOT));
235
-		}
236
-
237
-		return $this->getBaseUrl() . $separator . $url;
238
-	}
239
-
240
-	/**
241
-	 * @param string $key
242
-	 * @return string url to the online documentation
243
-	 */
244
-	public function linkToDocs(string $key): string {
245
-		$theme = \OC::$server->getThemingDefaults();
246
-		return $theme->buildDocLinkToKey($key);
247
-	}
248
-
249
-	/**
250
-	 * @return string base url of the current request
251
-	 */
252
-	public function getBaseUrl(): string {
253
-		return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT;
254
-	}
49
+    /** @var IConfig */
50
+    private $config;
51
+    /** @var ICacheFactory */
52
+    private $cacheFactory;
53
+    /** @var IRequest */
54
+    private $request;
55
+
56
+    /**
57
+     * @param IConfig $config
58
+     * @param ICacheFactory $cacheFactory
59
+     * @param IRequest $request
60
+     */
61
+    public function __construct(IConfig $config,
62
+                                ICacheFactory $cacheFactory,
63
+                                IRequest $request) {
64
+        $this->config = $config;
65
+        $this->cacheFactory = $cacheFactory;
66
+        $this->request = $request;
67
+    }
68
+
69
+    /**
70
+     * Creates an url using a defined route
71
+     * @param string $route
72
+     * @param array $parameters args with param=>value, will be appended to the returned url
73
+     * @return string the url
74
+     *
75
+     * Returns a url to the given route.
76
+     */
77
+    public function linkToRoute(string $route, array $parameters = array()): string {
78
+        // TODO: mock router
79
+        return \OC::$server->getRouter()->generate($route, $parameters);
80
+    }
81
+
82
+    /**
83
+     * Creates an absolute url using a defined route
84
+     * @param string $routeName
85
+     * @param array $arguments args with param=>value, will be appended to the returned url
86
+     * @return string the url
87
+     *
88
+     * Returns an absolute url to the given route.
89
+     */
90
+    public function linkToRouteAbsolute(string $routeName, array $arguments = array()): string {
91
+        return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments));
92
+    }
93
+
94
+    /**
95
+     * Creates an url
96
+     * @param string $app app
97
+     * @param string $file file
98
+     * @param array $args array with param=>value, will be appended to the returned url
99
+     *    The value of $args will be urlencoded
100
+     * @return string the url
101
+     *
102
+     * Returns a url to the given app and file.
103
+     */
104
+    public function linkTo(string $app, string $file, array $args = array()): string {
105
+        $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
106
+
107
+        if( $app !== '' ) {
108
+            $app_path = \OC_App::getAppPath($app);
109
+            // Check if the app is in the app folder
110
+            if ($app_path && file_exists($app_path . '/' . $file)) {
111
+                if (substr($file, -3) === 'php') {
112
+
113
+                    $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
114
+                    if ($frontControllerActive) {
115
+                        $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
116
+                    }
117
+                    $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : '';
118
+                } else {
119
+                    $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
120
+                }
121
+            } else {
122
+                $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
123
+            }
124
+        } else {
125
+            if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
126
+                $urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
127
+            } else {
128
+                if ($frontControllerActive && $file === 'index.php') {
129
+                    $urlLinkTo = \OC::$WEBROOT . '/';
130
+                } else {
131
+                    $urlLinkTo = \OC::$WEBROOT . '/' . $file;
132
+                }
133
+            }
134
+        }
135
+
136
+        if ($args && $query = http_build_query($args, '', '&')) {
137
+            $urlLinkTo .= '?' . $query;
138
+        }
139
+
140
+        return $urlLinkTo;
141
+    }
142
+
143
+    /**
144
+     * Creates path to an image
145
+     * @param string $app app
146
+     * @param string $image image name
147
+     * @throws \RuntimeException If the image does not exist
148
+     * @return string the url
149
+     *
150
+     * Returns the path to the image.
151
+     */
152
+    public function imagePath(string $app, string $image): string {
153
+        $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-');
154
+        $cacheKey = $app.'-'.$image;
155
+        if($key = $cache->get($cacheKey)) {
156
+            return $key;
157
+        }
158
+
159
+        // Read the selected theme from the config file
160
+        $theme = \OC_Util::getTheme();
161
+
162
+        //if a theme has a png but not an svg always use the png
163
+        $basename = substr(basename($image),0,-4);
164
+
165
+        $appPath = \OC_App::getAppPath($app);
166
+
167
+        // Check if the app is in the app folder
168
+        $path = '';
169
+        $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming');
170
+        $themingImagePath = false;
171
+        if($themingEnabled) {
172
+            $themingDefaults = \OC::$server->getThemingDefaults();
173
+            if ($themingDefaults instanceof ThemingDefaults) {
174
+                $themingImagePath = $themingDefaults->replaceImagePath($app, $image);
175
+            }
176
+        }
177
+
178
+        if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
179
+            $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
180
+        } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
181
+            && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
182
+            $path =  \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
183
+        } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
184
+            $path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$image";
185
+        } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
186
+            && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
187
+            $path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
188
+        } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
189
+            $path =  \OC::$WEBROOT . "/themes/$theme/core/img/$image";
190
+        } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
191
+            && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
192
+            $path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
193
+        } elseif($themingEnabled && $themingImagePath) {
194
+            $path = $themingImagePath;
195
+        } elseif ($appPath && file_exists($appPath . "/img/$image")) {
196
+            $path =  \OC_App::getAppWebPath($app) . "/img/$image";
197
+        } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
198
+            && file_exists($appPath . "/img/$basename.png")) {
199
+            $path =  \OC_App::getAppWebPath($app) . "/img/$basename.png";
200
+        } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) {
201
+            $path =  \OC::$WEBROOT . "/$app/img/$image";
202
+        } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
203
+                && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
204
+            $path =  \OC::$WEBROOT . "/$app/img/$basename.png";
205
+        } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) {
206
+            $path =  \OC::$WEBROOT . "/core/img/$image";
207
+        } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg")
208
+            && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) {
209
+            $path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
210
+        }
211
+
212
+        if($path !== '') {
213
+            $cache->set($cacheKey, $path);
214
+            return $path;
215
+        }
216
+
217
+        throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
218
+    }
219
+
220
+
221
+    /**
222
+     * Makes an URL absolute
223
+     * @param string $url the url in the ownCloud host
224
+     * @return string the absolute version of the url
225
+     */
226
+    public function getAbsoluteURL(string $url): string {
227
+        $separator = $url[0] === '/' ? '' : '/';
228
+
229
+        if (\OC::$CLI && !\defined('PHPUNIT_RUN')) {
230
+            return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
231
+        }
232
+        // The ownCloud web root can already be prepended.
233
+        if(substr($url, 0, \strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) {
234
+            $url = substr($url, \strlen(\OC::$WEBROOT));
235
+        }
236
+
237
+        return $this->getBaseUrl() . $separator . $url;
238
+    }
239
+
240
+    /**
241
+     * @param string $key
242
+     * @return string url to the online documentation
243
+     */
244
+    public function linkToDocs(string $key): string {
245
+        $theme = \OC::$server->getThemingDefaults();
246
+        return $theme->buildDocLinkToKey($key);
247
+    }
248
+
249
+    /**
250
+     * @return string base url of the current request
251
+     */
252
+    public function getBaseUrl(): string {
253
+        return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT;
254
+    }
255 255
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2016, ownCloud, Inc.
5 5
  *
@@ -104,37 +104,37 @@  discard block
 block discarded – undo
104 104
 	public function linkTo(string $app, string $file, array $args = array()): string {
105 105
 		$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
106 106
 
107
-		if( $app !== '' ) {
107
+		if ($app !== '') {
108 108
 			$app_path = \OC_App::getAppPath($app);
109 109
 			// Check if the app is in the app folder
110
-			if ($app_path && file_exists($app_path . '/' . $file)) {
110
+			if ($app_path && file_exists($app_path.'/'.$file)) {
111 111
 				if (substr($file, -3) === 'php') {
112 112
 
113
-					$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
113
+					$urlLinkTo = \OC::$WEBROOT.'/index.php/apps/'.$app;
114 114
 					if ($frontControllerActive) {
115
-						$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
115
+						$urlLinkTo = \OC::$WEBROOT.'/apps/'.$app;
116 116
 					}
117
-					$urlLinkTo .= ($file !== 'index.php') ? '/' . $file : '';
117
+					$urlLinkTo .= ($file !== 'index.php') ? '/'.$file : '';
118 118
 				} else {
119
-					$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
119
+					$urlLinkTo = \OC_App::getAppWebPath($app).'/'.$file;
120 120
 				}
121 121
 			} else {
122
-				$urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
122
+				$urlLinkTo = \OC::$WEBROOT.'/'.$app.'/'.$file;
123 123
 			}
124 124
 		} else {
125
-			if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
126
-				$urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
125
+			if (file_exists(\OC::$SERVERROOT.'/core/'.$file)) {
126
+				$urlLinkTo = \OC::$WEBROOT.'/core/'.$file;
127 127
 			} else {
128 128
 				if ($frontControllerActive && $file === 'index.php') {
129
-					$urlLinkTo = \OC::$WEBROOT . '/';
129
+					$urlLinkTo = \OC::$WEBROOT.'/';
130 130
 				} else {
131
-					$urlLinkTo = \OC::$WEBROOT . '/' . $file;
131
+					$urlLinkTo = \OC::$WEBROOT.'/'.$file;
132 132
 				}
133 133
 			}
134 134
 		}
135 135
 
136 136
 		if ($args && $query = http_build_query($args, '', '&')) {
137
-			$urlLinkTo .= '?' . $query;
137
+			$urlLinkTo .= '?'.$query;
138 138
 		}
139 139
 
140 140
 		return $urlLinkTo;
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	public function imagePath(string $app, string $image): string {
153 153
 		$cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-');
154 154
 		$cacheKey = $app.'-'.$image;
155
-		if($key = $cache->get($cacheKey)) {
155
+		if ($key = $cache->get($cacheKey)) {
156 156
 			return $key;
157 157
 		}
158 158
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		$theme = \OC_Util::getTheme();
161 161
 
162 162
 		//if a theme has a png but not an svg always use the png
163
-		$basename = substr(basename($image),0,-4);
163
+		$basename = substr(basename($image), 0, -4);
164 164
 
165 165
 		$appPath = \OC_App::getAppPath($app);
166 166
 
@@ -168,53 +168,53 @@  discard block
 block discarded – undo
168 168
 		$path = '';
169 169
 		$themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming');
170 170
 		$themingImagePath = false;
171
-		if($themingEnabled) {
171
+		if ($themingEnabled) {
172 172
 			$themingDefaults = \OC::$server->getThemingDefaults();
173 173
 			if ($themingDefaults instanceof ThemingDefaults) {
174 174
 				$themingImagePath = $themingDefaults->replaceImagePath($app, $image);
175 175
 			}
176 176
 		}
177 177
 
178
-		if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
179
-			$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
180
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
181
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
182
-			$path =  \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
183
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
184
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$image";
185
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
186
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
187
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
188
-		} elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
189
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$image";
190
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
191
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
192
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
193
-		} elseif($themingEnabled && $themingImagePath) {
178
+		if (file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image")) {
179
+			$path = \OC::$WEBROOT."/themes/$theme/apps/$app/img/$image";
180
+		} elseif (!file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$basename.svg")
181
+			&& file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$basename.png")) {
182
+			$path = \OC::$WEBROOT."/themes/$theme/apps/$app/img/$basename.png";
183
+		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$image")) {
184
+			$path = \OC::$WEBROOT."/themes/$theme/$app/img/$image";
185
+		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$basename.svg")
186
+			&& file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$basename.png"))) {
187
+			$path = \OC::$WEBROOT."/themes/$theme/$app/img/$basename.png";
188
+		} elseif (file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$image")) {
189
+			$path = \OC::$WEBROOT."/themes/$theme/core/img/$image";
190
+		} elseif (!file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$basename.svg")
191
+			&& file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$basename.png")) {
192
+			$path = \OC::$WEBROOT."/themes/$theme/core/img/$basename.png";
193
+		} elseif ($themingEnabled && $themingImagePath) {
194 194
 			$path = $themingImagePath;
195
-		} elseif ($appPath && file_exists($appPath . "/img/$image")) {
196
-			$path =  \OC_App::getAppWebPath($app) . "/img/$image";
197
-		} elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
198
-			&& file_exists($appPath . "/img/$basename.png")) {
199
-			$path =  \OC_App::getAppWebPath($app) . "/img/$basename.png";
200
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) {
201
-			$path =  \OC::$WEBROOT . "/$app/img/$image";
202
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
203
-				&& file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
204
-			$path =  \OC::$WEBROOT . "/$app/img/$basename.png";
205
-		} elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) {
206
-			$path =  \OC::$WEBROOT . "/core/img/$image";
207
-		} elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg")
208
-			&& file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) {
209
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
195
+		} elseif ($appPath && file_exists($appPath."/img/$image")) {
196
+			$path = \OC_App::getAppWebPath($app)."/img/$image";
197
+		} elseif ($appPath && !file_exists($appPath."/img/$basename.svg")
198
+			&& file_exists($appPath."/img/$basename.png")) {
199
+			$path = \OC_App::getAppWebPath($app)."/img/$basename.png";
200
+		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT."/$app/img/$image")) {
201
+			$path = \OC::$WEBROOT."/$app/img/$image";
202
+		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT."/$app/img/$basename.svg")
203
+				&& file_exists(\OC::$SERVERROOT."/$app/img/$basename.png"))) {
204
+			$path = \OC::$WEBROOT."/$app/img/$basename.png";
205
+		} elseif (file_exists(\OC::$SERVERROOT."/core/img/$image")) {
206
+			$path = \OC::$WEBROOT."/core/img/$image";
207
+		} elseif (!file_exists(\OC::$SERVERROOT."/core/img/$basename.svg")
208
+			&& file_exists(\OC::$SERVERROOT."/core/img/$basename.png")) {
209
+			$path = \OC::$WEBROOT."/themes/$theme/core/img/$basename.png";
210 210
 		}
211 211
 
212
-		if($path !== '') {
212
+		if ($path !== '') {
213 213
 			$cache->set($cacheKey, $path);
214 214
 			return $path;
215 215
 		}
216 216
 
217
-		throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
217
+		throw new RuntimeException('image not found: image:'.$image.' webroot:'.\OC::$WEBROOT.' serverroot:'.\OC::$SERVERROOT);
218 218
 	}
219 219
 
220 220
 
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 		$separator = $url[0] === '/' ? '' : '/';
228 228
 
229 229
 		if (\OC::$CLI && !\defined('PHPUNIT_RUN')) {
230
-			return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
230
+			return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/').'/'.ltrim($url, '/');
231 231
 		}
232 232
 		// The ownCloud web root can already be prepended.
233
-		if(substr($url, 0, \strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) {
233
+		if (substr($url, 0, \strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) {
234 234
 			$url = substr($url, \strlen(\OC::$WEBROOT));
235 235
 		}
236 236
 
237
-		return $this->getBaseUrl() . $separator . $url;
237
+		return $this->getBaseUrl().$separator.$url;
238 238
 	}
239 239
 
240 240
 	/**
@@ -250,6 +250,6 @@  discard block
 block discarded – undo
250 250
 	 * @return string base url of the current request
251 251
 	 */
252 252
 	public function getBaseUrl(): string {
253
-		return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT;
253
+		return $this->request->getServerProtocol().'://'.$this->request->getServerHost().\OC::$WEBROOT;
254 254
 	}
255 255
 }
Please login to merge, or discard this patch.