2100) { $filterYear = 0; } if ($filterMonth < 1 || $filterMonth > 12) { $filterMonth = 0; } if ($filterSince < 0 || $filterSince > time()) { $filterSince = 0; } $allPosts = get_all_posts_meta(true); usort($allPosts, function (array $a, array $b): int { $order = ['draft' => 0, 'scheduled' => 1, 'published' => 2]; $aOrder = $order[$a['status'] ?? 'draft'] ?? 0; $bOrder = $order[$b['status'] ?? 'draft'] ?? 0; if ($aOrder !== $bOrder) { return $aOrder <=> $bOrder; } // Scheduled: soonest first so you see what's coming up next if (($a['status'] ?? '') === 'scheduled') { return ($a['timestamp'] <=> $b['timestamp']); } return ($b['timestamp'] <=> $a['timestamp']); }); // Build filter option lists from the unfiltered set $availableYears = []; $availableTags = []; foreach ($allPosts as $p) { $ts = (int) ($p['timestamp'] ?? 0); if ($ts > 0) { $availableYears[(int) (new DateTimeImmutable('@' . $ts))->format('Y')] = true; } foreach (($p['tags'] ?? []) as $t) { $t = trim((string) $t); if ($t !== '') { $slug = normalize_tag($t); if ($slug !== '') { $availableTags[$slug] ??= $t; } } } } krsort($availableYears); ksort($availableTags); $availableYears = array_keys($availableYears); $usedLayouts = []; foreach ($allPosts as $p) { $l = trim((string) ($p['layout'] ?? '')); if ($l !== '') { $usedLayouts[$l] ??= ucfirst($l); } } foreach ($availableLayouts as $lay) { if (isset($usedLayouts[$lay['name']])) { $usedLayouts[$lay['name']] = $lay['label']; } } ksort($usedLayouts); if ($filterLayout !== '' && !isset($usedLayouts[$filterLayout])) { $filterLayout = ''; } // Apply filters $filteredPosts = filter_posts_by_query($allPosts, $search); if ($filterYear > 0 || $filterMonth > 0) { $filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterYear, $filterMonth): bool { $ts = (int) ($post['timestamp'] ?? 0); if ($ts === 0) { return false; } $dt = new DateTimeImmutable('@' . $ts); if ($filterYear > 0 && (int) $dt->format('Y') !== $filterYear) { return false; } if ($filterMonth > 0 && (int) $dt->format('n') !== $filterMonth) { return false; } return true; })); } if ($filterTag !== '') { $filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterTag): bool { $tags = $post['tags'] ?? []; return is_array($tags) && in_array(normalize_tag($filterTag), array_map(fn($t) => normalize_tag((string) $t), $tags), true); })); } if ($filterStatus !== '') { $filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterStatus): bool { return ($post['status'] ?? '') === $filterStatus; })); } if ($filterSince > 0) { $filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterSince): bool { return (int) ($post['timestamp'] ?? 0) >= $filterSince; })); } if ($filterLayout !== '') { $filteredPosts = array_values(array_filter($filteredPosts, function (array $post) use ($filterLayout): bool { return trim((string) ($post['layout'] ?? '')) === $filterLayout; })); } // Build a human-readable label and clear-URL for any active filter $filterLabel = ''; $filterClearUrl = ''; $anyFilter = $filterYear > 0 || $filterMonth > 0 || $filterTag !== '' || $filterStatus !== '' || $filterSince > 0 || $filterLayout !== ''; if ($anyFilter) { $parts = []; if ($filterYear > 0 && $filterMonth > 0) { $parts[] = t('date.months.' . ($filterMonth - 1)) . ' ' . $filterYear; } elseif ($filterYear > 0) { $parts[] = (string) $filterYear; } elseif ($filterMonth > 0) { $parts[] = t('date.months.' . ($filterMonth - 1)); } if ($filterTag !== '') { $parts[] = $availableTags[$filterTag] ?? $filterTag; } if ($filterStatus !== '') { $parts[] = t('admin.editor.status_' . $filterStatus); } if ($filterLayout !== '') { $parts[] = $usedLayouts[$filterLayout]; } if ($filterSince > 0 && $filterYear === 0) { $parts[] = t('admin.content.filter_recent'); } $filterLabel = implode(', ', $parts); $clearParams = array_filter(['tab' => $tab, 'q' => $search !== '' ? $search : null]); $filterClearUrl = base_path() . '/admin/content.php?' . http_build_query($clearParams); } $detailsOpen = $anyFilter || $search !== ''; $totalPosts = count($filteredPosts); $totalPages = $totalPosts > 0 ? (int) ceil($totalPosts / $perPage) : 1; $offset = ($page - 1) * $perPage; $posts = array_slice($filteredPosts, $offset, $perPage); // Pages data $pages = get_all_pages(true); usort($pages, function (array $a, array $b): int { if ($a['status'] !== $b['status']) { return $a['status'] === 'draft' ? -1 : 1; } return ($a['title'] <=> $b['title']); }); $fontStack = font_stack_css($config['theme']['admin_font_stack'] ?? 'sans'); $postDateFmt = site_date_format($config); if (strpbrk($postDateFmt, 'HhGgi') === false) { $postDateFmt .= ' @ H:i'; } $adminTitle = t('admin.content.page_title'); require __DIR__ . '/../includes/admin-head.php'; ?>

>

$filterLabel !== '' ? $filterLabel : $search])) ?>

1): ?> 'posts']; if ($filterYear > 0) { $pageParams['year'] = $filterYear; } if ($filterMonth > 0) { $pageParams['month'] = $filterMonth; } if ($filterTag !== '') { $pageParams['tag'] = $filterTag; } if ($filterStatus !== '') { $pageParams['status'] = $filterStatus; } if ($filterLayout !== '') { $pageParams['layout'] = $filterLayout; } if ($filterSince > 0) { $pageParams['since'] = $filterSince; } if ($search !== '') { $pageParams['q'] = $search; } ?>