@@ -40,229 +40,229 @@ |
||
40 | 40 | |
41 | 41 | class TemplateLayout extends \OC_Template { |
42 | 42 | |
43 | - private static $versionHash = ''; |
|
43 | + private static $versionHash = ''; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var \OCP\IConfig |
|
47 | - */ |
|
48 | - private $config; |
|
45 | + /** |
|
46 | + * @var \OCP\IConfig |
|
47 | + */ |
|
48 | + private $config; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $renderAs |
|
52 | - * @param string $appId application id |
|
53 | - */ |
|
54 | - public function __construct( $renderAs, $appId = '' ) { |
|
50 | + /** |
|
51 | + * @param string $renderAs |
|
52 | + * @param string $appId application id |
|
53 | + */ |
|
54 | + public function __construct( $renderAs, $appId = '' ) { |
|
55 | 55 | |
56 | - // yes - should be injected .... |
|
57 | - $this->config = \OC::$server->getConfig(); |
|
56 | + // yes - should be injected .... |
|
57 | + $this->config = \OC::$server->getConfig(); |
|
58 | 58 | |
59 | - // Decide which page we show |
|
60 | - if($renderAs == 'user') { |
|
61 | - parent::__construct( 'core', 'layout.user' ); |
|
62 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
63 | - $this->assign('bodyid', 'body-settings'); |
|
64 | - }else{ |
|
65 | - $this->assign('bodyid', 'body-user'); |
|
66 | - } |
|
59 | + // Decide which page we show |
|
60 | + if($renderAs == 'user') { |
|
61 | + parent::__construct( 'core', 'layout.user' ); |
|
62 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
63 | + $this->assign('bodyid', 'body-settings'); |
|
64 | + }else{ |
|
65 | + $this->assign('bodyid', 'body-user'); |
|
66 | + } |
|
67 | 67 | |
68 | - // Code integrity notification |
|
69 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
70 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
71 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
72 | - } |
|
68 | + // Code integrity notification |
|
69 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
70 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
71 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
72 | + } |
|
73 | 73 | |
74 | - // Add navigation entry |
|
75 | - $this->assign( 'application', ''); |
|
76 | - $this->assign( 'appid', $appId ); |
|
77 | - $navigation = \OC_App::getNavigation(); |
|
78 | - $this->assign( 'navigation', $navigation); |
|
79 | - $navigation = \OC_App::getHeaderNavigation(); |
|
80 | - $this->assign( 'headernavigation', $navigation); |
|
81 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
82 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
83 | - foreach($navigation as $entry) { |
|
84 | - if ($entry['active']) { |
|
85 | - $this->assign( 'application', $entry['name'] ); |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
74 | + // Add navigation entry |
|
75 | + $this->assign( 'application', ''); |
|
76 | + $this->assign( 'appid', $appId ); |
|
77 | + $navigation = \OC_App::getNavigation(); |
|
78 | + $this->assign( 'navigation', $navigation); |
|
79 | + $navigation = \OC_App::getHeaderNavigation(); |
|
80 | + $this->assign( 'headernavigation', $navigation); |
|
81 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
82 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
83 | + foreach($navigation as $entry) { |
|
84 | + if ($entry['active']) { |
|
85 | + $this->assign( 'application', $entry['name'] ); |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - foreach($settingsNavigation as $entry) { |
|
91 | - if ($entry['active']) { |
|
92 | - $this->assign( 'application', $entry['name'] ); |
|
93 | - break; |
|
94 | - } |
|
95 | - } |
|
96 | - $userDisplayName = \OC_User::getDisplayName(); |
|
97 | - $appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0; |
|
98 | - if ($appsMgmtActive) { |
|
99 | - $l = \OC::$server->getL10N('lib'); |
|
100 | - $this->assign('application', $l->t('Apps')); |
|
101 | - } |
|
102 | - $this->assign('user_displayname', $userDisplayName); |
|
103 | - $this->assign('user_uid', \OC_User::getUser()); |
|
104 | - $this->assign('appsmanagement_active', $appsMgmtActive); |
|
90 | + foreach($settingsNavigation as $entry) { |
|
91 | + if ($entry['active']) { |
|
92 | + $this->assign( 'application', $entry['name'] ); |
|
93 | + break; |
|
94 | + } |
|
95 | + } |
|
96 | + $userDisplayName = \OC_User::getDisplayName(); |
|
97 | + $appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0; |
|
98 | + if ($appsMgmtActive) { |
|
99 | + $l = \OC::$server->getL10N('lib'); |
|
100 | + $this->assign('application', $l->t('Apps')); |
|
101 | + } |
|
102 | + $this->assign('user_displayname', $userDisplayName); |
|
103 | + $this->assign('user_uid', \OC_User::getUser()); |
|
104 | + $this->assign('appsmanagement_active', $appsMgmtActive); |
|
105 | 105 | |
106 | - if (\OC_User::getUser() === false) { |
|
107 | - $this->assign('userAvatarSet', false); |
|
108 | - } else { |
|
109 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
110 | - $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
111 | - } |
|
106 | + if (\OC_User::getUser() === false) { |
|
107 | + $this->assign('userAvatarSet', false); |
|
108 | + } else { |
|
109 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
110 | + $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
111 | + } |
|
112 | 112 | |
113 | - } else if ($renderAs == 'error') { |
|
114 | - parent::__construct('core', 'layout.guest', '', false); |
|
115 | - $this->assign('bodyid', 'body-login'); |
|
116 | - } else if ($renderAs == 'guest') { |
|
117 | - parent::__construct('core', 'layout.guest'); |
|
118 | - $this->assign('bodyid', 'body-login'); |
|
119 | - } else { |
|
120 | - parent::__construct('core', 'layout.base'); |
|
113 | + } else if ($renderAs == 'error') { |
|
114 | + parent::__construct('core', 'layout.guest', '', false); |
|
115 | + $this->assign('bodyid', 'body-login'); |
|
116 | + } else if ($renderAs == 'guest') { |
|
117 | + parent::__construct('core', 'layout.guest'); |
|
118 | + $this->assign('bodyid', 'body-login'); |
|
119 | + } else { |
|
120 | + parent::__construct('core', 'layout.base'); |
|
121 | 121 | |
122 | - } |
|
123 | - // Send the language to our layouts |
|
124 | - $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
122 | + } |
|
123 | + // Send the language to our layouts |
|
124 | + $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
125 | 125 | |
126 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
127 | - if (empty(self::$versionHash)) { |
|
128 | - $v = \OC_App::getAppVersions(); |
|
129 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
130 | - self::$versionHash = md5(implode(',', $v)); |
|
131 | - } |
|
132 | - } else { |
|
133 | - self::$versionHash = md5('not installed'); |
|
134 | - } |
|
126 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
127 | + if (empty(self::$versionHash)) { |
|
128 | + $v = \OC_App::getAppVersions(); |
|
129 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
130 | + self::$versionHash = md5(implode(',', $v)); |
|
131 | + } |
|
132 | + } else { |
|
133 | + self::$versionHash = md5('not installed'); |
|
134 | + } |
|
135 | 135 | |
136 | - // Add the js files |
|
137 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
138 | - $this->assign('jsfiles', array()); |
|
139 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
140 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
141 | - $jsConfigHelper = new JSConfigHelper( |
|
142 | - \OC::$server->getL10N('core'), |
|
143 | - \OC::$server->getThemingDefaults(), |
|
144 | - \OC::$server->getAppManager(), |
|
145 | - \OC::$server->getSession(), |
|
146 | - \OC::$server->getUserSession()->getUser(), |
|
147 | - \OC::$server->getConfig(), |
|
148 | - \OC::$server->getGroupManager(), |
|
149 | - \OC::$server->getIniWrapper(), |
|
150 | - \OC::$server->getURLGenerator() |
|
151 | - ); |
|
152 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
153 | - } else { |
|
154 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
155 | - } |
|
156 | - } |
|
157 | - foreach($jsFiles as $info) { |
|
158 | - $web = $info[1]; |
|
159 | - $file = $info[2]; |
|
160 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
161 | - } |
|
136 | + // Add the js files |
|
137 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
138 | + $this->assign('jsfiles', array()); |
|
139 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
140 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
141 | + $jsConfigHelper = new JSConfigHelper( |
|
142 | + \OC::$server->getL10N('core'), |
|
143 | + \OC::$server->getThemingDefaults(), |
|
144 | + \OC::$server->getAppManager(), |
|
145 | + \OC::$server->getSession(), |
|
146 | + \OC::$server->getUserSession()->getUser(), |
|
147 | + \OC::$server->getConfig(), |
|
148 | + \OC::$server->getGroupManager(), |
|
149 | + \OC::$server->getIniWrapper(), |
|
150 | + \OC::$server->getURLGenerator() |
|
151 | + ); |
|
152 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
153 | + } else { |
|
154 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
155 | + } |
|
156 | + } |
|
157 | + foreach($jsFiles as $info) { |
|
158 | + $web = $info[1]; |
|
159 | + $file = $info[2]; |
|
160 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
161 | + } |
|
162 | 162 | |
163 | - try { |
|
164 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
165 | - } catch (\Exception $e) { |
|
166 | - $pathInfo = ''; |
|
167 | - } |
|
163 | + try { |
|
164 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
165 | + } catch (\Exception $e) { |
|
166 | + $pathInfo = ''; |
|
167 | + } |
|
168 | 168 | |
169 | - // Do not initialise scss appdata until we have a fully installed instance |
|
170 | - // Do not load scss for update, errors, installation or login page |
|
171 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
172 | - && !\OCP\Util::needUpgrade() |
|
173 | - && $pathInfo !== '' |
|
174 | - && !preg_match('/^\/login/', $pathInfo)) { |
|
175 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
176 | - } else { |
|
177 | - // If we ignore the scss compiler, |
|
178 | - // we need to load the guest css fallback |
|
179 | - \OC_Util::addStyle('guest'); |
|
180 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
181 | - } |
|
169 | + // Do not initialise scss appdata until we have a fully installed instance |
|
170 | + // Do not load scss for update, errors, installation or login page |
|
171 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
172 | + && !\OCP\Util::needUpgrade() |
|
173 | + && $pathInfo !== '' |
|
174 | + && !preg_match('/^\/login/', $pathInfo)) { |
|
175 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
176 | + } else { |
|
177 | + // If we ignore the scss compiler, |
|
178 | + // we need to load the guest css fallback |
|
179 | + \OC_Util::addStyle('guest'); |
|
180 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
181 | + } |
|
182 | 182 | |
183 | - $this->assign('cssfiles', array()); |
|
184 | - $this->assign('printcssfiles', []); |
|
185 | - $this->assign('versionHash', self::$versionHash); |
|
186 | - foreach($cssFiles as $info) { |
|
187 | - $web = $info[1]; |
|
188 | - $file = $info[2]; |
|
183 | + $this->assign('cssfiles', array()); |
|
184 | + $this->assign('printcssfiles', []); |
|
185 | + $this->assign('versionHash', self::$versionHash); |
|
186 | + foreach($cssFiles as $info) { |
|
187 | + $web = $info[1]; |
|
188 | + $file = $info[2]; |
|
189 | 189 | |
190 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
191 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
192 | - } else { |
|
193 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
190 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
191 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
192 | + } else { |
|
193 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | 197 | |
198 | - protected function getVersionHashSuffix() { |
|
199 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
200 | - // allows chrome workspace mapping in debug mode |
|
201 | - return ""; |
|
202 | - } |
|
198 | + protected function getVersionHashSuffix() { |
|
199 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
200 | + // allows chrome workspace mapping in debug mode |
|
201 | + return ""; |
|
202 | + } |
|
203 | 203 | |
204 | - return '?v=' . self::$versionHash; |
|
205 | - } |
|
204 | + return '?v=' . self::$versionHash; |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * @param array $styles |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
212 | - // Read the selected theme from the config file |
|
213 | - $theme = \OC_Util::getTheme(); |
|
207 | + /** |
|
208 | + * @param array $styles |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
212 | + // Read the selected theme from the config file |
|
213 | + $theme = \OC_Util::getTheme(); |
|
214 | 214 | |
215 | - if($compileScss) { |
|
216 | - $SCSSCacher = new SCSSCacher( |
|
217 | - \OC::$server->getLogger(), |
|
218 | - \OC::$server->getAppDataDir('css'), |
|
219 | - \OC::$server->getURLGenerator(), |
|
220 | - \OC::$server->getConfig(), |
|
221 | - \OC::$SERVERROOT |
|
222 | - ); |
|
223 | - } else { |
|
224 | - $SCSSCacher = null; |
|
225 | - } |
|
215 | + if($compileScss) { |
|
216 | + $SCSSCacher = new SCSSCacher( |
|
217 | + \OC::$server->getLogger(), |
|
218 | + \OC::$server->getAppDataDir('css'), |
|
219 | + \OC::$server->getURLGenerator(), |
|
220 | + \OC::$server->getConfig(), |
|
221 | + \OC::$SERVERROOT |
|
222 | + ); |
|
223 | + } else { |
|
224 | + $SCSSCacher = null; |
|
225 | + } |
|
226 | 226 | |
227 | - $locator = new \OC\Template\CSSResourceLocator( |
|
228 | - \OC::$server->getLogger(), |
|
229 | - $theme, |
|
230 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
231 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
232 | - $SCSSCacher); |
|
233 | - $locator->find($styles); |
|
234 | - return $locator->getResources(); |
|
235 | - } |
|
227 | + $locator = new \OC\Template\CSSResourceLocator( |
|
228 | + \OC::$server->getLogger(), |
|
229 | + $theme, |
|
230 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
231 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
232 | + $SCSSCacher); |
|
233 | + $locator->find($styles); |
|
234 | + return $locator->getResources(); |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @param array $scripts |
|
239 | - * @return array |
|
240 | - */ |
|
241 | - static public function findJavascriptFiles($scripts) { |
|
242 | - // Read the selected theme from the config file |
|
243 | - $theme = \OC_Util::getTheme(); |
|
237 | + /** |
|
238 | + * @param array $scripts |
|
239 | + * @return array |
|
240 | + */ |
|
241 | + static public function findJavascriptFiles($scripts) { |
|
242 | + // Read the selected theme from the config file |
|
243 | + $theme = \OC_Util::getTheme(); |
|
244 | 244 | |
245 | - $locator = new \OC\Template\JSResourceLocator( |
|
246 | - \OC::$server->getLogger(), |
|
247 | - $theme, |
|
248 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
249 | - array( \OC::$SERVERROOT => \OC::$WEBROOT )); |
|
250 | - $locator->find($scripts); |
|
251 | - return $locator->getResources(); |
|
252 | - } |
|
245 | + $locator = new \OC\Template\JSResourceLocator( |
|
246 | + \OC::$server->getLogger(), |
|
247 | + $theme, |
|
248 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
249 | + array( \OC::$SERVERROOT => \OC::$WEBROOT )); |
|
250 | + $locator->find($scripts); |
|
251 | + return $locator->getResources(); |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
256 | - * @param string $filePath Absolute path |
|
257 | - * @return string Relative path |
|
258 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
259 | - */ |
|
260 | - public static function convertToRelativePath($filePath) { |
|
261 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
262 | - if(count($relativePath) !== 2) { |
|
263 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
264 | - } |
|
254 | + /** |
|
255 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
256 | + * @param string $filePath Absolute path |
|
257 | + * @return string Relative path |
|
258 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
259 | + */ |
|
260 | + public static function convertToRelativePath($filePath) { |
|
261 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
262 | + if(count($relativePath) !== 2) { |
|
263 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
264 | + } |
|
265 | 265 | |
266 | - return $relativePath[1]; |
|
267 | - } |
|
266 | + return $relativePath[1]; |
|
267 | + } |
|
268 | 268 | } |