PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.9
Yatra – Travel Booking & Tour Operator Software v3.0.9
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 / shortcodes / trip-search.php

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

307 lines 18.6 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 // Per-field visibility is owned entirely by the SearchShortcode: for each field
93 // an explicit shortcode attribute (e.g. [yatra_search budget="no"]) wins, and
94 // when omitted it inherits the global Settings → Search & Listing toggle. The
95 // resolved result is handed to this template in $field_visibility. This template
96 // is purely presentational — it never reads the settings itself. Missing keys
97 // default to visible, so the bar still renders if loaded without the shortcode.
98 $field_visibility = (isset($field_visibility) && is_array($field_visibility)) ? $field_visibility : [];
99 $show_keyword = (bool) ($field_visibility['keyword'] ?? true);
100 $show_destination = (bool) ($field_visibility['destination'] ?? true);
101 $show_activities = (bool) ($field_visibility['activities'] ?? true);
102 $show_duration = (bool) ($field_visibility['duration'] ?? true);
103 $show_budget = (bool) ($field_visibility['budget'] ?? true);
104
105 // Tracks whether a field has been rendered yet, so a divider is only emitted
106 // BETWEEN visible fields (no leading/trailing/double dividers when some are off).
107 $yatra_search_rendered = false;
108 ?>
109
110 <div class="yatra-trip-search-shortcode" data-listing-url="<?php echo esc_url($listing_url); ?>">
111 <div class="yatra-horizontal-search">
112 <div class="yatra-horizontal-search-container">
113 <div class="yatra-search-bar">
114 <?php if ($show_keyword) : ?>
115 <div class="yatra-search-keyword-segment">
116 <label class="screen-reader-text" for="yatra-trip-search-s"><?php esc_html_e('Search trips', 'yatra'); ?></label>
117 <div class="yatra-search-keyword-inner">
118 <span class="yatra-search-keyword-leading" aria-hidden="true"><?php echo yatra_svg_icon('search'); ?></span>
119 <div class="yatra-search-keyword-stack">
120 <span class="yatra-dropdown-label"><?php esc_html_e('Search', 'yatra'); ?></span>
121 <input
122 type="search"
123 id="yatra-trip-search-s"
124 name="s"
125 class="yatra-search-keyword-input"
126 autocomplete="off"
127 inputmode="search"
128 enterkeyhint="search"
129 placeholder="<?php esc_attr_e('Trip name or keyword…', 'yatra'); ?>"
130 value="<?php echo esc_attr($active_filters['s']); ?>"
131 >
132 </div>
133 </div>
134 </div>
135 <?php $yatra_search_rendered = true; endif; ?>
136
137 <?php if ($show_destination) : ?>
138 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
139 <div class="yatra-search-dropdown" data-dropdown="destination">
140 <div class="yatra-dropdown-trigger">
141 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
142 <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"/>
143 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"/>
144 </svg>
145 <div class="yatra-dropdown-content">
146 <span class="yatra-dropdown-label"><?php esc_html_e('Destination', 'yatra'); ?></span>
147 <span class="yatra-dropdown-value"><?php echo esc_html($dest_label); ?></span>
148 </div>
149 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
150 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
151 </svg>
152 </div>
153 <div class="yatra-dropdown-menu yatra-dropdown-menu--filterable">
154 <div class="yatra-dropdown-search-wrap">
155 <label class="screen-reader-text" for="yatra-trip-search-dest-filter"><?php esc_html_e('Search destinations', 'yatra'); ?></label>
156 <input
157 type="search"
158 id="yatra-trip-search-dest-filter"
159 class="yatra-dropdown-filter-input"
160 placeholder="<?php esc_attr_e('Search destinations…', 'yatra'); ?>"
161 autocomplete="off"
162 tabindex="0"
163 >
164 </div>
165 <div class="yatra-dropdown-options">
166 <?php if (!empty($destinations)) : ?>
167 <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>
168 <?php foreach ($destinations as $dest) : ?>
169 <?php
170 $dname = (string) ($dest->name ?? '');
171 $dslug = (string) ($dest->slug ?? '');
172 ?>
173 <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); ?>">
174 <?php echo esc_html($dname); ?>
175 </div>
176 <?php endforeach; ?>
177 <?php else : ?>
178 <div class="yatra-dropdown-option selected" data-value="" data-search-text=""><?php esc_html_e('All destinations', 'yatra'); ?></div>
179 <?php endif; ?>
180 </div>
181 </div>
182 </div>
183 <?php $yatra_search_rendered = true; endif; ?>
184
185 <?php if ($show_activities) : ?>
186 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
187 <div class="yatra-search-dropdown" data-dropdown="activities">
188 <div class="yatra-dropdown-trigger">
189 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
190 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
191 </svg>
192 <div class="yatra-dropdown-content">
193 <span class="yatra-dropdown-label"><?php esc_html_e('Activities', 'yatra'); ?></span>
194 <span class="yatra-dropdown-value"><?php echo esc_html($act_label); ?></span>
195 </div>
196 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
197 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
198 </svg>
199 </div>
200 <div class="yatra-dropdown-menu yatra-dropdown-menu--filterable">
201 <div class="yatra-dropdown-search-wrap">
202 <label class="screen-reader-text" for="yatra-trip-search-act-filter"><?php esc_html_e('Search activities', 'yatra'); ?></label>
203 <input
204 type="search"
205 id="yatra-trip-search-act-filter"
206 class="yatra-dropdown-filter-input"
207 placeholder="<?php esc_attr_e('Search activities…', 'yatra'); ?>"
208 autocomplete="off"
209 tabindex="0"
210 >
211 </div>
212 <div class="yatra-dropdown-options">
213 <?php if (!empty($activities)) : ?>
214 <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>
215 <?php foreach ($activities as $act) : ?>
216 <?php
217 $aname = (string) ($act->name ?? '');
218 $aslug = (string) ($act->slug ?? '');
219 ?>
220 <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); ?>">
221 <?php echo esc_html($aname); ?>
222 </div>
223 <?php endforeach; ?>
224 <?php else : ?>
225 <div class="yatra-dropdown-option selected" data-value="" data-search-text=""><?php esc_html_e('All activities', 'yatra'); ?></div>
226 <?php endif; ?>
227 </div>
228 </div>
229 </div>
230 <?php $yatra_search_rendered = true; endif; ?>
231
232 <?php if ($show_duration) : ?>
233 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
234 <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); ?>">
235 <div class="yatra-dropdown-trigger">
236 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
237 <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"/>
238 </svg>
239 <div class="yatra-dropdown-content">
240 <span class="yatra-dropdown-label"><?php esc_html_e('Duration', 'yatra'); ?></span>
241 <span class="yatra-dropdown-value"><?php echo esc_html($dur_display_label); ?></span>
242 </div>
243 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
244 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
245 </svg>
246 </div>
247 <div class="yatra-dropdown-menu yatra-duration-menu">
248 <div class="yatra-duration-slider-wrapper">
249 <div class="yatra-duration-header">
250 <div class="yatra-duration-title"><?php esc_html_e('Select Trip Duration', 'yatra'); ?></div>
251 <div class="yatra-duration-subtitle"><?php esc_html_e('Choose your preferred trip length', 'yatra'); ?></div>
252 </div>
253 <div class="yatra-duration-badges">
254 <span class="yatra-duration-badge yatra-duration-min-badge"></span>
255 <span class="yatra-duration-badge yatra-duration-max-badge"></span>
256 </div>
257 <div class="yatra-dual-range-slider">
258 <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">
259 <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">
260 <div class="yatra-slider-track"></div>
261 <div class="yatra-slider-range"></div>
262 </div>
263 </div>
264 </div>
265 </div>
266 <?php $yatra_search_rendered = true; endif; ?>
267
268 <?php if ($show_budget) : ?>
269 <?php if ($yatra_search_rendered) : ?><div class="yatra-search-divider"></div><?php endif; ?>
270 <div class="yatra-search-dropdown" data-dropdown="budget">
271 <div class="yatra-dropdown-trigger">
272 <svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
273 <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"/>
274 </svg>
275 <div class="yatra-dropdown-content">
276 <span class="yatra-dropdown-label"><?php esc_html_e('Budget', 'yatra'); ?></span>
277 <span class="yatra-dropdown-value"><?php echo esc_html($budget_label); ?></span>
278 </div>
279 <svg class="yatra-dropdown-arrow" width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
280 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
281 </svg>
282 </div>
283 <div class="yatra-dropdown-menu">
284 <?php if (!empty($budget_presets)) : ?>
285 <div class="yatra-dropdown-option<?php echo $active_filters['budget'] === '' ? ' selected' : ''; ?>" data-value=""><?php esc_html_e('Any budget', 'yatra'); ?></div>
286 <?php foreach ($budget_presets as $preset) : ?>
287 <div class="yatra-dropdown-option<?php echo ($active_filters['budget'] === (string) ($preset->value ?? '')) ? ' selected' : ''; ?>" data-value="<?php echo esc_attr($preset->value ?? ''); ?>">
288 <?php echo esc_html($preset->label ?? ''); ?>
289 </div>
290 <?php endforeach; ?>
291 <?php else : ?>
292 <div class="yatra-dropdown-option selected" data-value=""><?php esc_html_e('No price data yet', 'yatra'); ?></div>
293 <?php endif; ?>
294 </div>
295 </div>
296 <?php $yatra_search_rendered = true; endif; ?>
297
298 <div class="yatra-search-button-container">
299 <button type="button" class="yatra-search-main-btn">
300 <?php esc_html_e('Search', 'yatra'); ?>
301 </button>
302 </div>
303 </div>
304 </div>
305 </div>
306 </div>
307