$method($name, $value, $config); } if ($return) { return $output; } echo $output; return true; } protected function renderTextField(string $name, string $value, array $field):string { return apply_filters('the_content', $value); } protected function renderTextareaField(string $name, string $value, array $field):string { return $this->renderTextField($name, $value, $field); } protected function renderNumberField(string $name, string $value, array $field):string { return $this->renderTextField($name, $value, $field); } protected function renderEmailField(string $name, string $value, array $field):string { $link = 'mailto:'.$value.'?subject='.rawurlencode('Contact from edmonton.ink').'&body='.rawurlencode('Hey, I found you on edmonton.ink, and I wanted to reach out!'); return ''.jvbIcon('email').'Email'; } protected function renderUrlField(string $name, string $value, array $field):string { // jvbDump($value, 'URL Field:'); // jvbDump($field); return ''; } protected function renderImageField(string $name, string $value, array $field):string { if (!is_numeric($value)) { return ''; } return jvbFormatImage($value, 'tiny', 'medium'); } protected function renderGalleryField(string $name, array|null|false $value, array $field):string { // jvbDump($value, 'Gallery Field:'); // jvbDump($field); return ''; } protected function renderTaxonomyField($name, $value, $field):string { if ($value === '') { return ''; } $value = explode(',', $value); $terms = get_terms([ 'taxonomy' => jvbCheckBase($field['taxonomy']), 'terms_in' => $value ]); return jvbRenderTermList($terms, $field['label']); } protected function renderRepeaterField($name, $value, $field):string { // jvbDump($value, 'Repeater Field:'); // jvbDump($field); return ''; } protected function renderGroupField(string $name, array|bool $value, array $field):string { if (empty($value) || !$value || !isset($field['fields'])) { return ''; } $output = '
'; // Add field label if configured to show if (isset($field['show_label']) && $field['show_label'] && !empty($field['label'])) { $output .= '

' . esc_html($field['label']) . '

'; } $output .= '
'; foreach ($field['fields'] as $subfield_name => $subfield_config) { if (!isset($value[$subfield_name]) || empty($value[$subfield_name])) { continue; } $subfield_value = $value[$subfield_name]; // Check if subfield has conditions that prevent display if (isset($subfield_config['condition'])) { $condition = $subfield_config['condition']; $condition_field = $condition['field']; $condition_value = $value[$condition_field] ?? ''; $operator = $condition['operator'] ?? '=='; $expected_value = $condition['value']; $condition_met = false; switch ($operator) { case '==': $condition_met = $condition_value == $expected_value; break; case '!=': $condition_met = $condition_value != $expected_value; break; case 'in': $condition_met = is_array($expected_value) && in_array($condition_value, $expected_value); break; case 'not_in': $condition_met = is_array($expected_value) && !in_array($condition_value, $expected_value); break; } if (!$condition_met) { continue; } } // Render the subfield $subfield_output = $this->render($subfield_name, $subfield_value, $subfield_config, true); if (!empty($subfield_output)) { $output .= '
'; // Add label if configured if (isset($subfield_config['show_label']) && $subfield_config['show_label'] && !empty($subfield_config['label'])) { $output .= '' . esc_html($subfield_config['label']) . ': '; } $output .= $subfield_output; $output .= '
'; } } $output .= '
'; return $output; } protected function renderLocationField(string $name, array|bool $value, array $field): string { if (!$value) { return ''; } // Early return if no location data if (empty($value) || empty($value['lat']) || empty($value['lng'])) { return ''; } $googleMaps = JVB()->connect('maps'); if (!$googleMaps->isSetUp()) { error_log('Google Maps is not set up'); // Fallback to text-only display return $this->renderLocationFallback($value, $field); } error_log('Google Maps: '.print_r($googleMaps, true)); $lat = (float)$value['lat']; $lng = (float)$value['lng']; $address = $googleMaps->formatAddress($value, 'full'); // Map display options (can be configured via field config) $map_options = array_merge([ 'height' => '200px', 'zoom' => 14, 'show_marker' => true, 'show_info_window' => true, 'interactive' => true ], $field['map_options'] ?? []); // Link options $link_options = array_merge([ 'show_icons' => true, 'style' => 'buttons', 'include' => ['google', 'apple'] ], $field['link_options'] ?? []); ob_start(); ?>
renderDisplayMap($value, $map_options); ?>
renderMapLinks($lat, $lng, $address, $link_options); ?>
'; if (!empty($field['label']) && ($field['show_label'] ?? false)) { $output .= '' . esc_html($field['label']) . ': '; } $items = []; foreach ($value as $key) { if (isset($field['options'][$key])) { $items[] = '' . esc_html($field['options'][$key]) . ''; } } $separator = $field['separator'] ?? ', '; $output .= implode($separator, $items); $output .= ''; return $output; } protected function renderCheckboxField(string $name, string $value, array $field):string { // Checkbox fields are essentially the same as set fields for display return $this->renderSetField($name, $value, $field); } protected function renderRadioField(string $name, string $value, array $field):string { if (empty($value) || !isset($field['options'][$value])) { return ''; } $display_value = $field['options'][$value]; $output = '
'; if (!empty($field['label']) && ($field['show_label'] ?? false)) { $output .= '' . esc_html($field['label']) . ': '; } $output .= '' . esc_html($display_value) . ''; $output .= '
'; return $output; } protected function renderSelectField(string $name, string $value, array $field):string { // Select fields display the same as radio fields return $this->renderRadioField($name, $value, $field); } protected function renderTrueFalseField(string $name, bool $value, array $field):string { $display_text = $value ? ($field['true_text'] ?? 'Yes') : ($field['false_text'] ?? 'No'); $css_class = $value ? 'true-value' : 'false-value'; $output = '
'; if (!empty($field['label']) && ($field['show_label'] ?? false)) { $output .= '' . esc_html($field['label']) . ': '; } $output .= '' . esc_html($display_text) . ''; $output .= '
'; return $output; } protected function renderTimeField(string $name, string $value, array $field):string { if (empty($value)) { return ''; } // Format time for display $display_format = $field['display_format'] ?? 'g:i A'; // Default: 12-hour format with AM/PM // Parse the time value $timestamp = strtotime($value); if ($timestamp === false) { return ''; } $formatted_time = date($display_format, $timestamp); // Add icon if configured $show_icon = $field['show_icon'] ?? true; $icon_html = $show_icon ? jvbIcon('time') : ''; return sprintf( '
%s%s
', $icon_html, esc_html($formatted_time) ); } protected function renderDatetimeField(string $name, string $value, array $field):string { if (empty($value)) { return ''; } // Parse datetime $date = DateTime::createFromFormat('Y-m-d H:i:s', $value); if (!$date) { // Try alternative formats $formats = ['Y-m-d\TH:i:s', 'Y-m-d\TH:i', 'Y-m-d H:i']; foreach ($formats as $format) { $date = DateTime::createFromFormat($format, $value); if ($date) break; } } if (!$date) { return ''; } // Format for display $display_format = $field['display_format'] ?? 'F j, Y \a\t g:i A'; // Default: March 15, 2024 at 2:30 PM $formatted_datetime = $date->format($display_format); // Add icon if configured $show_icon = $field['show_icon'] ?? true; $icon_html = $show_icon ? jvbIcon('event') : ''; return sprintf( '
%s%s
', $icon_html, esc_html($formatted_datetime) ); } protected function renderDateField(string $name, string $value, array $field):string { if (empty($value)) { return ''; } $timestamp = strtotime($value); if ($timestamp === false) { return ''; } // Format for display $display_format = $field['display_format'] ?? 'F j, Y'; // Default: March 15, 2024 $formatted_date = date($display_format, $timestamp); // Add icon if configured $show_icon = $field['show_icon'] ?? true; $icon_html = $show_icon ? jvbIcon('event') : ''; return sprintf( '
%s%s
', $icon_html, esc_html($formatted_date) ); } }