{$setting})) $result = $defaults->{$setting}; else $result = array(); // Load user config if (file_exists($configpath) && defined('BMI_CONFIG_STATUS') && BMI_CONFIG_STATUS) { // Get file contents $bmi_config_contents = file_get_contents($configpath); if (defined('BMI_CONFIG_PHP') && BMI_CONFIG_PHP) { $bmi_config_contents = substr($bmi_config_contents, 8); } $bmi_config_json = json_decode($bmi_config_contents); // If config is correct set it if (json_last_error() == JSON_ERROR_NONE) { // Setting exist? if (isset($bmi_config_json->{$setting})) { // Get result $result = $bmi_config_json->{$setting}; } } } // Replace exceptions if ($setting == 'STORAGE::LOCAL::PATH' && $result == 'default') { $result = BMI_BACKUPS_DEFAULT; } // Replace backshashes if ($setting == 'STORAGE::LOCAL::PATH') { $result = str_replace('\\\\', DIRECTORY_SEPARATOR, $result); $result = str_replace('\\', DIRECTORY_SEPARATOR, $result); $result = str_replace('/', DIRECTORY_SEPARATOR, $result); } // Return setting return $result; } } if (!function_exists('bmi_set_config')) { function bmi_set_config($setting, $value) { // Load default and additional if (file_exists(BMI_CONFIG_PATH)) { // Get file contents $bmi_config_contents = file_get_contents(BMI_CONFIG_PATH); if (defined('BMI_CONFIG_PHP') && BMI_CONFIG_PHP) { $bmi_config_contents = substr($bmi_config_contents, 8); } $bmi_config_json = json_decode($bmi_config_contents); // Result default $default = bmi_get_config($setting); // If config is correct set it if (!(json_last_error() == JSON_ERROR_NONE)) { // Setting refill base $bmi_config_json = (object)[]; } // Allow empty $allow_empty = ['OTHER:CLI:PATH']; // Check if setting is not empty if (isset($value) && (!is_string($value) || (in_array($setting, $allow_empty) || strlen(trim($value)) > 0))) { // Set new setting if (is_array($bmi_config_json)) { $bmi_config_json[$setting] = $value; } else if (is_object($bmi_config_json)) { $bmi_config_json->{$setting} = $value; } else return false; } else return false; // Write edited settings if (defined('BMI_CONFIG_PHP') && BMI_CONFIG_PHP) { file_put_contents(BMI_CONFIG_PATH, " $file) { if (file_exists($prev_path . DIRECTORY_SEPARATOR . $file) && !is_dir($prev_path . DIRECTORY_SEPARATOR . $file)) { rename($prev_path . DIRECTORY_SEPARATOR . $file, $localStoragePath . DIRECTORY_SEPARATOR . $file); } } if ($prev_path != $localStoragePath && sizeof(scandir($prev_path_backups)) <= 2) { @rmdir($prev_path_backups); } } if (file_exists($prev_path) && is_dir($prev_path)) { $scanned_directory = array_diff(scandir($prev_path), ['..', '.']); foreach ($scanned_directory as $i => $file) { if (file_exists($prev_path . DIRECTORY_SEPARATOR . $file) && !is_dir($prev_path . DIRECTORY_SEPARATOR . $file)) { rename($prev_path . DIRECTORY_SEPARATOR . $file, $localStoragePath . DIRECTORY_SEPARATOR . $file); } } if ($localStoragePath != $prev_path && sizeof(scandir($prev_path)) <= 2) { @rmdir($prev_path); } } update_option('BMI::STORAGE::LOCAL::PATH', $localStoragePath); } } else bmi_render_default_config($bmi_initial_config_filepath, $bmi_initial_config_dirpath); } else bmi_render_default_config($bmi_initial_config_filepath, $bmi_initial_config_dirpath); if (!bmi_get_config('REQUEST:SECRET')) { bmi_set_config('REQUEST:SECRET', bmi_config_random_string(16)); }