| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?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(t('wordpress_import_config_required'));
- }
-
- // 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 = t('wordpress_connection_success') . ': ' .
- t('posts') . ': ' . $stats['posts'] . ', ' .
- t('categories') . ': ' . $stats['categories'] . ', ' .
- t('users') . ': ' . $stats['users'] . ', ' .
- t('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><?php echo t('wordpress_import_info'); ?></h3>
- <div class="info-content">
- <div class="info-item">
- <h4><?php echo t('what_gets_imported'); ?></h4>
- <ul>
- <li><?php echo t('import_posts_info'); ?></li>
- <li><?php echo t('import_categories_info'); ?></li>
- <li><?php echo t('import_users_info'); ?></li>
- <li><?php echo t('import_comments_info'); ?></li>
- </ul>
- </div>
-
- <div class="info-item">
- <h4><?php echo t('import_requirements'); ?></h4>
- <ul>
- <li><?php echo t('import_db_access'); ?></li>
- <li><?php echo t('import_wp_structure'); ?></li>
- <li><?php echo t('import_backup'); ?></li>
- </ul>
- </div>
-
- <div class="info-item">
- <h4><?php echo t('import_notes'); ?></h4>
- <ul>
- <li><?php echo t('import_existing_data'); ?></li>
- <li><?php echo t('import_content_processing'); ?></li>
- <li><?php echo t('import_user_mapping'); ?></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 || '<?php echo t('loading'); ?>...';
- } else {
- button.disabled = false;
- button.textContent = button.dataset.originalText;
- }
- }
-
- // Test connection loading
- testBtn.addEventListener('click', function() {
- setLoading(this, true);
- this.dataset.loadingText = '<?php echo t('testing_connection'); ?>';
- });
-
- // Import loading
- importBtn.addEventListener('click', function() {
- setLoading(this, true);
- this.dataset.loadingText = '<?php echo t('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>
|