Skip to content

Commit

Permalink
Merge branch 'fix/TEC-4916-filter-outlook-links' into fix/TEC-4831-su…
Browse files Browse the repository at this point in the history
…bscribe-outlook-timezone
  • Loading branch information
Camwyn committed Dec 6, 2023
2 parents 858fbaf + eaef749 commit abb0819
Show file tree
Hide file tree
Showing 19 changed files with 422 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ node_modules
compiler.jar
*.ps1
*.code-workspace
bun.lockb

wpml-config.xml
.env.testing
Expand Down
2 changes: 1 addition & 1 deletion common
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "the-events-calendar",
"version": "6.2.8",
"version": "6.2.9",
"repository": "git@github.com:the-events-calendar/the-events-calendar.git",
"_zipname": "the-events-calendar",
"_zipfoldername": "the-events-calendar",
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Expand Up @@ -4,6 +4,7 @@ Contributors: theeventscalendar, borkweb, bordoni, brianjessee, aguseo, camwynsp
Tags: events, calendar, event, schedule, organizer
Donate link: https://evnt.is/29
Requires at least: 6.2.0
Stable tag: 6.2.9
Stable tag: 6.2.8.2
Tested up to: 6.4.1
Requires PHP: 7.4
Expand Down Expand Up @@ -231,9 +232,13 @@ Remember to always make a backup of your database and files before updating!

== Changelog ==

= [TBD] TBD =
= [6.2.9] TBD =

* Fix - Adjusted how event times and time zones are handled when using Subscribe to Outlook on a single event page. [TEC-4831]
* Tweak - Define image sizes on the List view featured image to avoid Content Layout Shifting. [TEC-4919]
* Tweak - Add new filters to allow customization of the subscribe and export links. [TEC-4916]
* Tweak - Added filters: , `tec_events_subscribe_link_url`, `tec_events_{$slug}_subscribe_link_url`, `tec_events_export_link_visibility`, `tec_events_{$slug}_export_link_visibility`, `tec_events_export_link_url_single`, `tec_events_{$slug}_export_link_url_single`, `tec_events_export_link_url`, `tec_events_{$slug}_export_link_url`
* Tweak - Updated the `tribe_get_venues` function to work with recurring events that have provisional IDs. [ECP-1597]

= [6.2.8.2] 2023-12-04 =

Expand Down
2 changes: 1 addition & 1 deletion src/Tribe/Main.php
Expand Up @@ -41,7 +41,7 @@ class Tribe__Events__Main {
const VENUE_POST_TYPE = 'tribe_venue';
const ORGANIZER_POST_TYPE = 'tribe_organizer';

const VERSION = '6.2.8.2';
const VERSION = '6.2.9';

/**
* Min Pro Addon
Expand Down
46 changes: 37 additions & 9 deletions src/Tribe/Views/V2/iCalendar/Links/Link_Abstract.php
Expand Up @@ -8,11 +8,10 @@

namespace Tribe\Events\Views\V2\iCalendar\Links;

use Tribe__Date_Utils as Dates;
use \Tribe\Events\Views\V2\View;

/**
* Class Abstract_Link
* Class Link_Abstract
*
* @since 5.12.0
* @package Tribe\Events\Views\V2\iCalendar
Expand Down Expand Up @@ -161,23 +160,27 @@ public function is_visible() {
* Allows filtering of the visibility for the links.
*
* @since 5.14.0
* @since TBD Now passing the link object as a param.
*
* @param boolean $visible Whether to display the link.
* @param boolean $visible Whether to display the link.
* @param Link_Abstract $link_obj The link object the visibility is for.
*
* @return boolean $visible Whether to display the link.
*/
$visible = (boolean) apply_filters( 'tec_views_v2_subscribe_link_visibility', $visible );
$visible = (bool) apply_filters( 'tec_views_v2_subscribe_link_visibility', $visible, $this );

/**
* Allows link-specific filtering of the visibility.
*
* @since 5.14.0
* @since TBD Now passing the link object as a param.
*
* @param boolean $visible Whether to display the link.
* @param boolean $visible Whether to display the link.
* @param Link_Abstract $link_obj The link object the visibility is for.
*
* @return boolean $visible Whether to display the link.
*/
$visible = (boolean) apply_filters( 'tec_views_v2_subscribe_link_' . self::get_slug() . '_visibility', $visible );
$visible = (bool) apply_filters( 'tec_views_v2_subscribe_link_' . self::get_slug() . '_visibility', $visible, $this );

// Set the object property to the filtered value.
$this->set_visibility( $visible );
Expand Down Expand Up @@ -248,8 +251,9 @@ public function set_visibility( bool $visible ) {
* {@inheritDoc}
*/
public function get_uri( View $view = null ) {
$is_single = is_single();
// If we're on a Single Event view, let's bypass the canonical function call and logic.
if ( is_single() ) {
if ( $is_single ) {
$feed_url = null === $view ? tribe_get_single_ical_link() : $view->get_context()->get( 'single_ical_link', false );
}

Expand All @@ -261,9 +265,33 @@ public function get_uri( View $view = null ) {
return '';
}

$feed_url = str_replace( [ 'http://', 'https://' ], 'webcal://', $feed_url );
/**
* Allows filtering of the URL for the subscribe links.
*
* @since TBD
*
* @param string $url The URL for the subscribe link.
* @param boolean $is_single Whether the link is for a single event page.
* @param Link_Abstract $link_obj The link object the url is for.
*/
$url = apply_filters( 'tec_events_subscribe_link_url', $feed_url, $is_single, $this );

$slug = static::get_slug();

/**
* Allows filtering of the URL for a service-specific subscribe link.
*
* @since TBD
*
* @param string $url The URL for the subscribe link.
* @param boolean $is_single Whether the link is for a single event page.
* @param Link_Abstract $link_obj The link object the url is for.
*/
$url = apply_filters( "tec_events_{$slug}_subscribe_link_url", $url, $is_single, $this );

$url = str_replace( [ 'http://', 'https://' ], 'webcal://', $url );

return $feed_url;
return $url;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Tribe/Views/V2/iCalendar/Links/Outlook_365.php
Expand Up @@ -27,11 +27,6 @@ class Outlook_365 extends Link_Abstract {
*/
public static $slug = 'outlook-365';

/**
* {@inheritDoc}
*/
public static $calendar_slug = 'office';

/**
* {@inheritDoc}
*/
Expand All @@ -43,5 +38,8 @@ class Outlook_365 extends Link_Abstract {
public function register() {
$this->label = __( 'Outlook 365', 'the-events-calendar' );
$this->single_label = $this->label;

// Defined and used in the trait.
self::$service_slug = 'office';
}
}
47 changes: 14 additions & 33 deletions src/Tribe/Views/V2/iCalendar/Links/Outlook_Export.php
Expand Up @@ -10,6 +10,7 @@
namespace Tribe\Events\Views\V2\iCalendar\Links;
use Tribe\Events\Views\V2\View;
use Tribe__Events__Main;
use Tribe\Events\Views\V2\iCalendar\Traits\Export_Link;

/**
* Class Outlook
Expand All @@ -19,61 +20,41 @@
* @package Tribe\Events\Views\V2\iCalendar
*/
class Outlook_Export extends Link_Abstract {
use Export_Link;

/**
* {@inheritDoc}
* The link provider slug.
*
* @since 5.12.0
*
* @var string
*/
public static $slug = 'outlook-ics';

/**
* {@inheritDoc}
*/
public function register() {
$this->label = __( 'Export Outlook .ics file', 'the-events-calendar' );
self::$query_arg = 'outlook-ical';
$this->label = _x( 'Export Outlook .ics file', 'The text for the link to export and Outlook ics file.', 'the-events-calendar' );
$this->single_label = $this->label;

add_filter( 'tec_views_v2_subscribe_link_outlook-ics_visibility', [ $this, 'filter_tec_views_v2_subscribe_link_outlook_ics_visibility'], 10, 2 );
$this->filters();
}

/**
* Filters the is_visible() function to not display on single events.
*
* @since 5.16.0
* @deprecated TBD
*
* @param boolean $visible Whether to display the link.
* @param View $view The current View object.
*
* @return boolean $visible Whether to display the link.
*/
public function filter_tec_views_v2_subscribe_link_outlook_ics_visibility( $visible ) {
_deprecated_function( __METHOD__, 'TBD', 'Outlook_Export::filter_tec_views_v2_subscribe_link_visibility' );
// Don't display on single event by default.
return ! is_single();
}

/**
* {@inheritDoc}
*/
public function get_uri( View $view = null ) {
if ( null === $view || is_single( Tribe__Events__Main::POSTTYPE ) ) {
// Try to construct it for the event single.
return add_query_arg( [ 'outlook-ical' => 1 ], get_the_permalink() );
}

$template_vars = $view->get_template_vars();

$ical = ! empty( $template_vars['ical'] ) ? $template_vars['ical'] : $view->get_ical_data();

if ( empty( $ical->display_link ) ) {
return '';
}

if ( empty( $ical->link->url ) ) {
return '';
}

// Remove ical query argument and add Outlook.
$url = remove_query_arg( 'ical', $ical->link->url );
$url = add_query_arg( [ 'outlook-ical' => 1 ], $url );

return $url;
return self::filter_tec_views_v2_subscribe_link_visibility( $visible, $this );
}
}
8 changes: 3 additions & 5 deletions src/Tribe/Views/V2/iCalendar/Links/Outlook_Live.php
Expand Up @@ -32,16 +32,14 @@ class Outlook_Live extends Link_Abstract {
*/
public $block_slug = 'hasOutlookLive';

/**
* {@inheritDoc}
*/
public static $calendar_slug = 'live';

/**
* {@inheritDoc}
*/
public function register() {
$this->label = __( 'Outlook Live', 'the-events-calendar' );
$this->single_label = $this->label;

// Defined and used in the trait.
self::$service_slug = 'live';
}
}
40 changes: 13 additions & 27 deletions src/Tribe/Views/V2/iCalendar/Links/iCalendar_Export.php
Expand Up @@ -10,6 +10,7 @@
namespace Tribe\Events\Views\V2\iCalendar\Links;
use Tribe\Events\Views\V2\View;
use Tribe__Events__Main;
use Tribe\Events\Views\V2\iCalendar\Traits\Export_Link;

/**
* Class iCal
Expand All @@ -19,19 +20,25 @@
* @package Tribe\Events\Views\V2\iCalendar
*/
class iCalendar_Export extends Link_Abstract {
use Export_Link;

/**
* {@inheritDoc}
* The link provider slug.
*
* @since 5.12.0
*
* @var string
*/
public static $slug = 'ics';

/**
* {@inheritDoc}
*/
public function register() {
$this->label = __( 'Export .ics file', 'the-events-calendar' );
self::$query_arg = 'ical';
$this->label = __( 'Export .ics file', 'the-events-calendar' );
$this->single_label = $this->label;

add_filter( 'tec_views_v2_subscribe_link_ics_visibility', [ $this, 'filter_tec_views_v2_subscribe_link_ics_visibility'], 10, 2 );
$this->filters();
}

/**
Expand All @@ -45,29 +52,8 @@ public function register() {
* @return boolean $visible Whether to display the link.
*/
public function filter_tec_views_v2_subscribe_link_ics_visibility( $visible ) {
_deprecated_function( __METHOD__, 'TBD', 'iCalendar_Export::filter_tec_views_v2_subscribe_link_visibility' );
// Don't display on single event by default.
return ! is_single();
}

/**
* {@inheritDoc}
*/
public function get_uri( View $view = null ) {
if ( null === $view || is_single( Tribe__Events__Main::POSTTYPE ) ) {
// Try to construct it for the event single.
return add_query_arg( [ 'ical' => 1 ], get_the_permalink() );
}

$ical = $view->get_ical_data();

if ( empty( $ical->display_link ) ) {
return '';
}

if ( empty( $ical->link->url ) ) {
return '';
}

return $ical->link->url;
return self::filter_tec_views_v2_subscribe_link_visibility( $visible, $this );
}
}

0 comments on commit abb0819

Please sign in to comment.