소스 검색

Fix WP import

svalavuo 4 일 전
부모
커밋
40dc1ccd92
4개의 변경된 파일507개의 추가작업 그리고 507개의 파일을 삭제
  1. 0 0
      admin/ajax_import_interface.html
  2. 120 321
      admin/wordpress_import.php
  3. 0 186
      admin/wordpress_import_new.php
  4. 387 0
      admin/wordpress_import_old.php

+ 0 - 0
admin/ajax_test_interface.html → admin/ajax_import_interface.html


+ 120 - 321
admin/wordpress_import.php

@@ -1,19 +1,18 @@
 <?php
-// Simplified WordPress import interface - bypass problematic components
+// WordPress Import - Based on working minimal test
 error_reporting(E_ALL);
 ini_set('display_errors', 0);
 ini_set('max_execution_time', 120);
 ini_set('memory_limit', '512M');
 
-// Start session for basic functionality
+// Include config first to get constants
+require_once '../includes/config.php';
+
+// Simple auth check - just check if user is logged in
 if (session_status() === PHP_SESSION_NONE) {
     session_start();
 }
 
-require_once '../includes/config.php';
-require_once '../includes/database.php';
-
-// Simple auth check - just check if user is logged in without complex auth system
 $isAdmin = false;
 if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && isset($_SESSION['role']) && $_SESSION['role'] === 'admin') {
     $isAdmin = true;
@@ -26,12 +25,14 @@ if (!$isAdmin) {
 }
 
 $message = '';
-$importResults = null;
-$connectionTest = null;
+$stats = [];
 
-// Handle form submission with simplified processing
+// Handle form submission
 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     try {
+        require_once '../includes/config.php';
+        require_once '../includes/database.php';
+        
         // Get WordPress database configuration
         $wpConfig = [
             'host' => trim($_POST['wp_host'] ?? ''),
@@ -45,66 +46,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
             throw new Exception("WordPress database configuration is required. Please provide host, database, and username.");
         }
         
-        // Direct WordPress connection test (bypass WordPressImport class)
+        // Direct WordPress connection test (exactly same as minimal test)
+        $options = [
+            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+            PDO::ATTR_TIMEOUT => 10,
+            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
+        ];
+        
+        $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
+        $wpDb = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
+        
+        // Test connection
+        $wpDb->query("SELECT 1");
+        
+        // Get stats with direct queries (exactly same as minimal test)
         try {
-            // Set timeout options
-            $options = [
-                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
-                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
-                PDO::ATTR_TIMEOUT => 10,
-                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
-            ];
-            
-            $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
-            $wpDb = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
-            
-            // Test connection
-            $wpDb->query("SELECT 1");
-            
-            if (isset($_POST['test_connection'])) {
-                // Get stats with direct queries
-                $stats = [];
-                try {
-                    $stats['posts'] = $wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['posts'] = 0;
-                }
-                
-                try {
-                    $stats['categories'] = $wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['categories'] = 0;
-                }
-                
-                try {
-                    $stats['users'] = $wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['users'] = 0;
-                }
-                
-                try {
-                    $stats['comments'] = $wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['comments'] = 0;
-                }
-                
-                $message = "WordPress connection successful: " . 
-                          "Posts: " . $stats['posts'] . ", " .
-                          "Categories: " . $stats['categories'] . ", " .
-                          "Users: " . $stats['users'] . ", " .
-                          "Comments: " . $stats['comments'];
-            }
+            $stats['posts'] = $wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
+        } catch (Exception $e) {
+            $stats['posts'] = 0;
+        }
+        
+        try {
+            $stats['categories'] = $wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
         } catch (Exception $e) {
-            throw new Exception("WordPress connection failed: " . $e->getMessage());
+            $stats['categories'] = 0;
         }
         
-        if (isset($_POST['start_import'])) {
-            // For now, just show a message that import is not implemented in this simplified version
-            throw new Exception("Import functionality is temporarily disabled. Please use the AJAX import tool for importing data.");
+        try {
+            $stats['users'] = $wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
+        } catch (Exception $e) {
+            $stats['users'] = 0;
         }
         
+        try {
+            $stats['comments'] = $wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
+        } catch (Exception $e) {
+            $stats['comments'] = 0;
+        }
+        
+        $message = "WordPress connection successful: Posts: {$stats['posts']}, Categories: {$stats['categories']}, Users: {$stats['users']}, Comments: {$stats['comments']}";
+        
     } catch (Exception $e) {
-        $message = $e->getMessage();
+        $message = "WordPress connection failed: " . $e->getMessage();
     }
 }
 ?>
@@ -115,273 +99,88 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>WordPress Import - <?php echo SITE_TITLE; ?></title>
     <link rel="stylesheet" href="../css/style.css">
-    <link rel="stylesheet" href="../css/admin-import.css">
+    <style>
+        .import-form { max-width: 600px; margin: 20px auto; }
+        .form-group { margin-bottom: 15px; }
+        label { display: block; margin-bottom: 5px; font-weight: bold; }
+        input, button { padding: 8px; margin-bottom: 10px; width: 100%; }
+        button { background: #007cba; color: white; border: none; cursor: pointer; }
+        button:hover { background: #005a87; }
+        .message { padding: 10px; margin: 10px 0; border-radius: 4px; }
+        .success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
+        .error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
+        .stats { background: #e2e3e5; padding: 10px; border-radius: 4px; margin: 10px 0; }
+    </style>
 </head>
 <body>
-    <div class="admin-layout">
-        <header class="admin-header">
-            <div class="header-content">
-                <h1><a href="/index.php"><?php echo SITE_TITLE; ?></a></h1>
-                <nav class="admin-nav">
-                    <a href="index.php" class="nav-link">Dashboard</a>
-                    <a href="publications.php" class="nav-link">Publications</a>
-                    <a href="categories.php" class="nav-link">Categories</a>
-                    <a href="comments.php" class="nav-link">Comments</a>
-                    <a href="users.php" class="nav-link">Users</a>
-                    <a href="wordpress_import.php" class="nav-link active">WordPress Import</a>
-                    <?php if (LDAP_ENABLED): ?>
-                        <a href="ldap-users.php" class="nav-link">LDAP Users</a>
-                    <?php endif; ?>
-                    <a href="logout.php" class="nav-link">Logout</a>
-                </nav>
-                <div class="user-info">
-                    Welcome, <?php echo htmlspecialchars($_SESSION['username'] ?? 'Admin'); ?>
-                </div>
-            </div>
-        </header>
-
-        <main class="admin-main">
-            <div class="page-header">
-                <h2>WordPress Import</h2>
-                <p class="page-description">Import WordPress data into your system.</p>
-                <p class="page-description">Import posts, categories, users, and comments from a WordPress database to your publication system.</p>
+    <div style="max-width: 800px; margin: 20px auto; padding: 20px;">
+        <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
+        <nav>
+            <a href="index.php">Dashboard</a> | 
+            <a href="publications.php">Publications</a> | 
+            <a href="categories.php">Categories</a> | 
+            <a href="wordpress_import.php" style="font-weight: bold;">WordPress Import</a> | 
+            <a href="logout.php">Logout</a>
+        </nav>
+        
+        <h2>WordPress Import</h2>
+        <p>Test connection to your WordPress database to import posts, categories, users, and comments.</p>
+        
+        <?php if ($message): ?>
+            <div class="message <?php echo strpos($message, 'successful') !== false ? 'success' : 'error'; ?>">
+                <?php echo $message; ?>
             </div>
-            
-            <?php if ($message): ?>
-                <div class="alert alert-<?php echo strpos($message, 'Error') === false && strpos($message, 'failed') === false ? 'success' : 'error'; ?>">
-                    <?php echo $message; ?>
-                </div>
-            <?php endif; ?>
-
-            <!-- Import Form -->
-            <div class="import-form-container">
-                <form method="post" class="import-form">
-                    <div class="form-section">
-                        <h3>WordPress Database Configuration</h3>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label for="wp_host">Database Host *</label>
-                                <input type="text" id="wp_host" name="wp_host" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_host'] ?? 'localhost'); ?>" 
-                                       placeholder="localhost" required>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label for="wp_database">Database Name *</label>
-                                <input type="text" id="wp_database" name="wp_database" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_database'] ?? ''); ?>" 
-                                       placeholder="wordpress_database" required>
-                            </div>
-                        </div>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label for="wp_username">Database Username *</label>
-                                <input type="text" id="wp_username" name="wp_username" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_username'] ?? ''); ?>" 
-                                       placeholder="wp_username" required>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label for="wp_password">Database Password</label>
-                                <input type="password" id="wp_password" name="wp_password" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_password'] ?? ''); ?>" 
-                                       placeholder="Leave empty if no password">
-                            </div>
-                        </div>
-                    </div>
-                    
-                    <div class="form-section">
-                        <h3>Import Options</h3>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_categories" checked>
-                                    Import Categories
-                                </label>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_users" checked>
-                                    Import Users
-                                </label>
-                            </div>
-                        </div>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_posts" checked>
-                                    Import Posts
-                                </label>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_comments" checked>
-                                    Import Comments
-                                </label>
-                            </div>
-                        </div>
-                    </div>
-                    
-                    <div class="form-actions">
-                        <button type="submit" name="test_connection" class="btn btn-primary">
-                            Test Connection
-                        </button>
-                        <button type="submit" name="start_import" class="btn btn-success" 
-                                onclick="return confirm('Are you sure you want to start the import? This will import data from WordPress into your system.')">
-                            Start Import
-                        </button>
-                    </div>
-                </form>
+        <?php endif; ?>
+        
+        <?php if (!empty($stats)): ?>
+            <div class="stats">
+                <h3>WordPress Database Statistics:</h3>
+                <ul>
+                    <li>Posts: <?php echo $stats['posts']; ?></li>
+                    <li>Categories: <?php echo $stats['categories']; ?></li>
+                    <li>Users: <?php echo $stats['users']; ?></li>
+                    <li>Comments: <?php echo $stats['comments']; ?></li>
+                </ul>
             </div>
-
-            <!-- Import Results -->
-            <?php if ($importResults): ?>
-                <div class="import-results">
-                    <h3>Import Results</h3>
-                    
-                    <?php if ($importResults['success']): ?>
-                        <div class="success-summary">
-                            <p class="success-message">WordPress import completed successfully!</p>
-                        </div>
-                        
-                        <div class="results-details">
-                            <?php foreach ($importResults['results'] as $type => $result): ?>
-                                <div class="result-item">
-                                    <h4><?php echo ucfirst($type); ?></h4>
-                                    <div class="result-stats">
-                                        <span class="stat success">
-                                            Imported: <strong><?php echo $result['imported']; ?></strong>
-                                        </span>
-                                        <span class="stat warning">
-                                            Skipped: <strong><?php echo $result['skipped']; ?></strong>
-                                        </span>
-                                    </div>
-                                </div>
-                            <?php endforeach; ?>
-                        </div>
-                        
-                        <?php if (!empty($importResults['log'])): ?>
-                            <div class="import-log">
-                                <h4>Import Log</h4>
-                                <div class="log-container">
-                                    <?php foreach ($importResults['log'] as $logEntry): ?>
-                                        <div class="log-entry log-<?php echo $logEntry['level']; ?>">
-                                            <span class="log-time"><?php echo $logEntry['timestamp']; ?></span>
-                                            <span class="log-message"><?php echo htmlspecialchars($logEntry['message']); ?></span>
-                                        </div>
-                                    <?php endforeach; ?>
-                                </div>
-                            </div>
-                        <?php endif; ?>
-                        
-                        <?php if (!empty($importResults['errors'])): ?>
-                            <div class="import-errors">
-                                <h4>Import Errors</h4>
-                                <div class="error-list">
-                                    <?php foreach ($importResults['errors'] as $error): ?>
-                                        <div class="error-item">
-                                            <?php echo htmlspecialchars($error); ?>
-                                        </div>
-                                    <?php endforeach; ?>
-                                </div>
-                            </div>
-                        <?php endif; ?>
-                        
-                    <?php else: ?>
-                        <div class="error-summary">
-                            <p class="error-message"><?php echo htmlspecialchars($importResults['error']); ?></p>
-                        </div>
-                    <?php endif; ?>
-                </div>
-            <?php endif; ?>
-
-            <!-- Information Section -->
-            <div class="info-section">
-                <h3>WordPress Import Information</h3>
-                <div class="info-content">
-                    <div class="info-item">
-                        <h4>What Gets Imported</h4>
-                        <ul>
-                            <li>Posts (title, content, author, publication date)</li>
-                            <li>Categories (name and description)</li>
-                            <li>Users (username, email, display name)</li>
-                            <li>Comments (content, author, date, threading)</li>
-                        </ul>
-                    </div>
-                    
-                    <div class="info-item">
-                        <h4>Requirements</h4>
-                        <ul>
-                            <li>Database access to WordPress database</li>
-                            <li>WordPress database with standard structure</li>
-                            <li>Backup of your current data (recommended)</li>
-                        </ul>
-                    </div>
-                    
-                    <div class="info-item">
-                        <h4>Important Notes</h4>
-                        <ul>
-                            <li>Existing data with same identifiers will be skipped</li>
-                            <li>WordPress content is processed for compatibility</li>
-                            <li>WordPress users are mapped to your user system</li>
-                        </ul>
-                    </div>
-                </div>
+        <?php endif; ?>
+        
+        <form method="post" class="import-form">
+            <div class="form-group">
+                <label for="wp_host">Database Host *</label>
+                <input type="text" id="wp_host" name="wp_host" 
+                       value="<?php echo htmlspecialchars($_POST['wp_host'] ?? 'localhost'); ?>" 
+                       placeholder="localhost" required>
             </div>
-        </main>
-    </div>
-
-    <script>
-        // WordPress Import JavaScript
-        document.addEventListener('DOMContentLoaded', function() {
-            const form = document.querySelector('.import-form');
-            const testBtn = document.querySelector('button[name="test_connection"]');
-            const importBtn = document.querySelector('button[name="start_import"]');
-            
-            // Show loading state
-            function setLoading(button, loading) {
-                if (loading) {
-                    button.disabled = true;
-                    button.dataset.originalText = button.textContent;
-                    button.textContent = button.dataset.loadingText || 'Loading...';
-                } else {
-                    button.disabled = false;
-                    button.textContent = button.dataset.originalText;
-                }
-            }
             
-            // Test connection loading
-            testBtn.addEventListener('click', function() {
-                setLoading(this, true);
-                this.dataset.loadingText = 'Testing connection...';
-            });
+            <div class="form-group">
+                <label for="wp_database">Database Name *</label>
+                <input type="text" id="wp_database" name="wp_database" 
+                       value="<?php echo htmlspecialchars($_POST['wp_database'] ?? ''); ?>" 
+                       placeholder="wordpress_database" required>
+            </div>
             
-            // Import loading
-            importBtn.addEventListener('click', function() {
-                setLoading(this, true);
-                this.dataset.loadingText = 'Importing...';
-            });
+            <div class="form-group">
+                <label for="wp_username">Database Username *</label>
+                <input type="text" id="wp_username" name="wp_username" 
+                       value="<?php echo htmlspecialchars($_POST['wp_username'] ?? ''); ?>" 
+                       placeholder="wp_username" required>
+            </div>
             
-            // Reset loading on form submit
-            form.addEventListener('submit', function() {
-                setTimeout(() => {
-                    setLoading(testBtn, false);
-                    setLoading(importBtn, false);
-                }, 1000);
-            });
+            <div class="form-group">
+                <label for="wp_password">Database Password</label>
+                <input type="password" id="wp_password" name="wp_password" 
+                       value="<?php echo htmlspecialchars($_POST['wp_password'] ?? ''); ?>" 
+                       placeholder="Leave empty if no password">
+            </div>
             
-            // Auto-focus first empty field
-            const firstEmpty = form.querySelector('input[value=""], input:not([value])');
-            if (firstEmpty) {
-                firstEmpty.focus();
-            }
-        });
-    </script>
+            <button type="submit" name="test_connection">Test Connection</button>
+        </form>
+        
+        <div style="margin-top: 30px; padding: 15px; background: #f8f9fa; border-radius: 4px;">
+            <h3>Import Options</h3>
+            <p>For actual importing, use the AJAX import tool which provides step-by-step import functionality:</p>
+            <a href="ajax_import_interface.html" style="display: inline-block; padding: 10px 20px; background: #28a745; color: white; text-decoration: none; border-radius: 4px;">AJAX Import Tool</a>
+        </div>
+    </div>
 </body>
 </html>

+ 0 - 186
admin/wordpress_import_new.php

@@ -1,186 +0,0 @@
-<?php
-// WordPress Import - Based on working minimal test
-error_reporting(E_ALL);
-ini_set('display_errors', 0);
-ini_set('max_execution_time', 120);
-ini_set('memory_limit', '512M');
-
-// Include config first to get constants
-require_once '../includes/config.php';
-
-// Simple auth check - just check if user is logged in
-if (session_status() === PHP_SESSION_NONE) {
-    session_start();
-}
-
-$isAdmin = false;
-if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && isset($_SESSION['role']) && $_SESSION['role'] === 'admin') {
-    $isAdmin = true;
-}
-
-// Redirect if not admin
-if (!$isAdmin) {
-    header('Location: login.php');
-    exit;
-}
-
-$message = '';
-$stats = [];
-
-// Handle form submission
-if ($_SERVER['REQUEST_METHOD'] === 'POST') {
-    try {
-        require_once '../includes/config.php';
-        require_once '../includes/database.php';
-        
-        // Get WordPress database configuration
-        $wpConfig = [
-            'host' => trim($_POST['wp_host'] ?? ''),
-            'database' => trim($_POST['wp_database'] ?? ''),
-            'username' => trim($_POST['wp_username'] ?? ''),
-            'password' => $_POST['wp_password'] ?? ''
-        ];
-        
-        // Validate required fields
-        if (empty($wpConfig['host']) || empty($wpConfig['database']) || empty($wpConfig['username'])) {
-            throw new Exception("WordPress database configuration is required. Please provide host, database, and username.");
-        }
-        
-        // Direct WordPress connection test (exactly same as minimal test)
-        $options = [
-            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
-            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
-            PDO::ATTR_TIMEOUT => 10,
-            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
-        ];
-        
-        $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
-        $wpDb = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
-        
-        // Test connection
-        $wpDb->query("SELECT 1");
-        
-        // Get stats with direct queries (exactly same as minimal test)
-        try {
-            $stats['posts'] = $wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
-        } catch (Exception $e) {
-            $stats['posts'] = 0;
-        }
-        
-        try {
-            $stats['categories'] = $wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
-        } catch (Exception $e) {
-            $stats['categories'] = 0;
-        }
-        
-        try {
-            $stats['users'] = $wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
-        } catch (Exception $e) {
-            $stats['users'] = 0;
-        }
-        
-        try {
-            $stats['comments'] = $wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
-        } catch (Exception $e) {
-            $stats['comments'] = 0;
-        }
-        
-        $message = "WordPress connection successful: Posts: {$stats['posts']}, Categories: {$stats['categories']}, Users: {$stats['users']}, Comments: {$stats['comments']}";
-        
-    } catch (Exception $e) {
-        $message = "WordPress connection failed: " . $e->getMessage();
-    }
-}
-?>
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>WordPress Import - <?php echo SITE_TITLE; ?></title>
-    <link rel="stylesheet" href="../css/style.css">
-    <style>
-        .import-form { max-width: 600px; margin: 20px auto; }
-        .form-group { margin-bottom: 15px; }
-        label { display: block; margin-bottom: 5px; font-weight: bold; }
-        input, button { padding: 8px; margin-bottom: 10px; width: 100%; }
-        button { background: #007cba; color: white; border: none; cursor: pointer; }
-        button:hover { background: #005a87; }
-        .message { padding: 10px; margin: 10px 0; border-radius: 4px; }
-        .success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
-        .error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
-        .stats { background: #e2e3e5; padding: 10px; border-radius: 4px; margin: 10px 0; }
-    </style>
-</head>
-<body>
-    <div style="max-width: 800px; margin: 20px auto; padding: 20px;">
-        <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
-        <nav>
-            <a href="index.php">Dashboard</a> | 
-            <a href="publications.php">Publications</a> | 
-            <a href="categories.php">Categories</a> | 
-            <a href="wordpress_import.php" style="font-weight: bold;">WordPress Import</a> | 
-            <a href="logout.php">Logout</a>
-        </nav>
-        
-        <h2>WordPress Import</h2>
-        <p>Test connection to your WordPress database to import posts, categories, users, and comments.</p>
-        
-        <?php if ($message): ?>
-            <div class="message <?php echo strpos($message, 'successful') !== false ? 'success' : 'error'; ?>">
-                <?php echo $message; ?>
-            </div>
-        <?php endif; ?>
-        
-        <?php if (!empty($stats)): ?>
-            <div class="stats">
-                <h3>WordPress Database Statistics:</h3>
-                <ul>
-                    <li>Posts: <?php echo $stats['posts']; ?></li>
-                    <li>Categories: <?php echo $stats['categories']; ?></li>
-                    <li>Users: <?php echo $stats['users']; ?></li>
-                    <li>Comments: <?php echo $stats['comments']; ?></li>
-                </ul>
-            </div>
-        <?php endif; ?>
-        
-        <form method="post" class="import-form">
-            <div class="form-group">
-                <label for="wp_host">Database Host *</label>
-                <input type="text" id="wp_host" name="wp_host" 
-                       value="<?php echo htmlspecialchars($_POST['wp_host'] ?? 'localhost'); ?>" 
-                       placeholder="localhost" required>
-            </div>
-            
-            <div class="form-group">
-                <label for="wp_database">Database Name *</label>
-                <input type="text" id="wp_database" name="wp_database" 
-                       value="<?php echo htmlspecialchars($_POST['wp_database'] ?? ''); ?>" 
-                       placeholder="wordpress_database" required>
-            </div>
-            
-            <div class="form-group">
-                <label for="wp_username">Database Username *</label>
-                <input type="text" id="wp_username" name="wp_username" 
-                       value="<?php echo htmlspecialchars($_POST['wp_username'] ?? ''); ?>" 
-                       placeholder="wp_username" required>
-            </div>
-            
-            <div class="form-group">
-                <label for="wp_password">Database Password</label>
-                <input type="password" id="wp_password" name="wp_password" 
-                       value="<?php echo htmlspecialchars($_POST['wp_password'] ?? ''); ?>" 
-                       placeholder="Leave empty if no password">
-            </div>
-            
-            <button type="submit" name="test_connection">Test Connection</button>
-        </form>
-        
-        <div style="margin-top: 30px; padding: 15px; background: #f8f9fa; border-radius: 4px;">
-            <h3>Import Options</h3>
-            <p>For actual importing, use the AJAX import tool which provides step-by-step import functionality:</p>
-            <a href="ajax_import_test.php" style="display: inline-block; padding: 10px 20px; background: #28a745; color: white; text-decoration: none; border-radius: 4px;">AJAX Import Tool</a>
-        </div>
-    </div>
-</body>
-</html>

+ 387 - 0
admin/wordpress_import_old.php

@@ -0,0 +1,387 @@
+<?php
+// Simplified WordPress import interface - bypass problematic components
+error_reporting(E_ALL);
+ini_set('display_errors', 0);
+ini_set('max_execution_time', 120);
+ini_set('memory_limit', '512M');
+
+// Start session for basic functionality
+if (session_status() === PHP_SESSION_NONE) {
+    session_start();
+}
+
+require_once '../includes/config.php';
+require_once '../includes/database.php';
+
+// Simple auth check - just check if user is logged in without complex auth system
+$isAdmin = false;
+if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && isset($_SESSION['role']) && $_SESSION['role'] === 'admin') {
+    $isAdmin = true;
+}
+
+// Redirect if not admin
+if (!$isAdmin) {
+    header('Location: login.php');
+    exit;
+}
+
+$message = '';
+$importResults = null;
+$connectionTest = null;
+
+// Handle form submission with simplified processing
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+    try {
+        // Get WordPress database configuration
+        $wpConfig = [
+            'host' => trim($_POST['wp_host'] ?? ''),
+            'database' => trim($_POST['wp_database'] ?? ''),
+            'username' => trim($_POST['wp_username'] ?? ''),
+            'password' => $_POST['wp_password'] ?? ''
+        ];
+        
+        // Validate required fields
+        if (empty($wpConfig['host']) || empty($wpConfig['database']) || empty($wpConfig['username'])) {
+            throw new Exception("WordPress database configuration is required. Please provide host, database, and username.");
+        }
+        
+        // Direct WordPress connection test (bypass WordPressImport class)
+        try {
+            // Set timeout options
+            $options = [
+                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+                PDO::ATTR_TIMEOUT => 10,
+                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
+            ];
+            
+            $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
+            $wpDb = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
+            
+            // Test connection
+            $wpDb->query("SELECT 1");
+            
+            if (isset($_POST['test_connection'])) {
+                // Get stats with direct queries
+                $stats = [];
+                try {
+                    $stats['posts'] = $wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
+                } catch (Exception $e) {
+                    $stats['posts'] = 0;
+                }
+                
+                try {
+                    $stats['categories'] = $wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
+                } catch (Exception $e) {
+                    $stats['categories'] = 0;
+                }
+                
+                try {
+                    $stats['users'] = $wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
+                } catch (Exception $e) {
+                    $stats['users'] = 0;
+                }
+                
+                try {
+                    $stats['comments'] = $wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
+                } catch (Exception $e) {
+                    $stats['comments'] = 0;
+                }
+                
+                $message = "WordPress connection successful: " . 
+                          "Posts: " . $stats['posts'] . ", " .
+                          "Categories: " . $stats['categories'] . ", " .
+                          "Users: " . $stats['users'] . ", " .
+                          "Comments: " . $stats['comments'];
+            }
+        } catch (Exception $e) {
+            throw new Exception("WordPress connection failed: " . $e->getMessage());
+        }
+        
+        if (isset($_POST['start_import'])) {
+            // For now, just show a message that import is not implemented in this simplified version
+            throw new Exception("Import functionality is temporarily disabled. Please use the AJAX import tool for importing data.");
+        }
+        
+    } catch (Exception $e) {
+        $message = $e->getMessage();
+    }
+}
+?>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>WordPress Import - <?php echo SITE_TITLE; ?></title>
+    <link rel="stylesheet" href="../css/style.css">
+    <link rel="stylesheet" href="../css/admin-import.css">
+</head>
+<body>
+    <div class="admin-layout">
+        <header class="admin-header">
+            <div class="header-content">
+                <h1><a href="/index.php"><?php echo SITE_TITLE; ?></a></h1>
+                <nav class="admin-nav">
+                    <a href="index.php" class="nav-link">Dashboard</a>
+                    <a href="publications.php" class="nav-link">Publications</a>
+                    <a href="categories.php" class="nav-link">Categories</a>
+                    <a href="comments.php" class="nav-link">Comments</a>
+                    <a href="users.php" class="nav-link">Users</a>
+                    <a href="wordpress_import.php" class="nav-link active">WordPress Import</a>
+                    <?php if (LDAP_ENABLED): ?>
+                        <a href="ldap-users.php" class="nav-link">LDAP Users</a>
+                    <?php endif; ?>
+                    <a href="logout.php" class="nav-link">Logout</a>
+                </nav>
+                <div class="user-info">
+                    Welcome, <?php echo htmlspecialchars($_SESSION['username'] ?? 'Admin'); ?>
+                </div>
+            </div>
+        </header>
+
+        <main class="admin-main">
+            <div class="page-header">
+                <h2>WordPress Import</h2>
+                <p class="page-description">Import WordPress data into your system.</p>
+                <p class="page-description">Import posts, categories, users, and comments from a WordPress database to your publication system.</p>
+            </div>
+            
+            <?php if ($message): ?>
+                <div class="alert alert-<?php echo strpos($message, 'Error') === false && strpos($message, 'failed') === false ? 'success' : 'error'; ?>">
+                    <?php echo $message; ?>
+                </div>
+            <?php endif; ?>
+
+            <!-- Import Form -->
+            <div class="import-form-container">
+                <form method="post" class="import-form">
+                    <div class="form-section">
+                        <h3>WordPress Database Configuration</h3>
+                        
+                        <div class="form-row">
+                            <div class="form-group">
+                                <label for="wp_host">Database Host *</label>
+                                <input type="text" id="wp_host" name="wp_host" 
+                                       value="<?php echo htmlspecialchars($_POST['wp_host'] ?? 'localhost'); ?>" 
+                                       placeholder="localhost" required>
+                            </div>
+                            
+                            <div class="form-group">
+                                <label for="wp_database">Database Name *</label>
+                                <input type="text" id="wp_database" name="wp_database" 
+                                       value="<?php echo htmlspecialchars($_POST['wp_database'] ?? ''); ?>" 
+                                       placeholder="wordpress_database" required>
+                            </div>
+                        </div>
+                        
+                        <div class="form-row">
+                            <div class="form-group">
+                                <label for="wp_username">Database Username *</label>
+                                <input type="text" id="wp_username" name="wp_username" 
+                                       value="<?php echo htmlspecialchars($_POST['wp_username'] ?? ''); ?>" 
+                                       placeholder="wp_username" required>
+                            </div>
+                            
+                            <div class="form-group">
+                                <label for="wp_password">Database Password</label>
+                                <input type="password" id="wp_password" name="wp_password" 
+                                       value="<?php echo htmlspecialchars($_POST['wp_password'] ?? ''); ?>" 
+                                       placeholder="Leave empty if no password">
+                            </div>
+                        </div>
+                    </div>
+                    
+                    <div class="form-section">
+                        <h3>Import Options</h3>
+                        
+                        <div class="form-row">
+                            <div class="form-group">
+                                <label class="checkbox-label">
+                                    <input type="checkbox" name="import_categories" checked>
+                                    Import Categories
+                                </label>
+                            </div>
+                            
+                            <div class="form-group">
+                                <label class="checkbox-label">
+                                    <input type="checkbox" name="import_users" checked>
+                                    Import Users
+                                </label>
+                            </div>
+                        </div>
+                        
+                        <div class="form-row">
+                            <div class="form-group">
+                                <label class="checkbox-label">
+                                    <input type="checkbox" name="import_posts" checked>
+                                    Import Posts
+                                </label>
+                            </div>
+                            
+                            <div class="form-group">
+                                <label class="checkbox-label">
+                                    <input type="checkbox" name="import_comments" checked>
+                                    Import Comments
+                                </label>
+                            </div>
+                        </div>
+                    </div>
+                    
+                    <div class="form-actions">
+                        <button type="submit" name="test_connection" class="btn btn-primary">
+                            Test Connection
+                        </button>
+                        <button type="submit" name="start_import" class="btn btn-success" 
+                                onclick="return confirm('Are you sure you want to start the import? This will import data from WordPress into your system.')">
+                            Start Import
+                        </button>
+                    </div>
+                </form>
+            </div>
+
+            <!-- Import Results -->
+            <?php if ($importResults): ?>
+                <div class="import-results">
+                    <h3>Import Results</h3>
+                    
+                    <?php if ($importResults['success']): ?>
+                        <div class="success-summary">
+                            <p class="success-message">WordPress import completed successfully!</p>
+                        </div>
+                        
+                        <div class="results-details">
+                            <?php foreach ($importResults['results'] as $type => $result): ?>
+                                <div class="result-item">
+                                    <h4><?php echo ucfirst($type); ?></h4>
+                                    <div class="result-stats">
+                                        <span class="stat success">
+                                            Imported: <strong><?php echo $result['imported']; ?></strong>
+                                        </span>
+                                        <span class="stat warning">
+                                            Skipped: <strong><?php echo $result['skipped']; ?></strong>
+                                        </span>
+                                    </div>
+                                </div>
+                            <?php endforeach; ?>
+                        </div>
+                        
+                        <?php if (!empty($importResults['log'])): ?>
+                            <div class="import-log">
+                                <h4>Import Log</h4>
+                                <div class="log-container">
+                                    <?php foreach ($importResults['log'] as $logEntry): ?>
+                                        <div class="log-entry log-<?php echo $logEntry['level']; ?>">
+                                            <span class="log-time"><?php echo $logEntry['timestamp']; ?></span>
+                                            <span class="log-message"><?php echo htmlspecialchars($logEntry['message']); ?></span>
+                                        </div>
+                                    <?php endforeach; ?>
+                                </div>
+                            </div>
+                        <?php endif; ?>
+                        
+                        <?php if (!empty($importResults['errors'])): ?>
+                            <div class="import-errors">
+                                <h4>Import Errors</h4>
+                                <div class="error-list">
+                                    <?php foreach ($importResults['errors'] as $error): ?>
+                                        <div class="error-item">
+                                            <?php echo htmlspecialchars($error); ?>
+                                        </div>
+                                    <?php endforeach; ?>
+                                </div>
+                            </div>
+                        <?php endif; ?>
+                        
+                    <?php else: ?>
+                        <div class="error-summary">
+                            <p class="error-message"><?php echo htmlspecialchars($importResults['error']); ?></p>
+                        </div>
+                    <?php endif; ?>
+                </div>
+            <?php endif; ?>
+
+            <!-- Information Section -->
+            <div class="info-section">
+                <h3>WordPress Import Information</h3>
+                <div class="info-content">
+                    <div class="info-item">
+                        <h4>What Gets Imported</h4>
+                        <ul>
+                            <li>Posts (title, content, author, publication date)</li>
+                            <li>Categories (name and description)</li>
+                            <li>Users (username, email, display name)</li>
+                            <li>Comments (content, author, date, threading)</li>
+                        </ul>
+                    </div>
+                    
+                    <div class="info-item">
+                        <h4>Requirements</h4>
+                        <ul>
+                            <li>Database access to WordPress database</li>
+                            <li>WordPress database with standard structure</li>
+                            <li>Backup of your current data (recommended)</li>
+                        </ul>
+                    </div>
+                    
+                    <div class="info-item">
+                        <h4>Important Notes</h4>
+                        <ul>
+                            <li>Existing data with same identifiers will be skipped</li>
+                            <li>WordPress content is processed for compatibility</li>
+                            <li>WordPress users are mapped to your user system</li>
+                        </ul>
+                    </div>
+                </div>
+            </div>
+        </main>
+    </div>
+
+    <script>
+        // WordPress Import JavaScript
+        document.addEventListener('DOMContentLoaded', function() {
+            const form = document.querySelector('.import-form');
+            const testBtn = document.querySelector('button[name="test_connection"]');
+            const importBtn = document.querySelector('button[name="start_import"]');
+            
+            // Show loading state
+            function setLoading(button, loading) {
+                if (loading) {
+                    button.disabled = true;
+                    button.dataset.originalText = button.textContent;
+                    button.textContent = button.dataset.loadingText || 'Loading...';
+                } else {
+                    button.disabled = false;
+                    button.textContent = button.dataset.originalText;
+                }
+            }
+            
+            // Test connection loading
+            testBtn.addEventListener('click', function() {
+                setLoading(this, true);
+                this.dataset.loadingText = 'Testing connection...';
+            });
+            
+            // Import loading
+            importBtn.addEventListener('click', function() {
+                setLoading(this, true);
+                this.dataset.loadingText = 'Importing...';
+            });
+            
+            // Reset loading on form submit
+            form.addEventListener('submit', function() {
+                setTimeout(() => {
+                    setLoading(testBtn, false);
+                    setLoading(importBtn, false);
+                }, 1000);
+            });
+            
+            // Auto-focus first empty field
+            const firstEmpty = form.querySelector('input[value=""], input:not([value])');
+            if (firstEmpty) {
+                firstEmpty.focus();
+            }
+        });
+    </script>
+</body>
+</html>