[ 'password' => password_hash('Nbc1Abc2!', PASSWORD_DEFAULT), 'title' => '', 'description' => '', 'ascii_art' => '' ] ]; file_put_contents($file, json_encode($users)); return $users; } return json_decode(file_get_contents($file), true); } function saveUsers($users) { file_put_contents(DATA_DIR . 'users.json', json_encode($users)); } function getInvites() { $file = DATA_DIR . 'invites.json'; if (!file_exists($file)) return []; return json_decode(file_get_contents($file), true); } function saveInvites($invites) { file_put_contents(DATA_DIR . 'invites.json', json_encode($invites)); } function imageToAscii($filePath, $width = 80) { $ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION)); if ($ext == 'jpg' || $ext == 'jpeg') { $im = imagecreatefromjpeg($filePath); } elseif ($ext == 'png') { $im = imagecreatefrompng($filePath); } elseif ($ext == 'gif') { $im = imagecreatefromgif($filePath); } else { return 'Unsupported image format'; } $origWidth = imagesx($im); $origHeight = imagesy($im); $height = (int) (($origHeight / $origWidth) * $width); $im = imagescale($im, $width, $height); $chars = '@%#*+=-:. '; // Dark to light $ascii = ''; for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { $rgb = imagecolorat($im, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $gray = (int) (($r + $g + $b) / 3); $index = (int) (9 - ($gray / 28.3)); // 255/9 ≈ 28.3 $ascii .= $chars[$index]; } $ascii .= "\n"; } imagedestroy($im); unlink($filePath); // Delete original image return $ascii; } function listDirectory($dir, $baseUser, $currentPath = '') { $result = ''; $files = scandir($dir); foreach ($files as $file) { if ($file != '.' && $file != '..') { $ext = pathinfo($file, PATHINFO_EXTENSION); if ($ext === 'json') continue; // Skip JSON files $relPath = $currentPath . $file; if (is_dir($dir . '/' . $file)) { $result .= '
  • ' . htmlspecialchars($file) . '/'; if (isset($_SESSION['user']) && $_SESSION['user'] != $baseUser && $currentPath == '') { // Fork only top-level projects $result .= '
    '; } $result .= '
  • '; } else { $result .= '
  • ' . htmlspecialchars($file) . ' View
  • '; } } } return ''; } function copyDir($src, $dst) { if (!file_exists($dst)) mkdir($dst, 0777, true); $dir = opendir($src); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($src . '/' . $file)) { copyDir($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); } ?>