Passed
Push — master ( 1a3daa...2d67cb )
by Morris
14:19 queued 11s
created
lib/private/TemplateLayout.php 1 patch
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -58,325 +58,325 @@
 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
-			$jsConfigHelper = new JSConfigHelper(
198
-				\OC::$server->getL10N('lib'),
199
-				\OC::$server->query(Defaults::class),
200
-				\OC::$server->getAppManager(),
201
-				\OC::$server->getSession(),
202
-				\OC::$server->getUserSession()->getUser(),
203
-				$this->config,
204
-				\OC::$server->getGroupManager(),
205
-				\OC::$server->get(IniGetWrapper::class),
206
-				\OC::$server->getURLGenerator(),
207
-				\OC::$server->getCapabilitiesManager(),
208
-				\OC::$server->query(IInitialStateService::class)
209
-			);
210
-			$config = $jsConfigHelper->getConfig();
211
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
212
-				$this->assign('inline_ocjs', $config);
213
-			} else {
214
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
215
-			}
216
-		}
217
-		foreach ($jsFiles as $info) {
218
-			$web = $info[1];
219
-			$file = $info[2];
220
-			$this->append('jsfiles', $web.'/'.$file . $this->getVersionHashSuffix());
221
-		}
222
-
223
-		try {
224
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
225
-		} catch (\Exception $e) {
226
-			$pathInfo = '';
227
-		}
228
-
229
-		// Do not initialise scss appdata until we have a fully installed instance
230
-		// Do not load scss for update, errors, installation or login page
231
-		if (\OC::$server->getSystemConfig()->getValue('installed', false)
232
-			&& !\OCP\Util::needUpgrade()
233
-			&& $pathInfo !== ''
234
-			&& !preg_match('/^\/login/', $pathInfo)
235
-			&& $renderAs !== TemplateResponse::RENDER_AS_ERROR
236
-		) {
237
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
238
-		} else {
239
-			// If we ignore the scss compiler,
240
-			// we need to load the guest css fallback
241
-			\OC_Util::addStyle('guest');
242
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
243
-		}
244
-
245
-		$this->assign('cssfiles', []);
246
-		$this->assign('printcssfiles', []);
247
-		$this->assign('versionHash', self::$versionHash);
248
-		foreach ($cssFiles as $info) {
249
-			$web = $info[1];
250
-			$file = $info[2];
251
-
252
-			if (substr($file, -strlen('print.css')) === 'print.css') {
253
-				$this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix());
254
-			} else {
255
-				$suffix = $this->getVersionHashSuffix($web, $file);
256
-
257
-				if (strpos($file, '?v=') == false) {
258
-					$this->append('cssfiles', $web.'/'.$file . $suffix);
259
-				} else {
260
-					$this->append('cssfiles', $web.'/'.$file . '-' . substr($suffix, 3));
261
-				}
262
-			}
263
-		}
264
-
265
-		$this->assign('initialStates', $this->initialState->getInitialStates());
266
-	}
267
-
268
-	/**
269
-	 * @param string $path
270
-	 * @param string $file
271
-	 * @return string
272
-	 */
273
-	protected function getVersionHashSuffix($path = false, $file = false) {
274
-		if ($this->config->getSystemValue('debug', false)) {
275
-			// allows chrome workspace mapping in debug mode
276
-			return "";
277
-		}
278
-		$themingSuffix = '';
279
-		$v = [];
280
-
281
-		if ($this->config->getSystemValue('installed', false)) {
282
-			if (\OC::$server->getAppManager()->isInstalled('theming')) {
283
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
284
-			}
285
-			$v = \OC_App::getAppVersions();
286
-		}
287
-
288
-		// Try the webroot path for a match
289
-		if ($path !== false && $path !== '') {
290
-			$appName = $this->getAppNamefromPath($path);
291
-			if (array_key_exists($appName, $v)) {
292
-				$appVersion = $v[$appName];
293
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
294
-			}
295
-		}
296
-		// fallback to the file path instead
297
-		if ($file !== false && $file !== '') {
298
-			$appName = $this->getAppNamefromPath($file);
299
-			if (array_key_exists($appName, $v)) {
300
-				$appVersion = $v[$appName];
301
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
302
-			}
303
-		}
304
-
305
-		return '?v=' . self::$versionHash . $themingSuffix;
306
-	}
307
-
308
-	/**
309
-	 * @param array $styles
310
-	 * @return array
311
-	 */
312
-	public static function findStylesheetFiles($styles, $compileScss = true) {
313
-		// Read the selected theme from the config file
314
-		$theme = \OC_Util::getTheme();
315
-
316
-		if ($compileScss) {
317
-			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
318
-		} else {
319
-			$SCSSCacher = null;
320
-		}
321
-
322
-		$locator = new \OC\Template\CSSResourceLocator(
323
-			\OC::$server->getLogger(),
324
-			$theme,
325
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
326
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
327
-			$SCSSCacher
328
-		);
329
-		$locator->find($styles);
330
-		return $locator->getResources();
331
-	}
332
-
333
-	/**
334
-	 * @param string $path
335
-	 * @return string|boolean
336
-	 */
337
-	public function getAppNamefromPath($path) {
338
-		if ($path !== '' && is_string($path)) {
339
-			$pathParts = explode('/', $path);
340
-			if ($pathParts[0] === 'css') {
341
-				// This is a scss request
342
-				return $pathParts[1];
343
-			}
344
-			return end($pathParts);
345
-		}
346
-		return false;
347
-	}
348
-
349
-	/**
350
-	 * @param array $scripts
351
-	 * @return array
352
-	 */
353
-	public static function findJavascriptFiles($scripts) {
354
-		// Read the selected theme from the config file
355
-		$theme = \OC_Util::getTheme();
356
-
357
-		$locator = new \OC\Template\JSResourceLocator(
358
-			\OC::$server->getLogger(),
359
-			$theme,
360
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
361
-			[ \OC::$SERVERROOT => \OC::$WEBROOT ],
362
-			\OC::$server->query(JSCombiner::class)
363
-			);
364
-		$locator->find($scripts);
365
-		return $locator->getResources();
366
-	}
367
-
368
-	/**
369
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
370
-	 * @param string $filePath Absolute path
371
-	 * @return string Relative path
372
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
373
-	 */
374
-	public static function convertToRelativePath($filePath) {
375
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
376
-		if (count($relativePath) !== 2) {
377
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
378
-		}
379
-
380
-		return $relativePath[1];
381
-	}
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
+            $jsConfigHelper = new JSConfigHelper(
198
+                \OC::$server->getL10N('lib'),
199
+                \OC::$server->query(Defaults::class),
200
+                \OC::$server->getAppManager(),
201
+                \OC::$server->getSession(),
202
+                \OC::$server->getUserSession()->getUser(),
203
+                $this->config,
204
+                \OC::$server->getGroupManager(),
205
+                \OC::$server->get(IniGetWrapper::class),
206
+                \OC::$server->getURLGenerator(),
207
+                \OC::$server->getCapabilitiesManager(),
208
+                \OC::$server->query(IInitialStateService::class)
209
+            );
210
+            $config = $jsConfigHelper->getConfig();
211
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
212
+                $this->assign('inline_ocjs', $config);
213
+            } else {
214
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
215
+            }
216
+        }
217
+        foreach ($jsFiles as $info) {
218
+            $web = $info[1];
219
+            $file = $info[2];
220
+            $this->append('jsfiles', $web.'/'.$file . $this->getVersionHashSuffix());
221
+        }
222
+
223
+        try {
224
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
225
+        } catch (\Exception $e) {
226
+            $pathInfo = '';
227
+        }
228
+
229
+        // Do not initialise scss appdata until we have a fully installed instance
230
+        // Do not load scss for update, errors, installation or login page
231
+        if (\OC::$server->getSystemConfig()->getValue('installed', false)
232
+            && !\OCP\Util::needUpgrade()
233
+            && $pathInfo !== ''
234
+            && !preg_match('/^\/login/', $pathInfo)
235
+            && $renderAs !== TemplateResponse::RENDER_AS_ERROR
236
+        ) {
237
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
238
+        } else {
239
+            // If we ignore the scss compiler,
240
+            // we need to load the guest css fallback
241
+            \OC_Util::addStyle('guest');
242
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
243
+        }
244
+
245
+        $this->assign('cssfiles', []);
246
+        $this->assign('printcssfiles', []);
247
+        $this->assign('versionHash', self::$versionHash);
248
+        foreach ($cssFiles as $info) {
249
+            $web = $info[1];
250
+            $file = $info[2];
251
+
252
+            if (substr($file, -strlen('print.css')) === 'print.css') {
253
+                $this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix());
254
+            } else {
255
+                $suffix = $this->getVersionHashSuffix($web, $file);
256
+
257
+                if (strpos($file, '?v=') == false) {
258
+                    $this->append('cssfiles', $web.'/'.$file . $suffix);
259
+                } else {
260
+                    $this->append('cssfiles', $web.'/'.$file . '-' . substr($suffix, 3));
261
+                }
262
+            }
263
+        }
264
+
265
+        $this->assign('initialStates', $this->initialState->getInitialStates());
266
+    }
267
+
268
+    /**
269
+     * @param string $path
270
+     * @param string $file
271
+     * @return string
272
+     */
273
+    protected function getVersionHashSuffix($path = false, $file = false) {
274
+        if ($this->config->getSystemValue('debug', false)) {
275
+            // allows chrome workspace mapping in debug mode
276
+            return "";
277
+        }
278
+        $themingSuffix = '';
279
+        $v = [];
280
+
281
+        if ($this->config->getSystemValue('installed', false)) {
282
+            if (\OC::$server->getAppManager()->isInstalled('theming')) {
283
+                $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
284
+            }
285
+            $v = \OC_App::getAppVersions();
286
+        }
287
+
288
+        // Try the webroot path for a match
289
+        if ($path !== false && $path !== '') {
290
+            $appName = $this->getAppNamefromPath($path);
291
+            if (array_key_exists($appName, $v)) {
292
+                $appVersion = $v[$appName];
293
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
294
+            }
295
+        }
296
+        // fallback to the file path instead
297
+        if ($file !== false && $file !== '') {
298
+            $appName = $this->getAppNamefromPath($file);
299
+            if (array_key_exists($appName, $v)) {
300
+                $appVersion = $v[$appName];
301
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
302
+            }
303
+        }
304
+
305
+        return '?v=' . self::$versionHash . $themingSuffix;
306
+    }
307
+
308
+    /**
309
+     * @param array $styles
310
+     * @return array
311
+     */
312
+    public static function findStylesheetFiles($styles, $compileScss = true) {
313
+        // Read the selected theme from the config file
314
+        $theme = \OC_Util::getTheme();
315
+
316
+        if ($compileScss) {
317
+            $SCSSCacher = \OC::$server->query(SCSSCacher::class);
318
+        } else {
319
+            $SCSSCacher = null;
320
+        }
321
+
322
+        $locator = new \OC\Template\CSSResourceLocator(
323
+            \OC::$server->getLogger(),
324
+            $theme,
325
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
326
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
327
+            $SCSSCacher
328
+        );
329
+        $locator->find($styles);
330
+        return $locator->getResources();
331
+    }
332
+
333
+    /**
334
+     * @param string $path
335
+     * @return string|boolean
336
+     */
337
+    public function getAppNamefromPath($path) {
338
+        if ($path !== '' && is_string($path)) {
339
+            $pathParts = explode('/', $path);
340
+            if ($pathParts[0] === 'css') {
341
+                // This is a scss request
342
+                return $pathParts[1];
343
+            }
344
+            return end($pathParts);
345
+        }
346
+        return false;
347
+    }
348
+
349
+    /**
350
+     * @param array $scripts
351
+     * @return array
352
+     */
353
+    public static function findJavascriptFiles($scripts) {
354
+        // Read the selected theme from the config file
355
+        $theme = \OC_Util::getTheme();
356
+
357
+        $locator = new \OC\Template\JSResourceLocator(
358
+            \OC::$server->getLogger(),
359
+            $theme,
360
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
361
+            [ \OC::$SERVERROOT => \OC::$WEBROOT ],
362
+            \OC::$server->query(JSCombiner::class)
363
+            );
364
+        $locator->find($scripts);
365
+        return $locator->getResources();
366
+    }
367
+
368
+    /**
369
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
370
+     * @param string $filePath Absolute path
371
+     * @return string Relative path
372
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
373
+     */
374
+    public static function convertToRelativePath($filePath) {
375
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
376
+        if (count($relativePath) !== 2) {
377
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
378
+        }
379
+
380
+        return $relativePath[1];
381
+    }
382 382
 }
Please login to merge, or discard this patch.