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