PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.4
Yatra – Travel Booking & Tour Operator Software v3.0.4
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 2.0.10 All 83 releases
yatra / templates / shortcodes / trip-search.php

trip-search.php in Yatra – Travel Booking & Tour Operator Software 3.0.4, at templates/shortcodes/trip-search.php

284 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Trip Search Shortcode Template
4 *
5 * @package Yatra
6 * @var array $atts Shortcode attributes
7 * @var array $destinations
8 * @var array $activities
9 * @var string $listing_url
10 * @var array{min:int,max:int} $duration_bounds
11 * @var list<object{value:string,label:string}> $budget_presets
12 */
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 $listing_url = $listing_url ?? home_url('/' . \Yatra\Services\SettingsService::getTripBase() . '/');
19 $duration_bounds = is_array($duration_bounds ?? null) ? $duration_bounds : ['min' => 1, 'max' => 30];
20 $budget_presets = is_array($budget_presets ?? null) ? $budget_presets : [];
21
22 $dmin = max(1, (int) ($duration_bounds['min'] ?? 1));
23 $dmax = max($dmin, (int) ($duration_bounds['max'] ?? 30));
24
25 $active_filters = [
26 's' => isset($_GET['s']) ? sanitize_text_field(wp_unslash((string) $_GET['s'])) : '',
27 'destination' => isset($_GET['destination']) ? sanitize_text_field(wp_unslash((string) $_GET['destination'])) : '',
28 'activity' => isset($_GET['activity']) ? sanitize_text_field(wp_unslash((string) $_GET['activity'])) : '',
29 'duration' => isset($_GET['duration']) ? sanitize_text_field(wp_unslash((string) $_GET['duration'])) : '',
30 'budget' => isset($_GET['budget']) ? sanitize_text_field(wp_unslash((string) $_GET['budget'])) : '',
31 ];
32
33 $dur_initial_min = $dmin;
34 $dur_initial_max = $dmax;
35 if ($active_filters['duration'] !== '' && preg_match('/^(\d+)-(\d+)$/', $active_filters['duration'], $dm)) {
36 $dur_initial_min = max($dmin, (int) $dm[1]);
37 $dur_initial_max = min($dmax, max($dur_initial_min, (int) $dm[2]));
38 }
39
40 $dest_default = __('Destination', 'yatra');
41 $dest_label = $dest_default;
42 if ($active_filters['destination'] !== '') {
43 foreach ($destinations as $d) {
44 if ((string) ($d->slug ?? '') === $active_filters['destination']) {
45 $dest_label = (string) ($d->name ?? $active_filters['destination']);
46 break;
47 }
48 }
49 if ($dest_label === $dest_default) {
50 $dest_label = $active_filters['destination'];
51 }
52 }
53
54 $act_default = __('Activity', 'yatra');
55 $act_label = $act_default;
56 if ($active_filters['activity'] !== '') {
57 foreach ($activities as $a) {
58 if ((string) ($a->slug ?? '') === $active_filters['activity']) {
59 $act_label = (string) ($a->name ?? $active_filters['activity']);
60 break;
61 }
62 }
63 if ($act_label === $act_default) {
64 $act_label = $active_filters['activity'];
65 }
66 }
67
68 $budget_default = __('Budget', 'yatra');
69 $budget_label = $budget_default;
70 if ($active_filters['budget'] !== '') {
71 foreach ($budget_presets as $bp) {
72 if ((string) ($bp->value ?? '') === $active_filters['budget']) {
73 $budget_label = (string) ($bp->label ?? $active_filters['budget']);
74 break;
75 }
76 }
77 if ($budget_label === $budget_default) {
78 $budget_label = $active_filters['budget'];
79 }
80 }
81
82 $dur_display_label = __('Duration', 'yatra');
83 if ($active_filters['duration'] !== '' && preg_match('/^(\d+)-(\d+)$/', $active_filters['duration'], $dmDur)) {
84 $dur_display_label = sprintf(
85 /* translators: 1: min days, 2: max days */
86 __('%1$d – %2$d days', 'yatra'),
87 (int) $dmDur[1],
88 (int) $dmDur[2]
89 );
90 }
91 ?>
92
93 <div class="yatra-trip-search-shortcode" data-listing-url="<?php echo esc_url($listing_url); ?>">
94 <div class="yatra-horizontal-search">
95 <div class="yatra-horizontal-search-container">
96 <div class="yatra-search-bar">
97 <div class="yatra-search-keyword-segment">
98 <label class="screen-reader-text" for="yatra-trip-search-s"><?php esc_html_e('Search trips', 'yatra'); ?></label>
99 <div class="yatra-search-keyword-inner">
100 <span class="yatra-search-keyword-leading" aria-hidden="true"><?php echo yatra_svg_icon('search'); ?></span>
101 <div class="yatra-search-keyword-stack">
102 <span class="yatra-dropdown-label"><?php esc_html_e('Search', 'yatra'); ?></span>
103 <input
104 type="search"
105 id="yatra-trip-search-s"
106 name="s"
107 class="yatra-search-keyword-input"
108 autocomplete="off"
109 inputmode="search"
110 enterkeyhint="search"
111 placeholder="<?php esc_attr_e('Trip name or keyword…', 'yatra'); ?>"
112 value="<?php echo esc_attr($active_filters['s']); ?>"
113 >
114 </div>
115 </div>
116 </div>
117
118 <div class="yatra-search-divider"></div>
119
120 <div class="yatra-search-dropdown" data-dropdown="destination">
121 <div class="yatra-dropdown-trigger">
122 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
123 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"/>
124 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"/>
125 </svg>
126 <div class="yatra-dropdown-content">
127 <span class="yatra-dropdown-label"><?php esc_html_e('Destination', 'yatra'); ?></span>
128 <span class="yatra-dropdown-value"><?php echo esc_html($dest_label); ?></span>
129 </div>
130 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
131 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
132 </svg>
133 </div>
134 <div class="yatra-dropdown-menu yatra-dropdown-menu--filterable">
135 <div class="yatra-dropdown-search-wrap">
136 <label class="screen-reader-text" for="yatra-trip-search-dest-filter"><?php esc_html_e('Search destinations', 'yatra'); ?></label>
137 <input
138 type="search"
139 id="yatra-trip-search-dest-filter"
140 class="yatra-dropdown-filter-input"
141 placeholder="<?php esc_attr_e('Search destinations…', 'yatra'); ?>"
142 autocomplete="off"
143 tabindex="0"
144 >
145 </div>
146 <div class="yatra-dropdown-options">
147 <?php if (!empty($destinations)) : ?>
148 <div class="yatra-dropdown-option<?php echo $active_filters['destination'] === '' ? ' selected' : ''; ?>" data-value="" data-search-text="<?php echo esc_attr(__('Any destination', 'yatra')); ?>"><?php esc_html_e('Any destination', 'yatra'); ?></div>
149 <?php foreach ($destinations as $dest) : ?>
150 <?php
151 $dname = (string) ($dest->name ?? '');
152 $dslug = (string) ($dest->slug ?? '');
153 ?>
154 <div class="yatra-dropdown-option<?php echo ($active_filters['destination'] === $dslug) ? ' selected' : ''; ?>" data-value="<?php echo esc_attr($dslug); ?>" data-search-text="<?php echo esc_attr($dname . ' ' . $dslug); ?>">
155 <?php echo esc_html($dname); ?>
156 </div>
157 <?php endforeach; ?>
158 <?php else : ?>
159 <div class="yatra-dropdown-option selected" data-value="" data-search-text=""><?php esc_html_e('All destinations', 'yatra'); ?></div>
160 <?php endif; ?>
161 </div>
162 </div>
163 </div>
164
165 <div class="yatra-search-divider"></div>
166
167 <div class="yatra-search-dropdown" data-dropdown="activities">
168 <div class="yatra-dropdown-trigger">
169 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
170 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
171 </svg>
172 <div class="yatra-dropdown-content">
173 <span class="yatra-dropdown-label"><?php esc_html_e('Activities', 'yatra'); ?></span>
174 <span class="yatra-dropdown-value"><?php echo esc_html($act_label); ?></span>
175 </div>
176 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
177 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
178 </svg>
179 </div>
180 <div class="yatra-dropdown-menu yatra-dropdown-menu--filterable">
181 <div class="yatra-dropdown-search-wrap">
182 <label class="screen-reader-text" for="yatra-trip-search-act-filter"><?php esc_html_e('Search activities', 'yatra'); ?></label>
183 <input
184 type="search"
185 id="yatra-trip-search-act-filter"
186 class="yatra-dropdown-filter-input"
187 placeholder="<?php esc_attr_e('Search activities…', 'yatra'); ?>"
188 autocomplete="off"
189 tabindex="0"
190 >
191 </div>
192 <div class="yatra-dropdown-options">
193 <?php if (!empty($activities)) : ?>
194 <div class="yatra-dropdown-option<?php echo $active_filters['activity'] === '' ? ' selected' : ''; ?>" data-value="" data-search-text="<?php echo esc_attr(__('Any activity', 'yatra')); ?>"><?php esc_html_e('Any activity', 'yatra'); ?></div>
195 <?php foreach ($activities as $act) : ?>
196 <?php
197 $aname = (string) ($act->name ?? '');
198 $aslug = (string) ($act->slug ?? '');
199 ?>
200 <div class="yatra-dropdown-option<?php echo ($active_filters['activity'] === $aslug) ? ' selected' : ''; ?>" data-value="<?php echo esc_attr($aslug); ?>" data-search-text="<?php echo esc_attr($aname . ' ' . $aslug); ?>">
201 <?php echo esc_html($aname); ?>
202 </div>
203 <?php endforeach; ?>
204 <?php else : ?>
205 <div class="yatra-dropdown-option selected" data-value="" data-search-text=""><?php esc_html_e('All activities', 'yatra'); ?></div>
206 <?php endif; ?>
207 </div>
208 </div>
209 </div>
210
211 <div class="yatra-search-divider"></div>
212
213 <div class="yatra-search-dropdown" data-dropdown="duration" data-duration-min="<?php echo esc_attr((string) $dmin); ?>" data-duration-max="<?php echo esc_attr((string) $dmax); ?>">
214 <div class="yatra-dropdown-trigger">
215 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
216 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 018 0z"/>
217 </svg>
218 <div class="yatra-dropdown-content">
219 <span class="yatra-dropdown-label"><?php esc_html_e('Duration', 'yatra'); ?></span>
220 <span class="yatra-dropdown-value"><?php echo esc_html($dur_display_label); ?></span>
221 </div>
222 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
223 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
224 </svg>
225 </div>
226 <div class="yatra-dropdown-menu yatra-duration-menu">
227 <div class="yatra-duration-slider-wrapper">
228 <div class="yatra-duration-header">
229 <div class="yatra-duration-title"><?php esc_html_e('Select Trip Duration', 'yatra'); ?></div>
230 <div class="yatra-duration-subtitle"><?php esc_html_e('Choose your preferred trip length', 'yatra'); ?></div>
231 </div>
232 <div class="yatra-duration-badges">
233 <span class="yatra-duration-badge yatra-duration-min-badge"></span>
234 <span class="yatra-duration-badge yatra-duration-max-badge"></span>
235 </div>
236 <div class="yatra-dual-range-slider">
237 <input type="range" id="durationMin" min="<?php echo esc_attr((string) $dmin); ?>" max="<?php echo esc_attr((string) $dmax); ?>" value="<?php echo esc_attr((string) $dur_initial_min); ?>" class="yatra-range-min">
238 <input type="range" id="durationMax" min="<?php echo esc_attr((string) $dmin); ?>" max="<?php echo esc_attr((string) $dmax); ?>" value="<?php echo esc_attr((string) $dur_initial_max); ?>" class="yatra-range-max">
239 <div class="yatra-slider-track"></div>
240 <div class="yatra-slider-range"></div>
241 </div>
242 </div>
243 </div>
244 </div>
245
246 <div class="yatra-search-divider"></div>
247
248 <div class="yatra-search-dropdown" data-dropdown="budget">
249 <div class="yatra-dropdown-trigger">
250 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
251 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"/>
252 </svg>
253 <div class="yatra-dropdown-content">
254 <span class="yatra-dropdown-label"><?php esc_html_e('Budget', 'yatra'); ?></span>
255 <span class="yatra-dropdown-value"><?php echo esc_html($budget_label); ?></span>
256 </div>
257 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
258 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
259 </svg>
260 </div>
261 <div class="yatra-dropdown-menu">
262 <?php if (!empty($budget_presets)) : ?>
263 <div class="yatra-dropdown-option<?php echo $active_filters['budget'] === '' ? ' selected' : ''; ?>" data-value=""><?php esc_html_e('Any budget', 'yatra'); ?></div>
264 <?php foreach ($budget_presets as $preset) : ?>
265 <div class="yatra-dropdown-option<?php echo ($active_filters['budget'] === (string) ($preset->value ?? '')) ? ' selected' : ''; ?>" data-value="<?php echo esc_attr($preset->value ?? ''); ?>">
266 <?php echo esc_html($preset->label ?? ''); ?>
267 </div>
268 <?php endforeach; ?>
269 <?php else : ?>
270 <div class="yatra-dropdown-option selected" data-value=""><?php esc_html_e('No price data yet', 'yatra'); ?></div>
271 <?php endif; ?>
272 </div>
273 </div>
274
275 <div class="yatra-search-button-container">
276 <button type="button" class="yatra-search-main-btn">
277 <?php esc_html_e('Search', 'yatra'); ?>
278 </button>
279 </div>
280 </div>
281 </div>
282 </div>
283 </div>
284