All checks were successful
Deploy Production / Deploy to Production (push) Successful in 21s
- Plugin csv-export: authenticated route /wg-export/contacts generates CSV with UTF-8 BOM, semicolon separator, white-paper titles resolved - Panel section with k-button wired to the route, index.css for spacing - white-papers.yml dataTab converted to sections to host the custom section - Filename format: YYMMDD-contacts.csv Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
Kirby::plugin('world-game/csv-export', [
|
|
'sections' => [
|
|
'csv-export' => [],
|
|
],
|
|
|
|
'routes' => [
|
|
[
|
|
'pattern' => 'wg-export/contacts',
|
|
'method' => 'GET',
|
|
'action' => function () {
|
|
if (!kirby()->user()) {
|
|
http_response_code(403);
|
|
exit;
|
|
}
|
|
|
|
$entries = page('livres-blancs')->contactDatabase()->toStructure();
|
|
|
|
header('Content-Type: text/csv; charset=UTF-8');
|
|
header('Content-Disposition: attachment; filename="' . date('ymd') . '-contacts.csv"');
|
|
header('Cache-Control: no-cache');
|
|
|
|
$out = fopen('php://output', 'w');
|
|
fputs($out, "\xEF\xBB\xBF"); // BOM pour Excel
|
|
fputcsv($out, ['Prénom', 'Nom', 'Email', 'Entreprise', 'Fonction', 'Livres blancs', 'Date'], ';');
|
|
|
|
foreach ($entries as $entry) {
|
|
$titles = [];
|
|
foreach ($entry->whitePaper()->toPages() as $wp) {
|
|
$titles[] = $wp->title()->value();
|
|
}
|
|
|
|
fputcsv($out, [
|
|
$entry->firstName()->value(),
|
|
$entry->lastName()->value(),
|
|
$entry->email()->value(),
|
|
$entry->company()->value(),
|
|
$entry->role()->value(),
|
|
implode(' | ', $titles),
|
|
$entry->downloadedAt()->value(),
|
|
], ';');
|
|
}
|
|
|
|
fclose($out);
|
|
exit;
|
|
},
|
|
],
|
|
],
|
|
]);
|