@@ -11,20 +11,41 @@ public function __construct()
11
11
$ this ->docRoot = $ _SERVER ['DOCUMENT_ROOT ' ];
12
12
}
13
13
14
+ public function getDataDirDetails ()
15
+ {
16
+ clearstatcache ();
17
+
18
+ // Return details about the data dir
19
+ $ fullPath = dirname (__FILE__ ) . "/../data/ " ;
20
+ $ exists = file_exists ($ fullPath );
21
+ $ readable = is_readable ($ fullPath );
22
+ $ writable = is_writable ($ fullPath );
23
+ return [
24
+ "fullPath " => $ fullPath ,
25
+ "exists " => $ exists ,
26
+ "readable " => $ readable ,
27
+ "writable " => $ writable ,
28
+ ];
29
+ }
30
+
14
31
public function getConfigGlobalFileDetails ()
15
32
{
33
+ clearstatcache ();
34
+
16
35
// Return details about the global config file
17
36
$ fileName = 'config-global.php ' ;
18
37
$ fullPath = dirname (__FILE__ ) . "/../data/ " . $ fileName ;
19
38
$ exists = file_exists ($ fullPath );
20
39
$ readable = is_readable ($ fullPath );
21
40
$ writable = is_writable ($ fullPath );
41
+ $ filemtime = filemtime ($ fullPath );
22
42
return [
23
43
"fileName " => $ fileName ,
24
44
"fullPath " => $ fullPath ,
25
45
"exists " => $ exists ,
26
46
"readable " => $ readable ,
27
47
"writable " => $ writable ,
48
+ "filemtime " => $ filemtime
28
49
];
29
50
}
30
51
@@ -82,52 +103,96 @@ public function setConfigGlobalSettings($settings)
82
103
}
83
104
}
84
105
85
- public function updateConfigCreateDate (): void
106
+ public function getConfigUsersFileDetails ( $ fileName )
86
107
{
87
- global $ settingsFile , $ ICEcoderUserSettings ;
108
+ // Return details about the users config file
109
+ $ fullPath = dirname (__FILE__ ) . "/../data/ " . $ fileName ;
110
+ $ exists = file_exists ($ fullPath );
111
+ $ readable = is_readable ($ fullPath );
112
+ $ writable = is_writable ($ fullPath );
113
+ $ filemtime = filemtime ($ fullPath );
114
+ return [
115
+ "fileName " => $ fileName ,
116
+ "fullPath " => $ fullPath ,
117
+ "exists " => $ exists ,
118
+ "readable " => $ readable ,
119
+ "writable " => $ writable ,
120
+ "filemtime " => $ filemtime ,
121
+ ];
122
+ }
88
123
89
- $ settingsContents = getData (dirname (__FILE__ ) . "/../data/ " . $ settingsFile );
90
- clearstatcache ();
91
- $ configfilemtime = filemtime (dirname (__FILE__ ) . "/../data/ " . $ settingsFile );
124
+ public function getConfigUsersTemplate ()
125
+ {
126
+ // Return the serialized users config template
127
+ $ fileName = 'template-config-users.php ' ;
128
+ $ fullPath = dirname (__FILE__ ) . "/../lib/ " . $ fileName ;
129
+ if (function_exists ('opcache_invalidate ' )) {
130
+ opcache_invalidate ($ fullPath , true );
131
+ }
132
+ $ settings = file_get_contents ($ fullPath );
133
+ return $ settings ;
134
+ }
135
+
136
+ public function getConfigUsersSettings ($ fileName )
137
+ {
138
+ // Get users config file details
139
+ $ fullPath = $ this ->getConfigUsersFileDetails ($ fileName )['fullPath ' ];
140
+ // Load serialized data from the users config and convert to an array
141
+ if (function_exists ('opcache_invalidate ' )) {
142
+ opcache_invalidate ($ fullPath , true );
143
+ }
144
+ $ settingsFromFile = file_get_contents ($ fullPath );
145
+ $ settingsFromFile = str_replace ("<?php \n/* \n\n" , "" , $ settingsFromFile );
146
+ $ settingsFromFile = str_replace ("\n\n*/ \n?> " , "" , $ settingsFromFile );
147
+ $ settingsFromFile = unserialize ($ settingsFromFile );
148
+ // Now return
149
+ return $ settingsFromFile ;
150
+ }
151
+
152
+ public function setConfigUsersSettings ($ fileName , $ settings )
153
+ {
154
+ // Get the users config file details
155
+ $ fullPath = $ this ->getConfigUsersFileDetails ($ fileName )['fullPath ' ];
156
+ if ($ fConfigSettings = fopen ($ fullPath , 'w ' )) {
157
+ // If the settings we've received aren't in serialized format yet, do that now
158
+ // As $settings could be a serialized string or array
159
+ if (is_array ($ settings )) {
160
+ $ settings = "<?php \n/* \n\n" . serialize ($ settings ) . "\n\n*/ \n? " . "> " ;
161
+ }
162
+ // Now we have a serialized string, save it in the users config file
163
+ fwrite ($ fConfigSettings , $ settings );
164
+ fclose ($ fConfigSettings );
165
+ return true ;
166
+ } else {
167
+ return false ;
168
+ }
169
+ }
170
+
171
+ public function updateConfigUsersCreateDate ($ fileName ): void
172
+ {
173
+ // Get users config file details
174
+ $ filemtime = $ this ->getConfigUsersFileDetails ($ fileName )['filemtime ' ];
92
175
// Make it a number (avoids null, undefined etc)
93
- $ configfilemtime = intval ($ configfilemtime );
176
+ $ filemtime = intval ($ filemtime );
94
177
// Set it to the epoch time now if we don't have a real value
95
- if (0 === $ configfilemtime ) {
96
- $ configfilemtime = time ();
178
+ if (0 === $ filemtime ) {
179
+ $ filemtime = time ();
97
180
}
98
- $ settingsContents = str_replace ('"configCreateDate" => 0, ' , '"configCreateDate" => ' . $ configfilemtime . ', ' , $ settingsContents );
99
- // Now update the config file
100
- if (!$ fh = fopen (dirname (__FILE__ ) . "/../data/ " . $ settingsFile , 'w ' )) {
101
- $ reqsPassed = false ;
102
- $ reqsFailures = ["phpUpdateSettings " ];
103
- include dirname (__FILE__ ) . "/../lib/requirements.php " ;
104
- }
105
- fwrite ($ fh , $ settingsContents );
106
- fclose ($ fh );
181
+ // Update users config settings file
182
+ $ ICEcoderSettingsFromFile = $ this ->getConfigUsersSettings ($ fileName );
183
+ $ ICEcoderSettingsFromFile ['configCreateDate ' ] = $ filemtime ;
184
+ $ this ->setConfigUsersSettings ($ fileName , $ ICEcoderSettingsFromFile );
107
185
// Set the new value in array
108
- $ ICEcoderUserSettings ['configCreateDate ' ] = $ configfilemtime ;
109
- }
110
-
111
- public function updatePasswordCheckUpdates (): void
112
- {
113
- global $ settingsFile , $ password ;
114
-
115
- $ settingsContents = getData ("../data/ " . $ settingsFile );
116
- // Replace our empty password with the one submitted by user
117
- $ settingsContents = str_replace ('"password" => "", ' ,'"password" => " ' . $ password . '", ' , $ settingsContents );
118
- // Also set the update checker preference
119
- $ checkUpdates = $ _POST ['checkUpdates ' ] == "true " ? "true " : "false " ;
120
- // once to cover the true setting, once to cover false
121
- $ settingsContents = str_replace ('"checkUpdates" => true, ' ,'"checkUpdates" => ' . $ checkUpdates . ', ' , $ settingsContents );
122
- $ settingsContents = str_replace ('"checkUpdates" => false, ' ,'"checkUpdates" => ' . $ checkUpdates . ', ' , $ settingsContents );
123
- // Now update the config file
124
- if (!$ fh = fopen (dirname (__FILE__ ) . "/../data/ " . $ settingsFile , 'w ' )) {
125
- $ reqsPassed = false ;
126
- $ reqsFailures = ["phpUpdateSettings " ];
127
- include (dirname (__FILE__ ) . "/../lib/requirements.php " );
128
- }
129
- fwrite ($ fh , $ settingsContents );
130
- fclose ($ fh );
186
+ $ ICEcoderUserSettings ['configCreateDate ' ] = $ filemtime ;
187
+ }
188
+
189
+ public function updatePasswordCheckUpdates ($ fileName , $ password , $ checkUpdates ): void
190
+ {
191
+ // Update users config settings file
192
+ $ ICEcoderSettingsFromFile = $ this ->getConfigUsersSettings ($ fileName );
193
+ $ ICEcoderSettingsFromFile ['password ' ] = $ password ;
194
+ $ ICEcoderSettingsFromFile ['checkUpdates ' ] = $ checkUpdates ;
195
+ $ this ->setConfigUsersSettings ($ fileName , $ ICEcoderSettingsFromFile );
131
196
}
132
197
133
198
public function createIPSettingsFileIfNotExist (): void
@@ -159,4 +224,28 @@ public function disableFurtherRegistration(): void
159
224
$ this ->setConfigGlobalSettings ($ ICEcoderSettingsFromFile );
160
225
}
161
226
}
227
+
228
+ public function turnOffTutorialOnLogin ($ fileName ): bool
229
+ {
230
+ // Update users config settings file
231
+ $ ICEcoderSettingsFromFile = $ this ->getConfigUsersSettings ($ fileName );
232
+ $ ICEcoderSettingsFromFile ['tutorialOnLogin ' ] = false ;
233
+ return $ this ->setConfigUsersSettings ($ fileName , $ ICEcoderSettingsFromFile );
234
+ }
235
+
236
+ public function savePreviousFiles ($ fileName , $ files ): bool
237
+ {
238
+ // Update users config settings file
239
+ $ ICEcoderSettingsFromFile = $ this ->getConfigUsersSettings ($ fileName );
240
+ $ ICEcoderSettingsFromFile ['previousFiles ' ] = $ files ;
241
+ return $ this ->setConfigUsersSettings ($ fileName , $ ICEcoderSettingsFromFile );
242
+ }
243
+
244
+ public function savelast10Files ($ fileName , $ files ): bool
245
+ {
246
+ // Update users config settings file
247
+ $ ICEcoderSettingsFromFile = $ this ->getConfigUsersSettings ($ fileName );
248
+ $ ICEcoderSettingsFromFile ['last10Files ' ] = $ files ;
249
+ return $ this ->setConfigUsersSettings ($ fileName , $ ICEcoderSettingsFromFile );
250
+ }
162
251
}
0 commit comments