| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <?php
- // Start session for language preference
- if (session_status() === PHP_SESSION_NONE) {
- session_start();
- }
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/auth.php';
- require_once '../includes/wordpress_import.php';
- require_once '../includes/translation.php';
- // Translation system is auto-initialized when translation.php is included
- $auth = new Auth();
- $auth->requireAuth();
- $user = $auth->getUser();
- $message = '';
- $importResults = null;
- $connectionTest = null;
- // Handle form submission
- 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'));
- }
-
- // Create import instance
- $importer = new WordPressImport($wpConfig);
-
- if (isset($_POST['test_connection'])) {
- // Test connection only
- $connectionTest = $importer->testConnection();
- if ($connectionTest['success']) {
- $message = t('wordpress_connection_success') . ': ' .
- t('posts') . ': ' . $connectionTest['stats']['posts'] . ', ' .
- t('categories') . ': ' . $connectionTest['stats']['categories'] . ', ' .
- t('users') . ': ' . $connectionTest['stats']['users'] . ', ' .
- t('comments') . ': ' . $connectionTest['stats']['comments'];
- } else {
- throw new Exception($connectionTest['error']);
- }
- } elseif (isset($_POST['start_import'])) {
- // Start import
- $importOptions = [
- 'import_categories' => isset($_POST['import_categories']),
- 'import_users' => isset($_POST['import_users']),
- 'import_posts' => isset($_POST['import_posts']),
- 'import_comments' => isset($_POST['import_comments'])
- ];
-
- $importResults = $importer->importAll($importOptions);
-
- if ($importResults['success']) {
- $message = t('wordpress_import_success');
- } else {
- throw new Exception($importResults['error']);
- }
- }
-
- } catch (Exception $e) {
- $message = $e->getMessage();
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="<?php echo Translation::getCurrentLang(); ?>">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title><?php echo t('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"><?php echo t('admin_nav_dashboard'); ?></a>
- <a href="publications.php" class="nav-link"><?php echo t('admin_nav_publications'); ?></a>
- <a href="categories.php" class="nav-link"><?php echo t('admin_nav_categories'); ?></a>
- <a href="comments.php" class="nav-link"><?php echo t('admin_nav_comments'); ?></a>
- <a href="users.php" class="nav-link"><?php echo t('manage_users'); ?></a>
- <a href="wordpress_import.php" class="nav-link active"><?php echo t('wordpress_import'); ?></a>
- <?php if (LDAP_ENABLED): ?>
- <a href="ldap-users.php" class="nav-link"><?php echo t('admin_nav_ldap_users'); ?></a>
- <?php endif; ?>
- <a href="logout.php" class="nav-link"><?php echo t('admin_nav_logout'); ?></a>
- </nav>
- <div class="user-info">
- <?php echo t('welcome'); ?>, <?php echo htmlspecialchars($user['username']); ?>
- </div>
- <?php echo Translation::getLanguageSwitcher('wordpress_import.php'); ?>
- </div>
- </header>
- <main class="admin-main">
- <div class="page-header">
- <h2><?php echo t('wordpress_import'); ?></h2>
- <p class="page-description"><?php echo t('wordpress_import_description'); ?></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><?php echo t('wordpress_database_config'); ?></h3>
-
- <div class="form-row">
- <div class="form-group">
- <label for="wp_host"><?php echo t('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"><?php echo t('database_name'); ?> *</label>
- <input type="text" id="wp_database" name="wp_database"
- value="<?php echo htmlspecialchars($_POST['wp_database'] ?? ''); ?>"
- placeholder="wordpress" required>
- </div>
- </div>
-
- <div class="form-row">
- <div class="form-group">
- <label for="wp_username"><?php echo t('database_username'); ?> *</label>
- <input type="text" id="wp_username" name="wp_username"
- value="<?php echo htmlspecialchars($_POST['wp_username'] ?? ''); ?>"
- placeholder="wp_user" required>
- </div>
-
- <div class="form-group">
- <label for="wp_password"><?php echo t('database_password'); ?></label>
- <input type="password" id="wp_password" name="wp_password"
- placeholder="<?php echo t('database_password_placeholder'); ?>">
- </div>
- </div>
- </div>
-
- <div class="form-section">
- <h3><?php echo t('import_options'); ?></h3>
-
- <div class="checkbox-group">
- <label class="checkbox-label">
- <input type="checkbox" name="import_categories" checked>
- <span class="checkmark"></span>
- <?php echo t('import_categories'); ?>
- </label>
-
- <label class="checkbox-label">
- <input type="checkbox" name="import_users" checked>
- <span class="checkmark"></span>
- <?php echo t('import_users'); ?>
- </label>
-
- <label class="checkbox-label">
- <input type="checkbox" name="import_posts" checked>
- <span class="checkmark"></span>
- <?php echo t('import_posts'); ?>
- </label>
-
- <label class="checkbox-label">
- <input type="checkbox" name="import_comments" checked>
- <span class="checkmark"></span>
- <?php echo t('import_comments'); ?>
- </label>
- </div>
- </div>
-
- <div class="form-actions">
- <button type="submit" name="test_connection" class="btn btn-secondary">
- <?php echo t('test_connection'); ?>
- </button>
- <button type="submit" name="start_import" class="btn btn-primary"
- onclick="return confirm('<?php echo t('wordpress_import_confirm'); ?>')">
- <?php echo t('start_import'); ?>
- </button>
- </div>
- </form>
- </div>
- <!-- Import Results -->
- <?php if ($importResults): ?>
- <div class="import-results">
- <h3><?php echo t('import_results'); ?></h3>
-
- <?php if ($importResults['success']): ?>
- <div class="success-summary">
- <p class="success-message"><?php echo t('wordpress_import_success'); ?></p>
- </div>
-
- <div class="results-details">
- <?php foreach ($importResults['results'] as $type => $result): ?>
- <div class="result-item">
- <h4><?php echo t('import_' . $type); ?></h4>
- <div class="result-stats">
- <span class="stat success">
- <?php echo t('imported'); ?>: <strong><?php echo $result['imported']; ?></strong>
- </span>
- <span class="stat warning">
- <?php echo t('skipped'); ?>: <strong><?php echo $result['skipped']; ?></strong>
- </span>
- </div>
- </div>
- <?php endforeach; ?>
- </div>
-
- <?php if (!empty($importResults['log'])): ?>
- <div class="import-log">
- <h4><?php echo t('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><?php echo t('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>
|