3737use OCP \Defaults ;
3838use OCP \IConfig ;
3939use OCP \IGroupManager ;
40+ use OCP \IInitialStateService ;
4041use OCP \IL10N ;
4142use OCP \ISession ;
4243use OCP \IURLGenerator ;
@@ -75,6 +76,9 @@ class JSConfigHelper {
7576 /** @var CapabilitiesManager */
7677 private $ capabilitiesManager ;
7778
79+ /** @var IInitialStateService */
80+ private $ initialStateService ;
81+
7882 /** @var array user back-ends excluded from password verification */
7983 private $ excludedUserBackEnds = ['user_saml ' => true , 'user_globalsiteselector ' => true ];
8084
@@ -99,7 +103,8 @@ public function __construct(IL10N $l,
99103 IGroupManager $ groupManager ,
100104 IniGetWrapper $ iniWrapper ,
101105 IURLGenerator $ urlGenerator ,
102- CapabilitiesManager $ capabilitiesManager ) {
106+ CapabilitiesManager $ capabilitiesManager ,
107+ IInitialStateService $ initialStateService ) {
103108 $ this ->l = $ l ;
104109 $ this ->defaults = $ defaults ;
105110 $ this ->appManager = $ appManager ;
@@ -110,6 +115,7 @@ public function __construct(IL10N $l,
110115 $ this ->iniWrapper = $ iniWrapper ;
111116 $ this ->urlGenerator = $ urlGenerator ;
112117 $ this ->capabilitiesManager = $ capabilitiesManager ;
118+ $ this ->initialStateService = $ initialStateService ;
113119 }
114120
115121 public function getConfig () {
@@ -146,20 +152,20 @@ public function getConfig() {
146152 $ defaultExpireDateEnabled = $ this ->config ->getAppValue ('core ' , 'shareapi_default_expire_date ' , 'no ' ) === 'yes ' ;
147153 $ defaultExpireDate = $ enforceDefaultExpireDate = null ;
148154 if ($ defaultExpireDateEnabled ) {
149- $ defaultExpireDate = (int ) $ this ->config ->getAppValue ('core ' , 'shareapi_expire_after_n_days ' , '7 ' );
155+ $ defaultExpireDate = (int )$ this ->config ->getAppValue ('core ' , 'shareapi_expire_after_n_days ' , '7 ' );
150156 $ enforceDefaultExpireDate = $ this ->config ->getAppValue ('core ' , 'shareapi_enforce_expire_date ' , 'no ' ) === 'yes ' ;
151157 }
152158 $ outgoingServer2serverShareEnabled = $ this ->config ->getAppValue ('files_sharing ' , 'outgoing_server2server_share_enabled ' , 'yes ' ) === 'yes ' ;
153159
154160 $ defaultInternalExpireDateEnabled = $ this ->config ->getAppValue ('core ' , 'shareapi_default_internal_expire_date ' , 'no ' ) === 'yes ' ;
155161 $ defaultInternalExpireDate = $ defaultInternalExpireDateEnforced = null ;
156162 if ($ defaultInternalExpireDateEnabled ) {
157- $ defaultInternalExpireDate = (int ) $ this ->config ->getAppValue ('core ' , 'shareapi_internal_expire_after_n_days ' , '7 ' );
163+ $ defaultInternalExpireDate = (int )$ this ->config ->getAppValue ('core ' , 'shareapi_internal_expire_after_n_days ' , '7 ' );
158164 $ defaultInternalExpireDateEnforced = $ this ->config ->getAppValue ('core ' , 'shareapi_internal_enforce_expire_date ' , 'no ' ) === 'yes ' ;
159165 }
160166
161167 $ countOfDataLocation = 0 ;
162- $ dataLocation = str_replace (\OC ::$ SERVERROOT .'/ ' , '' , $ this ->config ->getSystemValue ('datadirectory ' , '' ), $ countOfDataLocation );
168+ $ dataLocation = str_replace (\OC ::$ SERVERROOT . '/ ' , '' , $ this ->config ->getSystemValue ('datadirectory ' , '' ), $ countOfDataLocation );
163169 if ($ countOfDataLocation !== 1 || !$ this ->groupManager ->isAdmin ($ uid )) {
164170 $ dataLocation = false ;
165171 }
@@ -175,17 +181,31 @@ public function getConfig() {
175181
176182 $ capabilities = $ this ->capabilitiesManager ->getCapabilities ();
177183
184+ $ config = [
185+ 'session_lifetime ' => min ($ this ->config ->getSystemValue ('session_lifetime ' , $ this ->iniWrapper ->getNumeric ('session.gc_maxlifetime ' )), $ this ->iniWrapper ->getNumeric ('session.gc_maxlifetime ' )),
186+ 'session_keepalive ' => $ this ->config ->getSystemValue ('session_keepalive ' , true ),
187+ 'auto_logout ' => $ this ->config ->getSystemValue ('auto_logout ' , false ),
188+ 'version ' => implode ('. ' , \OCP \Util::getVersion ()),
189+ 'versionstring ' => \OC_Util::getVersionString (),
190+ 'enable_avatars ' => true , // here for legacy reasons - to not crash existing code that relies on this value
191+ 'lost_password_link ' => $ this ->config ->getSystemValue ('lost_password_link ' , null ),
192+ 'modRewriteWorking ' => $ this ->config ->getSystemValue ('htaccess.IgnoreFrontController ' , false ) === true || getenv ('front_controller_active ' ) === 'true ' ,
193+ 'sharing.maxAutocompleteResults ' => (int )$ this ->config ->getSystemValue ('sharing.maxAutocompleteResults ' , 0 ),
194+ 'sharing.minSearchStringLength ' => (int )$ this ->config ->getSystemValue ('sharing.minSearchStringLength ' , 0 ),
195+ 'blacklist_files_regex ' => \OCP \Files \FileInfo::BLACKLIST_FILES_REGEX ,
196+ ];
197+
178198 $ array = [
179199 "_oc_debug " => $ this ->config ->getSystemValue ('debug ' , false ) ? 'true ' : 'false ' ,
180200 "_oc_isadmin " => $ this ->groupManager ->isAdmin ($ uid ) ? 'true ' : 'false ' ,
181201 "backendAllowsPasswordConfirmation " => $ userBackendAllowsPasswordConfirmation ? 'true ' : 'false ' ,
182- "oc_dataURL " => is_string ($ dataLocation ) ? "\"" . $ dataLocation. "\"" : 'false ' ,
183- "_oc_webroot " => "\"" . \OC ::$ WEBROOT . "\"" ,
184- "_oc_appswebroots " => str_replace ('\\/ ' , '/ ' , json_encode ($ apps_paths )), // Ugly unescape slashes waiting for better solution
202+ "oc_dataURL " => is_string ($ dataLocation ) ? "\"" . $ dataLocation . "\"" : 'false ' ,
203+ "_oc_webroot " => "\"" . \OC ::$ WEBROOT . "\"" ,
204+ "_oc_appswebroots " => str_replace ('\\/ ' , '/ ' , json_encode ($ apps_paths )), // Ugly unescape slashes waiting for better solution
185205 "datepickerFormatDate " => json_encode ($ this ->l ->l ('jsdate ' , null )),
186206 'nc_lastLogin ' => $ lastConfirmTimestamp ,
187207 'nc_pageLoad ' => time (),
188- "dayNames " => json_encode ([
208+ "dayNames " => json_encode ([
189209 (string )$ this ->l ->t ('Sunday ' ),
190210 (string )$ this ->l ->t ('Monday ' ),
191211 (string )$ this ->l ->t ('Tuesday ' ),
@@ -194,7 +214,7 @@ public function getConfig() {
194214 (string )$ this ->l ->t ('Friday ' ),
195215 (string )$ this ->l ->t ('Saturday ' )
196216 ]),
197- "dayNamesShort " => json_encode ([
217+ "dayNamesShort " => json_encode ([
198218 (string )$ this ->l ->t ('Sun. ' ),
199219 (string )$ this ->l ->t ('Mon. ' ),
200220 (string )$ this ->l ->t ('Tue. ' ),
@@ -203,7 +223,7 @@ public function getConfig() {
203223 (string )$ this ->l ->t ('Fri. ' ),
204224 (string )$ this ->l ->t ('Sat. ' )
205225 ]),
206- "dayNamesMin " => json_encode ([
226+ "dayNamesMin " => json_encode ([
207227 (string )$ this ->l ->t ('Su ' ),
208228 (string )$ this ->l ->t ('Mo ' ),
209229 (string )$ this ->l ->t ('Tu ' ),
@@ -240,19 +260,8 @@ public function getConfig() {
240260 (string )$ this ->l ->t ('Nov. ' ),
241261 (string )$ this ->l ->t ('Dec. ' )
242262 ]),
243- "firstDay " => json_encode ($ this ->l ->l ('firstday ' , null )) ,
244- "_oc_config " => json_encode ([
245- 'session_lifetime ' => min ($ this ->config ->getSystemValue ('session_lifetime ' , $ this ->iniWrapper ->getNumeric ('session.gc_maxlifetime ' )), $ this ->iniWrapper ->getNumeric ('session.gc_maxlifetime ' )),
246- 'session_keepalive ' => $ this ->config ->getSystemValue ('session_keepalive ' , true ),
247- 'version ' => implode ('. ' , \OCP \Util::getVersion ()),
248- 'versionstring ' => \OC_Util::getVersionString (),
249- 'enable_avatars ' => true , // here for legacy reasons - to not crash existing code that relies on this value
250- 'lost_password_link ' => $ this ->config ->getSystemValue ('lost_password_link ' , null ),
251- 'modRewriteWorking ' => $ this ->config ->getSystemValue ('htaccess.IgnoreFrontController ' , false ) === true || getenv ('front_controller_active ' ) === 'true ' ,
252- 'sharing.maxAutocompleteResults ' => (int )$ this ->config ->getSystemValue ('sharing.maxAutocompleteResults ' , 0 ),
253- 'sharing.minSearchStringLength ' => (int )$ this ->config ->getSystemValue ('sharing.minSearchStringLength ' , 0 ),
254- 'blacklist_files_regex ' => \OCP \Files \FileInfo::BLACKLIST_FILES_REGEX ,
255- ]),
263+ "firstDay " => json_encode ($ this ->l ->l ('firstday ' , null )),
264+ "_oc_config " => json_encode ($ config ),
256265 "oc_appconfig " => json_encode ([
257266 'core ' => [
258267 'defaultExpireDateEnabled ' => $ defaultExpireDateEnabled ,
@@ -296,6 +305,8 @@ public function getConfig() {
296305 ]);
297306 }
298307
308+ $ this ->initialStateService ->provideInitialState ('core ' , 'config ' , $ config );
309+
299310 // Allow hooks to modify the output values
300311 \OC_Hook::emit ('\OCP\Config ' , 'js ' , ['array ' => &$ array ]);
301312
0 commit comments