PluginProbe
Yatra – Travel Booking & Tour Operator Software / 2.0.0
Yatra – Travel Booking & Tour Operator Software v2.0.0
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 2.0.11 All 82 releases
yatra / includes / functions.php

functions.php in Yatra – Travel Booking & Tour Operator Software 2.0.0, at includes/functions.php

529 lines 15.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || exit;
3
4 // Load Helpers
5
6 include_once YATRA_ABSPATH . 'includes/helpers/yatra-country-helper.php';
7 include_once YATRA_ABSPATH . 'includes/helpers/yatra-currency-helper.php';
8 include_once YATRA_ABSPATH . 'includes/template-tags.php';
9
10
11 if (!function_exists('yatra_tour_tabs')) {
12 function yatra_tour_tabs()
13 {
14 $tour_tabs_array = array(
15 'options' => array(
16 'title' => __('Options', 'yatra'),
17 'icon' => '',
18 ),
19 'itinerary' => array(
20 'title' => __('Itinerary', 'yatra'),
21 'icon' => '',
22 ),
23 'cost_info' => array(
24 'title' => __('Cost Info', 'yatra'),
25 'icon' => '',
26 ),
27 'facts' => array(
28 'title' => __('Facts', 'yatra'),
29 'icon' => '',
30 ),
31 'faq' => array(
32 'title' => __('FAQ', 'yatra'),
33 'icon' => '',
34 ),
35 );
36
37 return apply_filters('yatra_tour_tabs', $tour_tabs_array);
38 }
39 }
40
41 if (!function_exists('yatra_tour_metabox_tabs')) {
42
43 function yatra_tour_metabox_tabs()
44 {
45 $metabox_tabs = array(
46
47 'tour-options' => array(
48 'label' => __('Tour Options', 'yatra'),
49 'config' => yatra_tour_general_configurations()
50 ),
51 'tour-attributes' => array(
52 'label' => __('Attributes', 'yatra'),
53 'config' => yatra_tour_attributes()
54 ),
55 'tour-tabs' => array(
56 'label' => __('Tour Tabs', 'yatra'),
57 'config' => yatra_tour_tab_configurations()
58 ),
59 );
60
61 return apply_filters('yatra_tour_metabox_tabs', $metabox_tabs);
62 }
63 }
64
65
66 if (!function_exists('yatra_set_session')) {
67
68 function yatra_set_session($key = '', $value = '')
69 {
70 if (!session_id()) {
71 session_start();
72 }
73
74 $yatra_session_id = "yatra_session";
75
76 if (!empty($key) && !empty($value)) {
77
78 $_SESSION[$yatra_session_id][$key] = $value;
79
80 return true;
81 }
82 return false;
83
84 }
85 }
86
87 if (!function_exists('yatra_get_session')) {
88
89 function yatra_get_session($key = '')
90 {
91
92 $yatra_session_id = "yatra_session";
93
94 if (!empty($key)) {
95
96 if (isset($_SESSION[$yatra_session_id][$key])) {
97
98 return $_SESSION[$yatra_session_id][$key];
99 }
100
101 }
102 if (isset($_SESSION[$yatra_session_id])) {
103
104 return $_SESSION[$yatra_session_id];
105 }
106
107 return array();
108
109 }
110 }
111
112 if (!function_exists('yatra_clear_session')) {
113
114 function yatra_clear_session($key = '')
115 {
116 if (!session_id()) {
117 session_start();
118 }
119
120
121 $yatra_session_id = "yatra_session";
122
123 if (!empty($key)) {
124
125 if (isset($_SESSION[$yatra_session_id][$key])) {
126
127 unset($_SESSION[$yatra_session_id][$key]);
128
129 return true;
130 }
131
132 }
133 if (isset($_SESSION[$yatra_session_id])) {
134
135 unset($_SESSION[$yatra_session_id]);
136
137 return true;
138 }
139
140 return false;
141
142 }
143 }
144
145 if (!function_exists('yatra_get_template')) {
146
147 function yatra_get_template($template_name, $args = array(), $template_path = '', $default_path = '')
148 {
149 $cache_key = sanitize_key(implode('-', array('template', $template_name, $template_path, $default_path)));
150 $template = (string)wp_cache_get($cache_key, 'yatra');
151
152 if (!$template) {
153 $template = yatra_locate_template($template_name, $template_path, $default_path);
154 wp_cache_set($cache_key, $template, 'yatra');
155 }
156 // Allow 3rd party plugin filter template file from their plugin.
157 $filter_template = apply_filters('yatra_get_template', $template, $template_name, $args, $template_path, $default_path);
158
159 if ($filter_template !== $template) {
160 if (!file_exists($filter_template)) {
161 /* translators: %s template */
162 _doing_it_wrong(__FUNCTION__, sprintf(__('%s does not exist.', 'yatra'), '<code>' . $template . '</code>'), '1.0.1');
163 return;
164 }
165 $template = $filter_template;
166 }
167
168 $action_args = array(
169 'template_name' => $template_name,
170 'template_path' => $template_path,
171 'located' => $template,
172 'args' => $args,
173 );
174
175 if (!empty($args) && is_array($args)) {
176 if (isset($args['action_args'])) {
177 _doing_it_wrong(
178 __FUNCTION__,
179 __('action_args should not be overwritten when calling yatra_get_template.', 'yatra'),
180 '1.0.0'
181 );
182 unset($args['action_args']);
183 }
184 extract($args); // @codingStandardsIgnoreLine
185 }
186
187 do_action('yatra_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args']);
188
189 include $action_args['located'];
190
191 do_action('yatra_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args']);
192 }
193 }
194
195 if (!function_exists('yatra_locate_template')) {
196 function yatra_locate_template($template_name, $template_path = '', $default_path = '')
197 {
198 if (!$template_path) {
199 $template_path = yatra_instance()->template_path();
200 }
201
202 if (!$default_path) {
203 $default_path = yatra_instance()->plugin_template_path();
204 }
205
206 // Look within passed path within the theme - this is priority.
207 $template = locate_template(
208 array(
209 trailingslashit($template_path) . $template_name,
210 $template_name,
211 )
212 );
213
214 // Get default template/.
215 if (!$template) {
216 $template = $default_path . $template_name;
217 }
218 // Return what we found.
219 return apply_filters('yatra_locate_template', $template, $template_name, $template_path);
220 }
221 }
222
223 if (!function_exists('yatra_single_tour_tabs')) {
224
225 function yatra_single_tour_tabs()
226 {
227 global $post;
228
229
230 }
231 }
232
233 if (!function_exists('yatra_get_checkout_page')) {
234
235 function yatra_get_checkout_page($get_permalink = false)
236 {
237
238 $page_id = absint(get_option('yatra_checkout_page'));
239
240 if ($page_id < 1) {
241
242 global $wpdb;
243
244 $page_id = $wpdb->get_var('SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE "%[yatra_checkout]%" AND post_parent = 0');
245 }
246
247 $page_permalink = get_permalink($page_id);
248
249 if ($get_permalink) {
250
251 return $page_permalink;
252 }
253
254 return $page_id;
255
256
257 }
258 }
259
260
261 if (!function_exists('yatra_get_cart_page')) {
262
263 function yatra_get_cart_page($get_permalink = false)
264 {
265 $page_id = absint(get_option('yatra_cart_page'));
266
267 if ($page_id < 1) {
268
269 global $wpdb;
270
271 $page_id = $wpdb->get_var('SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE "%[yatra_cart]%" AND post_parent = 0');
272 }
273
274 $page_permalink = get_permalink($page_id);
275
276 if ($get_permalink) {
277
278 return $page_permalink;
279 }
280
281 return $page_id;
282
283
284 }
285 }
286
287 if (!function_exists('yatra_get_booking_statuses')) {
288
289 function yatra_get_booking_statuses()
290 {
291 return apply_filters(
292 'yatra_booking_statuses', array(
293 'yatra-pending' => __('Pending', 'yatra'),
294 'yatra-processing' => __('Processing', 'yatra'),
295 'yatra-on-hold' => __('On Hold', 'yatra'),
296 'yatra-completed' => __('Completed', 'yatra'),
297 'yatra-cancelled' => __('Cancelled', 'yatra')
298 )
299 );
300
301 }
302 }
303
304 if (!function_exists('yatra_the_posts_navigation')) :
305 /**
306 * Documentation for function.
307 */
308 function yatra_the_posts_navigation()
309 {
310 the_post_navigation(array(
311 'prev_text' => '<span class="screen-reader-text">' . esc_html__('Previous Post', 'yatra') . '</span><span class="nav-title">%title</span>',
312 'next_text' => '<span class="screen-reader-text">' . esc_html__('Next Post', 'yatra') . '</span><span class="nav-title">%title</span>',
313 ));
314 }
315 endif;
316
317 if (!function_exists('yatra_get_template_part')) {
318
319 function yatra_get_template_part($slug, $name = '')
320 {
321 $path = "{$slug}.php";
322
323 if ('' !== $name) {
324
325 $path = "{$slug}-{$name}.php";
326 }
327 $template = yatra_locate_template($path, false, false);
328
329 require $template;
330
331 }
332
333 }
334 if (!function_exists('yatra_posted_by')) :
335 /**
336 * Prints HTML with meta information about theme author.
337 */
338 function yatra_posted_by()
339 {
340 printf(
341 /* translators: 1: SVG icon. 2: post author, only visible to screen readers. 3: author link. */
342 '<span class="byline"><span class="screen-reader-text">%1$s</span><span class="author vcard"><a class="url fn n" href="%2$s">%3$s</a></span></span>',
343 __('Posted by', 'yatra'),
344 esc_url(get_author_posts_url(get_the_author_meta('ID'))),
345 esc_html(get_the_author())
346 );
347 }
348 endif;
349
350 if (!function_exists('yatra_posted_on')) :
351 /**
352 * Prints HTML with meta information for the current post-date/time.
353 */
354 function yatra_posted_on()
355 {
356 $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
357 if (get_the_time('U') !== get_the_modified_time('U')) {
358 $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
359 }
360
361 $time_string = sprintf(
362 $time_string,
363 esc_attr(get_the_date(DATE_W3C)),
364 esc_html(get_the_date()),
365 esc_attr(get_the_modified_date(DATE_W3C)),
366 esc_html(get_the_modified_date())
367 );
368
369 printf(
370 '<span class="posted-on"><a href="%1$s" rel="bookmark">%2$s</a></span>',
371 esc_url(get_permalink()),
372 $time_string
373 );
374 }
375 endif;
376
377 if (!function_exists('yatra_entry_meta')) {
378
379 function yatra_entry_meta()
380 {
381 ?>
382 <div class="entry-meta">
383 <?php yatra_posted_by(); ?>
384 <?php yatra_posted_on(); ?>
385 <?php
386 // Edit post link.
387 edit_post_link(
388 sprintf(
389 wp_kses(
390 /* translators: %s: Name of current post. Only visible to screen readers. */
391 __('Edit <span class="screen-reader-text">%s</span>', 'yatra'),
392 array(
393 'span' => array(
394 'class' => array(),
395 ),
396 )
397 ),
398 get_the_title()
399 ),
400 '<span class="edit-link">',
401 '</span>'
402 );
403 ?>
404 </div><!-- .meta-info -->
405 <?php
406 }
407
408 }
409
410
411 /**
412 * Get permalink settings
413 *
414 * @since 1.0.0
415 * @return array
416 */
417 function yatra_get_permalink_structure()
418 {
419
420 $permalinks = wp_parse_args(
421 (array)get_option('yatra_permalinks', array()),
422 array(
423 'yatra_tour_base' => 'tour',
424 'yatra_destination_base' => 'destination',
425 'yatra_activity_base' => 'activity',
426 'yatra_attributes_base' => 'attributes',
427 )
428 );
429
430 // Ensure rewrite slugs are set.
431 $permalinks['yatra_tour_base'] = untrailingslashit(empty($permalinks['yatra_tour_base']) ? 'tour' : $permalinks['yatra_tour_base']);
432 $permalinks['yatra_destination_base'] = untrailingslashit(empty($permalinks['yatra_destination_base']) ? 'destination' : $permalinks['yatra_destination_base']);
433 $permalinks['yatra_activity_base'] = untrailingslashit(empty($permalinks['yatra_activity_base']) ? 'activity' : $permalinks['yatra_activity_base']);
434 return $permalinks;
435 }
436
437 if (!function_exists('yatra_tour_price')) {
438
439 function yatra_tour_price($tour_id, $is_html = true)
440 {
441 $yatra_tour_meta_regular_price = get_post_meta($tour_id, 'yatra_tour_meta_regular_price', true);
442
443 $yatra_tour_meta_sales_price = get_post_meta($tour_id, 'yatra_tour_meta_sales_price', true);
444
445 $price_per_person = empty($yatra_tour_meta_sales_price) || $yatra_tour_meta_sales_price == 0 ? $yatra_tour_meta_regular_price : $yatra_tour_meta_sales_price;
446
447 if (!$is_html) {
448
449 return $price_per_person;
450 }
451 $price_string = '<span class="regular-price"><del>' . yatra_get_current_currency_symbol() . '' . $yatra_tour_meta_regular_price . '</del></span>';
452
453 $price_string .= '<br/><span class="sales-price">' . yatra_get_current_currency_symbol() . '' . $yatra_tour_meta_sales_price . '</del></span>';
454
455 if (empty($yatra_tour_meta_sales_price) || $yatra_tour_meta_sales_price == 0) {
456
457 $price_string = '<span class="regular-price">' . yatra_get_current_currency_symbol() . '' . $yatra_tour_meta_regular_price . '</span>';
458
459
460 }
461 return $price_string;
462 }
463
464 }
465
466 if (!function_exists('yatra_get_final_tour_price')) {
467
468 function yatra_get_final_tour_price($tour_id, $number_of_people = 1)
469 {
470 $yatra_tour_meta_regular_price = get_post_meta($tour_id, 'yatra_tour_meta_regular_price', true);
471
472 $yatra_tour_meta_sales_price = get_post_meta($tour_id, 'yatra_tour_meta_sales_price', true);
473
474 $price_per_person = empty($yatra_tour_meta_sales_price) || $yatra_tour_meta_sales_price == 0 ? $yatra_tour_meta_regular_price : $yatra_tour_meta_sales_price;
475
476 $yatra_tour_meta_price_per = get_post_meta($tour_id, 'yatra_tour_meta_price_per', true);
477
478 if ($yatra_tour_meta_price_per == 'person') {
479
480 return $price_per_person * $number_of_people;
481 }
482 if ($yatra_tour_meta_price_per == 'group') {
483
484 $yatra_tour_meta_group_size = get_post_meta($tour_id, 'yatra_tour_meta_group_size', true);
485
486 if ($yatra_tour_meta_group_size == 0) {
487
488 $yatra_tour_meta_group_size = 1;
489 }
490 $number_of_group = ceil($number_of_people / $yatra_tour_meta_group_size);
491
492 return $price_per_person * $number_of_group;
493 }
494 return $price_per_person;
495 }
496 }
497
498
499 if (!function_exists('yatra_update_booking_status')) {
500
501 function yatra_update_booking_status($booking_id = 0, $status = 'pending')
502 {
503 $yatra_booking_statuses = yatra_get_booking_statuses();
504
505 if ($booking_id < 1 || !isset($yatra_booking_statuses[$status])) {
506
507 return false;
508 }
509
510 do_action('yatra_before_booking_status_change', array(
511 'booking_id' => $booking_id,
512 'status' => $status
513 ));
514
515 $booking_array = array();
516 $booking_array['ID'] = $booking_id;
517 $booking_array['post_status'] = $status;
518
519 // Update the post into the database
520 wp_update_post($booking_array);
521
522 do_action('yatra_after_booking_status_change', array(
523 'booking_id' => $booking_id,
524 'status' => $status
525 ));
526
527 return true;
528 }
529 }