| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- // Simple AJAX endpoint without output buffering
- error_reporting(E_ALL);
- ini_set('display_errors', 0);
- ini_set('max_execution_time', 60);
- ini_set('memory_limit', '512M');
- // Set header first
- header('Content-Type: application/json');
- // Simple response function
- function sendResponse($success, $message, $data = []) {
- $response = array_merge([
- 'success' => $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()
- ]
- ]);
- }
- ?>
- ?>
|