<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 8.0.00
// Randem Systems: https://randemsystems.support
// BotBanish define updates for Websites
// Date: 06/18/2026
// Usage:
//
// Function: Create the BotBanish_Settings.php file that will be used upon loading with the
// 				Settings_Client.php or the Settings_Server.php files.
///////////////////////////////////////////////////////////////////////////////////////////////////////

function BotBanishSettingsCreate(&$BotBanishSettings) {

	global $BotBanishSettings;
	
	$str = '';

	if (defined('ABSPATH')) {

		require_once BOTBANISH_PLUGIN_DIR . 'bot/Subs/BotBanish_Settings_Update_WordPress.php';
		$str = BotBanishSettingsCreateWordPress($BotBanishSettings);

	} else {

		if (defined('SMF')) {

			global $boarddir;
			require_once $boarddir . '/BotBanish/bot/Subs/BotBanish_Settings_Update_SMF.php';
			$str = BotBanishSettingsCreateSMF($BotBanishSettings);

		} else {

			if (defined('DIR_APPLICATION')) {

				$dir = rtrim(realpath(DIR_APPLICATION . '../' . $BotBanishSettings['BOTBANISH_LOCATION']), '/') . '/';
				require_once  $dir . 'Subs/BotBanish_Settings_Update_OpenCart.php';
				$str = BotBanishSettingsCreateOpenCart($BotBanishSettings);
				
			} else {
				
				$str = BotBanishSettingsCreateWebsite($BotBanishSettings);
			}
		}
	}
	
	return $str;
}

function BotBanishSettingsCreateWebsite(&$BotBanishSettings) {

	global $BotBanishSettings;
	
	$user_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
	$user_host = (empty($user_host) && isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $user_host;
	$user_host = trim(str_ireplace('\\', '/', $user_host), '/');
	
	$config = array(
		'BOTBANISH_DIR' => BOTBANISH_DIR,
		'BOTBANISH_SYSTEM' => $BotBanishSettings['BOTBANISH_SYSTEM'],
//		'BOTBANISH_SYSTEM' => 'WEBSITE',
		'BOTBANISH_TIMEZONE' => $BotBanishSettings['BOTBANISH_TIMEZONE'],
		'BOTBANISH_TABLE_PREFIX' => '',
		'BOTBANISH_DB_NAME' => $BotBanishSettings['BOTBANISH_DB_NAME'],
		'BOTBANISH_DB_USERNAME' => $BotBanishSettings['BOTBANISH_DB_USERNAME'],
		'BOTBANISH_DB_PASSWORD' => $BotBanishSettings['BOTBANISH_DB_PASSWORD'],
		'BOTBANISH_DB_SERVERNAME' => $BotBanishSettings['BOTBANISH_USER_HOST'],
		'BOTBANISH_DB_PORT' => $BotBanishSettings['BOTBANISH_DB_PORT'],
		'BOTBANISH_UPDATE_HTML_ACTIVE' => $BotBanishSettings['BOTBANISH_UPDATE_HTML_ACTIVE'],
		'BOTBANISH_USER_HOST' => $user_host,
		'BOTBANISH_SMTP_SERVER' => $BotBanishSettings['BOTBANISH_SMTP_SERVER'],
		'BOTBANISH_SMTP_PORT' => $BotBanishSettings['BOTBANISH_SMTP_PORT'],
		'BOTBANISH_SMTP_USERNAME' => $BotBanishSettings['BOTBANISH_SMTP_USERNAME'],
		'BOTBANISH_SMTP_PASSWORD' => $BotBanishSettings['BOTBANISH_SMTP_PASSWORD'],
		'BOTBANISH_WEBMASTER_EMAIL' => $BotBanishSettings['BOTBANISH_WEBMASTER_EMAIL'],
		'BOTBANISH_DATABASE_TABLE_CHARSET_DEFAULT' => $BotBanishSettings['BOTBANISH_DATABASE_TABLE_CHARSET_DEFAULT'],
		'BOTBANISH_DATABASE_TABLE_COLLATION_DEFAULT' => $BotBanishSettings['BOTBANISH_DATABASE_TABLE_COLLATION_DEFAULT'],
	);

	foreach ($config as $key => $value)
		BotBanishDefineGlobals($key, $value);
		
	return BotBanishSetupSettings($BotBanishSettings, 'Website');
}

function BotBanishSettingsFileSave($str) {

	global $BotBanishSettings;

	require_once $BotBanishSettings['BOTBANISH_SUBS_DIR'] . 'BotBanish_Subs.php';
	BotBanishWriteFile($BotBanishSettings['BOTBANISH_DIR'] . 'BotBanish_Settings.php', $str);
}

function BotBanishSetupSettings($BotBanishSettings, $system) {
					
	$str = "

		if (!defined('BOTBANISH_DIR'))
			define('BOTBANISH_DIR', '" . $BotBanishSettings['BOTBANISH_DIR'] . "');

		if (!defined('BOTBANISH_SYSTEM'))
			define('BOTBANISH_SYSTEM', '" . $BotBanishSettings['BOTBANISH_SYSTEM'] . "');

		require_once BOTBANISH_DIR . 'Include/BotBanish_PreIncludes.php';

		BotBanishDefineGlobals('BOTBANISH_WEBMASTER_EMAIL', '" . $BotBanishSettings['BOTBANISH_WEBMASTER_EMAIL'] . "');

		";


	return $str;
}
?>