Passed
Push — master ( 8f1440...eb9faa )
by Morris
12:18 queued 10s
created
lib/private/TemplateLayout.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -58,327 +58,327 @@
 block discarded – undo
58 58
 use OCP\Util;
59 59
 
60 60
 class TemplateLayout extends \OC_Template {
61
-	private static $versionHash = '';
62
-
63
-	/** @var IConfig */
64
-	private $config;
65
-
66
-	/** @var IInitialStateService */
67
-	private $initialState;
68
-
69
-	/** @var INavigationManager */
70
-	private $navigationManager;
71
-
72
-	/**
73
-	 * @param string $renderAs
74
-	 * @param string $appId application id
75
-	 */
76
-	public function __construct($renderAs, $appId = '') {
77
-
78
-		/** @var IConfig */
79
-		$this->config = \OC::$server->get(IConfig::class);
80
-
81
-		/** @var IInitialStateService */
82
-		$this->initialState = \OC::$server->get(IInitialStateService::class);
83
-
84
-		if (Util::isIE()) {
85
-			Util::addStyle('ie');
86
-		}
87
-
88
-		// Decide which page we show
89
-		if ($renderAs === TemplateResponse::RENDER_AS_USER) {
90
-			/** @var INavigationManager */
91
-			$this->navigationManager = \OC::$server->get(INavigationManager::class);
92
-
93
-			parent::__construct('core', 'layout.user');
94
-			if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
95
-				$this->assign('bodyid', 'body-settings');
96
-			} else {
97
-				$this->assign('bodyid', 'body-user');
98
-			}
99
-
100
-			$this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry());
101
-			$this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT);
102
-			Util::addScript('dist/unified-search', null, true);
103
-
104
-			// Add navigation entry
105
-			$this->assign('application', '');
106
-			$this->assign('appid', $appId);
107
-
108
-			$navigation = $this->navigationManager->getAll();
109
-			$this->assign('navigation', $navigation);
110
-			$settingsNavigation = $this->navigationManager->getAll('settings');
111
-			$this->assign('settingsnavigation', $settingsNavigation);
112
-
113
-			foreach ($navigation as $entry) {
114
-				if ($entry['active']) {
115
-					$this->assign('application', $entry['name']);
116
-					break;
117
-				}
118
-			}
119
-
120
-			foreach ($settingsNavigation as $entry) {
121
-				if ($entry['active']) {
122
-					$this->assign('application', $entry['name']);
123
-					break;
124
-				}
125
-			}
126
-			$userDisplayName = \OC_User::getDisplayName();
127
-			$this->assign('user_displayname', $userDisplayName);
128
-			$this->assign('user_uid', \OC_User::getUser());
129
-
130
-			if (\OC_User::getUser() === false) {
131
-				$this->assign('userAvatarSet', false);
132
-			} else {
133
-				$this->assign('userAvatarSet', true);
134
-				$this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
135
-			}
136
-
137
-			// check if app menu icons should be inverted
138
-			try {
139
-				/** @var \OCA\Theming\Util $util */
140
-				$util = \OC::$server->query(\OCA\Theming\Util::class);
141
-				$this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
142
-			} catch (\OCP\AppFramework\QueryException $e) {
143
-				$this->assign('themingInvertMenu', false);
144
-			} catch (\OCP\AutoloadNotAllowedException $e) {
145
-				$this->assign('themingInvertMenu', false);
146
-			}
147
-		} elseif ($renderAs === TemplateResponse::RENDER_AS_ERROR) {
148
-			parent::__construct('core', 'layout.guest', '', false);
149
-			$this->assign('bodyid', 'body-login');
150
-			$this->assign('user_displayname', '');
151
-			$this->assign('user_uid', '');
152
-		} elseif ($renderAs === TemplateResponse::RENDER_AS_GUEST) {
153
-			parent::__construct('core', 'layout.guest');
154
-			\OC_Util::addStyle('guest');
155
-			$this->assign('bodyid', 'body-login');
156
-
157
-			$userDisplayName = \OC_User::getDisplayName();
158
-			$this->assign('user_displayname', $userDisplayName);
159
-			$this->assign('user_uid', \OC_User::getUser());
160
-		} elseif ($renderAs === TemplateResponse::RENDER_AS_PUBLIC) {
161
-			parent::__construct('core', 'layout.public');
162
-			$this->assign('appid', $appId);
163
-			$this->assign('bodyid', 'body-public');
164
-
165
-			/** @var IRegistry $subscription */
166
-			$subscription = \OC::$server->query(IRegistry::class);
167
-			$showSimpleSignup = $this->config->getSystemValueBool('simpleSignUpLink.shown', true);
168
-			if ($showSimpleSignup && $subscription->delegateHasValidSubscription()) {
169
-				$showSimpleSignup = false;
170
-			}
171
-			$this->assign('showSimpleSignUpLink', $showSimpleSignup);
172
-		} else {
173
-			parent::__construct('core', 'layout.base');
174
-		}
175
-		// Send the language and the locale to our layouts
176
-		$lang = \OC::$server->getL10NFactory()->findLanguage();
177
-		$locale = \OC::$server->getL10NFactory()->findLocale($lang);
178
-
179
-		$lang = str_replace('_', '-', $lang);
180
-		$this->assign('language', $lang);
181
-		$this->assign('locale', $locale);
182
-
183
-		if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
184
-			if (empty(self::$versionHash)) {
185
-				$v = \OC_App::getAppVersions();
186
-				$v['core'] = implode('.', \OCP\Util::getVersion());
187
-				self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
188
-			}
189
-		} else {
190
-			self::$versionHash = md5('not installed');
191
-		}
192
-
193
-		// Add the js files
194
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
195
-		$this->assign('jsfiles', []);
196
-		if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) {
197
-			// this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call)
198
-			// see https://github.com/nextcloud/server/pull/22636 for details
199
-			$jsConfigHelper = new JSConfigHelper(
200
-				\OC::$server->getL10N('lib'),
201
-				\OC::$server->query(Defaults::class),
202
-				\OC::$server->getAppManager(),
203
-				\OC::$server->getSession(),
204
-				\OC::$server->getUserSession()->getUser(),
205
-				$this->config,
206
-				\OC::$server->getGroupManager(),
207
-				\OC::$server->get(IniGetWrapper::class),
208
-				\OC::$server->getURLGenerator(),
209
-				\OC::$server->getCapabilitiesManager(),
210
-				\OC::$server->query(IInitialStateService::class)
211
-			);
212
-			$config = $jsConfigHelper->getConfig();
213
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
214
-				$this->assign('inline_ocjs', $config);
215
-			} else {
216
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
217
-			}
218
-		}
219
-		foreach ($jsFiles as $info) {
220
-			$web = $info[1];
221
-			$file = $info[2];
222
-			$this->append('jsfiles', $web.'/'.$file . $this->getVersionHashSuffix());
223
-		}
224
-
225
-		try {
226
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
227
-		} catch (\Exception $e) {
228
-			$pathInfo = '';
229
-		}
230
-
231
-		// Do not initialise scss appdata until we have a fully installed instance
232
-		// Do not load scss for update, errors, installation or login page
233
-		if (\OC::$server->getSystemConfig()->getValue('installed', false)
234
-			&& !\OCP\Util::needUpgrade()
235
-			&& $pathInfo !== ''
236
-			&& !preg_match('/^\/login/', $pathInfo)
237
-			&& $renderAs !== TemplateResponse::RENDER_AS_ERROR
238
-		) {
239
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
240
-		} else {
241
-			// If we ignore the scss compiler,
242
-			// we need to load the guest css fallback
243
-			\OC_Util::addStyle('guest');
244
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
245
-		}
246
-
247
-		$this->assign('cssfiles', []);
248
-		$this->assign('printcssfiles', []);
249
-		$this->assign('versionHash', self::$versionHash);
250
-		foreach ($cssFiles as $info) {
251
-			$web = $info[1];
252
-			$file = $info[2];
253
-
254
-			if (substr($file, -strlen('print.css')) === 'print.css') {
255
-				$this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix());
256
-			} else {
257
-				$suffix = $this->getVersionHashSuffix($web, $file);
258
-
259
-				if (strpos($file, '?v=') == false) {
260
-					$this->append('cssfiles', $web.'/'.$file . $suffix);
261
-				} else {
262
-					$this->append('cssfiles', $web.'/'.$file . '-' . substr($suffix, 3));
263
-				}
264
-			}
265
-		}
266
-
267
-		$this->assign('initialStates', $this->initialState->getInitialStates());
268
-	}
269
-
270
-	/**
271
-	 * @param string $path
272
-	 * @param string $file
273
-	 * @return string
274
-	 */
275
-	protected function getVersionHashSuffix($path = false, $file = false) {
276
-		if ($this->config->getSystemValue('debug', false)) {
277
-			// allows chrome workspace mapping in debug mode
278
-			return "";
279
-		}
280
-		$themingSuffix = '';
281
-		$v = [];
282
-
283
-		if ($this->config->getSystemValue('installed', false)) {
284
-			if (\OC::$server->getAppManager()->isInstalled('theming')) {
285
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
286
-			}
287
-			$v = \OC_App::getAppVersions();
288
-		}
289
-
290
-		// Try the webroot path for a match
291
-		if ($path !== false && $path !== '') {
292
-			$appName = $this->getAppNamefromPath($path);
293
-			if (array_key_exists($appName, $v)) {
294
-				$appVersion = $v[$appName];
295
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
296
-			}
297
-		}
298
-		// fallback to the file path instead
299
-		if ($file !== false && $file !== '') {
300
-			$appName = $this->getAppNamefromPath($file);
301
-			if (array_key_exists($appName, $v)) {
302
-				$appVersion = $v[$appName];
303
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
304
-			}
305
-		}
306
-
307
-		return '?v=' . self::$versionHash . $themingSuffix;
308
-	}
309
-
310
-	/**
311
-	 * @param array $styles
312
-	 * @return array
313
-	 */
314
-	public static function findStylesheetFiles($styles, $compileScss = true) {
315
-		// Read the selected theme from the config file
316
-		$theme = \OC_Util::getTheme();
317
-
318
-		if ($compileScss) {
319
-			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
320
-		} else {
321
-			$SCSSCacher = null;
322
-		}
323
-
324
-		$locator = new \OC\Template\CSSResourceLocator(
325
-			\OC::$server->getLogger(),
326
-			$theme,
327
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
328
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
329
-			$SCSSCacher
330
-		);
331
-		$locator->find($styles);
332
-		return $locator->getResources();
333
-	}
334
-
335
-	/**
336
-	 * @param string $path
337
-	 * @return string|boolean
338
-	 */
339
-	public function getAppNamefromPath($path) {
340
-		if ($path !== '' && is_string($path)) {
341
-			$pathParts = explode('/', $path);
342
-			if ($pathParts[0] === 'css') {
343
-				// This is a scss request
344
-				return $pathParts[1];
345
-			}
346
-			return end($pathParts);
347
-		}
348
-		return false;
349
-	}
350
-
351
-	/**
352
-	 * @param array $scripts
353
-	 * @return array
354
-	 */
355
-	public static function findJavascriptFiles($scripts) {
356
-		// Read the selected theme from the config file
357
-		$theme = \OC_Util::getTheme();
358
-
359
-		$locator = new \OC\Template\JSResourceLocator(
360
-			\OC::$server->getLogger(),
361
-			$theme,
362
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
363
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
364
-			\OC::$server->query(JSCombiner::class)
365
-			);
366
-		$locator->find($scripts);
367
-		return $locator->getResources();
368
-	}
369
-
370
-	/**
371
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
372
-	 * @param string $filePath Absolute path
373
-	 * @return string Relative path
374
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
375
-	 */
376
-	public static function convertToRelativePath($filePath) {
377
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
378
-		if (count($relativePath) !== 2) {
379
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
380
-		}
381
-
382
-		return $relativePath[1];
383
-	}
61
+    private static $versionHash = '';
62
+
63
+    /** @var IConfig */
64
+    private $config;
65
+
66
+    /** @var IInitialStateService */
67
+    private $initialState;
68
+
69
+    /** @var INavigationManager */
70
+    private $navigationManager;
71
+
72
+    /**
73
+     * @param string $renderAs
74
+     * @param string $appId application id
75
+     */
76
+    public function __construct($renderAs, $appId = '') {
77
+
78
+        /** @var IConfig */
79
+        $this->config = \OC::$server->get(IConfig::class);
80
+
81
+        /** @var IInitialStateService */
82
+        $this->initialState = \OC::$server->get(IInitialStateService::class);
83
+
84
+        if (Util::isIE()) {
85
+            Util::addStyle('ie');
86
+        }
87
+
88
+        // Decide which page we show
89
+        if ($renderAs === TemplateResponse::RENDER_AS_USER) {
90
+            /** @var INavigationManager */
91
+            $this->navigationManager = \OC::$server->get(INavigationManager::class);
92
+
93
+            parent::__construct('core', 'layout.user');
94
+            if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
95
+                $this->assign('bodyid', 'body-settings');
96
+            } else {
97
+                $this->assign('bodyid', 'body-user');
98
+            }
99
+
100
+            $this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry());
101
+            $this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT);
102
+            Util::addScript('dist/unified-search', null, true);
103
+
104
+            // Add navigation entry
105
+            $this->assign('application', '');
106
+            $this->assign('appid', $appId);
107
+
108
+            $navigation = $this->navigationManager->getAll();
109
+            $this->assign('navigation', $navigation);
110
+            $settingsNavigation = $this->navigationManager->getAll('settings');
111
+            $this->assign('settingsnavigation', $settingsNavigation);
112
+
113
+            foreach ($navigation as $entry) {
114
+                if ($entry['active']) {
115
+                    $this->assign('application', $entry['name']);
116
+                    break;
117
+                }
118
+            }
119
+
120
+            foreach ($settingsNavigation as $entry) {
121
+                if ($entry['active']) {
122
+                    $this->assign('application', $entry['name']);
123
+                    break;
124
+                }
125
+            }
126
+            $userDisplayName = \OC_User::getDisplayName();
127
+            $this->assign('user_displayname', $userDisplayName);
128
+            $this->assign('user_uid', \OC_User::getUser());
129
+
130
+            if (\OC_User::getUser() === false) {
131
+                $this->assign('userAvatarSet', false);
132
+            } else {
133
+                $this->assign('userAvatarSet', true);
134
+                $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
135
+            }
136
+
137
+            // check if app menu icons should be inverted
138
+            try {
139
+                /** @var \OCA\Theming\Util $util */
140
+                $util = \OC::$server->query(\OCA\Theming\Util::class);
141
+                $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
142
+            } catch (\OCP\AppFramework\QueryException $e) {
143
+                $this->assign('themingInvertMenu', false);
144
+            } catch (\OCP\AutoloadNotAllowedException $e) {
145
+                $this->assign('themingInvertMenu', false);
146
+            }
147
+        } elseif ($renderAs === TemplateResponse::RENDER_AS_ERROR) {
148
+            parent::__construct('core', 'layout.guest', '', false);
149
+            $this->assign('bodyid', 'body-login');
150
+            $this->assign('user_displayname', '');
151
+            $this->assign('user_uid', '');
152
+        } elseif ($renderAs === TemplateResponse::RENDER_AS_GUEST) {
153
+            parent::__construct('core', 'layout.guest');
154
+            \OC_Util::addStyle('guest');
155
+            $this->assign('bodyid', 'body-login');
156
+
157
+            $userDisplayName = \OC_User::getDisplayName();
158
+            $this->assign('user_displayname', $userDisplayName);
159
+            $this->assign('user_uid', \OC_User::getUser());
160
+        } elseif ($renderAs === TemplateResponse::RENDER_AS_PUBLIC) {
161
+            parent::__construct('core', 'layout.public');
162
+            $this->assign('appid', $appId);
163
+            $this->assign('bodyid', 'body-public');
164
+
165
+            /** @var IRegistry $subscription */
166
+            $subscription = \OC::$server->query(IRegistry::class);
167
+            $showSimpleSignup = $this->config->getSystemValueBool('simpleSignUpLink.shown', true);
168
+            if ($showSimpleSignup && $subscription->delegateHasValidSubscription()) {
169
+                $showSimpleSignup = false;
170
+            }
171
+            $this->assign('showSimpleSignUpLink', $showSimpleSignup);
172
+        } else {
173
+            parent::__construct('core', 'layout.base');
174
+        }
175
+        // Send the language and the locale to our layouts
176
+        $lang = \OC::$server->getL10NFactory()->findLanguage();
177
+        $locale = \OC::$server->getL10NFactory()->findLocale($lang);
178
+
179
+        $lang = str_replace('_', '-', $lang);
180
+        $this->assign('language', $lang);
181
+        $this->assign('locale', $locale);
182
+
183
+        if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
184
+            if (empty(self::$versionHash)) {
185
+                $v = \OC_App::getAppVersions();
186
+                $v['core'] = implode('.', \OCP\Util::getVersion());
187
+                self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
188
+            }
189
+        } else {
190
+            self::$versionHash = md5('not installed');
191
+        }
192
+
193
+        // Add the js files
194
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
195
+        $this->assign('jsfiles', []);
196
+        if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) {
197
+            // this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call)
198
+            // see https://github.com/nextcloud/server/pull/22636 for details
199
+            $jsConfigHelper = new JSConfigHelper(
200
+                \OC::$server->getL10N('lib'),
201
+                \OC::$server->query(Defaults::class),
202
+                \OC::$server->getAppManager(),
203
+                \OC::$server->getSession(),
204
+                \OC::$server->getUserSession()->getUser(),
205
+                $this->config,
206
+                \OC::$server->getGroupManager(),
207
+                \OC::$server->get(IniGetWrapper::class),
208
+                \OC::$server->getURLGenerator(),
209
+                \OC::$server->getCapabilitiesManager(),
210
+                \OC::$server->query(IInitialStateService::class)
211
+            );
212
+            $config = $jsConfigHelper->getConfig();
213
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
214
+                $this->assign('inline_ocjs', $config);
215
+            } else {
216
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
217
+            }
218
+        }
219
+        foreach ($jsFiles as $info) {
220
+            $web = $info[1];
221
+            $file = $info[2];
222
+            $this->append('jsfiles', $web.'/'.$file . $this->getVersionHashSuffix());
223
+        }
224
+
225
+        try {
226
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
227
+        } catch (\Exception $e) {
228
+            $pathInfo = '';
229
+        }
230
+
231
+        // Do not initialise scss appdata until we have a fully installed instance
232
+        // Do not load scss for update, errors, installation or login page
233
+        if (\OC::$server->getSystemConfig()->getValue('installed', false)
234
+            && !\OCP\Util::needUpgrade()
235
+            && $pathInfo !== ''
236
+            && !preg_match('/^\/login/', $pathInfo)
237
+            && $renderAs !== TemplateResponse::RENDER_AS_ERROR
238
+        ) {
239
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
240
+        } else {
241
+            // If we ignore the scss compiler,
242
+            // we need to load the guest css fallback
243
+            \OC_Util::addStyle('guest');
244
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
245
+        }
246
+
247
+        $this->assign('cssfiles', []);
248
+        $this->assign('printcssfiles', []);
249
+        $this->assign('versionHash', self::$versionHash);
250
+        foreach ($cssFiles as $info) {
251
+            $web = $info[1];
252
+            $file = $info[2];
253
+
254
+            if (substr($file, -strlen('print.css')) === 'print.css') {
255
+                $this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix());
256
+            } else {
257
+                $suffix = $this->getVersionHashSuffix($web, $file);
258
+
259
+                if (strpos($file, '?v=') == false) {
260
+                    $this->append('cssfiles', $web.'/'.$file . $suffix);
261
+                } else {
262
+                    $this->append('cssfiles', $web.'/'.$file . '-' . substr($suffix, 3));
263
+                }
264
+            }
265
+        }
266
+
267
+        $this->assign('initialStates', $this->initialState->getInitialStates());
268
+    }
269
+
270
+    /**
271
+     * @param string $path
272
+     * @param string $file
273
+     * @return string
274
+     */
275
+    protected function getVersionHashSuffix($path = false, $file = false) {
276
+        if ($this->config->getSystemValue('debug', false)) {
277
+            // allows chrome workspace mapping in debug mode
278
+            return "";
279
+        }
280
+        $themingSuffix = '';
281
+        $v = [];
282
+
283
+        if ($this->config->getSystemValue('installed', false)) {
284
+            if (\OC::$server->getAppManager()->isInstalled('theming')) {
285
+                $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
286
+            }
287
+            $v = \OC_App::getAppVersions();
288
+        }
289
+
290
+        // Try the webroot path for a match
291
+        if ($path !== false && $path !== '') {
292
+            $appName = $this->getAppNamefromPath($path);
293
+            if (array_key_exists($appName, $v)) {
294
+                $appVersion = $v[$appName];
295
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
296
+            }
297
+        }
298
+        // fallback to the file path instead
299
+        if ($file !== false && $file !== '') {
300
+            $appName = $this->getAppNamefromPath($file);
301
+            if (array_key_exists($appName, $v)) {
302
+                $appVersion = $v[$appName];
303
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
304
+            }
305
+        }
306
+
307
+        return '?v=' . self::$versionHash . $themingSuffix;
308
+    }
309
+
310
+    /**
311
+     * @param array $styles
312
+     * @return array
313
+     */
314
+    public static function findStylesheetFiles($styles, $compileScss = true) {
315
+        // Read the selected theme from the config file
316
+        $theme = \OC_Util::getTheme();
317
+
318
+        if ($compileScss) {
319
+            $SCSSCacher = \OC::$server->query(SCSSCacher::class);
320
+        } else {
321
+            $SCSSCacher = null;
322
+        }
323
+
324
+        $locator = new \OC\Template\CSSResourceLocator(
325
+            \OC::$server->getLogger(),
326
+            $theme,
327
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
328
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
329
+            $SCSSCacher
330
+        );
331
+        $locator->find($styles);
332
+        return $locator->getResources();
333
+    }
334
+
335
+    /**
336
+     * @param string $path
337
+     * @return string|boolean
338
+     */
339
+    public function getAppNamefromPath($path) {
340
+        if ($path !== '' && is_string($path)) {
341
+            $pathParts = explode('/', $path);
342
+            if ($pathParts[0] === 'css') {
343
+                // This is a scss request
344
+                return $pathParts[1];
345
+            }
346
+            return end($pathParts);
347
+        }
348
+        return false;
349
+    }
350
+
351
+    /**
352
+     * @param array $scripts
353
+     * @return array
354
+     */
355
+    public static function findJavascriptFiles($scripts) {
356
+        // Read the selected theme from the config file
357
+        $theme = \OC_Util::getTheme();
358
+
359
+        $locator = new \OC\Template\JSResourceLocator(
360
+            \OC::$server->getLogger(),
361
+            $theme,
362
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
363
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
364
+            \OC::$server->query(JSCombiner::class)
365
+            );
366
+        $locator->find($scripts);
367
+        return $locator->getResources();
368
+    }
369
+
370
+    /**
371
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
372
+     * @param string $filePath Absolute path
373
+     * @return string Relative path
374
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
375
+     */
376
+    public static function convertToRelativePath($filePath) {
377
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
378
+        if (count($relativePath) !== 2) {
379
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
380
+        }
381
+
382
+        return $relativePath[1];
383
+    }
384 384
 }
Please login to merge, or discard this patch.