Download editor.php from CatPtain/VvvebJs: direct link, hf CLI and curl.
- Browser
- Download file 6.93 kB
-
https://huggingface.co/spaces/CatPtain/VvvebJs/resolve/main/editor.php
- Command line
-
hf download hf://spaces/CatPtain/VvvebJs/editor.php
-
curl -L -o editor.php https://huggingface.co/spaces/CatPtain/VvvebJs/resolve/main/editor.php
6.93 kB
| require_once 'user-manager.php'; | |
| require_once 'storage.php'; | |
| // Initialize user manager and require login | |
| $userManager = new UserManager(); | |
| if (!$userManager->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 .= '<li class="file" data-url="' . htmlspecialchars($url) . '" data-folder="' . htmlspecialchars($folder) . '">'; | |
| $files .= '<label class="folder-name">' . htmlspecialchars($folder) . '</label>'; | |
| $files .= '<div class="file-name"><span>' . htmlspecialchars($title) . '</span> <div class="file-actions">'; | |
| $files .= '<button class="btn btn-sm btn-light load-file-btn" data-file="' . htmlspecialchars($url) . '">Load</button>'; | |
| $files .= '</div></div></li>'; | |
| $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 .= '<li class="file" data-url="' . htmlspecialchars($url) . '" data-folder="' . htmlspecialchars($folder) . '">'; | |
| $files .= '<label class="folder-name">' . htmlspecialchars($folder) . '</label>'; | |
| $files .= '<div class="file-name"><span>' . htmlspecialchars($title) . '</span> <div class="file-actions">'; | |
| $files .= '<button class="btn btn-sm btn-light load-file-btn" data-file="' . htmlspecialchars($url) . '">Load</button>'; | |
| $files .= '</div></div></li>'; | |
| $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 .= '<li class="file" data-url="' . htmlspecialchars($url) . '" data-folder="' . htmlspecialchars($folder) . '">'; | |
| $files .= '<label class="folder-name">' . htmlspecialchars($folder) . ' (Demo)</label>'; | |
| $files .= '<div class="file-name"><span>' . htmlspecialchars($title) . '</span> <div class="file-actions">'; | |
| $files .= '<button class="btn btn-sm btn-light load-file-btn" data-file="' . htmlspecialchars($url) . '">Load</button>'; | |
| $files .= '</div></div></li>'; | |
| } | |
| // Add user info and file list to the HTML | |
| $userInfo = '<div class="user-info alert alert-info">'; | |
| $userInfo .= '<strong>当前用户:</strong> ' . htmlspecialchars($currentUser); | |
| $userInfo .= '<br><strong>存储:</strong> ' . StorageConfig::getStorageType(); | |
| $userInfo .= '<br><strong>GitHub文件:</strong> ' . count($githubFiles ?? []) . ' 个'; | |
| if (isset($localFiles)) { | |
| $userInfo .= '<br><strong>本地缓存:</strong> ' . count($localFiles) . ' 个'; | |
| } | |
| $userInfo .= '</div>'; | |
| // Inject JavaScript for file management | |
| $fileManagementScript = ' | |
| <script> | |
| window.vvvebUserFiles = ' . json_encode($userFiles) . '; | |
| window.vvvebCurrentUser = "' . htmlspecialchars($currentUser) . '"; | |
| // Enhanced file loading with GitHub support | |
| function loadFileFromGitHub(filename) { | |
| console.log("Loading file from GitHub:", filename); | |
| fetch("save.php?action=loadFile&file=" + encodeURIComponent(filename)) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.success) { | |
| Vvveb.Builder.loadHtml(data.content); | |
| console.log("File loaded successfully from GitHub"); | |
| // Update current file reference | |
| window.currentFile = filename; | |
| // Update page title if available | |
| const titleMatch = data.content.match(/<title>(.*?)<\/title>/i); | |
| if (titleMatch) { | |
| const titleInput = document.querySelector("input[name=title]"); | |
| if (titleInput) titleInput.value = titleMatch[1]; | |
| } | |
| } else { | |
| alert("Error loading file: " + (data.message || "Unknown error")); | |
| } | |
| }) | |
| .catch(error => { | |
| console.error("Error loading file:", error); | |
| alert("Error loading file from GitHub"); | |
| }); | |
| } | |
| // Override the existing file loading | |
| document.addEventListener("DOMContentLoaded", function() { | |
| // Add enhanced file loading for GitHub files | |
| document.querySelectorAll(".load-file-btn").forEach(btn => { | |
| btn.addEventListener("click", function() { | |
| const filename = this.getAttribute("data-file"); | |
| loadFileFromGitHub(filename); | |
| }); | |
| }); | |
| // Add refresh button for file list | |
| const refreshBtn = document.createElement("button"); | |
| refreshBtn.className = "btn btn-sm btn-secondary"; | |
| refreshBtn.innerHTML = "🔄 刷新文件列表"; | |
| refreshBtn.onclick = function() { | |
| location.reload(); | |
| }; | |
| const fileManager = document.querySelector("#filemanager .file-manager-header"); | |
| if (fileManager) { | |
| fileManager.appendChild(refreshBtn); | |
| } | |
| }); | |
| </script>'; | |
| // Insert user info and files into the HTML | |
| $html = str_replace('<!--files-li-->', $files, $html); | |
| $html = str_replace('</head>', $fileManagementScript . '</head>', $html); | |
| $html = str_replace('<div id="filemanager">', '<div id="filemanager">' . $userInfo, $html); | |
| echo $html; | |