-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathccs7up_inc.php
750 lines (645 loc) · 31.6 KB
/
ccs7up_inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
<?php
/**
* Updates PHP files generated by CodeCharge Studio v5.1.1.18992 to work with PHP v7.1+.
*
* To use, place at the top of Common.php:
* if (version_compare(phpversion(), '7.1') >= 0) {
* include(RelativePath . "/ccs7up_inc.php");
* }
*
* Every CodeCharge Studio generated page will load this script.
* First, this script will update the page that is being loaded
* in case a Quick Publish using Ctrl-F8 was used.
* Then it will look into the Common.php file to see if it has already
* been updated by CCS7Up, and if so, discontinue scanning any more files.
* Otherwise, all remaining PHP files will be scanned and updated accordingly.
*
* The ccs7up.log file will be created and updated in the web root directory.
*
* 2024-12-29, DataDoIT: Added MySQL adapters to list of CodeCharge generated files.
* 2023-09-21, DataDoIT: Created.
*
*/
// This page cannot be viewed directly. It MUST be included from somewhere else.
if (count(get_included_files()) == 1) {
header('HTTP/1.0 403 Forbidden');
$content = "[" . date("Y-m-d H:i:s") . "] Direct access denied from " . $_SERVER['REMOTE_ADDR'] . ".\n";
CCS7Up_Log($content);
exit("Forbidden");
}
// Give more time for anything here to run. 5 minutes should suffice.
set_time_limit(600);
// Start a timer for the log.
$starttime = microtime(true);
$ChangesCounter = 0;
// Determine if the current page has been published without updates. If so, make the changes
// to the current files only. This is in case of using Ctrl-F8 to Quick Publish page.
// Check for and fix Classes in current main PHP file:
$CurrentFileName = basename($_SERVER['PHP_SELF']);
$CurrentFile = $_SERVER['SCRIPT_FILENAME'];
$CurrentContents = file_get_contents($CurrentFile);
$CurrentFileClassesChangesCounter = CCS7Up_FixClasses($CurrentFileName, $CurrentFile, $CurrentContents);
$ChangesCounter = $ChangesCounter + $CurrentFileClassesChangesCounter;
// Check for and fix Events in current main PHP file:
$CurrentContents = file_get_contents($CurrentFile); //reload
$CurrentFileEventsChangesCounter = CCS7Up_FixEvents($CurrentFileName, $CurrentFile, $CurrentContents);
$ChangesCounter = $ChangesCounter + $CurrentFileEventsChangesCounter;
// Check for and fix Misc in current main PHP file:
$CurrentContents = file_get_contents($CurrentFile); //reload
$CurrentFileMiscChangesCounter = CCS7Up_FixMisc($CurrentFileName, $CurrentFile, $CurrentContents);
$ChangesCounter = $ChangesCounter + $CurrentFileMiscChangesCounter;
// Fixes for any current _events.php file:
$EventsFileName = basename($_SERVER['PHP_SELF'], '.php') . "_events.php";
$EventsFile = getcwd() . "/" . $EventsFileName;
if (file_exists($EventsFile)) {
$EventsContents = file_get_contents($EventsFile);
// Check for and fix Classes in _events.php file:
$EventsFileClassesChangesCounter = CCS7Up_FixClasses($EventsFileName, $EventsFile, $EventsContents);
$ChangesCounter = $ChangesCounter + $EventsFileClassesChangesCounter;
// Check for and fix Events in _events.php file:
$EventsContents = file_get_contents($EventsFile); //reload any new updates
$EventsFileEventsChangesCounter = CCS7Up_FixEvents($EventsFileName, $EventsFile, $EventsContents);
$ChangesCounter = $ChangesCounter + $EventsFileEventsChangesCounter;
// Check for and fix Misc in _events.php file:
$MiscContents = file_get_contents($EventsFile); //reload any new updates
$EventsFileMiscChangesCounter = CCS7Up_FixMisc($EventsFileName, $EventsFile, $EventsContents);
$ChangesCounter = $ChangesCounter + $EventsFileMiscChangesCounter;
}
if ($ChangesCounter > 0) {
$content = "[" . date("Y-m-d H:i:s") . "] " . $CurrentFileName . " and " . $EventsFileName . " scanned and " . $ChangesCounter . " changes made. \n";
CCS7Up_Log($content);
header('Location: '.$_SERVER['REQUEST_URI']); exit; //need to reload the page.
}
// Determine if the Common file has been published without the updates. We can do this by
// looking in Common.php at the CCGetListValues function where $values needs to be defined
// as an array. So see if that's been done already.
$CommonFile = dirname(__FILE__) . "/Common.php";
$CommonContents = file_get_contents($CommonFile);
$CommonString = 'function CCGetListValues(&$db, $sql, $where = "", $order_by = "", $bound_column = "", $text_column = "", $dbformat = "", $datatype = "", $errorclass = "", $fieldname = "", $DSType = dsSQL)' . PHP_EOL . '{' . PHP_EOL . ' $errors = new clsErrors();' . PHP_EOL . ' $values = array()';
$CommonStringQuoted = preg_quote($CommonString, '/');
if (preg_match('/' . $CommonStringQuoted . '/i', $CommonContents)) {
return; //No updates needed. Goodbye.
}
// Common file hasn't been updated, so go ahead and do all updates for the entire project.
$ChangesCounter = 0; //reset
$PHPFileCount = 0;
// Load the CCS project folder and contents into an array.
$projectFolder = getcwd() . "/";
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($projectFolder, RecursiveDirectoryIterator::SKIP_DOTS));
$files = array();
foreach ($rii as $file) {
if ($file->isDir()) {
continue;
}
$files[] = $file->getPathname();
}
// Now go through each file found.
foreach ($files as $dirKey => $dirVal) {
// We only care about PHP and CCS generated files.
if (strtoupper(pathinfo($dirVal, PATHINFO_EXTENSION)) == "PHP") {
$PHPFile = $dirVal;
// Skip this script, obviously.
if (basename($PHPFile) == basename(__FILE__)) {
continue;
}
$PHPFileName = basename($PHPFile);
$PHPFileContents = file_get_contents($PHPFile);
// Skip if not a CodeCharge Studio generated file.
// Array of phrases to look for that denotes a CCS generated file.
$CCSGeneratedFile = false;
$CCSNeedles = array(
"//Include Files @0-",
"//Include Common Files @1-",
"//BindEvents Method @1-",
"//CalendarNavigator Class @0-",
"//File Description @0-",
"//Client @0-",
"//DB Adapter Class @0-",
"//DB Array Class @0-",
"//DB MySQL Class @0-",
"//DB MySQLi Class @0-",
"//Navigator Class @0-",
"//Service Class @100-",
"//Sorter Class @0-",
"//Template class @0-",
"//Variables @1-"
);
foreach ($CCSNeedles as $needle) {
if (strpos($PHPFileContents, $needle) !== false) {
$CCSGeneratedFile = true;
}
}
if ($CCSGeneratedFile == false) {
continue; //not a CCS file so load next file
}
$PHPFileCount++;
// Fix classes.
$PHPFileClassesChangesCounter = CCS7Up_FixClasses($PHPFileName, $PHPFile, $PHPFileContents);
$ChangesCounter = $ChangesCounter + $PHPFileClassesChangesCounter;
$PHPFileContents = file_get_contents($PHPFile); //reload
// Fix events.
$PHPFileEventsChangesCounter = CCS7Up_FixEvents($PHPFileName, $PHPFile, $PHPFileContents);
$ChangesCounter = $ChangesCounter + $PHPFileEventsChangesCounter;
$PHPFileContents = file_get_contents($PHPFile); //reload
// Fix common files.
$PHPFileCommonChangesCounter = CCS7Up_FixCommonFiles($PHPFileName, $PHPFile, $PHPFileContents);
$ChangesCounter = $ChangesCounter + $PHPFileCommonChangesCounter;
$PHPFileContents = file_get_contents($PHPFile); //reload
// Fix miscellaneous.
$PHPFileMiscChangesCounter = CCS7Up_FixMisc($PHPFileName, $PHPFile, $PHPFileContents);
$ChangesCounter = $ChangesCounter + $PHPFileMiscChangesCounter;
} // end of if PHP file.
} // end of foreach file found.
// Results from full scan.
$content = "[" . date("Y-m-d H:i:s") . "] " . $PHPFileCount . " CodeCharge PHP files scanned with " . $ChangesCounter . " changes made in " . round(microtime(true)-$starttime,1) . " seconds.\n";
CCS7Up_Log($content);
header('Location: ' . $_SERVER['REQUEST_URI']); exit; //need to reload the page.
//** Local functions in alpha order:
function CCS7Up_ApplyChanges($CCSFileName, $CCSFile, $CCSFileResult) {
// All done looking for changes, now actually apply the changes to the file.
if (strlen($CCSFileResult) > 0) {
file_put_contents($CCSFile, $CCSFileResult);
$content = "[" . date("Y-m-d H:i:s") . "] " . $CCSFileName . " rewritten successfully. \n";
CCS7Up_Log($content);
}
}
// End CCS7Up_ApplyChanges
function CCS7Up_FixClasses($CCSFileName, $CCSFile, $CCSFileContents) {
$CCSFileLength = strlen($CCSFileContents);
$CCSFileResult = null;
$offset = 0;
$offset_prev = 0;
$offset1 = 0;
$offset2 = 0;
$CCSFileReplacedContent = null;
$CCSFileClassFound = false;
$CCSFileClassCounter = 0;
$CCSFileClassChangesCounter = 0;
// Looks for 'class' or 'class extends class'.
$CCSFileClassPattern = "/(class[\s\r\n]+[a-z_0-9]+[\n\r\s]+extends[\s\r\n]+[a-z_0-9]+[\s\r\n]*{|class[\s\r\n]+[a-z_0-9]+[\s\r\n]*{)/i"; //$pattern
while (preg_match($CCSFileClassPattern, $CCSFileContents, $matches, PREG_OFFSET_CAPTURE, $offset) and $offset < $CCSFileLength) {
$CCSFileClassFound = true;
$CCSFileClassCounter++;
// Since PHP Release 8.2 dynamic properties are deprecated and the logfile is filled with warnings.
// This patch adds the AllowDynamicProperties attribute to classes. See https://www.php.net/manual/de/class.allowdynamicproperties.php
// @mweinbergh
preg_match('/(#\[AllowDynamicProperties\])/', $CCSFileContents, $m, PREG_OFFSET_CAPTURE, (int)$matches[0][1]-strlen('#[AllowDynamicProperties]')-2);
if (isset($m[0])) {
$AllowDynamicProperties = '';
}
else {
$AllowDynamicProperties = "#[AllowDynamicProperties]\r\n";
$content = "[" . date("Y-m-d H:i:s") . "] AllowDynamicProperties attribute added for the class reference in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileClassChangesCounter++;
}
// Get the class name found.
// Ex: class clsTemplate
// Ex: class Tpl {
// Ex: class TreePlainFormatter extends JsonFormatter {
$res = CCS7Up_SelectMinMatch($matches);
$temp = $matches[$res][0];
// Next clean up what was found.
// Ex: clsTemplate
// Ex: Tpl
// Ex: TreePlainFormatter
$temp = str_replace(array("\r", "\n", "{"), " ", $temp);
$temp = str_replace(" ", " ", $temp);
$tokens = explode(" ", $temp);
$class_name = $tokens[1];
$parent_class_name = null;
if ($tokens[2] == "extends") {
$parent_class_name = $tokens[3];
}
// Move the inter-file pointer to the start of our matching string found.
$new_offset = $matches[$res][1];
$offset1 = $new_offset + 1;
if (strlen($CCSFileResult) == 0) {
$CCSFileResult = substr($CCSFileContents, 0, $new_offset);
}
// Get the location of the next class found, if any, so that only the
// current class found is processed.
if (preg_match($CCSFileClassPattern, $CCSFileContents, $matches1, PREG_OFFSET_CAPTURE, $offset1)) {
// Found another class.
$res1 = CCS7Up_SelectMinMatch($matches1);
$next_offset = $matches1[$res1][1];
$string_to_process = substr($CCSFileContents, $new_offset, $next_offset - $new_offset);
}
else {
// There isn't another class definition, so use the rest of the input string.
$string_to_process = substr($CCSFileContents, $new_offset);
$next_offset = $CCSFileLength;
}
// Look for functions within the class using the same name as the class.
// Ref: https://www.php.net/manual/en/migration70.deprecated.php#:~:text=PHP%204%20style%20constructors%20(methods,construct()%20method%20are%20unaffected
if (preg_match('/function[ ]+' . $class_name . '[(]/i', $string_to_process)) {
$string_to_process = preg_replace('/function[ ]+' . $class_name . '[(]/i', "function __construct(", $string_to_process);
if ($string_to_process == NULL) {
$content = "[" . date("Y-m-d H:i:s") . "] Fatal error attempting to change class " . $class_name . " using same function name as the class in " . $CCSFile . "! \n";
CCS7Up_Log($content);
return $CCSFileClassChangesCounter;
}
else {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed class " . $class_name . " using same function name as the class in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileClassChangesCounter++;
}
}
// Look for class parents using the same name as the class, and change to a constructor. Same as above.
if ($parent_class_name and preg_match('/parent::' . $parent_class_name . '[(]/i', $string_to_process)) {
$string_to_process = preg_replace('/parent::' . $parent_class_name . '[(]/i', "parent::__construct(", $string_to_process);
if ($string_to_process == NULL) {
$content = "[" . date("Y-m-d H:i:s") . "] Fatal error attempting to change parent class " . $parent_class_name . " using same function name as the class in " . $CCSFile . "! \n";
CCS7Up_Log($content);
return $CCSFileClassChangesCounter;
}
else {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed parent class " . $parent_class_name . " using same function name as the class in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileClassChangesCounter++;
}
}
// Move our pointer to the next occurence (or end of file).
$offset = $next_offset;
$CCSFileResult .= "$AllowDynamicProperties$string_to_process";
} // end of while class found.
// No class definition found in the file, so just use what was brought in.
# Is this even needed?
if (!$CCSFileClassFound) {
$CCSFileResult = $CCSFileContents;
}
// Rebuild the file if changes made.
if ($CCSFileClassChangesCounter > 0) {
CCS7Up_ApplyChanges($CCSFileName, $CCSFile, $CCSFileResult);
}
return $CCSFileClassChangesCounter;
}
// End CCS7Up_FixClasses
function CCS7Up_FixCommonFiles($CCSFileName, $CCSFile, $CCSFileContents) {
$CCSFileLength = strlen($CCSFileContents);
$CCSFileResult = $CCSFileContents;
$offset = 0;
$offset_prev = 0;
$offset1 = 0;
$offset2 = 0;
$CCSFileReplacedContent = null;
$CCSFileCommonFound = false;
$CCSFileCommonCounter = 0;
$CCSFileCommonChangesCounter = 0;
// The CodeCharge generated Template.php file uses deprecated each() functions.
// See: https://www.php.net/manual/en/function.each.php
// Replace accordingly.
if (preg_match('/Template.php$/i', $CCSFile)) {
$occurences = null; //reset
$each1_pattern = preg_quote('while (list($key,) = each($searching_array))', '/');
if (preg_match( '/' . $each1_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $each1_pattern . '/i', 'foreach($searching_array as $key => $dontcare)', $CCSFileResult, 1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of each(\$searching_array) with foreach in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$each2_pattern = preg_quote('while(list($key, $value) = each($this->blocks[$block_name]))', '/');
if (preg_match( '/' . $each2_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $each2_pattern . '/i', 'foreach($this->blocks[$block_name] as $key => $value)', $CCSFileResult, 1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of each(\$this->blocks) with foreach in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$each3_pattern = preg_quote('while(list($key, $value) = each($this->globals))', '/');
if (preg_match('/' . $each3_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $each3_pattern . '/i', 'foreach($this->globals as $key => $value)', $CCSFileResult, 1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of each(\$this->globals) with foreach in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
} // end of if Template.php
// Replace each() functions in Classes.php to use foreach().
if (preg_match('/Classes.php$/i', $CCSFile)) {
$occurences = null; //reset
$each4_pattern = preg_quote('while ($blnResult && list ($key, $Parameter) = each ($this->Parameters)) ' . PHP_EOL . ' {', '/');
if (preg_match( '/' . $each4_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $each4_pattern . '/i', 'foreach ($this->Parameters as $key => $Parameter) {' . PHP_EOL . ' if (!$blnResult)' . PHP_EOL . ' continue;', $CCSFileResult, 1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of each (\$this->Parameters) with foreach in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
} // end of if Classes.php
// Fix casting string to int in DB_Adapter::PageCount().
if (preg_match('/db_adapter.php$/i', $CCSFile)) {
$occurences = null; //reset
$ceil_pattern = preg_quote('return $this->PageSize && $this->RecordsCount != "CCS not counted" ? ceil($this->RecordsCount', '/');
if (preg_match( '/' . $ceil_pattern . '/i' , $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $ceil_pattern . '/i', 'return $this->PageSize && $this->RecordsCount != "CCS not counted" ? ceil((int)$this->RecordsCount', $CCSFileResult, 1, $occurences);
}
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of ceil(\$this->RecordsCount) with ceil(int)\$this->RecordsCount in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
} // end of if db_adapter.php
// Replace deprecated array curly braces in Services.php.
// See: https://wiki.php.net/rfc/deprecate_curly_braces_array_access
if (preg_match('/Services.php$/i', $CCSFile)) {
$occurences = null; //reset
$curly1_pattern = preg_quote('$utf8{0}', '/');
if (preg_match( '/' . $curly1_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly1_pattern . '/i', '$utf8[0]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$utf8{0} with \$utf8[0] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly2_pattern = preg_quote('$utf8{1}', '/');
if (preg_match( '/' . $curly2_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly2_pattern . '/i', '$utf8[1]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$utf8{1} with \$utf8[1] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly3_pattern = preg_quote('$utf8{2}', '/');
if (preg_match( '/' . $curly3_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly3_pattern . '/i', '$utf8[2]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$utf8{2} with \$utf8[2] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly4_pattern = preg_quote('$utf16{0}', '/');
if (preg_match( '/' . $curly4_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly4_pattern . '/i', '$utf16[0]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$utf16{0} with \$utf16[0] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly5_pattern = preg_quote('$utf16{1}', '/');
if (preg_match( '/' . $curly5_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly5_pattern . '/i', '$utf16[1]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$utf16{1} with \$utf16[1] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly6_pattern = preg_quote('$var{$c}', '/');
if (preg_match( '/' . $curly6_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly6_pattern . '/i', '$var[$c]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$var{\$c} with \$var[\$c] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly7_pattern = preg_quote('$var{$c + 1}', '/');
if (preg_match( '/' . $curly7_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly7_pattern . '/i', '$var[$c] + 1', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$var{\$c + 1} with \$var[\$c] + 1 in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly8_pattern = preg_quote('$var{$c + 2}', '/');
if (preg_match( '/' . $curly8_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly8_pattern . '/i', '$var[$c] + 2', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$var{\$c + 2} with \$var[\$c] + 2 in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly9_pattern = preg_quote('$var{$c + 3}', '/');
if (preg_match( '/' . $curly9_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly9_pattern . '/i', '$var[$c] + 3', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$var{\$c + 3} with \$var[\$c] + 3 in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly10_pattern = preg_quote('$var{$c + 4}', '/');
if (preg_match( '/' . $curly10_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly10_pattern . '/i', '$var[$c] + 4', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$var{\$c + 4} with \$var[\$c] + 4 in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly11_pattern = preg_quote('$var{$c + 5}', '/');
if (preg_match( '/' . $curly11_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly11_pattern . '/i', '$var[$c] + 5', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$var{\$c + 5} with \$var[\$c] + 5 in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly12_pattern = preg_quote('$chrs{$c}', '/');
if (preg_match( '/' . $curly12_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly12_pattern . '/i', '$chrs[$c]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$chrs{\$c} with \$chrs[\$c] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly13_pattern = preg_quote('$chrs{++$c}', '/');
if (preg_match( '/' . $curly13_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly13_pattern . '/i', '$chrs[++$c]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$chrs{++\$c} with \$chrs[++\$c] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
$occurences = null; //reset
$curly14_pattern = preg_quote('$str{0}', '/');
if (preg_match( '/' . $curly14_pattern . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace('/' . $curly14_pattern . '/i', '$str[0]', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$str{0} with \$str[0] in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
} // end of if Services.php
// The Common file has a function CCGetListValues with variables that all need to be defined as arrays.
// Check Common last since it is checked at the beginning of this script to determine if
// the entire project needs to be scanned and updated.
if (preg_match('/(common.php|commonserv.php)$/i', $CCSFile)) {
$occurences = null; //reset
$str222 = 'function CCGetListValues(&$db, $sql, $where = "", $order_by = "", $bound_column = "", $text_column = "", $dbformat = "", $datatype = "", $errorclass = "", $fieldname = "", $DSType = dsSQL)' . PHP_EOL . '{' . PHP_EOL . ' $errors = new clsErrors();' . PHP_EOL . ' $values = ';
$str222_pattern = preg_quote($str222, '/');
if (preg_match('/' . $str222_pattern . '("")' . '/i', $CCSFileResult)) {
$CCSFileResult = preg_replace( '/' . $str222_pattern . '("")' . '/i', $str222 . "array()", $CCSFileResult, 1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of CCGetListValues() and \$value not defined as an array in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileCommonChangesCounter++;
}
}
} // end of if Common.php
// Rebuild the file if changes made.
if ($CCSFileCommonChangesCounter > 0) {
CCS7Up_ApplyChanges($CCSFileName, $CCSFile, $CCSFileResult);
}
return $CCSFileCommonChangesCounter;
}
// End CCS7Up_FixCommonFiles
function CCS7Up_FixEvents($CCSFileName, $CCSFile, $CCSFileContents) {
// Looks for CCSEvents defined as a variable and change to an array.
$CCSFileLength = strlen($CCSFileContents);
$CCSFileResult = $CCSFileContents;
$offset = 0;
$offset_prev = 0;
$offset1 = 0;
$offset2 = 0;
$CCSFileReplacedContent = null;
$CCSFileEventsFound = false;
$CCSFileEventsCounter = 0;
$CCSFileEventsChangesCounter = 0;
// Look for [on its own line]: $CCSEvents then all characters case-insensitive all the way to a semicolon (end of PHP line)
// Replace with: $CCSEvents = array();
$occurences = null; //reset
$CCSFileResult = preg_replace('/([\r\n]+[\s]*)(\$CCSEvents[\s]*);/i', '$1$2 = array();', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$CCSEvents on its own line not properly declared as an array in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileEventsChangesCounter++;
}
// Look for: public $CCSEvents all the way to a semicolon (end of PHP line)
// Ex: public $CCSEvents;
// Replace with: public $CCSEvents = array();
$occurences = null; //reset
$CCSFileResult = preg_replace('/(public[\s]+\$CCSEvents[\s]*[;])/i', 'public \$CCSEvents = array();', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of public \$CCSEvents not properly declared as an array in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileEventsChangesCounter++;
}
// Look for: public $CCSEvents = then all the way to a semicolon (end of PHP line)
// Ex: public $CCSEvents = ""
// Replace with: public $CCSEvents = array();
$occurences = null; //reset
$CCSFileResult = preg_replace('/(public[\s]+\$CCSEvents[\s]*=[\s]*""[\s]*[;])/i', 'public \$CCSEvents = array();', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of public \$CCSEvents = \"\" not properly declared as an array in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileEventsChangesCounter++;
}
// Look for [on its own line]: $CCSEvents = then all the way to a semicolon (end of PHP line)
// Ex: $CCSEvents = ""
// Replace with: $CCSEvents = array();
$occurences = null; //reset
$CCSFileResult = preg_replace('/([\r\n]+)(\$CCSEvents[\s]*=[\s]*""[\s]*;)/i', '$1\$CCSEvents = array();', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$CCSEvents = \"\" on its own line not properly declared as an array in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileEventsChangesCounter++;
}
// Look for: var $CCSEvents = "" then all the way to a semicolon (end of PHP line)
// Ex: var $CCSEvents = ""
// Replace with: var $CCSEvents = array();
$occurences = null; //reset
$CCSFileResult = preg_replace('/(var[\s]+\$CCSEvents[\s]*=[\s]*""[\s]*[;])/i', 'var \$CCSEvents = array();', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of var \$CCSEvents = \"\" not properly declared as an array in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileEventsChangesCounter++;
}
// Look for: $this->CCSEvents = "" then all the way to a semicolon (end of PHP line)
// Ex: $this->CCSEvents = ""
// Replace with: $this->CCSEvents = array();
$occurences = null; //reset
$CCSFileResult = preg_replace('/(\$this->CCSEvents[\s]*=[\s]*""[\s]*;)/i', '\$this->CCSEvents = array();', $CCSFileResult, -1, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Fixed " . $occurences . " occurences of \$this->CCSEvents = \"\" not properly declared as an array in " . $CCSFile . ". \n";
CCS7Up_Log($content);
$CCSFileEventsChangesCounter++;
}
// Rebuild the file if changes made.
if ($CCSFileEventsChangesCounter > 0) {
CCS7Up_ApplyChanges($CCSFileName, $CCSFile, $CCSFileResult);
}
return $CCSFileEventsChangesCounter;
}
// End CCS7Up_FixEvents
function CCS7Up_FixMisc($CCSFileName, $CCSFile, $CCSFileContents) {
$CCSFileLength = strlen($CCSFileContents);
$CCSFileResult = $CCSFileContents;
$offset = 0;
$offset_prev = 0;
$offset1 = 0;
$offset2 = 0;
$CCSFileReplacedContent = null;
$CCSFileMiscFound = false;
$CCSFileMiscCounter = 0;
$CCSFileMiscChangesCounter = 0;
// Replace any occurences of deprecated get_magic_quotes_gpc() function with a false constant.
// See: https://www.php.net/manual/en/function.get-magic-quotes-gpc.php
$occurences = null; //reset
$CCSFileResult = str_replace("get_magic_quotes_gpc()", "false", $CCSFileResult, $occurences);
if ($occurences) {
$content = "[" . date("Y-m-d H:i:s") . "] Removed " . $occurences . " occurences of get_magic_quotes_gpc() function in " . $CCSFile . ".\n";
CCS7Up_Log($content);
$CCSFileMiscChangesCounter++;
}
// Other miscellaneous changes needed should go here.
// Rebuild the file if changes made.
if ($CCSFileMiscChangesCounter > 0) {
CCS7Up_ApplyChanges($CCSFileName, $CCSFile, $CCSFileResult);
}
return $CCSFileMiscChangesCounter;
}
// End CCS7Up_FixMisc
function CCS7Up_Log($content) {
if ($content) {
file_put_contents(dirname(__FILE__) . "/ccs7up.log", $content, FILE_APPEND);
}
return;
}
// End CCS7Up_Log
function CCS7Up_SelectMinMatch($matches) {
// Gets the match location. Called while looking for a class.
// $res = CCS7Up_SelectMinMatch($matches);
if (sizeof($matches) == 0) {
return false;
}
$offsets = array();
foreach ($matches as $n => $match) {
$offsets[$match[1]] = $n;
}
ksort($offsets);
reset($offsets);
return current($offsets);
}
// End CCS7Up_SelectMinMatch
?>