'; $get = ['is_free' => 'Free', 'rsvp_required' => 'Must RSVP', 'public' => 'Private Event']; foreach ($get as $k => $g) { $check = !empty($fields[$k]) && $fields[$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 .= ''; return $out; } /** * @param string $date * * @return string */ public static function calendarDay(string $date):string { if (empty($date)) { return ''; } try { $date = new DateTime($date, wp_timezone()); $weekday = $date->format('D'); $num = $date->format('d'); $month = $date->format('M'); return sprintf( '
%s %s %d
', $weekday, $month, $num ); } catch (Exception $e){ return ''; } } public static 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); } return $out; } public static function getMonthName(int $num):string { return match($num) { 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December', }; } public static function location(array $fields):string { $out = ''; if (!array_key_exists('location', $fields)) { return ''; } if (!empty($fields['location']['address']??'')) { $out .= sprintf( '', jvbIcon('map-pin'), self::renderLocationString($fields['location']), jvbLocationLinks($fields['location']), empty($location['location_notes']??'') ? '' : '
  • '.$fields['location_notes'].'
  • ', ); } return $out; } public static 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'] ); } public static function terms(array $fields, bool $showTaxonomy = true):string { $out = ''; $get = ['city', 'event_category']; foreach ($get as $g) { if (!empty($fields[$g])) { $out .= jvbMetaTermList($fields[$g], $g, true, $showTaxonomy); } } return $out; } }