Updated the proostekrant to work properly again.

This commit is contained in:
douwe
2026-10-09 10:33:21 +02:00
parent 56d143b74b
commit 256a81a770
133 changed files with 10491 additions and 837 deletions
+141
View File
@@ -0,0 +1,141 @@
<?php
namespace App\Controllers;
use App\Models\Article;
use App\Models\Season;
use App\Models\User;
class PublicController extends Controller {
public function index() {
$config = $this->config;
// Get current season
$currentSeason = Season::getCurrent();
// Get recent articles (draft status for WIP)
$draftArticles = Article::all('draft');
// Get published articles for archive preview
$publishedArticles = Article::all('published');
// Scan for PDF files in multiple directories
$pdfFiles = [];
// Check storage/latex directory
$pdfDirs = [
__DIR__ . '/../../storage/latex/',
__DIR__ . '/../../../Latex/',
__DIR__ . '/../../../Build/',
__DIR__ . '/../../../Proostenkrant.NET/',
];
foreach ($pdfDirs as $pdfDir) {
if (is_dir($pdfDir)) {
$files = scandir($pdfDir);
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'pdf') {
$filepath = $pdfDir . $file;
$pdfFiles[] = [
'filename' => $file,
'path' => $this->getPdfPath($pdfDir, $file),
'date' => date('Y-m-d', filemtime($filepath)),
'fullpath' => $filepath
];
}
}
}
}
// Sort by date descending
usort($pdfFiles, function($a, $b) {
return strtotime($b['date']) - strtotime($a['date']);
});
$users = User::all();
$usersById = [];
foreach ($users as $user) {
$usersById[$user['id']] = $user['display_name'];
}
$this->view('public/home', [
'page_title' => 'Home',
'show_nav' => true,
'config' => $config,
'currentSeason' => $currentSeason,
'draftArticles' => $draftArticles,
'publishedArticles' => $publishedArticles,
'pdfFiles' => $pdfFiles,
'usersById' => $usersById
]);
}
private function getPdfPath($directory, $filename) {
// Map directory to public URL
$baseDir = __DIR__ . '/../../';
if (strpos($directory, '/storage/latex') !== false) {
return '/storage/latex/' . $filename;
} elseif (strpos($directory, '/Latex/') !== false) {
return '/Latex/' . $filename;
} elseif (strpos($directory, '/Build/') !== false) {
return '/Build/' . $filename;
} elseif (strpos($directory, '/Proostenkrant.NET/') !== false) {
return '/Proostenkrant.NET/' . $filename;
}
return '/' . basename($directory) . '/' . $filename;
}
public function archive() {
$pdfFiles = [];
// Check multiple directories for PDFs
$pdfDirs = [
__DIR__ . '/../../storage/latex/',
__DIR__ . '/../../../Latex/',
__DIR__ . '/../../../Build/',
__DIR__ . '/../../../Proostenkrant.NET/',
];
foreach ($pdfDirs as $pdfDir) {
if (is_dir($pdfDir)) {
$files = scandir($pdfDir);
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'pdf') {
$filepath = $pdfDir . $file;
// Try to extract date and edition from filename
$basename = pathinfo($file, PATHINFO_FILENAME);
$date = date('Y-m-d', filemtime($filepath));
// Check if filename has a date pattern
if (preg_match('/(\d{4}-\d{2}-\d{2})/', $basename, $matches)) {
$date = $matches[1];
}
$editionName = str_replace(['_', '-'], ' ', $basename);
$pdfFiles[] = [
'filename' => $file,
'path' => $this->getPdfPath($pdfDir, $file),
'date' => $date,
'edition_name' => $editionName,
'fullpath' => $filepath
];
}
}
}
}
// Sort by date descending
usort($pdfFiles, function($a, $b) {
return strtotime($b['date']) - strtotime($a['date']);
});
$this->view('public/archive', [
'page_title' => 'Archief',
'show_nav' => true,
'pdfFiles' => $pdfFiles
]);
}
}