renderer = new ViewRenderer($events); } public function register(): void { add_shortcode('pcwp_calendar', [$this, 'calendar']); add_shortcode('pcwp_event_list', [$this, 'list']); add_shortcode('pcwp_upcoming_events', [$this, 'upcoming']); add_shortcode('pcwp_add_to_calendar', [$this, 'addToCalendar']); add_shortcode('pcwp_event_details', [$this, 'details']); add_shortcode('pcwp_event_field', [$this, 'field']); add_shortcode('pcwp_event_map', [$this, 'map']); } /** @param array $attributes */ public function calendar(array $attributes = []): string { return $this->renderer->render(array_merge($this->requestAttributes(), $attributes)); } /** @param array $attributes */ public function list(array $attributes = []): string { return $this->calendar(array_merge(['view' => 'list'], $attributes)); } /** @param array $attributes */ public function upcoming(array $attributes = []): string { return $this->calendar(array_merge(['view' => 'list', 'past_events' => false, 'limit' => 5, 'filter_bar' => false], $attributes)); } /** @param array $attributes */ public function addToCalendar(array $attributes = []): string { $eventId = absint($attributes['event_id'] ?? get_the_ID()); if (! \ProCalendarWP\Events\EventVisibility::isPublic($eventId)) { return ''; } $url = add_query_arg(['pcwp_ics' => $eventId, '_pcwp_nonce' => wp_create_nonce('pcwp_ics_' . $eventId)], home_url('/')); $event = $this->events->find($eventId); if ($event === null) { return ''; } wp_enqueue_style('pcwp-calendar-blocks'); $links = ''; foreach (\ProCalendarWP\Calendar\CalendarLinks::urls($event, (string) get_permalink($eventId), $url) as $label => $link) { $links .= '
  • ' . esc_html($label) . '
  • '; } $calendarIcon = ''; $arrowIcon = ''; return '
    ' . $calendarIcon . '' . esc_html__('Add to calendar', 'proeventswp') . '' . $arrowIcon . '
      ' . $links . '
    '; } /** @param array $attributes */ public function field(array $attributes = []): string { $id = absint($attributes['event_id'] ?? get_the_ID()); if (! \ProCalendarWP\Events\EventVisibility::isPublic($id)) { return ''; } $allowed = ['date' => 'event-datetime', 'venue' => 'event-venue', 'organizer' => 'event-organizers', 'cost' => 'event-cost', 'status' => 'event-status', 'mode' => 'event-mode', 'website' => 'event-website', 'schedule' => 'event-schedule', 'series' => 'event-series']; $type = $allowed[sanitize_key((string) ($attributes['field'] ?? 'date'))] ?? ''; return $type === '' ? '' : render_block(['blockName' => 'pro-calendar-wp/' . $type, 'attrs' => ['eventId' => $id], 'innerBlocks' => [], 'innerHTML' => '', 'innerContent' => []]); } /** @param array $attributes */ public function details(array $attributes = []): string { $html = ''; foreach (['date', 'venue', 'organizer', 'cost', 'status', 'mode', 'website', 'schedule'] as $field) { $html .= $this->field($attributes + ['field' => $field]); } return $html; } /** @param array $attributes */ public function map(array $attributes = []): string { $id = absint($attributes['event_id'] ?? get_the_ID()); if (! \ProCalendarWP\Events\EventVisibility::isPublic($id)) { return ''; } return render_block(['blockName' => 'pro-calendar-wp/event-map', 'attrs' => ['eventId' => $id], 'innerBlocks' => [], 'innerHTML' => '', 'innerContent' => []]); } /** @return array */ private function requestAttributes(): array { $attributes = []; foreach (['view', 'start', 'end', 'category', 'tag', 'keyword'] as $key) { $requestKey = 'pcwp_' . $key; if (isset($_GET[$requestKey])) { $attributes[$key] = sanitize_text_field(wp_unslash($_GET[$requestKey])); } } return $attributes; } }