iCal Feed Bugfix & Enhancement

-Added new function to properly escape feed information [line 17]
-Fixed bug with iCal feed information not being properly escaped and
thus losing most of its address information. [lines 85, 138]
-Enhanced iCal feed to include escaped post content from events
(currently only supports plain text data) [line 139]
This commit is contained in:
Cody Bromley
2016-03-02 11:56:29 -06:00
parent 843e84b5ad
commit 36f2b7398d

View File

@@ -14,8 +14,14 @@ if ( 'sp_calendar' !== get_post_type( $post ) ) {
wp_die( __( 'ERROR: This is not a valid feed template.', 'sportspress' ), '', array( 'response' => 404 ) ); wp_die( __( 'ERROR: This is not a valid feed template.', 'sportspress' ), '', array( 'response' => 404 ) );
} }
// Escapes a string of characters
function escapeString($string) {
return preg_replace('/([\,;])/','\\\$1', $string);
}
// Get events in calendar // Get events in calendar
$calendar = new SP_Calendar( $post ); $calendar = new SP_Calendar( $post );
$postcontent = "$post->post_content";
$events = $calendar->data(); $events = $calendar->data();
// Get blog locale // Get blog locale
@@ -77,7 +83,7 @@ foreach ( $events as $event):
// Add details to location // Add details to location
$address = sp_array_value( $meta, 'sp_address', false ); $address = sp_array_value( $meta, 'sp_address', false );
if ( false !== $address ) { if ( false !== $address ) {
$location = $address; $location = $venue->name . '\, ' . escapeString($address);
} }
// Generate geo tag // Generate geo tag
@@ -130,7 +136,8 @@ foreach ( $events as $event):
// Append to output string // Append to output string
$output .= $output .=
"BEGIN:VEVENT\n" . "BEGIN:VEVENT\n" .
"SUMMARY:" . $summary . "\n" . "SUMMARY:" . escapeString($summary) . "\n" .
"DESCRIPTION:" . escapeString($event->post_content) . "\n" .
"UID:$event->ID\n" . "UID:$event->ID\n" .
"STATUS:CONFIRMED\n" . "STATUS:CONFIRMED\n" .
"DTSTART:" . mysql2date( $date_format, $event->post_date ) . "\n" . "DTSTART:" . mysql2date( $date_format, $event->post_date ) . "\n" .