PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.15
Yatra – Travel Booking & Tour Operator Software v3.0.15
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.15, at templates/shortcodes/trip-search.php

340 lines 20.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 // Pre-fill the date picker from the URL, but only if it is a real Y-m-d date.
32 'available_date' => isset($_GET['available_date'])
33 ? \Yatra\Helpers\TripListingFilterBuilder::normalizeAvailableDate((string) wp_unslash($_GET['available_date']))
34 : '',
35 ];
36
37 $dur_initial_min = $dmin;
38 $dur_initial_max = $dmax;
39 if ($active_filters['duration'] !== '' && preg_match('/^(\d+)-(\d+)$/', $active_filters['duration'], $dm)) {
40 $dur_initial_min = max($dmin, (int) $dm[1]);
41 $dur_initial_max = min($dmax, max($dur_initial_min, (int) $dm[2]));
42 }
43
44 $dest_default = __('Destination', 'yatra');
45 $dest_label = $dest_default;
46 if ($active_filters['destination'] !== '') {
47 foreach ($destinations as $d) {
48 if ((string) ($d->slug ?? '') === $active_filters['destination']) {
49 $dest_label = (string) ($d->name ?? $active_filters['destination']);
50 break;
51 }
52 }
53 if ($dest_label === $dest_default) {
54 $dest_label = $active_filters['destination'];
55 }
56 }
57
58 $act_default = __('Activity', 'yatra');
59 $act_label = $act_default;
60 if ($active_filters['activity'] !== '') {
61 foreach ($activities as $a) {
62 if ((string) ($a->slug ?? '') === $active_filters['activity']) {
63 $act_label = (string) ($a->name ?? $active_filters['activity']);
64 break;
65 }
66 }
67 if ($act_label === $act_default) {
68 $act_label = $active_filters['activity'];
69 }
70 }
71
72 $budget_default = __('Budget', 'yatra');
73 $budget_label = $budget_default;
74 if ($active_filters['budget'] !== '') {
75 foreach ($budget_presets as $bp) {
76 if ((string) ($bp->value ?? '') === $active_filters['budget']) {
77 $budget_label = (string) ($bp->label ?? $active_filters['budget']);
78 break;
79 }
80 }
81 if ($budget_label === $budget_default) {
82 $budget_label = $active_filters['budget'];
83 }
84 }
85
86 $dur_display_label = __('Duration', 'yatra');
87 if ($active_filters['duration'] !== '' && preg_match('/^(\d+)-(\d+)$/', $active_filters['duration'], $dmDur)) {
88 $dur_display_label = sprintf(
89 /* translators: 1: min days, 2: max days */
90 __('%1$d – %2$d days', 'yatra'),
91 (int) $dmDur[1],
92 (int) $dmDur[2]
93 );
94 }
95
96 // Per-field visibility is owned entirely by the SearchShortcode: for each field
97 // an explicit shortcode attribute (e.g. [yatra_search budget="no"]) wins, and
98 // when omitted it inherits the global Settings → Search & Listing toggle. The
99 // resolved result is handed to this template in $field_visibility. This template
100 // is purely presentational — it never reads the settings itself. Missing keys
101 // default to visible, so the bar still renders if loaded without the shortcode.
102 $field_visibility = (isset($field_visibility) && is_array($field_visibility)) ? $field_visibility : [];
103 $show_keyword = (bool) ($field_visibility['keyword'] ?? true);
104 $show_destination = (bool) ($field_visibility['destination'] ?? true);
105 $show_activities = (bool) ($field_visibility['activities'] ?? true);
106 $show_duration = (bool) ($field_visibility['duration'] ?? true);
107 $show_budget = (bool) ($field_visibility['budget'] ?? true);
108 $show_date = (bool) ($field_visibility['date'] ?? false);
109 $date_min = current_time('Y-m-d');
110
111 // Tracks whether a field has been rendered yet, so a divider is only emitted
112 // BETWEEN visible fields (no leading/trailing/double dividers when some are off).
113 $yatra_search_rendered = false;
114 ?>
115
116 <div class="yatra-trip-search-shortcode" data-listing-url="<?php echo esc_url($listing_url); ?>">
117 <div class="yatra-horizontal-search">
118 <div class="yatra-horizontal-search-container">
119 <div class="yatra-search-bar">
120 <?php if ($show_keyword) : ?>
121 <div class="yatra-search-keyword-segment">
122 <label class="screen-reader-text" for="yatra-trip-search-s"><?php esc_html_e('Search trips', 'yatra'); ?></label>
123 <div class="yatra-search-keyword-inner">
124 <span class="yatra-search-keyword-leading" aria-hidden="true"><?php echo yatra_svg_icon('search'); ?></span>
125 <div class="yatra-search-keyword-stack">
126 <span class="yatra-dropdown-label"><?php esc_html_e('Search', 'yatra'); ?></span>
127 <input
128 type="search"
129 id="yatra-trip-search-s"
130 name="s"
131 class="yatra-search-keyword-input"
132 autocomplete="off"
133 inputmode="search"
134 enterkeyhint="search"
135 placeholder="<?php esc_attr_e('Trip name or keyword…', 'yatra'); ?>"
136 value="<?php echo esc_attr($active_filters['s']); ?>"
137 >
138 </div>
139 </div>
140 </div>
141 <?php $yatra_search_rendered = true; endif; ?>
142
143 <?php if ($show_destination) : ?>
144 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
145 <div class="yatra-search-dropdown" data-dropdown="destination">
146 <div class="yatra-dropdown-trigger">
147 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
148 <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"/>
149 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"/>
150 </svg>
151 <div class="yatra-dropdown-content">
152 <span class="yatra-dropdown-label"><?php esc_html_e('Destination', 'yatra'); ?></span>
153 <span class="yatra-dropdown-value"><?php echo esc_html($dest_label); ?></span>
154 </div>
155 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
156 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
157 </svg>
158 </div>
159 <div class="yatra-dropdown-menu yatra-dropdown-menu--filterable">
160 <div class="yatra-dropdown-search-wrap">
161 <label class="screen-reader-text" for="yatra-trip-search-dest-filter"><?php esc_html_e('Search destinations', 'yatra'); ?></label>
162 <input
163 type="search"
164 id="yatra-trip-search-dest-filter"
165 class="yatra-dropdown-filter-input"
166 placeholder="<?php esc_attr_e('Search destinations…', 'yatra'); ?>"
167 autocomplete="off"
168 tabindex="0"
169 >
170 </div>
171 <div class="yatra-dropdown-options">
172 <?php if (!empty($destinations)) : ?>
173 <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>
174 <?php foreach ($destinations as $dest) : ?>
175 <?php
176 $dname = (string) ($dest->name ?? '');
177 $dslug = (string) ($dest->slug ?? '');
178 ?>
179 <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); ?>">
180 <?php echo esc_html($dname); ?>
181 </div>
182 <?php endforeach; ?>
183 <?php else : ?>
184 <div class="yatra-dropdown-option selected" data-value="" data-search-text=""><?php esc_html_e('All destinations', 'yatra'); ?></div>
185 <?php endif; ?>
186 </div>
187 </div>
188 </div>
189 <?php $yatra_search_rendered = true; endif; ?>
190
191 <?php if ($show_date) : ?>
192 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
193 <div class="yatra-search-date-segment">
194 <label class="screen-reader-text" for="yatra-trip-search-date"><?php esc_html_e('Travel date', 'yatra'); ?></label>
195 <div class="yatra-search-date-inner">
196 <span class="yatra-search-date-leading" aria-hidden="true">
197 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
198 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
199 </svg>
200 </span>
201 <div class="yatra-search-date-stack">
202 <span class="yatra-dropdown-label"><?php esc_html_e('Date', 'yatra'); ?></span>
203 <input
204 type="date"
205 id="yatra-trip-search-date"
206 name="available_date"
207 class="yatra-search-date-input"
208 autocomplete="off"
209 placeholder="<?php esc_attr_e('Any date', 'yatra'); ?>"
210 min="<?php echo esc_attr($date_min); ?>"
211 value="<?php echo esc_attr($active_filters['available_date']); ?>"
212 >
213 </div>
214 </div>
215 </div>
216 <?php $yatra_search_rendered = true; endif; ?>
217
218 <?php if ($show_activities) : ?>
219 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
220 <div class="yatra-search-dropdown" data-dropdown="activities">
221 <div class="yatra-dropdown-trigger">
222 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
223 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
224 </svg>
225 <div class="yatra-dropdown-content">
226 <span class="yatra-dropdown-label"><?php esc_html_e('Activities', 'yatra'); ?></span>
227 <span class="yatra-dropdown-value"><?php echo esc_html($act_label); ?></span>
228 </div>
229 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
230 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
231 </svg>
232 </div>
233 <div class="yatra-dropdown-menu yatra-dropdown-menu--filterable">
234 <div class="yatra-dropdown-search-wrap">
235 <label class="screen-reader-text" for="yatra-trip-search-act-filter"><?php esc_html_e('Search activities', 'yatra'); ?></label>
236 <input
237 type="search"
238 id="yatra-trip-search-act-filter"
239 class="yatra-dropdown-filter-input"
240 placeholder="<?php esc_attr_e('Search activities…', 'yatra'); ?>"
241 autocomplete="off"
242 tabindex="0"
243 >
244 </div>
245 <div class="yatra-dropdown-options">
246 <?php if (!empty($activities)) : ?>
247 <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>
248 <?php foreach ($activities as $act) : ?>
249 <?php
250 $aname = (string) ($act->name ?? '');
251 $aslug = (string) ($act->slug ?? '');
252 ?>
253 <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); ?>">
254 <?php echo esc_html($aname); ?>
255 </div>
256 <?php endforeach; ?>
257 <?php else : ?>
258 <div class="yatra-dropdown-option selected" data-value="" data-search-text=""><?php esc_html_e('All activities', 'yatra'); ?></div>
259 <?php endif; ?>
260 </div>
261 </div>
262 </div>
263 <?php $yatra_search_rendered = true; endif; ?>
264
265 <?php if ($show_duration) : ?>
266 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
267 <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); ?>">
268 <div class="yatra-dropdown-trigger">
269 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
270 <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"/>
271 </svg>
272 <div class="yatra-dropdown-content">
273 <span class="yatra-dropdown-label"><?php esc_html_e('Duration', 'yatra'); ?></span>
274 <span class="yatra-dropdown-value"><?php echo esc_html($dur_display_label); ?></span>
275 </div>
276 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
277 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
278 </svg>
279 </div>
280 <div class="yatra-dropdown-menu yatra-duration-menu">
281 <div class="yatra-duration-slider-wrapper">
282 <div class="yatra-duration-header">
283 <div class="yatra-duration-title"><?php esc_html_e('Select Trip Duration', 'yatra'); ?></div>
284 <div class="yatra-duration-subtitle"><?php esc_html_e('Choose your preferred trip length', 'yatra'); ?></div>
285 </div>
286 <div class="yatra-duration-badges">
287 <span class="yatra-duration-badge yatra-duration-min-badge"></span>
288 <span class="yatra-duration-badge yatra-duration-max-badge"></span>
289 </div>
290 <div class="yatra-dual-range-slider">
291 <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">
292 <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">
293 <div class="yatra-slider-track"></div>
294 <div class="yatra-slider-range"></div>
295 </div>
296 </div>
297 </div>
298 </div>
299 <?php $yatra_search_rendered = true; endif; ?>
300
301 <?php if ($show_budget) : ?>
302 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
303 <div class="yatra-search-dropdown" data-dropdown="budget">
304 <div class="yatra-dropdown-trigger">
305 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
306 <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"/>
307 </svg>
308 <div class="yatra-dropdown-content">
309 <span class="yatra-dropdown-label"><?php esc_html_e('Budget', 'yatra'); ?></span>
310 <span class="yatra-dropdown-value"><?php echo esc_html($budget_label); ?></span>
311 </div>
312 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
313 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
314 </svg>
315 </div>
316 <div class="yatra-dropdown-menu">
317 <?php if (!empty($budget_presets)) : ?>
318 <div class="yatra-dropdown-option<?php echo $active_filters['budget'] === '' ? ' selected' : ''; ?>" data-value=""><?php esc_html_e('Any budget', 'yatra'); ?></div>
319 <?php foreach ($budget_presets as $preset) : ?>
320 <div class="yatra-dropdown-option<?php echo ($active_filters['budget'] === (string) ($preset->value ?? '')) ? ' selected' : ''; ?>" data-value="<?php echo esc_attr($preset->value ?? ''); ?>">
321 <?php echo esc_html($preset->label ?? ''); ?>
322 </div>
323 <?php endforeach; ?>
324 <?php else : ?>
325 <div class="yatra-dropdown-option selected" data-value=""><?php esc_html_e('No price data yet', 'yatra'); ?></div>
326 <?php endif; ?>
327 </div>
328 </div>
329 <?php $yatra_search_rendered = true; endif; ?>
330
331 <div class="yatra-search-button-container">
332 <button type="button" class="yatra-search-main-btn">
333 <?php esc_html_e('Search', 'yatra'); ?>
334 </button>
335 </div>
336 </div>
337 </div>
338 </div>
339 </div>
340