Files
wp-donations/includes/Admin/Csv.php
T
shadowdaoandClaude Sonnet 5.5 4efdef72f6
Test and Release / test (push) Successful in 2m34s
Test and Release / release (push) Successful in 9s
Add admin UI: setup wizard, goals, rules editor, donations, moderation, overlays, settings
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 10:26:03 -08:00

31 lines
850 B
PHP

<?php
declare( strict_types=1 );
namespace StreamGoals\Admin;
/** CSV helpers. Guards against spreadsheet formula injection (=, +, -, @, tab, CR prefixes). */
final class Csv {
public static function cell( mixed $v ): string {
$s = is_scalar( $v ) || null === $v ? (string) $v : '';
if ( '' !== $s && str_contains( "=+-@\t\r", $s[0] ) ) {
return "'" . $s;
}
return $s;
}
/** @return string[] */
public static function row( array $cells ): array {
return array_map( array( self::class, 'cell' ), array_values( $cells ) );
}
/** Render one RFC-4180 line (no WordPress needed; used for tests and streaming). */
public static function line( array $cells ): string {
$out = array();
foreach ( self::row( $cells ) as $c ) {
$out[] = '"' . str_replace( '"', '""', $c ) . '"';
}
return implode( ',', $out ) . "\r\n";
}
}