$success, 'message' => $message ], $data); echo json_encode($response); exit; } try { require_once '../includes/config.php'; require_once '../includes/database.php'; require_once '../includes/wordpress_import.php'; } catch (Exception $e) { sendResponse(false, 'Include error: ' . $e->getMessage(), ['step' => 'includes']); } $action = $_GET['action'] ?? ''; $step = $action; try { switch ($action) { case 'test_connection': $wpConfig = [ 'host' => trim($_GET['wp_host'] ?? ''), 'database' => trim($_GET['wp_database'] ?? ''), 'username' => trim($_GET['wp_username'] ?? ''), 'password' => $_GET['wp_password'] ?? '' ]; $importer = new WordPressImport($wpConfig); $connectionTest = $importer->testConnection(); if ($connectionTest['success']) { sendResponse(true, 'Connection successful', [ 'step' => $step, 'stats' => $connectionTest['stats'] ]); } else { sendResponse(false, $connectionTest['error'], ['step' => $step]); } break; case 'import_categories': $wpConfig = [ 'host' => trim($_GET['wp_host'] ?? ''), 'database' => trim($_GET['wp_database'] ?? ''), 'username' => trim($_GET['wp_username'] ?? ''), 'password' => $_GET['wp_password'] ?? '' ]; $importer = new WordPressImport($wpConfig); $result = $importer->importCategories(); sendResponse(true, 'Categories imported', [ 'step' => $step, 'result' => $result ]); break; case 'import_users': $wpConfig = [ 'host' => trim($_GET['wp_host'] ?? ''), 'database' => trim($_GET['wp_database'] ?? ''), 'username' => trim($_GET['wp_username'] ?? ''), 'password' => $_GET['wp_password'] ?? '' ]; $importer = new WordPressImport($wpConfig); $result = $importer->importUsers(); sendResponse(true, 'Users imported', [ 'step' => $step, 'result' => $result ]); break; case 'import_posts': $wpConfig = [ 'host' => trim($_GET['wp_host'] ?? ''), 'database' => trim($_GET['wp_database'] ?? ''), 'username' => trim($_GET['wp_username'] ?? ''), 'password' => $_GET['wp_password'] ?? '' ]; $importer = new WordPressImport($wpConfig); $result = $importer->importPosts(); sendResponse(true, 'Posts imported', [ 'step' => $step, 'result' => $result ]); break; case 'import_comments': $wpConfig = [ 'host' => trim($_GET['wp_host'] ?? ''), 'database' => trim($_GET['wp_database'] ?? ''), 'username' => trim($_GET['wp_username'] ?? ''), 'password' => $_GET['wp_password'] ?? '' ]; $importer = new WordPressImport($wpConfig); $result = $importer->importComments(); sendResponse(true, 'Comments imported', [ 'step' => $step, 'result' => $result, 'logs' => $importer->getImportLog() ]); break; default: sendResponse(false, 'Unknown action', ['step' => $step]); } } catch (Exception $e) { sendResponse(false, 'Error: ' . $e->getMessage(), [ 'step' => $step, 'error' => [ 'file' => $e->getFile(), 'line' => $e->getLine() ] ]); } ?> ?>