From 3df0ecfd3c008d348b735bc0989b1082cc6bfd37 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 22 Jan 2023 14:49:26 +0100 Subject: Replace homegrown file name sanitization with WP function. --- includes/class-giglogadmin-icalexport.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/includes/class-giglogadmin-icalexport.php b/includes/class-giglogadmin-icalexport.php index ba1d7f0..d12db13 100644 --- a/includes/class-giglogadmin-icalexport.php +++ b/includes/class-giglogadmin-icalexport.php @@ -18,12 +18,6 @@ if ( ! class_exists( 'GiglogAdmin_IcalExport' ) ) { */ class Giglogadmin_IcalExport { - static function textclean( string $txt ) : string { - $cleantext = preg_replace( '/[^A-Za-z0-9 ]/', '', $txt ); - $cleantext = str_replace( ' ', '_', $cleantext ); - return( $cleantext ); - } - public static function export_ical() { $evid = $_GET['evid']; @@ -32,8 +26,12 @@ if ( ! class_exists( 'GiglogAdmin_IcalExport' ) ) { $cshortname = substr( $cfullname, 0, 20 ); $fdate = strtotime( $concert->cdate() ); $newformat = date( 'Ymd', $fdate ); - $filename = 'Concert ' . $concert->venue()->name() . ' ' . $newformat . ' ' . substr( $concert->cname(), 0, 30 ); - $filename = self::textclean( $filename ); + + $filename = sanitize_file_name( + "Concert-{$concert->venue()->name()}-{$newformat}-" + . substr( $concert->cname(), 0, 30 ) + ); + // create a new calendar $vcalendar = Vcalendar::factory( array( Vcalendar::UNIQUE_ID => 'kigkonsult.se' ) ) // with calendaring info -- cgit v1.2.3