Invalid user.

'; } else { $users = getUsers(); echo '

' . htmlspecialchars($user) . '\'s Profile

'; echo '

Title: ' . htmlspecialchars($users[$user]['title']) . '

'; echo '

Description: ' . htmlspecialchars($users[$user]['description']) . '

'; echo '
' . htmlspecialchars($users[$user]['ascii_art']) . '
'; echo '

Repositories

'; $userDir = USERS_DIR . $user . '/' . $path; if (file_exists($userDir)) { // If path is a top-level project (ends with / and no further /), show download button if (substr_count($path, '/') == 1 && substr($path, -1) == '/') { $project = trim($path, '/'); echo '

'; } echo listDirectory($userDir, $user, $path); } else { echo '

No repositories.

'; } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'fork' && isset($_SESSION['user']) && $_SESSION['user'] != $user) { $project = $_POST['project']; $new_name = $_POST['new_name']; $srcDir = USERS_DIR . $user . '/' . $project; $dstDir = USERS_DIR . $_SESSION['user'] . '/' . $new_name; if (file_exists($srcDir) && !file_exists($dstDir)) { copyDir($srcDir, $dstDir); echo '

Project forked successfully as ' . htmlspecialchars($new_name) . '.

'; } else { echo '

Error forking project: Destination exists or source missing.

'; } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'edit' && isset($_SESSION['user']) && $_SESSION['user'] == $user) { $file = USERS_DIR . $user . '/' . $_POST['file']; if (strpos(realpath($file), realpath(USERS_DIR . $user)) === 0 && pathinfo($file, PATHINFO_EXTENSION) == 'txt') { $content = $_POST['content']; $language = $_POST['language'] ?? ''; file_put_contents($file, $content); $jsonFile = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.json'; if ($language) { file_put_contents($jsonFile, json_encode(['language' => $language])); } else if (file_exists($jsonFile)) { unlink($jsonFile); // Remove metadata if language is empty } echo '

File updated successfully.

'; } else { echo '

Invalid file or permission denied.

'; } } if (isset($_GET['file'])) { $file = USERS_DIR . $user . '/' . $_GET['file']; if (strpos(realpath($file), realpath(USERS_DIR . $user)) === 0) { // Security check $content = file_get_contents($file); $ext = pathinfo($file, PATHINFO_EXTENSION); if ($ext == 'txt' || $ext == 'json') { echo '

Viewing: ' . htmlspecialchars(basename($file)) . '

'; if ($ext == 'txt') { $fileId = 'source-' . md5($file); // Unique ID for JavaScript echo ' '; echo ''; if (isset($_SESSION['user']) && $_SESSION['user'] == $user) { // Load current language metadata $jsonFile = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.json'; $language = ''; if (file_exists($jsonFile)) { $meta = json_decode(file_get_contents($jsonFile), true); $language = $meta['language'] ?? ''; } // Edit form echo '
'; echo ''; echo ''; echo '
'; echo '
'; echo ''; echo '
'; } echo '
' . htmlspecialchars($content) . '
'; echo ' '; echo ''; // Check for language metadata $jsonFile = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.json'; if (file_exists($jsonFile)) { $meta = json_decode(file_get_contents($jsonFile), true); echo '

Language: ' . htmlspecialchars($meta['language'] ?? 'None') . '

'; } } else { echo '
' . htmlspecialchars($content) . '
'; } } } } } ?>