Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEC-4831 outlook timezone omitted with subscribe #4444

Open
wants to merge 8 commits into
base: fix/TEC-4916-filter-outlook-links
Choose a base branch
from
47 changes: 29 additions & 18 deletions src/Tribe/Views/V2/iCalendar/Traits/Outlook_Methods.php
Expand Up @@ -45,7 +45,7 @@ trait Outlook_Methods {
*
* @since 5.16.0
*
* @param string $calendar Whether it's Outlook live or Outlook 365.
* @param string $calendar Whether it's Outlook Live or Outlook 365.
*
* @return string Part of the URL containing the event information.
*/
Expand All @@ -57,20 +57,31 @@ protected function generate_outlook_add_url_parameters( $calendar = 'live' ) {
$rrv = 'addevent';

/**
* If event is an all day event, then adjust the end time.
* Filters whether the time zone offset should be removed from the URL or not.
*
* @var bool $remove_timezone_offset
*/
$remove_timezone_offset = apply_filters( 'tec_remove_outlook_timezone_offset', false );

/**
* If the event is an all-day event, then adjust the end time.
* Using the 'allday' parameter doesn't work well through time zones.
*/
if ( $event->all_day ) {
$enddt = Dates::build_date_object( $event->end_date )->format( 'Y-m-d' )
$enddt = Dates::build_date_object( $event->end_date, $event->timezone )->format( 'Y-m-d' )
. 'T'
. Dates::build_date_object( $event->start_date )->format( 'H:i:s' );
. Dates::build_date_object( $event->start_date, $event->timezone )->format( 'H:i:s' );
} else {
$enddt = Dates::build_date_object( $event->end_date )->format( 'c' );
$enddt = substr( $enddt, 0, strlen( $enddt ) - 6 );
$enddt = Dates::build_date_object( $event->end_date, $event->timezone )->format( 'c' );
if ( $remove_timezone_offset ) {
$enddt = substr( $enddt, 0, strlen( $enddt ) - 6 );
}
}

$startdt = Dates::build_date_object( $event->start_date )->format( 'c' );
$startdt = substr( $startdt, 0, strlen( $startdt ) - 6 );
$startdt = Dates::build_date_object( $event->start_date, $event->timezone )->format( 'c' );
if ( $remove_timezone_offset ) {
$startdt = substr( $startdt, 0, strlen( $startdt ) - 6 );
}

$location = Venue::generate_string_address( $event );

Expand All @@ -91,7 +102,7 @@ protected function generate_outlook_add_url_parameters( $calendar = 'live' ) {
// Stripping tags
Camwyn marked this conversation as resolved.
Show resolved Hide resolved
$body = strip_tags( $body, '<p>' );
Camwyn marked this conversation as resolved.
Show resolved Hide resolved

// Truncate Event Description and add permalink if greater than 900 characters
// Truncate the Event Description and add permalink if greater than 900 characters
Camwyn marked this conversation as resolved.
Show resolved Hide resolved
if ( strlen( $body ) > 900 ) {

$body = substr( $body, 0, 900 );
Expand Down Expand Up @@ -142,21 +153,21 @@ protected function generate_outlook_add_url_parameters( $calendar = 'live' ) {
*
* @since 5.16.0
*
* @return string The singe event add to calendar URL.
* @return string The single event add to calendar URL.
*/
public function generate_outlook_full_url() {
$params = $this->generate_outlook_add_url_parameters();
$base_url = 'https://outlook.' . static::$calendar_slug . '.com/owa/';
$url = add_query_arg( $params, $base_url );

/**
* Filter the Outlook single event import url.
* Filter the Outlook single event import URL.
*
* @since 5.16.0
*
* @param string $url The url used to subscribe to a calendar in Outlook.
* @param string $base_url The base url used to subscribe in Outlook.
* @param array<string|string> $params An array of parameters added to the base url.
* @param string $url The URL used to subscribe to a calendar in Outlook.
* @param string $base_url The base URL used to subscribe in Outlook.
* @param array<string|string> $params An array of parameters added to the base URL.
* @param Outlook_Methods $this An instance of the link abstract.
*/
$url = apply_filters( 'tec_events_ical_outlook_single_event_import_url', $url, $base_url, $params, $this );
Expand All @@ -169,7 +180,7 @@ public function generate_outlook_full_url() {
*
* @since 5.16.0
*
* @return string The subscribe url.
* @return string The subscribe URL.
*/
public function generate_outlook_subscribe_url( View $view = null ) {
$base_url = 'https://outlook.' . static::$calendar_slug . '.com/owa?path=/calendar/action/compose';
Expand Down Expand Up @@ -200,10 +211,10 @@ public function generate_outlook_subscribe_url( View $view = null ) {
*
* @since 5.16.0
*
* @param string $url The url used to subscribe to a calendar in Outlook.
* @param string $base_url The base url used to subscribe in Outlook.
* @param string $url The URL used to subscribe to a calendar in Outlook.
* @param string $base_url The base URL used to subscribe in Outlook.
* @param string $feed_url The subscribe url used on the site.
* @param array<string|string> $params An array of parameters added to the base url.
* @param array<string|string> $params An array of parameters added to the base URL.
* @param Outlook_Abstract_Export $this An instance of the link abstract.
*/
$url = apply_filters( 'tec_events_ical_outlook_subscribe_url', $url, $base_url, $feed_url, $params, $this );
Expand Down