From 187837d8a4b8bf8ff02b94a343e86cbd8a766a3b Mon Sep 17 00:00:00 2001 From: Shawn Bulen Date: Mon, 22 Jul 2024 16:11:03 -0700 Subject: [PATCH 1/2] Fix eval return; set dir consistently throughnout Signed by Shawn Bulen, bulens@pacbell.net --- Sources/Config.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Sources/Config.php b/Sources/Config.php index 2b63cb6985..e65e4dd371 100644 --- a/Sources/Config.php +++ b/Sources/Config.php @@ -682,7 +682,7 @@ class Config * Path to the cache directory for the file-based cache system. */ END, - 'default' => 'dirname(__FILE__) . \'/cache\'', + 'default' => '__DIR__ . \'/cache\'', 'raw_default' => true, 'type' => 'string', ], @@ -745,7 +745,7 @@ class Config * The absolute path to the forum's folder. (not just '.'!) */ END, - 'default' => 'dirname(__FILE__)', + 'default' => '__DIR__', 'raw_default' => true, 'type' => 'string', ], @@ -757,7 +757,7 @@ class Config * Path to the Sources directory. */ END, - 'default' => 'dirname(__FILE__) . \'/Sources\'', + 'default' => '__DIR__ . \'/Sources\'', 'raw_default' => true, 'type' => 'string', ], @@ -769,7 +769,7 @@ class Config * Path to the Packages directory. */ END, - 'default' => 'dirname(__FILE__) . \'/Packages\'', + 'default' => '__DIR__ . \'/Packages\'', 'raw_default' => true, 'type' => 'string', ], @@ -920,7 +920,7 @@ public static function set(array $settings): void '__DIR__' => var_export(dirname(SMF_SETTINGS_FILE), true), ]); - self::${$var} = eval($default . ';'); + self::${$var} = eval('return ' . $default . ';'); } else { self::${$var} = $def['default']; } @@ -1697,14 +1697,6 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes if (!empty($setting_def['raw_default']) && $setting_def['default'] !== '') { $var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote($setting_def['default'], '~')); - - if (str_contains($setting_def['default'], 'dirname(__FILE__)')) { - $var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote(str_replace('dirname(__FILE__)', '__DIR__', $setting_def['default']), '~')); - } - - if (str_contains($setting_def['default'], '__DIR__')) { - $var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote(str_replace('__DIR__', 'dirname(__FILE__)', $setting_def['default']), '~')); - } } $var_pattern = array_unique($var_pattern); From 7ba18f9a92334397ad3284be203849c73eb6e5a7 Mon Sep 17 00:00:00 2001 From: Shawn Bulen Date: Mon, 7 Oct 2024 16:05:56 -0700 Subject: [PATCH 2/2] Bring settings.php in line with Config.php Signed by Shawn Bulen, bulens@pacbell.net --- Sources/Config.php | 8 ++++++++ other/Settings.php | 12 ++++++------ other/Settings_bak.php | 12 ++++++------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Sources/Config.php b/Sources/Config.php index e65e4dd371..370b69a65b 100644 --- a/Sources/Config.php +++ b/Sources/Config.php @@ -1697,6 +1697,14 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes if (!empty($setting_def['raw_default']) && $setting_def['default'] !== '') { $var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote($setting_def['default'], '~')); + + if (str_contains($setting_def['default'], 'dirname(__FILE__)')) { + $var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote(str_replace('dirname(__FILE__)', '__DIR__', $setting_def['default']), '~')); + } + + if (str_contains($setting_def['default'], '__DIR__')) { + $var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote(str_replace('__DIR__', 'dirname(__FILE__)', $setting_def['default']), '~')); + } } $var_pattern = array_unique($var_pattern); diff --git a/other/Settings.php b/other/Settings.php index 3b7e0ccae6..920e6aff93 100644 --- a/other/Settings.php +++ b/other/Settings.php @@ -173,7 +173,7 @@ * * Path to the cache directory for the file-based cache system. */ -$cachedir = dirname(__FILE__) . '/cache'; +$cachedir = __DIR__ . '/cache'; ########## Image Proxy ########## /** @@ -202,25 +202,25 @@ * * The absolute path to the forum's folder. (not just '.'!) */ -$boarddir = dirname(__FILE__); +$boarddir = __DIR__; /** * @var string * * Path to the Sources directory. */ -$sourcedir = dirname(__FILE__) . '/Sources'; +$sourcedir = __DIR__ . '/Sources'; /** * @var string * * Path to the Packages directory. */ -$packagesdir = dirname(__FILE__) . '/Packages'; +$packagesdir = __DIR__ . '/Packages'; /** * @var string * * Path to the language directory. */ -$languagesdir = dirname(__FILE__) . '/Languages'; +$languagesdir = __DIR__ . '/Languages'; ######### Modification Support ######### /** @@ -242,7 +242,7 @@ */ $db_character_set = 'utf8'; -if (file_exists(dirname(__FILE__) . '/install.php')) +if (file_exists(__DIR__ . '/install.php')) { $secure = false; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') diff --git a/other/Settings_bak.php b/other/Settings_bak.php index 3b7e0ccae6..920e6aff93 100644 --- a/other/Settings_bak.php +++ b/other/Settings_bak.php @@ -173,7 +173,7 @@ * * Path to the cache directory for the file-based cache system. */ -$cachedir = dirname(__FILE__) . '/cache'; +$cachedir = __DIR__ . '/cache'; ########## Image Proxy ########## /** @@ -202,25 +202,25 @@ * * The absolute path to the forum's folder. (not just '.'!) */ -$boarddir = dirname(__FILE__); +$boarddir = __DIR__; /** * @var string * * Path to the Sources directory. */ -$sourcedir = dirname(__FILE__) . '/Sources'; +$sourcedir = __DIR__ . '/Sources'; /** * @var string * * Path to the Packages directory. */ -$packagesdir = dirname(__FILE__) . '/Packages'; +$packagesdir = __DIR__ . '/Packages'; /** * @var string * * Path to the language directory. */ -$languagesdir = dirname(__FILE__) . '/Languages'; +$languagesdir = __DIR__ . '/Languages'; ######### Modification Support ######### /** @@ -242,7 +242,7 @@ */ $db_character_set = 'utf8'; -if (file_exists(dirname(__FILE__) . '/install.php')) +if (file_exists(__DIR__ . '/install.php')) { $secure = false; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')