@@ -46,303 +46,303 @@ |
||
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 | - } else if ($renderAs == 'guest') { |
|
122 | - parent::__construct('core', 'layout.guest'); |
|
123 | - \OC_Util::addStyle('guest'); |
|
124 | - $this->assign('bodyid', 'body-login'); |
|
125 | - |
|
126 | - $userDisplayName = \OC_User::getDisplayName(); |
|
127 | - $this->assign('user_displayname', $userDisplayName); |
|
128 | - $this->assign('user_uid', \OC_User::getUser()); |
|
129 | - } else if ($renderAs == 'public') { |
|
130 | - parent::__construct('core', 'layout.public'); |
|
131 | - $this->assign( 'appid', $appId ); |
|
132 | - $this->assign('bodyid', 'body-public'); |
|
133 | - $this->assign('showSimpleSignUpLink', $this->config->getSystemValue('simpleSignUpLink.shown', true) !== false); |
|
134 | - } else { |
|
135 | - parent::__construct('core', 'layout.base'); |
|
136 | - |
|
137 | - } |
|
138 | - // Send the language and the locale to our layouts |
|
139 | - $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
140 | - $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
|
141 | - $localeLang = \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale); |
|
142 | - |
|
143 | - $lang = str_replace('_', '-', $lang); |
|
144 | - $this->assign('language', $lang); |
|
145 | - $this->assign('locale', $locale); |
|
146 | - |
|
147 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
148 | - if (empty(self::$versionHash)) { |
|
149 | - $v = \OC_App::getAppVersions(); |
|
150 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
151 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
152 | - } |
|
153 | - } else { |
|
154 | - self::$versionHash = md5('not installed'); |
|
155 | - } |
|
156 | - |
|
157 | - // Add the js files |
|
158 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
159 | - $this->assign('jsfiles', array()); |
|
160 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
161 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
162 | - $jsConfigHelper = new JSConfigHelper( |
|
163 | - \OC::$server->getL10N('lib', $localeLang ?: $lang), |
|
164 | - \OC::$server->query(Defaults::class), |
|
165 | - \OC::$server->getAppManager(), |
|
166 | - \OC::$server->getSession(), |
|
167 | - \OC::$server->getUserSession()->getUser(), |
|
168 | - $this->config, |
|
169 | - \OC::$server->getGroupManager(), |
|
170 | - \OC::$server->getIniWrapper(), |
|
171 | - \OC::$server->getURLGenerator(), |
|
172 | - \OC::$server->getCapabilitiesManager() |
|
173 | - ); |
|
174 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
175 | - } else { |
|
176 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
177 | - } |
|
178 | - } |
|
179 | - foreach($jsFiles as $info) { |
|
180 | - $web = $info[1]; |
|
181 | - $file = $info[2]; |
|
182 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
183 | - } |
|
184 | - |
|
185 | - try { |
|
186 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
187 | - } catch (\Exception $e) { |
|
188 | - $pathInfo = ''; |
|
189 | - } |
|
190 | - |
|
191 | - // Do not initialise scss appdata until we have a fully installed instance |
|
192 | - // Do not load scss for update, errors, installation or login page |
|
193 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
194 | - && !\OCP\Util::needUpgrade() |
|
195 | - && $pathInfo !== '' |
|
196 | - && !preg_match('/^\/login/', $pathInfo) |
|
197 | - && $renderAs !== 'error' |
|
198 | - ) { |
|
199 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
200 | - } else { |
|
201 | - // If we ignore the scss compiler, |
|
202 | - // we need to load the guest css fallback |
|
203 | - \OC_Util::addStyle('guest'); |
|
204 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
205 | - } |
|
206 | - |
|
207 | - $this->assign('cssfiles', array()); |
|
208 | - $this->assign('printcssfiles', []); |
|
209 | - $this->assign('versionHash', self::$versionHash); |
|
210 | - foreach($cssFiles as $info) { |
|
211 | - $web = $info[1]; |
|
212 | - $file = $info[2]; |
|
213 | - |
|
214 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
215 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
216 | - } else { |
|
217 | - $suffix = $this->getVersionHashSuffix($web, $file); |
|
218 | - |
|
219 | - if (strpos($file, '?v=') == false) { |
|
220 | - $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
221 | - } else { |
|
222 | - $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
223 | - } |
|
224 | - |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - /** @var InitialStateService $initialState */ |
|
229 | - $initialState = \OC::$server->query(InitialStateService::class); |
|
230 | - $this->assign('initialStates', $initialState->getInitialStates()); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $path |
|
235 | - * @param string $file |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
239 | - if ($this->config->getSystemValue('debug', false)) { |
|
240 | - // allows chrome workspace mapping in debug mode |
|
241 | - return ""; |
|
242 | - } |
|
243 | - $themingSuffix = ''; |
|
244 | - $v = []; |
|
245 | - |
|
246 | - if ($this->config->getSystemValue('installed', false)) { |
|
247 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
248 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
249 | - } |
|
250 | - $v = \OC_App::getAppVersions(); |
|
251 | - } |
|
252 | - |
|
253 | - // Try the webroot path for a match |
|
254 | - if ($path !== false && $path !== '') { |
|
255 | - $appName = $this->getAppNamefromPath($path); |
|
256 | - if(array_key_exists($appName, $v)) { |
|
257 | - $appVersion = $v[$appName]; |
|
258 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
259 | - } |
|
260 | - } |
|
261 | - // fallback to the file path instead |
|
262 | - if ($file !== false && $file !== '') { |
|
263 | - $appName = $this->getAppNamefromPath($file); |
|
264 | - if(array_key_exists($appName, $v)) { |
|
265 | - $appVersion = $v[$appName]; |
|
266 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @param array $styles |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
278 | - // Read the selected theme from the config file |
|
279 | - $theme = \OC_Util::getTheme(); |
|
280 | - |
|
281 | - if($compileScss) { |
|
282 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
283 | - } else { |
|
284 | - $SCSSCacher = null; |
|
285 | - } |
|
286 | - |
|
287 | - $locator = new \OC\Template\CSSResourceLocator( |
|
288 | - \OC::$server->getLogger(), |
|
289 | - $theme, |
|
290 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
291 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
292 | - $SCSSCacher |
|
293 | - ); |
|
294 | - $locator->find($styles); |
|
295 | - return $locator->getResources(); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * @param string $path |
|
300 | - * @return string|boolean |
|
301 | - */ |
|
302 | - public function getAppNamefromPath($path) { |
|
303 | - if ($path !== '' && is_string($path)) { |
|
304 | - $pathParts = explode('/', $path); |
|
305 | - if ($pathParts[0] === 'css') { |
|
306 | - // This is a scss request |
|
307 | - return $pathParts[1]; |
|
308 | - } |
|
309 | - return end($pathParts); |
|
310 | - } |
|
311 | - return false; |
|
312 | - |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * @param array $scripts |
|
317 | - * @return array |
|
318 | - */ |
|
319 | - static public function findJavascriptFiles($scripts) { |
|
320 | - // Read the selected theme from the config file |
|
321 | - $theme = \OC_Util::getTheme(); |
|
322 | - |
|
323 | - $locator = new \OC\Template\JSResourceLocator( |
|
324 | - \OC::$server->getLogger(), |
|
325 | - $theme, |
|
326 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
327 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
328 | - \OC::$server->query(JSCombiner::class) |
|
329 | - ); |
|
330 | - $locator->find($scripts); |
|
331 | - return $locator->getResources(); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
336 | - * @param string $filePath Absolute path |
|
337 | - * @return string Relative path |
|
338 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
339 | - */ |
|
340 | - public static function convertToRelativePath($filePath) { |
|
341 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
342 | - if(count($relativePath) !== 2) { |
|
343 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
344 | - } |
|
345 | - |
|
346 | - return $relativePath[1]; |
|
347 | - } |
|
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 | + } else if ($renderAs == 'guest') { |
|
122 | + parent::__construct('core', 'layout.guest'); |
|
123 | + \OC_Util::addStyle('guest'); |
|
124 | + $this->assign('bodyid', 'body-login'); |
|
125 | + |
|
126 | + $userDisplayName = \OC_User::getDisplayName(); |
|
127 | + $this->assign('user_displayname', $userDisplayName); |
|
128 | + $this->assign('user_uid', \OC_User::getUser()); |
|
129 | + } else if ($renderAs == 'public') { |
|
130 | + parent::__construct('core', 'layout.public'); |
|
131 | + $this->assign( 'appid', $appId ); |
|
132 | + $this->assign('bodyid', 'body-public'); |
|
133 | + $this->assign('showSimpleSignUpLink', $this->config->getSystemValue('simpleSignUpLink.shown', true) !== false); |
|
134 | + } else { |
|
135 | + parent::__construct('core', 'layout.base'); |
|
136 | + |
|
137 | + } |
|
138 | + // Send the language and the locale to our layouts |
|
139 | + $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
140 | + $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
|
141 | + $localeLang = \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale); |
|
142 | + |
|
143 | + $lang = str_replace('_', '-', $lang); |
|
144 | + $this->assign('language', $lang); |
|
145 | + $this->assign('locale', $locale); |
|
146 | + |
|
147 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
148 | + if (empty(self::$versionHash)) { |
|
149 | + $v = \OC_App::getAppVersions(); |
|
150 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
151 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
152 | + } |
|
153 | + } else { |
|
154 | + self::$versionHash = md5('not installed'); |
|
155 | + } |
|
156 | + |
|
157 | + // Add the js files |
|
158 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
159 | + $this->assign('jsfiles', array()); |
|
160 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
161 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
162 | + $jsConfigHelper = new JSConfigHelper( |
|
163 | + \OC::$server->getL10N('lib', $localeLang ?: $lang), |
|
164 | + \OC::$server->query(Defaults::class), |
|
165 | + \OC::$server->getAppManager(), |
|
166 | + \OC::$server->getSession(), |
|
167 | + \OC::$server->getUserSession()->getUser(), |
|
168 | + $this->config, |
|
169 | + \OC::$server->getGroupManager(), |
|
170 | + \OC::$server->getIniWrapper(), |
|
171 | + \OC::$server->getURLGenerator(), |
|
172 | + \OC::$server->getCapabilitiesManager() |
|
173 | + ); |
|
174 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
175 | + } else { |
|
176 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
177 | + } |
|
178 | + } |
|
179 | + foreach($jsFiles as $info) { |
|
180 | + $web = $info[1]; |
|
181 | + $file = $info[2]; |
|
182 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
183 | + } |
|
184 | + |
|
185 | + try { |
|
186 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
187 | + } catch (\Exception $e) { |
|
188 | + $pathInfo = ''; |
|
189 | + } |
|
190 | + |
|
191 | + // Do not initialise scss appdata until we have a fully installed instance |
|
192 | + // Do not load scss for update, errors, installation or login page |
|
193 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
194 | + && !\OCP\Util::needUpgrade() |
|
195 | + && $pathInfo !== '' |
|
196 | + && !preg_match('/^\/login/', $pathInfo) |
|
197 | + && $renderAs !== 'error' |
|
198 | + ) { |
|
199 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
200 | + } else { |
|
201 | + // If we ignore the scss compiler, |
|
202 | + // we need to load the guest css fallback |
|
203 | + \OC_Util::addStyle('guest'); |
|
204 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
205 | + } |
|
206 | + |
|
207 | + $this->assign('cssfiles', array()); |
|
208 | + $this->assign('printcssfiles', []); |
|
209 | + $this->assign('versionHash', self::$versionHash); |
|
210 | + foreach($cssFiles as $info) { |
|
211 | + $web = $info[1]; |
|
212 | + $file = $info[2]; |
|
213 | + |
|
214 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
215 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
216 | + } else { |
|
217 | + $suffix = $this->getVersionHashSuffix($web, $file); |
|
218 | + |
|
219 | + if (strpos($file, '?v=') == false) { |
|
220 | + $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
221 | + } else { |
|
222 | + $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
223 | + } |
|
224 | + |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + /** @var InitialStateService $initialState */ |
|
229 | + $initialState = \OC::$server->query(InitialStateService::class); |
|
230 | + $this->assign('initialStates', $initialState->getInitialStates()); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $path |
|
235 | + * @param string $file |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
239 | + if ($this->config->getSystemValue('debug', false)) { |
|
240 | + // allows chrome workspace mapping in debug mode |
|
241 | + return ""; |
|
242 | + } |
|
243 | + $themingSuffix = ''; |
|
244 | + $v = []; |
|
245 | + |
|
246 | + if ($this->config->getSystemValue('installed', false)) { |
|
247 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
248 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
249 | + } |
|
250 | + $v = \OC_App::getAppVersions(); |
|
251 | + } |
|
252 | + |
|
253 | + // Try the webroot path for a match |
|
254 | + if ($path !== false && $path !== '') { |
|
255 | + $appName = $this->getAppNamefromPath($path); |
|
256 | + if(array_key_exists($appName, $v)) { |
|
257 | + $appVersion = $v[$appName]; |
|
258 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
259 | + } |
|
260 | + } |
|
261 | + // fallback to the file path instead |
|
262 | + if ($file !== false && $file !== '') { |
|
263 | + $appName = $this->getAppNamefromPath($file); |
|
264 | + if(array_key_exists($appName, $v)) { |
|
265 | + $appVersion = $v[$appName]; |
|
266 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @param array $styles |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
278 | + // Read the selected theme from the config file |
|
279 | + $theme = \OC_Util::getTheme(); |
|
280 | + |
|
281 | + if($compileScss) { |
|
282 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
283 | + } else { |
|
284 | + $SCSSCacher = null; |
|
285 | + } |
|
286 | + |
|
287 | + $locator = new \OC\Template\CSSResourceLocator( |
|
288 | + \OC::$server->getLogger(), |
|
289 | + $theme, |
|
290 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
291 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
292 | + $SCSSCacher |
|
293 | + ); |
|
294 | + $locator->find($styles); |
|
295 | + return $locator->getResources(); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * @param string $path |
|
300 | + * @return string|boolean |
|
301 | + */ |
|
302 | + public function getAppNamefromPath($path) { |
|
303 | + if ($path !== '' && is_string($path)) { |
|
304 | + $pathParts = explode('/', $path); |
|
305 | + if ($pathParts[0] === 'css') { |
|
306 | + // This is a scss request |
|
307 | + return $pathParts[1]; |
|
308 | + } |
|
309 | + return end($pathParts); |
|
310 | + } |
|
311 | + return false; |
|
312 | + |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * @param array $scripts |
|
317 | + * @return array |
|
318 | + */ |
|
319 | + static public function findJavascriptFiles($scripts) { |
|
320 | + // Read the selected theme from the config file |
|
321 | + $theme = \OC_Util::getTheme(); |
|
322 | + |
|
323 | + $locator = new \OC\Template\JSResourceLocator( |
|
324 | + \OC::$server->getLogger(), |
|
325 | + $theme, |
|
326 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
327 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
328 | + \OC::$server->query(JSCombiner::class) |
|
329 | + ); |
|
330 | + $locator->find($scripts); |
|
331 | + return $locator->getResources(); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
336 | + * @param string $filePath Absolute path |
|
337 | + * @return string Relative path |
|
338 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
339 | + */ |
|
340 | + public static function convertToRelativePath($filePath) { |
|
341 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
342 | + if(count($relativePath) !== 2) { |
|
343 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
344 | + } |
|
345 | + |
|
346 | + return $relativePath[1]; |
|
347 | + } |
|
348 | 348 | } |
@@ -57,41 +57,41 @@ discard block |
||
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 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $this->assign('user_uid', \OC_User::getUser()); |
129 | 129 | } else if ($renderAs == 'public') { |
130 | 130 | parent::__construct('core', 'layout.public'); |
131 | - $this->assign( 'appid', $appId ); |
|
131 | + $this->assign('appid', $appId); |
|
132 | 132 | $this->assign('bodyid', 'body-public'); |
133 | 133 | $this->assign('showSimpleSignUpLink', $this->config->getSystemValue('simpleSignUpLink.shown', true) !== false); |
134 | 134 | } else { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $this->assign('language', $lang); |
145 | 145 | $this->assign('locale', $locale); |
146 | 146 | |
147 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
147 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
148 | 148 | if (empty(self::$versionHash)) { |
149 | 149 | $v = \OC_App::getAppVersions(); |
150 | 150 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
177 | 177 | } |
178 | 178 | } |
179 | - foreach($jsFiles as $info) { |
|
179 | + foreach ($jsFiles as $info) { |
|
180 | 180 | $web = $info[1]; |
181 | 181 | $file = $info[2]; |
182 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
182 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | try { |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | // Do not initialise scss appdata until we have a fully installed instance |
192 | 192 | // Do not load scss for update, errors, installation or login page |
193 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
193 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
194 | 194 | && !\OCP\Util::needUpgrade() |
195 | 195 | && $pathInfo !== '' |
196 | 196 | && !preg_match('/^\/login/', $pathInfo) |
@@ -207,19 +207,19 @@ discard block |
||
207 | 207 | $this->assign('cssfiles', array()); |
208 | 208 | $this->assign('printcssfiles', []); |
209 | 209 | $this->assign('versionHash', self::$versionHash); |
210 | - foreach($cssFiles as $info) { |
|
210 | + foreach ($cssFiles as $info) { |
|
211 | 211 | $web = $info[1]; |
212 | 212 | $file = $info[2]; |
213 | 213 | |
214 | 214 | if (substr($file, -strlen('print.css')) === 'print.css') { |
215 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
215 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
216 | 216 | } else { |
217 | 217 | $suffix = $this->getVersionHashSuffix($web, $file); |
218 | 218 | |
219 | 219 | if (strpos($file, '?v=') == false) { |
220 | - $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
220 | + $this->append('cssfiles', $web.'/'.$file.$suffix); |
|
221 | 221 | } else { |
222 | - $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
222 | + $this->append('cssfiles', $web.'/'.$file.'-'.substr($suffix, 3)); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | if ($this->config->getSystemValue('installed', false)) { |
247 | 247 | if (\OC::$server->getAppManager()->isInstalled('theming')) { |
248 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
248 | + $themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
249 | 249 | } |
250 | 250 | $v = \OC_App::getAppVersions(); |
251 | 251 | } |
@@ -253,21 +253,21 @@ discard block |
||
253 | 253 | // Try the webroot path for a match |
254 | 254 | if ($path !== false && $path !== '') { |
255 | 255 | $appName = $this->getAppNamefromPath($path); |
256 | - if(array_key_exists($appName, $v)) { |
|
256 | + if (array_key_exists($appName, $v)) { |
|
257 | 257 | $appVersion = $v[$appName]; |
258 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
258 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | // fallback to the file path instead |
262 | 262 | if ($file !== false && $file !== '') { |
263 | 263 | $appName = $this->getAppNamefromPath($file); |
264 | - if(array_key_exists($appName, $v)) { |
|
264 | + if (array_key_exists($appName, $v)) { |
|
265 | 265 | $appVersion = $v[$appName]; |
266 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
266 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
270 | + return '?v='.self::$versionHash.$themingSuffix; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | // Read the selected theme from the config file |
279 | 279 | $theme = \OC_Util::getTheme(); |
280 | 280 | |
281 | - if($compileScss) { |
|
281 | + if ($compileScss) { |
|
282 | 282 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
283 | 283 | } else { |
284 | 284 | $SCSSCacher = null; |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | $locator = new \OC\Template\CSSResourceLocator( |
288 | 288 | \OC::$server->getLogger(), |
289 | 289 | $theme, |
290 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
291 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
290 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
291 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
292 | 292 | $SCSSCacher |
293 | 293 | ); |
294 | 294 | $locator->find($styles); |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | $locator = new \OC\Template\JSResourceLocator( |
324 | 324 | \OC::$server->getLogger(), |
325 | 325 | $theme, |
326 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
327 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
326 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
327 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
328 | 328 | \OC::$server->query(JSCombiner::class) |
329 | 329 | ); |
330 | 330 | $locator->find($scripts); |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public static function convertToRelativePath($filePath) { |
341 | 341 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
342 | - if(count($relativePath) !== 2) { |
|
342 | + if (count($relativePath) !== 2) { |
|
343 | 343 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
344 | 344 | } |
345 | 345 |