@@ -129,20 +129,16 @@ function getData($url, $type='fopen', $dieMessage = false, $timeout = 60) {
129
129
// Require a re-index dir/file data next time we index
130
130
function requireReIndexNextTime () {
131
131
// If we have a data/index.php file
132
- global $ docRoot , $ ICEcoderDir , $ systemClass ;
132
+ global $ docRoot , $ ICEcoderDir , $ settingsClass , $ systemClass ;
133
133
if (true === file_exists ($ docRoot . $ ICEcoderDir . "/data/index.php " )) {
134
134
// Get serialized array back out of PHP file inside a comment block as prevIndexData
135
135
$ systemClass ->invalidateOPCache ($ docRoot . $ ICEcoderDir . "/data/index.php " );
136
136
$ prevIndexData = file_get_contents ($ docRoot . $ ICEcoderDir . "/data/index.php " );
137
137
if (strpos ($ prevIndexData , "<?php " ) !== false ) {
138
- $ prevIndexData = str_replace ("<?php \n/* \n\n" , "" , $ prevIndexData );
139
- $ prevIndexData = str_replace ("\n\n*/ \n?> " , "" , $ prevIndexData );
140
- $ prevIndexData = unserialize ($ prevIndexData );
141
-
138
+ $ prevIndexData = $ settingsClass ->serializedFileData ("get " , $ docRoot . $ ICEcoderDir . "/data/index.php " );
142
139
// Set timestamp back to epoch to force a re-index next time
143
140
$ prevIndexData ['timestamps ' ]['indexed ' ] = 0 ;
144
-
145
- file_put_contents ($ docRoot . $ ICEcoderDir . "/data/index.php " , "<?php \n/* \n\n" .serialize ($ prevIndexData )."\n\n*/ \n? " . "> " );
141
+ $ settingsClass ->serializedFileData ("set " , $ docRoot . $ ICEcoderDir . "/data/index.php " , $ prevIndexData );
146
142
}
147
143
}
148
144
}
@@ -184,34 +180,34 @@ function numClean($var) {
184
180
}
185
181
186
182
// Clean XSS attempts using different contexts
187
- function xssClean ($ data ,$ type ) {
183
+ function xssClean ($ data , $ type ) {
188
184
189
185
// === html ===
190
- if ($ type == " html " ) {
186
+ if (" html " === $ type ) {
191
187
$ bad = array ("< " , "> " );
192
188
$ good = array ("< " , "> " );
193
189
}
194
190
195
191
// === style ===
196
- if ($ type == " style " ) {
192
+ if (" style " === $ type ) {
197
193
$ bad = array ("< " , "> " , "\"" , "' " , "`` " , "( " , ") " , "& " , "\\\\" );
198
194
$ good = array ("< " , "> " , "" " , "' " , "` " , "( " , ") " , "& " , "\ " );
199
195
}
200
196
201
197
// === attribute ===
202
- if ($ type == " attribute " ) {
198
+ if (" attribute " === $ type ) {
203
199
$ bad = array ("\"" , "' " , "`` " );
204
200
$ good = array ("" " , "' " , "` " );
205
201
}
206
202
207
203
// === script ===
208
- if ($ type == " script " ) {
204
+ if (" script " === $ type ) {
209
205
$ bad = array ("< " , "> " , "\"" , "' " , "\\\\" , "% " , "& " );
210
206
$ good = array ("< " , "> " , "" " , "' " , "\ " , "% " , "& " );
211
207
}
212
208
213
209
// === url ===
214
- if ($ type == " url " ) {
210
+ if (" url " === $ type ) {
215
211
if (preg_match ("#^(?:(?:https?|ftp):{1})\/\/[^ \"\s \\\\]*.[^ \"\s \\\\]*$#iu " , (string )$ data , $ match )) {
216
212
return $ match [0 ];
217
213
} else {
@@ -223,13 +219,6 @@ function xssClean($data,$type) {
223
219
return $ output ;
224
220
}
225
221
226
-
227
- // Clean PHP code injection attempts
228
- function injClean ($ data ) {
229
- $ output = str_replace ("( " , "" , str_replace (") " , "" , str_replace ("; " , "" , $ data )));
230
- return $ output ;
231
- }
232
-
233
222
// returns a UTF8 based string with any UFT8 BOM removed
234
223
function toUTF8noBOM ($ string , $ message = false ) {
235
224
global $ text ;
@@ -269,48 +258,18 @@ function toUTF8noBOM($string, $message = false) {
269
258
return $ string ;
270
259
}
271
260
272
- // Polyfill for array_replace_recursive, which is in PHP 5.3+
273
- if (!function_exists ('array_replace_recursive ' )) {
274
- function array_replace_recursive ($ base , $ replacements ) {
275
- foreach (array_slice (func_get_args (), 1 ) as $ replacements ) {
276
- $ bref_stack = array (&$ base );
277
- $ head_stack = array ($ replacements );
278
-
279
- do {
280
- end ($ bref_stack );
281
-
282
- $ bref = &$ bref_stack [key ($ bref_stack )];
283
- $ head = array_pop ($ head_stack );
284
-
285
- unset($ bref_stack [key ($ bref_stack )]);
286
-
287
- foreach (array_keys ($ head ) as $ key ) {
288
- if (isset ($ key , $ bref ) && is_array ($ bref [$ key ]) && is_array ($ head [$ key ])) {
289
- $ bref_stack [] = &$ bref [$ key ];
290
- $ head_stack [] = $ head [$ key ];
291
- } else {
292
- $ bref [$ key ] = $ head [$ key ];
293
- }
294
- }
295
- } while (count ($ head_stack ));
296
- }
297
-
298
- return $ base ;
299
- }
300
- }
301
-
302
261
// Get number of versions total for a file
303
262
function getVersionsCount ($ fileLoc , $ fileName ) {
304
263
global $ context ;
305
264
$ count = 0 ;
306
- $ dateCounts = array () ;
307
- $ backupDateDirs = array () ;
265
+ $ dateCounts = [] ;
266
+ $ backupDateDirs = [] ;
308
267
// Establish the base, host and date dirs within...
309
268
$ backupDirBase = str_replace ("\\" , "/ " , dirname (__FILE__ )) . "/../data/backups/ " ;
310
269
$ backupDirHost = isset ($ ftpSite ) ? parse_url ($ ftpSite , PHP_URL_HOST ) : "localhost " ;
311
270
// check if folder exists if local before enumerating contents
312
- if (! isset ($ ftpSite )) {
313
- if ( is_dir ($ backupDirBase . $ backupDirHost )) {
271
+ if ( false === isset ($ ftpSite )) {
272
+ if ( true === is_dir ($ backupDirBase . $ backupDirHost )) {
314
273
$ backupDateDirs = scandir ($ backupDirBase . $ backupDirHost , 1 );
315
274
}
316
275
} else {
@@ -352,19 +311,3 @@ function getVersionsCount($fileLoc, $fileName) {
352
311
"dateCounts " => $ dateCounts
353
312
);
354
313
}
355
-
356
- function serializedFileData ($ do , $ path , $ output =null ) {
357
- global $ systemClass ;
358
-
359
- if ($ do === "get " ) {
360
- $ systemClass ->invalidateOPCache ($ path );
361
- $ data = file_get_contents ($ path );
362
- $ data = str_replace ("< " ."?php \n/* \n\n" , "" , $ data );
363
- $ data = str_replace ("\n\n*/ \n? " ."> " , "" , $ data );
364
- $ data = unserialize ($ data );
365
- return $ data ;
366
- }
367
- if ($ do === "set " ) {
368
- file_put_contents ($ path , "< " ."?php \n/* \n\n" . serialize ($ output ) . "\n\n*/ \n? " . "> " );
369
- }
370
- }
0 commit comments