-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathConfig.php
2934 lines (2553 loc) · 90.6 KB
/
Config.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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 2
*/
declare(strict_types=1);
namespace SMF;
/**
* Handles loading and saving SMF's settings, both in Settings.php and database.
* Handles checking and modifying certain server and forum configuration values.
*/
class Config
{
/**************************
* Public static properties
**************************/
########## Maintenance ##########
/**
* @var int 0, 1, 2
*
* The maintenance "mode":
* 0: Disable maintenance mode. This is the default.
* 1: Enable maintenance mode but allow admins to login normally.
* 2: Make the forum untouchable. You'll need to make it 0 again manually!
*/
public static int $maintenance;
/**
* @var string
*
* Title for the maintenance mode message.
*/
public static string $mtitle;
/**
* Description of why the forum is in maintenance mode.
*
* @var string
*/
public static string $mmessage;
########## Forum info ##########
/**
* @var string
*
* The name of your forum.
*/
public static string $mbname;
/**
* @var string
*
* The default language file set for the forum.
*/
public static string $language;
/**
* @var string
*
* URL to your forum's folder. (without the trailing /!)
*/
public static string $boardurl;
/**
* @var string
*
* Email address to send emails from. (like [email protected].)
*/
public static string $webmaster_email;
/**
* @var string
*
* Name of the cookie to set for authentication.
*/
public static string $cookiename;
########## Database info ##########
/**
* @var string
*
* The database type.
* Default options: mysql, postgresql
*/
public static string $db_type;
/**
* @var int
*
* The database port.
* 0 to use default port for the database type.
*/
public static int $db_port;
/**
* @var string
*
* The server to connect to (or a Unix socket)
*/
public static string $db_server;
/**
* @var string
*
* The database name.
*/
public static string $db_name;
/**
* @var string
*
* Database username.
*/
public static string $db_user;
/**
* @var string
*
* Database password.
*/
public static string $db_passwd;
/**
* @var string
*
* Database user for when connecting with SSI.
*/
public static string $ssi_db_user;
/**
* @var string
*
* Database password for when connecting with SSI.
*/
public static string $ssi_db_passwd;
/**
* @var string
*
* A prefix to put in front of your table names.
* This helps to prevent conflicts.
*/
public static string $db_prefix;
/**
* @var bool
*
* Use a persistent database connection.
*/
public static bool $db_persist;
/**
* @var bool
*
* Send emails on database connection error.
*/
public static bool $db_error_send;
/**
* @var null|bool
*
* Override the default behavior of the database layer for mb4 handling.
* null keep the default behavior untouched.
*/
public static ?bool $db_mb4;
########## Cache info ##########
/**
* @var string
*
* Select a cache system. You should leave this up to the cache area of the
* admin panel for proper detection of the available options.
*/
public static string $cache_accelerator;
/**
* @var int
*
* The level at which you would like to cache.
* Between 0 (off) through 3 (cache a lot).
*/
public static int $cache_enable;
/**
* @var string
*
* This is only used for the memcache / memcached cache systems.
* Should be a string of 'server:port,server:port'
*/
public static string $cache_memcached;
/**
* @var string
*
* Path to the cache directory for the file-based cache system.
*/
public static string $cachedir;
/**
* @var string
*
* This is only used for the SQLite3 cache system.
* Path to the directory where the SQLite3 database file will be saved.
*/
public static string $cachedir_sqlite;
########## Image proxy ##########
/**
* @var bool
*
* Whether the proxy is enabled or not.
*/
public static bool $image_proxy_enabled;
/**
* @var string
*
* Secret key to be used by the proxy.
*/
public static string $image_proxy_secret;
/**
* @var int
*
* Maximum file size (in KB) for individual files.
*/
public static int $image_proxy_maxsize;
########## Directories/Files ##########
# Note: These directories do not have to be changed unless you move things.
/**
* @var string
*
* The absolute path to the forum's folder. (not just '.'!)
*/
public static string $boarddir;
/**
* @var string
*
* Path to the Sources directory.
*/
public static string $sourcedir;
/**
* Path to the Packages directory.
*
* @var string
*/
public static string $packagesdir;
/**
* Path to the Packages directory.
*
* @var string
*/
public static string $languagesdir;
/**
* @var string
*
* Path to the tasks directory.
*/
public static string $tasksdir;
######### Modification Support #########
/**
* @var int
*
* Master switch to enable backward compatibility behaviours:
* 0: Off. This is the default.
* 1: On. This will be set automatically if an installed modification needs it.
* 2: Forced on. Use this to enable backward compatibility behaviours even when
* no installed modifications require them. This is usually not necessary.
*/
public static int $backward_compatibility;
######### Legacy settings #########
/**
* @var string
*
* Database character set. Should always be utf8.
*/
public static string $db_character_set;
######### Developer settings #########
/**
* @var bool
*
* Whether to show debug info.
*/
public static bool $db_show_debug;
/**
* @var int
*
* Last database error.
*/
public static int $db_last_error;
######### Custom settings #########
/**
* @var array
*
* Holds any custom settings found in Settings.php.
*/
public static array $custom = [];
######### Runtime configuration values #########
/**
* @var array
*
* Holds settings loaded from the settings table in the database.
*/
public static array $modSettings = [];
/**
* @var string
*
* URL of SMF's main index.php.
*/
public static string $scripturl;
/****************************
* Internal static properties
****************************/
/**
* @var array
*
* A big, fat array to define properties of all the Settings.php variables
* and other content like code blocks.
*
* - String keys are used to identify actual variables.
*
* - Integer keys are used for content not connected to any particular
* variable, such as code blocks or the license block.
*
* - The content of the 'text' element is simply printed out, if it is used
* at all. Use it for comments or to insert code blocks, etc.
*
* - The 'default' element, not surprisingly, gives a default value for
* the variable.
*
* - The 'type' element defines the expected variable type or types. If
* more than one type is allowed, this should be an array listing them.
* Types should match the possible types returned by gettype().
*
* - If 'raw_default' is true, the default should be printed directly,
* rather than being handled as a string. Use it if the default contains
* code, e.g. 'dirname(__FILE__)'
*
* - If 'required' is true and a value for the variable is undefined,
* the update will be aborted. (The only exception is during the SMF
* installation process.)
*
* - If 'auto_delete' is 1 or true and the variable is empty, the variable
* will be deleted from Settings.php. If 'auto_delete' is 0/false/null,
* the variable will never be deleted. If 'auto_delete' is 2, behaviour
* depends on $rebuild: if $rebuild is true, 'auto_delete' == 2 behaves
* like 'auto_delete' == 1; if $rebuild is false, 'auto_delete' == 2
* behaves like 'auto_delete' == 0.
*
* - The 'is_password' element indicates that a value is a password. This
* is used primarily to tell SMF how to interpret input when the value
* is being set to a new value.
*
* - The optional 'search_pattern' element defines a custom regular
* expression to search for the existing entry in the file. This is
* primarily useful for code blocks rather than variables.
*
* - The optional 'replace_pattern' element defines a custom regular
* expression to decide where the replacement entry should be inserted.
* Note: 'replace_pattern' should be avoided unless ABSOLUTELY necessary.
*/
protected static array $settings_defs = [
[
'text' =>
"\n" .
'/**' . "\n" .
' * The settings file contains all of the basic settings that need to be present when a database/cache is not available.' . "\n" .
' *' . "\n" .
' * Simple Machines Forum (SMF)' . "\n" .
' *' . "\n" .
' * @package SMF' . "\n" .
' * @author Simple Machines https://www.simplemachines.org' . "\n" .
' * @copyright ' . SMF_SOFTWARE_YEAR . ' Simple Machines and individual contributors' . "\n" .
' * @license https://www.simplemachines.org/about/smf/license.php BSD' . "\n" .
' *' . "\n" .
' * @version ' . SMF_VERSION . "\n" .
' */' . "\n" .
'',
'search_pattern' => '~/\*\*.*?@package\h+SMF\b.*?\*/\n{0,2}~s',
],
'maintenance' => [
'text' => <<<'END'
########## Maintenance ##########
/**
* @var int 0, 1, 2
*
* The maintenance "mode":
* 0: Disable maintenance mode. This is the default.
* 1: Enable maintenance mode but allow admins to login normally.
* 2: Make the forum untouchable. You'll need to make it 0 again manually!
*/
END,
'default' => 0,
'type' => 'integer',
],
'mtitle' => [
'text' => <<<'END'
/**
* @var string
*
* Title for the Maintenance Mode message.
*/
END,
'default' => 'Maintenance Mode',
'type' => 'string',
],
'mmessage' => [
'text' => <<<'END'
/**
* @var string
*
* Description of why the forum is in maintenance mode.
*/
END,
'default' => 'Okay faithful users...we\'re attempting to restore an older backup of the database...news will be posted once we\'re back!',
'type' => 'string',
],
'mbname' => [
'text' => <<<'END'
########## Forum Info ##########
/**
* @var string
*
* The name of your forum.
*/
END,
'default' => 'My Community',
'type' => 'string',
],
'language' => [
'text' => <<<'END'
/**
* @var string
*
* The default language file set for the forum.
*/
END,
'default' => 'en_US',
'type' => 'string',
],
'boardurl' => [
'text' => <<<'END'
/**
* @var string
*
* URL to your forum's folder. (without the trailing /!)
*/
END,
'default' => 'http://127.0.0.1/smf',
'type' => 'string',
],
'webmaster_email' => [
'text' => <<<'END'
/**
* @var string
*
* Email address to send emails from. (like [email protected].)
*/
END,
'default' => '[email protected]',
'type' => 'string',
],
'cookiename' => [
'text' => <<<'END'
/**
* @var string
*
* Name of the cookie to set for authentication.
*/
END,
'default' => 'SMFCookie11',
'type' => 'string',
],
'auth_secret' => [
'text' => <<<'END'
/**
* @var string
*
* Secret key used to create and verify cookies, tokens, etc.
* Do not change this unless absolutely necessary, and NEVER share it.
*
* Note: Changing this will immediately log out all members of your forum
* and break the token-based links in all previous email notifications,
* among other possible effects.
*/
END,
'default' => null,
'auto_delete' => 1,
'type' => 'string',
],
'db_type' => [
'text' => <<<'END'
########## Database Info ##########
/**
* @var string
*
* The database type.
* Default options: mysql, postgresql
*/
END,
'default' => 'mysql',
'type' => 'string',
],
'db_port' => [
'text' => <<<'END'
/**
* @var int
*
* The database port.
* 0 to use default port for the database type.
*/
END,
'default' => 0,
'type' => 'integer',
],
'db_server' => [
'text' => <<<'END'
/**
* @var string
*
* The server to connect to (or a Unix socket)
*/
END,
'default' => 'localhost',
'required' => true,
'type' => 'string',
],
'db_name' => [
'text' => <<<'END'
/**
* @var string
*
* The database name.
*/
END,
'default' => 'smf',
'required' => true,
'type' => 'string',
],
'db_user' => [
'text' => <<<'END'
/**
* @var string
*
* Database username.
*/
END,
'default' => 'root',
'required' => true,
'type' => 'string',
],
'db_passwd' => [
'text' => <<<'END'
/**
* @var string
*
* Database password.
*/
END,
'default' => '',
'required' => true,
'type' => 'string',
'is_password' => true,
],
'ssi_db_user' => [
'text' => <<<'END'
/**
* @var string
*
* Database user for when connecting with SSI.
*/
END,
'default' => '',
'type' => 'string',
],
'ssi_db_passwd' => [
'text' => <<<'END'
/**
* @var string
*
* Database password for when connecting with SSI.
*/
END,
'default' => '',
'type' => 'string',
'is_password' => true,
],
'db_prefix' => [
'text' => <<<'END'
/**
* @var string
*
* A prefix to put in front of your table names.
* This helps to prevent conflicts.
*/
END,
'default' => 'smf_',
'required' => true,
'type' => 'string',
],
'db_persist' => [
'text' => <<<'END'
/**
* @var bool
*
* Use a persistent database connection.
*/
END,
'default' => false,
'type' => 'boolean',
],
'db_error_send' => [
'text' => <<<'END'
/**
* @var bool
*
* Send emails on database connection error.
*/
END,
'default' => false,
'type' => 'boolean',
],
'db_mb4' => [
'text' => <<<'END'
/**
* @var null|bool
*
* Override the default behavior of the database layer for mb4 handling.
* null keep the default behavior untouched.
*/
END,
'default' => null,
'type' => ['NULL', 'boolean'],
],
'cache_accelerator' => [
'text' => <<<'END'
########## Cache Info ##########
/**
* @var string
*
* Select a cache system. You should leave this up to the cache area of the
* admin panel for proper detection of the available options.
*/
END,
'default' => '',
'type' => 'string',
],
'cache_enable' => [
'text' => <<<'END'
/**
* @var int
*
* The level at which you would like to cache.
* Between 0 (off) through 3 (cache a lot).
*/
END,
'default' => 0,
'type' => 'integer',
],
'cache_memcached' => [
'text' => <<<'END'
/**
* @var array
*
* This is only used for memcache / memcached.
* Should be a string of 'server:port,server:port'
*/
END,
'default' => '',
'type' => 'string',
],
'cachedir' => [
'text' => <<<'END'
/**
* @var string
*
* Path to the cache directory for the file-based cache system.
*/
END,
'default' => 'dirname(__FILE__) . \'/cache\'',
'raw_default' => true,
'type' => 'string',
],
'cachedir_sqlite' => [
'text' => <<<'END'
/**
* @var string
*
* This is only used for the SQLite3 cache system.
* Path to the directory where the SQLite3 database file will be saved.
*/
END,
'default' => '',
'auto_delete' => 2,
'type' => 'string',
],
'image_proxy_enabled' => [
'text' => <<<'END'
########## Image Proxy ##########
/**
* @var bool
*
* Whether the proxy is enabled or not.
*/
END,
'default' => true,
'type' => 'boolean',
],
'image_proxy_secret' => [
'text' => <<<'END'
/**
* @var string
*
* Secret key to be used by the proxy.
*/
END,
'default' => 'smfisawesome',
'type' => 'string',
],
'image_proxy_maxsize' => [
'text' => <<<'END'
/**
* @var int
*
* Maximum file size (in KB) for individual files.
*/
END,
'default' => 5192,
'type' => 'integer',
],
'boarddir' => [
'text' => <<<'END'
########## Directories/Files ##########
# Note: These directories do not have to be changed unless you move things.
/**
* @var string
*
* The absolute path to the forum's folder. (not just '.'!)
*/
END,
'default' => 'dirname(__FILE__)',
'raw_default' => true,
'type' => 'string',
],
'sourcedir' => [
'text' => <<<'END'
/**
* @var string
*
* Path to the Sources directory.
*/
END,
'default' => 'dirname(__FILE__) . \'/Sources\'',
'raw_default' => true,
'type' => 'string',
],
'packagesdir' => [
'text' => <<<'END'
/**
* @var string
*
* Path to the Packages directory.
*/
END,
'default' => 'dirname(__FILE__) . \'/Packages\'',
'raw_default' => true,
'type' => 'string',
],
'languagesdir' => [
'text' => <<<'END'
/**
* @var string
*
* Path to the Languages directory.
*/
END,
'default' => '__DIR__ . \'/Languages\'',
'raw_default' => true,
'type' => 'string',
],
'backward_compatibility' => [
'text' => <<<'END'
######### Modification Support #########
/**
* @var int
*
* Master switch to enable backward compatibility behaviours:
* 0: Off. This is the default.
* 1: On. This will be set automatically if an installed modification needs it.
* 2: Forced on. Use this to enable backward compatibility behaviours even when
* no installed modifications require them. This is usually not necessary.
*/
END,
'default' => 0,
'type' => 'integer',
],
'db_character_set' => [
'text' => <<<'END'
######### Legacy Settings #########
/**
* @var string
*
* Database character set. Should always be utf8.
*/
END,
'default' => 'utf8',
'type' => 'string',
],
'db_show_debug' => [
'text' => <<<'END'
######### Developer Settings #########
/**
* @var bool
*
* Whether to show debug info.
*/
END,
'default' => false,
'auto_delete' => 2,
'type' => 'boolean',
],
// Temporary variable used during the upgrade process.
'upgradeData' => [
'default' => '',
'auto_delete' => 1,
'type' => 'string',
],
// This should be removed if found.
'db_last_error' => [
'default' => 0,
'auto_delete' => 1,
'type' => 'integer',
],
];
/**
* @var ?string
*
* Authentication secret.
* This is protected in order to force access via Config::getAuthSecret()
*/
protected static ?string $auth_secret;
/**
* @var string
*
* Path to a temporary directory.
*/
protected static string $temp_dir;
/**
* @var bool
*
* Tracks whether static variables and functions have been exported to
* global namespace.
*/
protected static bool $exported = false;
/***********************
* Public static methods
***********************/
/**
* Loads properties directly from Settings.php.
*/
public static function load(): void
{
// Load Settings.php.
if (!in_array(SMF_SETTINGS_FILE, get_included_files())) {
require SMF_SETTINGS_FILE;
}
// If it has already been included, make sure to avoid possible problems
// with already defined constants, etc.
else {
extract((array) self::getCurrentSettings(filemtime(SMF_SETTINGS_FILE), SMF_SETTINGS_FILE));
}
// Set this class's properties according to the values in Settings.php.
self::set(get_defined_vars());
}
/**
* Sets the properties of this class to the specified values.
*
* @param array $settings The settings values to use.
*/
public static function set(array $settings): void
{
foreach ($settings as $var => $val) {
if (property_exists(__CLASS__, $var)) {
self::${$var} = $val;
} else {
self::$custom[$var] = $val;
}
}
// Anything missing?
$class_vars = get_class_vars(__CLASS__);
foreach ($class_vars['settings_defs'] as $var => $def) {
if (is_string($var) && property_exists(__CLASS__, $var) && !isset(self::${$var})) {
if (!empty($def['raw_default'])) {
$default = strtr($def['default'], [
'__FILE__' => var_export(SMF_SETTINGS_FILE, true),
'__DIR__' => var_export(dirname(SMF_SETTINGS_FILE), true),
]);
self::${$var} = eval($default . ';');
} else {
self::${$var} = $def['default'];
}
// For convenience in the backward compatibility section below.
$settings[$var] = self::${$var};
}
}
// Ensure there are no trailing slashes in these settings.
foreach (['boardurl', 'boarddir', 'sourcedir', 'packagesdir', 'cachedir', 'languagesdir'] as $var) {
if (!is_null(self::${$var})) {
self::${$var} = rtrim(self::${$var}, '\\/');
}
}
// Make sure the paths are correct... at least try to fix them.
if (empty(self::$boarddir) || !is_dir(realpath(self::$boarddir))) {
self::$boarddir = !empty($_SERVER['SCRIPT_FILENAME']) ? dirname(realpath($_SERVER['SCRIPT_FILENAME'])) : dirname(__DIR__);
}
if ((empty(self::$sourcedir) || !is_dir(realpath(self::$sourcedir))) && is_dir(self::$boarddir . '/Sources')) {
self::$sourcedir = self::$boarddir . '/Sources';
}
// As of 3.0, this is no longer changeable.
self::$tasksdir = self::$sourcedir . '/Tasks';
if ((empty(self::$packagesdir) || !is_dir(realpath(self::$packagesdir))) && is_dir(self::$boarddir . '/Packages')) {
self::$packagesdir = self::$boarddir . '/Packages';
}
if ((empty(self::$languagesdir) || !is_dir(realpath(self::$languagesdir))) && is_dir(self::$boarddir . '/Languages')) {
self::$languagesdir = self::$boarddir . '/Languages';
}
// Make absolutely sure the cache directory is defined and writable.
if (empty(self::$cachedir) || !is_dir(self::$cachedir) || !is_writable(self::$cachedir)) {
if (is_dir(self::$boarddir . '/cache') && is_writable(self::$boarddir . '/cache')) {
self::$cachedir = self::$boarddir . '/cache';
} else {
self::$cachedir = self::getTempDir() . '/smf_cache_' . md5(self::$boarddir);
@mkdir(self::$cachedir, 0750);
}
}
// Makes it easier to refer to things this way.
self::$scripturl = self::$boardurl . '/index.php';
// For backward compatibility, make settings available as global variables.
// Must do this manually because SMF\BackwardCompatibility is not loaded yet.
if (!empty(self::$backward_compatibility) && !self::$exported) {
foreach ($settings as $var => $val) {
if (property_exists(__CLASS__, $var)) {
$GLOBALS[$var] = &self::${$var};
} else {
$GLOBALS[$var] = &self::$custom[$var];
}
}
$GLOBALS['modSettings'] = &self::$modSettings;
$GLOBALS['scripturl'] = &self::$scripturl;
eval('function reloadSettings() { return ' . __CLASS__ . '::reloadModSettings(); }');
eval('function updateSettings(...$args) { return ' . __CLASS__ . '::updateModSettings(...$args); }');
eval('function get_auth_secret() { return ' . __CLASS__ . '::getAuthSecret(); }');
eval('function get_settings_defs() { return ' . __CLASS__ . '::getSettingsDefs(); }');
eval('function updateSettingsFile(...$args) { return ' . __CLASS__ . '::updateSettingsFile(...$args); }');
eval('function safe_file_write(...$args) { return ' . __CLASS__ . '::safeFileWrite(...$args); }');
eval('function smf_var_export(...$args) { return ' . __CLASS__ . '::varExport(...$args); }');
eval('function updateDbLastError(...$args) { return ' . __CLASS__ . '::updateDbLastError(...$args); }');
eval('function sm_temp_dir() { return ' . __CLASS__ . '::getTempDir(); }');
eval('function smf_seed_generator() { return ' . __CLASS__ . '::generateSeed(); }');
eval('function check_cron() {return ' . __CLASS__ . '::checkCron(); }');
self::$exported = true;
}
}
/**
* Load the Config::$modSettings array.
*/
public static function reloadModSettings(): void
{
// We need some caching support, maybe.