'auto', // auto, tr_TR, en_US // Export Ayarları 'export_min_disk_space' => 500, // MB 'export_chunk_size' => 200, // dosya/chunk 'export_max_zip_size' => 50, // MB 'export_exclude_folders' => 'cache,backups,upgrade,wflogs', 'export_exclude_tables' => '', // Import Ayarları 'import_create_recovery_admin' => true, 'import_recovery_admin_prefix' => 'wpc_admin_', 'import_disable_plugins' => true, 'import_skip_url_replace' => false, // Performans 'performance_timeout' => 300, // saniye 'performance_memory_limit' => '512M', 'performance_sql_batch_size' => 1000, 'performance_db_rows' => 1000, // Varsayılanı 1000'e çektik (Stabilite için) // Güvenlik 'security_encrypt_export' => false, 'security_auto_cleanup' => true, 'security_required_role' => 'manage_options', 'security_import_token_enabled' => true, // YENİ: Token doğrulama // Gelişmiş 'advanced_debug_mode' => false, // YENİ: ReplaceEngine logging 'advanced_paranoid_mode' => true, // YENİ: Agresif serialize skip 'advanced_json_escape_slashes' => false, // YENİ: JSON'da \/ kullan // Bildirimler 'notifications_email_enabled' => false, 'notifications_email_address' => '', 'notifications_slack_webhook' => '', ]; private function __construct() { $this->load(); } /** * Singleton instance döndürür */ public static function getInstance(): Settings { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } /** * Ayarları veritabanından yükler */ private function load(): void { $saved = get_option($this->optionName, []); $this->settings = array_merge($this->defaults, $saved); } /** * Tek bir ayarı döndürür */ public function get(string $key, $default = null) { if (array_key_exists($key, $this->settings)) { return $this->settings[$key]; } if ($default !== null) { return $default; } return $this->defaults[$key] ?? null; } /** * Tek bir ayarı günceller */ public function set(string $key, $value): bool { $this->settings[$key] = $value; return $this->save(); } /** * Birden fazla ayarı günceller */ public function setMultiple(array $values): bool { foreach ($values as $key => $value) { if (array_key_exists($key, $this->defaults)) { $this->settings[$key] = $this->sanitize($key, $value); } } return $this->save(); } /** * Tüm ayarları döndürür */ public function getAll(): array { return $this->settings; } /** * Varsayılan ayarları döndürür */ public function getDefaults(): array { return $this->defaults; } /** * Ayarları veritabanına kaydeder */ private function save(): bool { return update_option($this->optionName, $this->settings); } /** * Ayarları varsayılana sıfırlar */ public function reset(): bool { $this->settings = $this->defaults; return $this->save(); } /** * Değeri temizler ve doğrular */ private function sanitize(string $key, $value) { // Boolean alanlar $booleanFields = [ 'import_create_recovery_admin', 'import_disable_plugins', 'import_skip_url_replace', 'security_encrypt_export', 'security_auto_cleanup', 'security_import_token_enabled', 'advanced_debug_mode', 'advanced_paranoid_mode', 'advanced_json_escape_slashes', 'notifications_email_enabled', ]; if (in_array($key, $booleanFields)) { return filter_var($value, FILTER_VALIDATE_BOOLEAN); } // Sayısal alanlar $numericFields = [ 'export_min_disk_space', 'export_chunk_size', 'export_max_zip_size', 'performance_timeout', 'performance_sql_batch_size', 'performance_db_rows', ]; if (in_array($key, $numericFields)) { return absint($value); } // E-posta alanları if ($key === 'notifications_email_address') { return sanitize_email($value); } // URL alanları if ($key === 'notifications_slack_webhook') { return esc_url_raw($value); } // Diğer string alanlar return sanitize_text_field($value); } /** * Ayar gruplarını döndürür (UI için) */ public function getSettingGroups(): array { return [ 'general' => [ 'title' => __('General', 'alldami-site-migration'), 'icon' => 'dashicons-admin-generic', 'fields' => [ 'general_language' => [ 'label' => __('Plugin Language', 'alldami-site-migration'), 'type' => 'select', 'options' => [ 'auto' => __('Auto (WordPress Language)', 'alldami-site-migration'), 'tr_TR' => __('Turkish', 'alldami-site-migration'), 'en_US' => __('English', 'alldami-site-migration'), ], 'description' => __('Language to be used for the plugin interface.', 'alldami-site-migration'), ], ], ], 'export' => [ 'title' => __('Export Settings', 'alldami-site-migration'), 'icon' => 'dashicons-upload', 'fields' => [ 'export_min_disk_space' => [ 'label' => __('Minimum Disk Space (MB)', 'alldami-site-migration'), 'type' => 'number', 'description' => __('Minimum free disk space required before starting export.', 'alldami-site-migration'), ], 'export_chunk_size' => [ 'label' => __('Chunk Size', 'alldami-site-migration'), 'type' => 'number', 'description' => __('Maximum number of files to add to each zip chunk.', 'alldami-site-migration'), ], 'export_max_zip_size' => [ 'label' => __('Max Zip Size (MB)', 'alldami-site-migration'), 'type' => 'number', 'description' => __('Maximum size of a single zip file.', 'alldami-site-migration'), ], 'export_exclude_folders' => [ 'label' => __('Excluded Folders', 'alldami-site-migration'), 'type' => 'text', 'description' => __('Comma-separated folder names (e.g: cache,backups)', 'alldami-site-migration'), ], 'export_exclude_tables' => [ 'label' => __('Excluded Tables', 'alldami-site-migration'), 'type' => 'text', 'description' => __('Comma-separated table names (e.g: wp_statistics)', 'alldami-site-migration'), ], ], ], 'import' => [ 'title' => __('Import Settings', 'alldami-site-migration'), 'icon' => 'dashicons-download', 'fields' => [ 'import_create_recovery_admin' => [ 'label' => __('Create Recovery Admin', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Creates a new admin user after import.', 'alldami-site-migration'), ], 'import_recovery_admin_prefix' => [ 'label' => __('Admin User Prefix', 'alldami-site-migration'), 'type' => 'text', 'description' => __('Prefix of the admin user to be created.', 'alldami-site-migration'), ], 'import_disable_plugins' => [ 'label' => __('Disable All Plugins', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Deactivates all plugins after import.', 'alldami-site-migration'), ], 'import_skip_url_replace' => [ 'label' => __('Skip URL Replacement', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Does not perform URL replacement for debugging purposes.', 'alldami-site-migration'), ], ], ], 'performance' => [ 'title' => __('Performance', 'alldami-site-migration'), 'icon' => 'dashicons-performance', 'fields' => [ 'performance_timeout' => [ 'label' => __('PHP Timeout (seconds)', 'alldami-site-migration'), 'type' => 'number', 'description' => __('Maximum duration per process.', 'alldami-site-migration'), ], 'performance_memory_limit' => [ 'label' => __('Memory Limit', 'alldami-site-migration'), 'type' => 'select', 'options' => [ '256M' => '256 MB', '512M' => '512 MB', '1G' => '1 GB', '2G' => '2 GB', ], 'description' => __('PHP memory limit.', 'alldami-site-migration'), ], 'performance_sql_batch_size' => [ 'label' => __('SQL Batch Size', 'alldami-site-migration'), 'type' => 'number', 'description' => __('Number of rows to process at once.', 'alldami-site-migration'), ], 'performance_db_rows' => [ 'label' => __('DB Row Limit (Chunk)', 'alldami-site-migration'), 'type' => 'number', 'description' => __('Number of rows to fetch in each request. Higher values are faster but require more memory.', 'alldami-site-migration'), ], ], ], 'security' => [ 'title' => __('Security', 'alldami-site-migration'), 'icon' => 'dashicons-shield', 'fields' => [ 'security_import_token_enabled' => [ 'label' => __('Import Token Verification', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Checks the security token during import operations.', 'alldami-site-migration'), ], 'security_encrypt_export' => [ 'label' => __('Encrypt Export Files', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Protects ZIP files with a password. (Coming Soon)', 'alldami-site-migration'), 'disabled' => true, ], 'security_auto_cleanup' => [ 'label' => __('Automatic Temp Cleanup', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Automatically deletes temporary files after operation.', 'alldami-site-migration'), ], 'security_required_role' => [ 'label' => __('Required Role', 'alldami-site-migration'), 'type' => 'select', 'options' => [ 'manage_options' => __('Administrator', 'alldami-site-migration'), 'edit_plugins' => __('Super Admin', 'alldami-site-migration'), ], 'description' => __('Minimum capability required for Export/Import.', 'alldami-site-migration'), ], ], ], 'advanced' => [ 'title' => __('Advanced', 'alldami-site-migration'), 'icon' => 'dashicons-admin-tools', 'fields' => [ 'advanced_debug_mode' => [ 'label' => __('Debug Mode', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Logs ReplaceEngine operations. Enable only for testing.', 'alldami-site-migration'), ], 'advanced_paranoid_mode' => [ 'label' => __('Paranoid Mode', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Skips serialize-like strings. Safer but sometimes too protective.', 'alldami-site-migration'), ], 'advanced_json_escape_slashes' => [ 'label' => __('JSON Slash Escape', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Escapes the slash character (\\/) in JSON encode. Required for some plugins.', 'alldami-site-migration'), ], ], ], 'notifications' => [ 'title' => __('Notifications', 'alldami-site-migration'), 'icon' => 'dashicons-bell', 'fields' => [ 'notifications_email_enabled' => [ 'label' => __('Email Notification', 'alldami-site-migration'), 'type' => 'checkbox', 'description' => __('Sends an email when the process is complete.', 'alldami-site-migration'), ], 'notifications_email_address' => [ 'label' => __('Email Address', 'alldami-site-migration'), 'type' => 'email', 'description' => __('Email address to send notifications to.', 'alldami-site-migration'), ], 'notifications_slack_webhook' => [ 'label' => __('Slack Webhook URL', 'alldami-site-migration'), 'type' => 'url', 'description' => __('Slack notification webhook URL.', 'alldami-site-migration'), ], ], ], ]; } }