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