n_name ); } /** * Get the names of the plugins that have been declared compatible or incompatible with a given feature. * * @param string $feature_id Feature id. * @return array An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin names. */ public static function get_compatible_plugins_for_feature( string $feature_id ): array { return wc_get_container()->get( FeaturesController::class )->get_compatible_plugins_for_feature( $feature_id ); } /** * Sets a flag indicating that it's allowed to enable features for which incompatible plugins are active * from the WooCommerce feature settings page. */ public static function allow_enabling_features_with_incompatible_plugins(): void { wc_get_container()->get( FeaturesController::class )->allow_enabling_features_with_incompatible_plugins(); } /** * Sets a flag indicating that it's allowed to activate plugins for which incompatible features are enabled * from the WordPress plugins page. */ public static function allow_activating_plugins_with_incompatible_features(): void { wc_get_container()->get( FeaturesController::class )->allow_activating_plugins_with_incompatible_features(); } } y() => 'past' ] ); } elseif ( $current_page > 1 ) { $url = View::prev_url( $canonical ); } else { $url = $this->get_past_url( $canonical ); } $url = $this->filter_prev_url( $canonical, $url ); $this->cached_urls[ $cache_key ] = $url; return $url; } /** * {@inheritDoc} */ public function next_url( $canonical = false, array $passthru_vars = [] ) { $cache_key = __METHOD__ . '_' . md5( wp_json_encode( func_get_args() ) ); if ( isset( $this->cached_urls[ $cache_key ] ) ) { return $this->cached_urls[ $cache_key ]; } $current_page = (int) $this->context->get( 'page', 1 ); $display = $this->context->get( 'event_display_mode', 'venue' ); if ( static::$view_slug === $display || 'default' === $display ) { $url = View::next_url( $canonical ); } elseif ( $current_page > 1 ) { $url = View::prev_url( $canonical, [ Utils\View::get_past_event_display_key() => 'past' ] ); } else { $url = $this->get_upcoming_url( $canonical ); } $url = $this->filter_next_url( $canonical, $url ); $this->cached_urls[ $cache_key ] = $url; return $url; } /** * Return the URL to a page of past events. * * @since 5.0.0 * * @param bool $canonical Whether to return the canonical version of the URL or the normal one. * @param int $page The page to return the URL for. * * @return string The URL to the past URL page, if available, or an empty string. */ protected function get_past_url( $canonical = false, $page = 1 ) { $default_date = 'now'; $date = $this->context->get( 'event_date', $default_date ); $event_date_var = $default_date === $date ? '' : $date; $past = tribe_events()->by_args( $this->setup_repository_args( $this->context->alter( [ 'event_display_mode' => 'past', 'paged' => $page, ] ) ) ); if ( $past->count() > 0 ) { $event_display_key = Utils\View::get_past_event_display_key(); $past_url = add_query_arg( array_filter( [ $this->page_key => $page > 1 ? $page : false, ] ), $this->get_url( false ) ); if ( ! $canonical ) { return $past_url; } // We've got rewrite rules handling `eventDate` and `eventDisplay`, but not List. Let's remove it. $canonical_url = tribe( 'events-pro.rewrite' ) ->get_clean_url( remove_query_arg( [ 'eventDate' ], $past_url ) ); // We use the `eventDisplay` query var as a display mode indicator: we have to make sure it's there. $url = add_query_arg( [ $event_display_key => 'past' ], $canonical_url ); // Let's re-add the `eventDate` if we had one and we're not already passing it with one of its aliases. if ( ! ( empty( $event_date_var ) || $this->url->get_query_arg_alias_of( 'event_date', $this->context ) ) ) { $url = add_query_arg( [ 'eventDate' => $event_date_var ], $url ); } return $url; } return ''; } /** * Return the URL to a page of upcoming events. * * @since 5.0.0 * * @param bool $canonical Whether to return the canonical version of the URL or the normal one. * @param int $page The page to return the URL for. * * @return string The URL to the upcoming URL page, if available, or an empty string. */ protected function get_upcoming_url( $canonical = false, $page = 1 ) { $default_date = 'now'; $date = $this->context->get( 'event_date', $default_date ); $event_date_var = $default_date === $date ? '' : $date; $url = ''; $upcoming = tribe_events()->by_args( $this->setup_repository_args( $this->context->alter( [ 'paged' => $page, ] ) ) ); if ( $upcoming->count() > 0 ) { $upcoming_url_object = clone $this->url->add_query_args( array_filter( [ $this->page_key => $page, 'eventDate' => $event_date_var, 'tribe-bar-search' => $this->context->get( 'keyword' ), 'eventDisplay' => static::$view_slug, ] ) ); $upcoming_url = (string) $upcoming_url_object; if ( ! $canonical ) { return $upcoming_url; } // We've got rewrite rules handling `eventDate`, but not List. Let's remove it to build the URL. $url = tribe( 'events.rewrite' )->get_clean_url( remove_query_arg( [ 'eventDate', 'page', 'paged', 'tribe_event_display' ], $upcoming_url ) ); // Let's re-add the `eventDate` if we had one and we're not already passing it with one of its aliases. if ( ! ( empty( $event_date_var ) || $upcoming_url_object->get_query_arg_alias_of( 'event_date', $this->context ) ) ) { $url = add_query_arg( [ 'eventDate' => $event_date_var ], $url ); } } return $url ?: $this->get_today_url( $canonical ); } /** * {@inheritDoc} * * @since 7.8.0 Made $context explicitly nullable. */ protected function setup_repository_args( ?Context $context = null ) { $args = parent::setup_repository_args( $context ); $context = null !== $context ? $context : $this->context; $venue_category_controller = tribe( Category::class ); if ( $context->is( $venue_category_controller->get_wp_slug() ) ) { $args = $venue_category_controller->setup_repository_args( $args, $this, $context ); } else { $post_name = $context->get( 'name', false ); if ( false === $post_name ) { // This is weird but let's show the user events anyway. return $args; } $post_id = tribe_venues()->where( 'name', $post_name )->fields( 'ids' )->first(); if ( empty( $post_id ) ) { // This is weirder but let's show the user events anyway. return $args; } $args['venue'] = $post_id; $this->set_post_id( $post_id ); } $date = $context->get( 'event_date', 'now' ); $event_display = $context->get( 'event_display_mode', $context->get( 'event_display' ) ); if ( 'past' !== $event_display ) { $args['ends_after'] = $date; } else { $args['order'] = 'DESC'; $args['ends_before'] = $date; } return $args; } /** * {@inheritDoc} */ protected function get_show_datepicker_submit() { $live_refresh = tribe_get_option( 'liveFiltersUpdate', 'automatic' ); return 'manual' === $live_refresh; } /** * {@inheritDoc} */ public function get_url( $canonical = false, $force = false ) { $page = $this->url->get_current_page(); $post_ids = $this->get_post_id(); $venue_category_controller = tribe( Category::class ); $is_taxonomy_page = $this->context->is( $venue_category_controller->get_wp_slug() ); $query_args = [ 'eventDisplay' => static::$view_slug, 'paged' => $page > 1 ? $page : false, ]; if ( ! $is_taxonomy_page ) { $venue_id = reset( $post_ids ); if ( ! empty( $venue_id ) ) { $venue = tribe_get_venue_object( $venue_id ); $query_args[ Venue::POSTTYPE ] = $venue->post_name; } } else { $query_args['post_type'] = Venue::POSTTYPE; $query_args[ $venue_category_controller->get_wp_slug() ] = $this->context->get( $venue_category_controller->get_wp_slug() ); } $url = add_query_arg( array_filter( $query_args ), home_url() ); if ( $canonical ) { $url = tribe( 'events-pro.rewrite' )->get_clean_url( $url, $force ); } if ( $is_taxonomy_page ) { $url = remove_query_arg( 'post_type', $url ); } $event_display_key = Utils\View::get_past_event_display_key(); $event_display_mode = $this->context->get( 'event_display_mode', false ); if ( 'past' === $event_display_mode ) { $url = add_query_arg( [ $event_display_key => $event_display_mode ], $url ); } $url = remove_query_arg( 'post_type', $url ); $event_date = $this->context->get( 'event_date', false ); if ( ! empty( $event_date ) ) { // If there's a date set, then add it as a query argument. $url = add_query_arg( [ 'tribe-bar-date' => $event_date ], $url ); } $url = $this->filter_view_url( $canonical, $url ); return $url; } /** * Overrides the base implementation to remove notions of a "past" events request on page reset. * * @since 4.9.11 */ protected function on_page_reset() { parent::on_page_reset(); $this->remove_past_query_args(); } /** * Setup the breadcrumbs for the "Venue" view. * * @see \Tribe\Events\Views\V2\View::get_breadcrumbs() for where this code is applying. * @since 4.7.9 *w * @param View $view The instance of the view being rendered. * * @param array $breadcrumbs The breadcrumbs array. * @param View $view The instance of the view being rendered. * * @return array The filtered breadcrumbs * */ public function setup_breadcrumbs( $breadcrumbs, $view ) { $post_id = $view->get_post_id(); if ( ! is_array( $post_id ) ) { return $breadcrumbs; } $breadcrumbs[] = [ 'link' => tribe_get_events_link(), 'label' => tribe_get_event_label_plural(), ]; $breadcrumbs[] = [ 'link' => '', 'label' => tribe_get_venue_label_plural(), ]; $breadcrumbs[] = [ 'link' => '', 'label' => get_the_title( reset( $post_id ) ), ]; return $breadcrumbs; } /** * Set up the default back link data for this View. * * This provides a structured array containing the URL and label * for the "Back to Events" link. * * @since 7.7.7 * * @param array|false $back_link Existing back link data, or false if none provided. * @param array $breadcrumbs The breadcrumbs array (may be empty). * * @return array Back link data with 'url' and 'label' keys. */ public function setup_back_link( $back_link, $breadcrumbs ) { return [ 'url' => tribe_get_events_link(), 'label' => sprintf( /* translators: %s: Plural event label, e.g. "All Events" */ __( 'All %s', 'the-events-calendar' ), tribe_get_event_label_plural() ), ]; } /** * Setups up the Header Title for this view. * * @since 6.2.0 * * @param string $header_title * @param View $view * * @return string */ public function setup_header_title( string $header_title, View $view ): string { $post_id = $view->get_post_id(); if ( ! is_array( $post_id ) ) { return ''; } return (string) get_the_title( reset( $post_id ) ); } /** * Setups up the Content Title for this view. * * @since 6.2.0 * * @param string $content_title * @param View $view * * @return string */ public function setup_content_title( string $content_title, View $view ): string { return sprintf( _x( '%1$s at this %2$s', 'Content title for the View, displays right above the date selector on the Venue View.', 'tribe-events-calendar-pro' ), tribe_get_event_label_plural(), strtolower( tribe_get_venue_label_singular() ) ); } /** * Render the venue meta. * * @since 5.0.0 * * @return string The venue meta HTML * */ public function render_meta() { $post_id = $this->get_post_id(); if ( ! is_array( $post_id ) ) { return ''; } $venue = tribe_get_venue_object( reset( $post_id ) ); // Bail if we don't have a venue. if ( ! $venue ) { return ''; } // Bail if we don't have a venue of the right type. if ( Venue::POSTTYPE !== $venue->post_type ) { return ''; } $template = $this->get_template(); return $template->template( 'venue/meta', array_merge( $template->get_values(), [ 'venue' => $venue ] ) ); } /** * {@inheritDoc} */ protected function setup_template_vars() { $template_vars = parent::setup_template_vars(); $template_vars = tribe( Maps::class )->setup_map_provider( $template_vars ); $post_id = $this->get_post_id(); $template_vars['show_map'] = tribe_embed_google_map( reset( $post_id ) ); // While we fetch events in DESC order, we want to show the results in ASC order in `past` display mode. if ( ! empty( $template_vars['events'] ) && is_array( $template_vars['events'] ) && 'past' === $this->context->get( 'event_display_mode' ) ) { $template_vars['events'] = array_reverse( $template_vars['events'] ); } $template_vars = $this->setup_datepicker_template_vars( $template_vars ); return $template_vars; } /** * Updates the URL query arguments for the Venue View to correctly build its URls. * * @since 5.0.1 * @since 7.8.0 Made $args explicitly nullable. * * {@inheritDoc} */ public function set_url( ?array $args = null, $merge = false ) { parent::set_url( $args, $merge ); $url_query_args = $this->url->get_query_args(); $url_query_args['post_type'] = null; $this->url->add_query_args( $url_query_args ); } }