PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.8
Yatra – Travel Booking & Tour Operator Software v3.0.2.8
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / templates / partials / single-trip / trip-attributes.php

trip-attributes.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.8, at templates/partials/single-trip/trip-attributes.php

145 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 // Trip Attributes Section for Single Trip Page
7 // Expected variables: $trip
8 ?>
9 <div class="yatra-trip-attributes">
10 <div class="yatra-section-header">
11 <h2 class="yatra-section-title"><?php echo esc_html__('Trip Attributes', 'yatra'); ?></h2>
12 <p class="yatra-section-description"><?php echo esc_html__('Key features and characteristics', 'yatra'); ?></p>
13 </div>
14
15 <div class="yatra-spec-sheet yatra-spec-sheet--attributes-grid">
16 <div class="yatra-attributes-grid">
17 <?php foreach ($trip->getAttributes() as $attribute): ?>
18 <div class="yatra-attribute-item">
19 <div class="yatra-attribute-icon">
20 <?php if ($attribute['icon']): ?>
21 <?php if ($attribute['icon']['type'] === 'image'): ?>
22 <img src="<?php echo esc_url($attribute['icon']['value']); ?>" alt="<?php echo esc_attr($attribute['name']); ?>" class="yatra-attribute-icon-img">
23 <?php else: ?>
24 <?php echo yatra_svg_icon($attribute['icon']['value'], 'yatra-icon'); ?>
25 <?php endif; ?>
26 <?php else: ?>
27 <?php echo yatra_svg_icon('tag', 'yatra-icon'); ?>
28 <?php endif; ?>
29 </div>
30
31 <div class="yatra-attribute-content">
32 <div class="yatra-attribute-name"><?php echo esc_html($attribute['name']); ?></div>
33 <div class="yatra-attribute-value">
34 <?php
35 // Display value based on field type
36 switch ($attribute['field_type']) {
37 case 'checkbox':
38 $cb_val = $attribute['value'] ?? null;
39 $cb_options = json_decode($attribute['field_options'] ?? '[]', true);
40 if (!is_array($cb_options)) {
41 $cb_options = [];
42 }
43 if (is_array($cb_val)) {
44 $labels = [];
45 foreach ($cb_options as $opt) {
46 if (!isset($opt['value'], $opt['label'])) {
47 continue;
48 }
49 foreach ($cb_val as $v) {
50 if ((string) $v === (string) $opt['value']) {
51 $labels[] = $opt['label'];
52 break;
53 }
54 }
55 }
56 echo esc_html($labels !== [] ? implode(', ', $labels) : '—');
57 } else {
58 echo $cb_val ? esc_html__('Yes', 'yatra') : esc_html__('No', 'yatra');
59 }
60 break;
61 case 'select':
62 case 'radio':
63 $options = json_decode($attribute['field_options'] ?? '[]', true);
64 if (!is_array($options)) {
65 $options = [];
66 }
67 $selected_value = is_array($attribute['value']) ? ($attribute['value'][0] ?? null) : ($attribute['value'] ?? null);
68 $matched_label = null;
69 foreach ($options as $option) {
70 if (!is_array($option) || !isset($option['value'], $option['label'])) {
71 continue;
72 }
73 if ((string) $option['value'] === (string) $selected_value) {
74 $matched_label = (string) $option['label'];
75 break;
76 }
77 }
78 if ($matched_label !== null) {
79 echo esc_html($matched_label);
80 } elseif ($selected_value !== null && $selected_value !== '') {
81 echo esc_html((string) $selected_value);
82 } else {
83 echo esc_html('—');
84 }
85 break;
86 case 'date':
87 echo esc_html(date_i18n(get_option('date_format'), strtotime($attribute['value'])));
88 break;
89 case 'time':
90 echo esc_html(date_i18n(get_option('time_format'), strtotime($attribute['value'])));
91 break;
92 case 'color':
93 echo '<span class="yatra-color-swatch" style="background-color: ' . esc_attr($attribute['value']) . ';" title="' . esc_attr($attribute['value']) . '"></span>' . esc_html($attribute['value']);
94 break;
95 case 'url':
96 case 'file':
97 $link = (string) ($attribute['value'] ?? '');
98 if ($link !== '' && filter_var($link, FILTER_VALIDATE_URL)) {
99 echo '<a href="' . esc_url($link) . '" target="_blank" rel="noopener noreferrer">' . esc_html($link) . '</a>';
100 } else {
101 echo esc_html($link !== '' ? $link : '—');
102 }
103 break;
104 case 'email':
105 echo '<a href="mailto:' . esc_attr($attribute['value']) . '">' . esc_html($attribute['value']) . '</a>';
106 break;
107 case 'textarea':
108 // Truncate long textareas for compact display
109 $text = wp_strip_all_tags((string) ($attribute['value'] ?? ''));
110 $snippet = function_exists('mb_substr') ? mb_substr($text, 0, 50) : substr($text, 0, 50);
111 $long = function_exists('mb_strlen') ? mb_strlen($text) : strlen($text);
112 echo esc_html($snippet . ($long > 50 ? '...' : ''));
113 break;
114 case 'number':
115 $nv = $attribute['value'] ?? null;
116 echo esc_html(is_numeric($nv) ? (string) (0 + $nv) : (string) $nv);
117 break;
118 case 'text_field':
119 default:
120 $raw = $attribute['value'] ?? '';
121 if (is_array($raw)) {
122 $flat = [];
123 foreach ($raw as $piece) {
124 $flat[] = is_scalar($piece) ? (string) $piece : '';
125 }
126 echo esc_html(implode(', ', array_filter($flat, static fn ($s) => $s !== '')));
127 } else {
128 $text = wp_strip_all_tags((string) $raw);
129 $snippet = function_exists('mb_substr') ? mb_substr($text, 0, 30) : substr($text, 0, 30);
130 $long = function_exists('mb_strlen') ? mb_strlen($text) : strlen($text);
131 echo esc_html($snippet . ($long > 30 ? '...' : ''));
132 }
133 break;
134 }
135 ?>
136 </div>
137 <?php if (!empty($attribute['description'])): ?>
138 <div class="yatra-attribute-description"><?php echo esc_html(substr($attribute['description'], 0, 40) . (strlen($attribute['description']) > 40 ? '...' : '')); ?></div>
139 <?php endif; ?>
140 </div>
141 </div>
142 <?php endforeach; ?>
143 </div>
144 </div>
145 </div>