[$this, 'render'] ] ); } public function render(array $attributes, string $content, WP_Block $block):string { if (!is_singular(BASE.'event')) { return ''; } $meta = Meta::forPost(get_the_ID()); $values = $meta->getAll(); $out = '
'; $out .= '
'; $get = ['is_free' => 'Free', 'rsvp_required' => 'Must RSVP', 'public' => 'Private Event']; foreach ($get as $k => $g) { $check = !empty($values[$k]) && $values[$k] === '1'; if ($k === 'public') { $check = !$check; } $icon = match ($k) { 'is_free' => jvbIcon('check-circle'), 'rsvp_required' => jvbIcon('envelope'), 'public' => jvbIcon('lock-key'), }; if ($check) { $out .= sprintf( '
%s%s
', $icon, $g ); } } $out .= '
'; if (!empty($values['post_thumbnail'])) { $out .= jvbFormatImage($values['post_thumbnail']); } $out .= '
'; if (!empty($values['post_title'])) { $out .= sprintf( '

%s

', sanitize_title($values['post_title']), $values['post_title'] ); } $out .= $this->calendarDay($values['date_start']??''); $out .= '
'; $out .= '
'; $out .= sprintf( ''; $out .= $this->location($values['location']??[], $values['location_notes']??''); $out .= $this->price($values['cost']??'', $values['ticket_url']??''); $out .= $this->participants($values['max_participants']??''); $get = ['city', 'event_category']; foreach ($get as $g) { if (!empty($values[$g])) { $out .= jvbMetaTermList($values[$g], $g); } } $out .= $this->rsvp($values['rsvp_required']??'', $values['rsvp_limit']??'', $values['rsvp_deadline']); $out .= '
'; $out .= $this->gallery($values['gallery']??''); $out .= $this->moreInfo($values['external_url']??''); $out .= '
'; return $out; } public function renderGallery():void { jvbRenderGallery(); } protected function calendarDay(string $day):string { $out = ''; if (!empty($day)) { $date = new DateTime($day, wp_timezone()); $weekday = $date->format('D'); $num = $date->format('d'); $month = $date->format('M'); $out .= sprintf( '
%s %s %d
', $weekday, $month, $num ); } return $out; } protected function renderLocationString(array $location):string { if (!array_key_exists('address', $location) || !array_key_exists('street', $location) || !array_key_exists('city', $location) || !array_key_exists('province', $location) || !array_key_exists('country', $location)) { return ''; } return sprintf( '

%s%s
%s, %s %s

', $location['address'], $location['street'], $location['city'], $location['province'], $location['country'] === 'CA' ? '' : $location['country'] ); } protected function formatDay(string $date, string $start, string $end, string $notes = ''):string { $out = '
  • '; if (!empty($date)) { $out .= sprintf( '
    ', date('c', strtotime($date)), date('F j, Y', strtotime($date)) ); } $doit = false; if (!empty($start)) { $doit = true; $d = strtotime($date.' '.$start); $out .= sprintf( '', date('c', $d), date('g:ia', $d) ); } if (!empty($end)) { if ($doit) { $out .= ' - '; } $d = strtotime($date.' '.$end); $out .= sprintf( '', date('c', $d), date('g:ia', $d) ); } if (!empty($notes)) { $out .= wpautop($notes); } $out .= '
  • '; return $out; } protected function location(array $location, string $notes = ''):string { $out = ''; if (!empty($location['address']??'')) { $out .= sprintf( '', jvbIcon('map-pin'), $this->renderLocationString($location), jvbLocationLinks($location), empty($notes) ? '' : '
  • '.$notes.'
  • ', ); } return $out; } protected function price(string $price, string $url):string { $out = ''; if (!empty($price) || $price !== '0') { $out = jvbCurrency($price); } if (!empty($url)) { $out .= sprintf( '
    %sPurchase Tickets', esc_url($url), jvbIcon('ticket') ); } return empty($out) ? $out : '

    '.$out.'

    '; } protected function participants(string $num):string { $out = ''; if (!empty($num) || $num !== '0') { $out .= sprintf( '

    Maximum %d participants

    ', $num ); } return $out; } protected function moreInfo(string $url):string { $out = ''; if (!empty($url)) { $out .= sprintf( '

    %sLearn More

    ', jvbIcon('link'), esc_url($url) ); } return $out; } protected function rsvp(string $mustRSVP, string $limit, string $deadline):string { $out = ''; if (!empty($mustRSVP) && $mustRSVP === '1') { $out = '

    RSVP Required'; if (!empty($limit) && $limit !== '0') { $out .= sprintf( '
    Maximum %d Seats', $limit ); } if (!empty($deadline)) { $out .= sprintf( '
    RSVP Deadline: ', date('c', $deadline), date('F j, Y', $deadline) ); } $out .= '

    '; } return $out; } protected function gallery(string $gallery):string { $out = ''; if (!empty($gallery)) { add_action('wp_footer', [$this, 'renderGallery']); $out = ''; } return $out; } }