isLoggedIn()) { header('Location: index.html'); exit; } $currentUser = $userManager->getCurrentUser(); // Initialize storage manager for GitHub file access $storageManager = new StorageManager(); // Get the editor HTML $html = file_get_contents('editor.html'); // Get user files from GitHub storage $files = ''; $userFiles = []; try { $githubFiles = $storageManager->listFiles(); // Add user files from GitHub foreach ($githubFiles as $file) { if (in_array($file['name'], array('new-page-blank-template.html', 'editor.html'))) continue; $pathInfo = pathinfo($file['name']); $filename = $pathInfo['filename']; $folder = 'My Files (GitHub)'; $url = $file['path']; $name = $filename; $title = ucfirst($name); $files .= '
  • '; $files .= ''; $files .= '
    ' . htmlspecialchars($title) . '
    '; $files .= ''; $files .= '
  • '; $userFiles[] = [ 'filename' => $url, 'title' => $title, 'folder' => $folder ]; } } catch (Exception $e) { error_log("Editor: Error loading GitHub files: " . $e->getMessage()); } // Fallback: check local user files as backup $localUserDir = "user-files/$currentUser"; if (is_dir($localUserDir)) { $localFiles = glob("$localUserDir/*.html"); foreach ($localFiles as $file) { if (in_array(basename($file), array('new-page-blank-template.html', 'editor.html'))) continue; $pathInfo = pathinfo($file); $filename = $pathInfo['filename']; $folder = 'Local Files'; $url = str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $file); $url = str_replace('\\', '/', $url); $name = $filename; $title = ucfirst($name); $files .= '
  • '; $files .= ''; $files .= '
    ' . htmlspecialchars($title) . '
    '; $files .= ''; $files .= '
  • '; $userFiles[] = [ 'filename' => $url, 'title' => $title, 'folder' => $folder ]; } } // Also include demo files for reference $demoFiles = array_merge(glob('demo/*/*.html'), glob('demo/*.html')); foreach ($demoFiles as $file) { if (in_array(basename($file), array('new-page-blank-template.html', 'editor.html'))) continue; $pathInfo = pathinfo($file); $filename = $pathInfo['filename']; $folder = ucfirst(basename(dirname($file))); $url = $file; $name = $filename; $title = ucfirst($name); $files .= '
  • '; $files .= ''; $files .= '
    ' . htmlspecialchars($title) . '
    '; $files .= ''; $files .= '
  • '; } // Add user info and file list to the HTML $userInfo = '
    '; $userInfo .= '当前用户: ' . htmlspecialchars($currentUser); $userInfo .= '
    存储: ' . StorageConfig::getStorageType(); $userInfo .= '
    GitHub文件: ' . count($githubFiles ?? []) . ' 个'; if (isset($localFiles)) { $userInfo .= '
    本地缓存: ' . count($localFiles) . ' 个'; } $userInfo .= '
    '; // Inject JavaScript for file management $fileManagementScript = ' '; // Insert user info and files into the HTML $html = str_replace('', $files, $html); $html = str_replace('', $fileManagementScript . '', $html); $html = str_replace('
    ', '
    ' . $userInfo, $html); echo $html; ?>