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 / app / Ajax / DestinationShortcodeAjax.php

DestinationShortcodeAjax.php in Yatra – Travel Booking & Tour Operator Software 3.0.15, at app/Ajax/DestinationShortcodeAjax.php

89 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Ajax;
6
7 /**
8 * AJAX handlers for Destination Shortcode
9 */
10 class DestinationShortcodeAjax
11 {
12 public function __construct()
13 {
14 add_action('wp_ajax_yatra_destination_shortcode_load', [$this, 'loadDestinations']);
15 add_action('wp_ajax_nopriv_yatra_destination_shortcode_load', [$this, 'loadDestinations']);
16 }
17
18 /**
19 * Load destinations via AJAX for pagination
20 */
21 public function loadDestinations(): void
22 {
23
24 // Verify nonce
25 if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_destination_shortcode_nonce')) {
26
27 wp_die(esc_html__('Security check failed', 'yatra'), '', ['response' => 403]);
28 }
29
30 // Parse shortcode attributes
31 $atts = $_POST['atts'] ?? [];
32 $page = (int) ($_POST['page'] ?? 1);
33
34 // Add page to attributes for AJAX pagination
35 $atts['current_page'] = $page;
36
37 try {
38 $destinationShortcode = new \Yatra\Shortcodes\DestinationShortcode();
39 $destinations_data = $destinationShortcode->getDestinations($atts);
40
41 // Prepare data for template - extract variables for template scope
42 $destinations = [
43 'destinations' => $destinations_data['destinations'] ?? [],
44 'max_pages' => $destinations_data['max_pages'] ?? 1,
45 'current_page' => $destinations_data['current_page'] ?? 1,
46 'total_found' => $destinations_data['total_found'] ?? 0
47 ];
48
49 // Extract variables to make them available in template
50 $atts = $atts;
51 $max_pages = $destinations_data['max_pages'] ?? 1;
52 $current_page = $destinations_data['current_page'] ?? 1;
53 $total_found = $destinations_data['total_found'] ?? 0;
54 $columns = (int) $atts['columns'];
55 $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 4);
56
57
58 // Load the template content with variables in scope
59 ob_start();
60 // Extract variables to make them available in template (matching trip shortcode pattern)
61 $destinations = $destinations_data['destinations'] ?? [];
62 $max_pages = $destinations_data['max_pages'] ?? 1;
63 $current_page = $destinations_data['current_page'] ?? 1;
64 $total_found = $destinations_data['total_found'] ?? 0;
65 $columns = (int) $atts['columns'];
66 $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 4);
67
68 include YATRA_PLUGIN_PATH . 'templates/shortcodes/destination.php';
69 $html = ob_get_clean();
70
71 wp_send_json_success([
72 'html' => $html,
73 'current_page' => $destinations_data['current_page'] ?? 1,
74 'max_pages' => $destinations_data['max_pages'] ?? 1,
75 'total_found' => $destinations_data['total_found'] ?? 0
76 ]);
77
78 } catch (\Exception $e) {
79
80
81 wp_send_json_error([
82 'message' => (defined('WP_DEBUG') && WP_DEBUG)
83 ? 'Error loading destinations: ' . $e->getMessage()
84 : __('Unable to load destinations. Please try again.', 'yatra'),
85 ]);
86 }
87 }
88 }
89