Skip to content

Commit

Permalink
Merge pull request #725 from carstingaxion/fix/724
Browse files Browse the repository at this point in the history
Add URL encoding to 'Add to calendar' links
  • Loading branch information
mauteri authored Jul 12, 2024
2 parents 5c74585 + 9f44bc3 commit aa09301
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
40 changes: 22 additions & 18 deletions includes/core/classes/class-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,17 @@ protected function get_google_calendar_link(): string {
$location .= sprintf( ', %s', $venue['full_address'] );
}

$params = array(
'action' => 'TEMPLATE',
'text' => sanitize_text_field( $this->event->post_title ),
'dates' => sanitize_text_field( $datetime ),
'details' => sanitize_text_field( $description ),
'location' => sanitize_text_field( $location ),
'sprop' => 'name:',
);

return add_query_arg(
array(
'action' => 'TEMPLATE',
'text' => sanitize_text_field( $this->event->post_title ),
'dates' => sanitize_text_field( $datetime ),
'details' => sanitize_text_field( $description ),
'location' => sanitize_text_field( $location ),
'sprop' => 'name:',
),
rawurlencode_deep( $params ),
'https://www.google.com/calendar/event'
);
}
Expand Down Expand Up @@ -533,17 +535,19 @@ protected function get_yahoo_calendar_link(): string {
$location .= sprintf( ', %s', $venue['full_address'] );
}

$params = array(
'v' => '60',
'view' => 'd',
'type' => '20',
'title' => sanitize_text_field( $this->event->post_title ),
'st' => sanitize_text_field( $datetime_start ),
'dur' => sanitize_text_field( (string) $hours . (string) $minutes ),
'desc' => sanitize_text_field( $description ),
'in_loc' => sanitize_text_field( $location ),
);

return add_query_arg(
array(
'v' => '60',
'view' => 'd',
'type' => '20',
'title' => sanitize_text_field( $this->event->post_title ),
'st' => sanitize_text_field( $datetime_start ),
'dur' => sanitize_text_field( (string) $hours . (string) $minutes ),
'desc' => sanitize_text_field( $description ),
'in_loc' => sanitize_text_field( $location ),
),
rawurlencode_deep( $params ),
'https://calendar.yahoo.com/'
);
}
Expand Down
10 changes: 7 additions & 3 deletions test/unit/php/includes/core/classes/class-test-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,15 @@ public function test_get_calendar_links(): void {

$event->save_datetimes( $params );

$output = $event->get_calendar_links();
$output = $event->get_calendar_links();

$expected_google_link = 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit%20Test%20Event&dates=20200511T150000Z%2F20200511T170000Z&details=' . rawurlencode( $description ) . '&location=Unit%20Test%20Venue%2C%20123%20Main%20Street%2C%20Montclair%2C%20NJ%2007042&sprop=name%3A';
$expected_yahoo_link = 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit%20Test%20Event&st=20200511T150000Z&dur=0200&desc=' . rawurlencode( $description ) . '&in_loc=Unit%20Test%20Venue%2C%20123%20Main%20Street%2C%20Montclair%2C%20NJ%2007042';

$expects = array(
'google' => array(
'name' => 'Google Calendar',
'link' => 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit Test Event&dates=20200511T150000Z/20200511T170000Z&details=' . $description . '&location=Unit Test Venue, 123 Main Street, Montclair, NJ 07042&sprop=name:',
'link' => $expected_google_link,
),
'ical' => array(
'name' => 'iCal',
Expand All @@ -422,7 +426,7 @@ public function test_get_calendar_links(): void {
),
'yahoo' => array(
'name' => 'Yahoo Calendar',
'link' => 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit Test Event&st=20200511T150000Z&dur=0200&desc=' . $description . '&in_loc=Unit Test Venue, 123 Main Street, Montclair, NJ 07042',
'link' => $expected_yahoo_link,
),
);

Expand Down

0 comments on commit aa09301

Please sign in to comment.