@@ -46,223 +46,223 @@ |
||
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; |
|
49 | + /** @var IConfig */ |
|
50 | + private $config; |
|
51 | + /** @var ICacheFactory */ |
|
52 | + private $cacheFactory; |
|
53 | + /** @var IRequest */ |
|
54 | + private $request; |
|
55 | 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 | - } |
|
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 | 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 | - } |
|
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 | 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 | - } |
|
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 | 93 | |
94 | - public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string { |
|
95 | - $route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments, false); |
|
94 | + public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string { |
|
95 | + $route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments, false); |
|
96 | 96 | |
97 | - if (strpos($route, '/index.php') === 0) { |
|
98 | - $route = substr($route, 10); |
|
99 | - } |
|
97 | + if (strpos($route, '/index.php') === 0) { |
|
98 | + $route = substr($route, 10); |
|
99 | + } |
|
100 | 100 | |
101 | - $route = substr($route, 7); |
|
102 | - $route = '/ocs/v2.php' . $route; |
|
101 | + $route = substr($route, 7); |
|
102 | + $route = '/ocs/v2.php' . $route; |
|
103 | 103 | |
104 | - return $this->getAbsoluteURL($route); |
|
105 | - } |
|
104 | + return $this->getAbsoluteURL($route); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Creates an url |
|
109 | - * @param string $app app |
|
110 | - * @param string $file file |
|
111 | - * @param array $args array with param=>value, will be appended to the returned url |
|
112 | - * The value of $args will be urlencoded |
|
113 | - * @return string the url |
|
114 | - * |
|
115 | - * Returns a url to the given app and file. |
|
116 | - */ |
|
117 | - public function linkTo(string $app, string $file, array $args = array()): string { |
|
118 | - $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
107 | + /** |
|
108 | + * Creates an url |
|
109 | + * @param string $app app |
|
110 | + * @param string $file file |
|
111 | + * @param array $args array with param=>value, will be appended to the returned url |
|
112 | + * The value of $args will be urlencoded |
|
113 | + * @return string the url |
|
114 | + * |
|
115 | + * Returns a url to the given app and file. |
|
116 | + */ |
|
117 | + public function linkTo(string $app, string $file, array $args = array()): string { |
|
118 | + $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
119 | 119 | |
120 | - if( $app !== '' ) { |
|
121 | - $app_path = \OC_App::getAppPath($app); |
|
122 | - // Check if the app is in the app folder |
|
123 | - if ($app_path && file_exists($app_path . '/' . $file)) { |
|
124 | - if (substr($file, -3) === 'php') { |
|
120 | + if( $app !== '' ) { |
|
121 | + $app_path = \OC_App::getAppPath($app); |
|
122 | + // Check if the app is in the app folder |
|
123 | + if ($app_path && file_exists($app_path . '/' . $file)) { |
|
124 | + if (substr($file, -3) === 'php') { |
|
125 | 125 | |
126 | - $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; |
|
127 | - if ($frontControllerActive) { |
|
128 | - $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; |
|
129 | - } |
|
130 | - $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : ''; |
|
131 | - } else { |
|
132 | - $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; |
|
133 | - } |
|
134 | - } else { |
|
135 | - $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file; |
|
136 | - } |
|
137 | - } else { |
|
138 | - if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { |
|
139 | - $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; |
|
140 | - } else { |
|
141 | - if ($frontControllerActive && $file === 'index.php') { |
|
142 | - $urlLinkTo = \OC::$WEBROOT . '/'; |
|
143 | - } else { |
|
144 | - $urlLinkTo = \OC::$WEBROOT . '/' . $file; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
126 | + $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; |
|
127 | + if ($frontControllerActive) { |
|
128 | + $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; |
|
129 | + } |
|
130 | + $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : ''; |
|
131 | + } else { |
|
132 | + $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; |
|
133 | + } |
|
134 | + } else { |
|
135 | + $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file; |
|
136 | + } |
|
137 | + } else { |
|
138 | + if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { |
|
139 | + $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; |
|
140 | + } else { |
|
141 | + if ($frontControllerActive && $file === 'index.php') { |
|
142 | + $urlLinkTo = \OC::$WEBROOT . '/'; |
|
143 | + } else { |
|
144 | + $urlLinkTo = \OC::$WEBROOT . '/' . $file; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - if ($args && $query = http_build_query($args, '', '&')) { |
|
150 | - $urlLinkTo .= '?' . $query; |
|
151 | - } |
|
149 | + if ($args && $query = http_build_query($args, '', '&')) { |
|
150 | + $urlLinkTo .= '?' . $query; |
|
151 | + } |
|
152 | 152 | |
153 | - return $urlLinkTo; |
|
154 | - } |
|
153 | + return $urlLinkTo; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Creates path to an image |
|
158 | - * @param string $app app |
|
159 | - * @param string $image image name |
|
160 | - * @throws \RuntimeException If the image does not exist |
|
161 | - * @return string the url |
|
162 | - * |
|
163 | - * Returns the path to the image. |
|
164 | - */ |
|
165 | - public function imagePath(string $app, string $image): string { |
|
166 | - $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-'); |
|
167 | - $cacheKey = $app.'-'.$image; |
|
168 | - if($key = $cache->get($cacheKey)) { |
|
169 | - return $key; |
|
170 | - } |
|
156 | + /** |
|
157 | + * Creates path to an image |
|
158 | + * @param string $app app |
|
159 | + * @param string $image image name |
|
160 | + * @throws \RuntimeException If the image does not exist |
|
161 | + * @return string the url |
|
162 | + * |
|
163 | + * Returns the path to the image. |
|
164 | + */ |
|
165 | + public function imagePath(string $app, string $image): string { |
|
166 | + $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-'); |
|
167 | + $cacheKey = $app.'-'.$image; |
|
168 | + if($key = $cache->get($cacheKey)) { |
|
169 | + return $key; |
|
170 | + } |
|
171 | 171 | |
172 | - // Read the selected theme from the config file |
|
173 | - $theme = \OC_Util::getTheme(); |
|
172 | + // Read the selected theme from the config file |
|
173 | + $theme = \OC_Util::getTheme(); |
|
174 | 174 | |
175 | - //if a theme has a png but not an svg always use the png |
|
176 | - $basename = substr(basename($image),0,-4); |
|
175 | + //if a theme has a png but not an svg always use the png |
|
176 | + $basename = substr(basename($image),0,-4); |
|
177 | 177 | |
178 | - $appPath = \OC_App::getAppPath($app); |
|
178 | + $appPath = \OC_App::getAppPath($app); |
|
179 | 179 | |
180 | - // Check if the app is in the app folder |
|
181 | - $path = ''; |
|
182 | - $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
|
183 | - $themingImagePath = false; |
|
184 | - if($themingEnabled) { |
|
185 | - $themingDefaults = \OC::$server->getThemingDefaults(); |
|
186 | - if ($themingDefaults instanceof ThemingDefaults) { |
|
187 | - $themingImagePath = $themingDefaults->replaceImagePath($app, $image); |
|
188 | - } |
|
189 | - } |
|
180 | + // Check if the app is in the app folder |
|
181 | + $path = ''; |
|
182 | + $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
|
183 | + $themingImagePath = false; |
|
184 | + if($themingEnabled) { |
|
185 | + $themingDefaults = \OC::$server->getThemingDefaults(); |
|
186 | + if ($themingDefaults instanceof ThemingDefaults) { |
|
187 | + $themingImagePath = $themingDefaults->replaceImagePath($app, $image); |
|
188 | + } |
|
189 | + } |
|
190 | 190 | |
191 | - if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
|
192 | - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
|
193 | - } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
|
194 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
|
195 | - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
|
196 | - } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
|
197 | - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
|
198 | - } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
199 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
|
200 | - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
|
201 | - } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
|
202 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
|
203 | - } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
204 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
|
205 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
206 | - } elseif($themingEnabled && $themingImagePath) { |
|
207 | - $path = $themingImagePath; |
|
208 | - } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
|
209 | - $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
|
210 | - } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
|
211 | - && file_exists($appPath . "/img/$basename.png")) { |
|
212 | - $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
|
213 | - } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
|
214 | - $path = \OC::$WEBROOT . "/$app/img/$image"; |
|
215 | - } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
216 | - && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
|
217 | - $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
|
218 | - } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
|
219 | - $path = \OC::$WEBROOT . "/core/img/$image"; |
|
220 | - } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
221 | - && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
|
222 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
223 | - } |
|
191 | + if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
|
192 | + $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
|
193 | + } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
|
194 | + && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
|
195 | + $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
|
196 | + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
|
197 | + $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
|
198 | + } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
199 | + && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
|
200 | + $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
|
201 | + } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
|
202 | + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
|
203 | + } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
204 | + && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
|
205 | + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
206 | + } elseif($themingEnabled && $themingImagePath) { |
|
207 | + $path = $themingImagePath; |
|
208 | + } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
|
209 | + $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
|
210 | + } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
|
211 | + && file_exists($appPath . "/img/$basename.png")) { |
|
212 | + $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
|
213 | + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
|
214 | + $path = \OC::$WEBROOT . "/$app/img/$image"; |
|
215 | + } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
216 | + && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
|
217 | + $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
|
218 | + } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
|
219 | + $path = \OC::$WEBROOT . "/core/img/$image"; |
|
220 | + } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
221 | + && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
|
222 | + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
223 | + } |
|
224 | 224 | |
225 | - if($path !== '') { |
|
226 | - $cache->set($cacheKey, $path); |
|
227 | - return $path; |
|
228 | - } |
|
225 | + if($path !== '') { |
|
226 | + $cache->set($cacheKey, $path); |
|
227 | + return $path; |
|
228 | + } |
|
229 | 229 | |
230 | - throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
|
231 | - } |
|
230 | + throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Makes an URL absolute |
|
236 | - * @param string $url the url in the ownCloud host |
|
237 | - * @return string the absolute version of the url |
|
238 | - */ |
|
239 | - public function getAbsoluteURL(string $url): string { |
|
240 | - $separator = strpos($url, '/') === 0 ? '' : '/'; |
|
234 | + /** |
|
235 | + * Makes an URL absolute |
|
236 | + * @param string $url the url in the ownCloud host |
|
237 | + * @return string the absolute version of the url |
|
238 | + */ |
|
239 | + public function getAbsoluteURL(string $url): string { |
|
240 | + $separator = strpos($url, '/') === 0 ? '' : '/'; |
|
241 | 241 | |
242 | - if (\OC::$CLI && !\defined('PHPUNIT_RUN')) { |
|
243 | - return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); |
|
244 | - } |
|
245 | - // The ownCloud web root can already be prepended. |
|
246 | - if(\OC::$WEBROOT !== '' && strpos($url, \OC::$WEBROOT) === 0) { |
|
247 | - $url = substr($url, \strlen(\OC::$WEBROOT)); |
|
248 | - } |
|
242 | + if (\OC::$CLI && !\defined('PHPUNIT_RUN')) { |
|
243 | + return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); |
|
244 | + } |
|
245 | + // The ownCloud web root can already be prepended. |
|
246 | + if(\OC::$WEBROOT !== '' && strpos($url, \OC::$WEBROOT) === 0) { |
|
247 | + $url = substr($url, \strlen(\OC::$WEBROOT)); |
|
248 | + } |
|
249 | 249 | |
250 | - return $this->getBaseUrl() . $separator . $url; |
|
251 | - } |
|
250 | + return $this->getBaseUrl() . $separator . $url; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * @param string $key |
|
255 | - * @return string url to the online documentation |
|
256 | - */ |
|
257 | - public function linkToDocs(string $key): string { |
|
258 | - $theme = \OC::$server->getThemingDefaults(); |
|
259 | - return $theme->buildDocLinkToKey($key); |
|
260 | - } |
|
253 | + /** |
|
254 | + * @param string $key |
|
255 | + * @return string url to the online documentation |
|
256 | + */ |
|
257 | + public function linkToDocs(string $key): string { |
|
258 | + $theme = \OC::$server->getThemingDefaults(); |
|
259 | + return $theme->buildDocLinkToKey($key); |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * @return string base url of the current request |
|
264 | - */ |
|
265 | - public function getBaseUrl(): string { |
|
266 | - return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT; |
|
267 | - } |
|
262 | + /** |
|
263 | + * @return string base url of the current request |
|
264 | + */ |
|
265 | + public function getBaseUrl(): string { |
|
266 | + return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT; |
|
267 | + } |
|
268 | 268 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | $route = substr($route, 7); |
102 | - $route = '/ocs/v2.php' . $route; |
|
102 | + $route = '/ocs/v2.php'.$route; |
|
103 | 103 | |
104 | 104 | return $this->getAbsoluteURL($route); |
105 | 105 | } |
@@ -117,37 +117,37 @@ discard block |
||
117 | 117 | public function linkTo(string $app, string $file, array $args = array()): string { |
118 | 118 | $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
119 | 119 | |
120 | - if( $app !== '' ) { |
|
120 | + if ($app !== '') { |
|
121 | 121 | $app_path = \OC_App::getAppPath($app); |
122 | 122 | // Check if the app is in the app folder |
123 | - if ($app_path && file_exists($app_path . '/' . $file)) { |
|
123 | + if ($app_path && file_exists($app_path.'/'.$file)) { |
|
124 | 124 | if (substr($file, -3) === 'php') { |
125 | 125 | |
126 | - $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; |
|
126 | + $urlLinkTo = \OC::$WEBROOT.'/index.php/apps/'.$app; |
|
127 | 127 | if ($frontControllerActive) { |
128 | - $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; |
|
128 | + $urlLinkTo = \OC::$WEBROOT.'/apps/'.$app; |
|
129 | 129 | } |
130 | - $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : ''; |
|
130 | + $urlLinkTo .= ($file !== 'index.php') ? '/'.$file : ''; |
|
131 | 131 | } else { |
132 | - $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; |
|
132 | + $urlLinkTo = \OC_App::getAppWebPath($app).'/'.$file; |
|
133 | 133 | } |
134 | 134 | } else { |
135 | - $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file; |
|
135 | + $urlLinkTo = \OC::$WEBROOT.'/'.$app.'/'.$file; |
|
136 | 136 | } |
137 | 137 | } else { |
138 | - if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { |
|
139 | - $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; |
|
138 | + if (file_exists(\OC::$SERVERROOT.'/core/'.$file)) { |
|
139 | + $urlLinkTo = \OC::$WEBROOT.'/core/'.$file; |
|
140 | 140 | } else { |
141 | 141 | if ($frontControllerActive && $file === 'index.php') { |
142 | - $urlLinkTo = \OC::$WEBROOT . '/'; |
|
142 | + $urlLinkTo = \OC::$WEBROOT.'/'; |
|
143 | 143 | } else { |
144 | - $urlLinkTo = \OC::$WEBROOT . '/' . $file; |
|
144 | + $urlLinkTo = \OC::$WEBROOT.'/'.$file; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | if ($args && $query = http_build_query($args, '', '&')) { |
150 | - $urlLinkTo .= '?' . $query; |
|
150 | + $urlLinkTo .= '?'.$query; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return $urlLinkTo; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | public function imagePath(string $app, string $image): string { |
166 | 166 | $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-'); |
167 | 167 | $cacheKey = $app.'-'.$image; |
168 | - if($key = $cache->get($cacheKey)) { |
|
168 | + if ($key = $cache->get($cacheKey)) { |
|
169 | 169 | return $key; |
170 | 170 | } |
171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $theme = \OC_Util::getTheme(); |
174 | 174 | |
175 | 175 | //if a theme has a png but not an svg always use the png |
176 | - $basename = substr(basename($image),0,-4); |
|
176 | + $basename = substr(basename($image), 0, -4); |
|
177 | 177 | |
178 | 178 | $appPath = \OC_App::getAppPath($app); |
179 | 179 | |
@@ -181,53 +181,53 @@ discard block |
||
181 | 181 | $path = ''; |
182 | 182 | $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
183 | 183 | $themingImagePath = false; |
184 | - if($themingEnabled) { |
|
184 | + if ($themingEnabled) { |
|
185 | 185 | $themingDefaults = \OC::$server->getThemingDefaults(); |
186 | 186 | if ($themingDefaults instanceof ThemingDefaults) { |
187 | 187 | $themingImagePath = $themingDefaults->replaceImagePath($app, $image); |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
|
192 | - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
|
193 | - } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
|
194 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
|
195 | - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
|
196 | - } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
|
197 | - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
|
198 | - } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
199 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
|
200 | - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
|
201 | - } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
|
202 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
|
203 | - } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
204 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
|
205 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
206 | - } elseif($themingEnabled && $themingImagePath) { |
|
191 | + if (file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image")) { |
|
192 | + $path = \OC::$WEBROOT."/themes/$theme/apps/$app/img/$image"; |
|
193 | + } elseif (!file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$basename.svg") |
|
194 | + && file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$basename.png")) { |
|
195 | + $path = \OC::$WEBROOT."/themes/$theme/apps/$app/img/$basename.png"; |
|
196 | + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$image")) { |
|
197 | + $path = \OC::$WEBROOT."/themes/$theme/$app/img/$image"; |
|
198 | + } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$basename.svg") |
|
199 | + && file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$basename.png"))) { |
|
200 | + $path = \OC::$WEBROOT."/themes/$theme/$app/img/$basename.png"; |
|
201 | + } elseif (file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$image")) { |
|
202 | + $path = \OC::$WEBROOT."/themes/$theme/core/img/$image"; |
|
203 | + } elseif (!file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$basename.svg") |
|
204 | + && file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$basename.png")) { |
|
205 | + $path = \OC::$WEBROOT."/themes/$theme/core/img/$basename.png"; |
|
206 | + } elseif ($themingEnabled && $themingImagePath) { |
|
207 | 207 | $path = $themingImagePath; |
208 | - } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
|
209 | - $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
|
210 | - } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
|
211 | - && file_exists($appPath . "/img/$basename.png")) { |
|
212 | - $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
|
213 | - } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
|
214 | - $path = \OC::$WEBROOT . "/$app/img/$image"; |
|
215 | - } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
216 | - && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
|
217 | - $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
|
218 | - } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
|
219 | - $path = \OC::$WEBROOT . "/core/img/$image"; |
|
220 | - } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
221 | - && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
|
222 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
208 | + } elseif ($appPath && file_exists($appPath."/img/$image")) { |
|
209 | + $path = \OC_App::getAppWebPath($app)."/img/$image"; |
|
210 | + } elseif ($appPath && !file_exists($appPath."/img/$basename.svg") |
|
211 | + && file_exists($appPath."/img/$basename.png")) { |
|
212 | + $path = \OC_App::getAppWebPath($app)."/img/$basename.png"; |
|
213 | + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT."/$app/img/$image")) { |
|
214 | + $path = \OC::$WEBROOT."/$app/img/$image"; |
|
215 | + } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT."/$app/img/$basename.svg") |
|
216 | + && file_exists(\OC::$SERVERROOT."/$app/img/$basename.png"))) { |
|
217 | + $path = \OC::$WEBROOT."/$app/img/$basename.png"; |
|
218 | + } elseif (file_exists(\OC::$SERVERROOT."/core/img/$image")) { |
|
219 | + $path = \OC::$WEBROOT."/core/img/$image"; |
|
220 | + } elseif (!file_exists(\OC::$SERVERROOT."/core/img/$basename.svg") |
|
221 | + && file_exists(\OC::$SERVERROOT."/core/img/$basename.png")) { |
|
222 | + $path = \OC::$WEBROOT."/themes/$theme/core/img/$basename.png"; |
|
223 | 223 | } |
224 | 224 | |
225 | - if($path !== '') { |
|
225 | + if ($path !== '') { |
|
226 | 226 | $cache->set($cacheKey, $path); |
227 | 227 | return $path; |
228 | 228 | } |
229 | 229 | |
230 | - throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
|
230 | + throw new RuntimeException('image not found: image:'.$image.' webroot:'.\OC::$WEBROOT.' serverroot:'.\OC::$SERVERROOT); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | |
@@ -240,14 +240,14 @@ discard block |
||
240 | 240 | $separator = strpos($url, '/') === 0 ? '' : '/'; |
241 | 241 | |
242 | 242 | if (\OC::$CLI && !\defined('PHPUNIT_RUN')) { |
243 | - return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); |
|
243 | + return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/').'/'.ltrim($url, '/'); |
|
244 | 244 | } |
245 | 245 | // The ownCloud web root can already be prepended. |
246 | - if(\OC::$WEBROOT !== '' && strpos($url, \OC::$WEBROOT) === 0) { |
|
246 | + if (\OC::$WEBROOT !== '' && strpos($url, \OC::$WEBROOT) === 0) { |
|
247 | 247 | $url = substr($url, \strlen(\OC::$WEBROOT)); |
248 | 248 | } |
249 | 249 | |
250 | - return $this->getBaseUrl() . $separator . $url; |
|
250 | + return $this->getBaseUrl().$separator.$url; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -263,6 +263,6 @@ discard block |
||
263 | 263 | * @return string base url of the current request |
264 | 264 | */ |
265 | 265 | public function getBaseUrl(): string { |
266 | - return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT; |
|
266 | + return $this->request->getServerProtocol().'://'.$this->request->getServerHost().\OC::$WEBROOT; |
|
267 | 267 | } |
268 | 268 | } |