= h(paste_preview((string) $item['body'])) ?>
'Text', 'html' => 'HTML', 'css' => 'CSS', 'javascript' => 'JavaScript', 'php' => 'PHP', 'python' => 'Python', 'powershell' => 'PowerShell', 'markdown' => 'Markdown', 'json' => 'JSON', 'sql' => 'SQL', ]; } function language_label(string $language): string { $options = language_options(); return $options[$language] ?? ucfirst($language); } function normalize_tags(string $value): array { $rawTags = preg_split('/\s*,\s*/', $value) ?: []; $tags = []; foreach ($rawTags as $tag) { $tag = strtolower(trim($tag)); $tag = ltrim($tag, '#'); $tag = preg_replace('/[^a-z0-9_-]+/', '-', $tag) ?? ''; $tag = trim($tag, '-_'); if ($tag !== '' && !in_array($tag, $tags, true)) { $tags[] = mb_substr($tag, 0, 40, 'UTF-8'); } } return array_slice($tags, 0, 20); } function paste_tags(array $data): array { $rawTags = $data['tags'] ?? []; if (is_string($rawTags)) { return normalize_tags($rawTags); } if (!is_array($rawTags)) { return []; } return normalize_tags(implode(',', array_map('strval', $rawTags))); } function all_pastes(string $pasteDir): array { $items = []; $files = glob($pasteDir . DIRECTORY_SEPARATOR . '*.json') ?: []; foreach ($files as $file) { $data = json_decode((string) file_get_contents($file), true); if (!is_array($data) || empty($data['id']) || !valid_id((string) $data['id'])) { continue; } $created = strtotime((string) ($data['created_at'] ?? '')) ?: filemtime($file); $body = (string) ($data['body'] ?? ''); $items[] = [ 'id' => (string) $data['id'], 'title' => (string) ($data['title'] ?? 'Untitled paste'), 'language' => strtolower((string) ($data['language'] ?? 'text')), 'tags' => paste_tags($data), 'body' => $body, 'created_at' => gmdate('c', $created), 'created_ts' => $created, 'bytes' => (int) ($data['bytes'] ?? strlen($body)), ]; } return $items; } function clamp_choice(string $value, array $allowed, string $fallback): string { return in_array($value, $allowed, true) ? $value : $fallback; } function current_url_with(array $changes): string { $query = $_GET; foreach ($changes as $key => $value) { if ($value === null || $value === '') { unset($query[$key]); } else { $query[$key] = (string) $value; } } $qs = http_build_query($query); return '/list' . ($qs === '' ? '' : '?' . $qs); } function paste_preview(string $body, int $limit = 260): string { $text = trim(preg_replace('/\s+/', ' ', $body) ?? ''); if (mb_strlen($text, 'UTF-8') <= $limit) { return $text; } return mb_substr($text, 0, $limit - 3, 'UTF-8') . '...'; } $error = ''; $createdUrl = ''; $paste = null; $pasteId = ''; $isList = false; $listPastes = []; $filteredPastes = []; $pagePastes = []; $typeCounts = []; $tagCounts = []; $selectedType = ''; $selectedTag = ''; $selectedSort = 'newest'; $selectedView = 'detailed'; $perPage = 10; $page = 1; $totalPages = 1; $totalPastes = 0; $path = parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/'; if (preg_match('#^/raw/([a-f0-9]{10})/?$#', $path, $matches)) { $paste = load_paste($matches[1]); if ($paste === null) { http_response_code(404); header('Content-Type: text/plain; charset=utf-8'); echo 'Paste not found.'; exit; } header('Content-Type: text/plain; charset=utf-8'); header('X-Content-Type-Options: nosniff'); echo (string) $paste['body']; exit; } if (preg_match('#^/p/([a-f0-9]{10})/?$#', $path, $matches)) { $pasteId = $matches[1]; } if ($path === '/list' || $path === '/list/') { $isList = true; } if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$isList) { $title = trim((string) ($_POST['title'] ?? '')); $language = trim((string) ($_POST['language'] ?? 'text')); $tags = normalize_tags((string) ($_POST['tags'] ?? '')); $body = (string) ($_POST['body'] ?? ''); if ($title === '') { $error = 'Add a title first.'; } elseif ($body === '') { $error = 'Paste something first.'; } elseif (strlen($body) > $maxBytes) { $error = 'That paste is too large. Keep it under 512 KB for now.'; } else { do { $pasteId = slug(); $path = paste_path($pasteId); } while (is_file($path)); $record = [ 'id' => $pasteId, 'title' => mb_substr($title, 0, 120, 'UTF-8'), 'language' => mb_substr($language, 0, 40, 'UTF-8'), 'tags' => $tags, 'body' => $body, 'created_at' => gmdate('c'), 'bytes' => strlen($body), ]; file_put_contents( $path, json_encode($record, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), LOCK_EX ); $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST'] ?? 'scriptjerk.online'; $createdUrl = $scheme . '://' . $host . '/p/' . $pasteId; $paste = $record; } } elseif (!$isList) { if ($pasteId === '') { $pasteId = (string) ($_GET['p'] ?? ''); } if ($pasteId !== '') { $paste = load_paste($pasteId); if ($paste === null) { http_response_code(404); $error = 'Paste not found.'; } } } if ($isList) { $listPastes = all_pastes($storageDir); foreach ($listPastes as $item) { $type = (string) $item['language']; $typeCounts[$type] = ($typeCounts[$type] ?? 0) + 1; foreach ($item['tags'] as $tag) { $tagCounts[$tag] = ($tagCounts[$tag] ?? 0) + 1; } } ksort($typeCounts); ksort($tagCounts); $selectedType = strtolower(trim((string) ($_GET['type'] ?? ''))); $selectedTag = strtolower(trim((string) ($_GET['tag'] ?? ''))); $selectedTag = ltrim($selectedTag, '#'); $selectedSort = clamp_choice((string) ($_GET['sort'] ?? 'newest'), ['newest', 'oldest', 'title', 'type', 'tag'], 'newest'); $selectedView = clamp_choice((string) ($_GET['view'] ?? 'detailed'), ['detailed', 'simple', 'preview'], 'detailed'); $perPage = (int) ($_GET['per_page'] ?? 10); if (!in_array($perPage, [10, 25, 50, 100], true)) { $perPage = 10; } $filteredPastes = array_values(array_filter($listPastes, static function (array $item) use ($selectedType, $selectedTag): bool { $typeMatches = $selectedType === '' || $item['language'] === $selectedType; $tagMatches = $selectedTag === '' || in_array($selectedTag, $item['tags'], true); return $typeMatches && $tagMatches; })); usort($filteredPastes, static function (array $a, array $b) use ($selectedSort): int { if ($selectedSort === 'oldest') { return $a['created_ts'] <=> $b['created_ts']; } if ($selectedSort === 'title') { return strcasecmp((string) $a['title'], (string) $b['title']); } if ($selectedSort === 'type') { return strcasecmp((string) $a['language'], (string) $b['language']) ?: ($b['created_ts'] <=> $a['created_ts']); } if ($selectedSort === 'tag') { return strcasecmp((string) ($a['tags'][0] ?? ''), (string) ($b['tags'][0] ?? '')) ?: ($b['created_ts'] <=> $a['created_ts']); } return $b['created_ts'] <=> $a['created_ts']; }); $totalPastes = count($filteredPastes); $totalPages = max(1, (int) ceil($totalPastes / $perPage)); $page = max(1, min((int) ($_GET['page'] ?? 1), $totalPages)); $offset = ($page - 1) * $perPage; $pagePastes = array_slice($filteredPastes, $offset, $perPage); } $pageTitle = $isList ? 'All Pastes | ScriptJerk Online' : ($paste ? ($paste['title'] . ' | ScriptJerk Online') : 'ScriptJerk Online | Copy Paste Pages'); ?>
Drop text here, create a clean reference link, and come back to it later. Simple on purpose: no account wall, no database ceremony, no dashboard maze.
= h(paste_preview((string) $item['body'])) ?>
= h((string) $paste['body']) ?>