PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
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 / app / Ajax / ActivityShortcodeAjax.php

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

88 lines 3.2 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 Activity Shortcode
9 */
10 class ActivityShortcodeAjax
11 {
12 public function __construct()
13 {
14 add_action('wp_ajax_yatra_activity_shortcode_load', [$this, 'loadActivities']);
15 add_action('wp_ajax_nopriv_yatra_activity_shortcode_load', [$this, 'loadActivities']);
16 }
17
18 /**
19 * Load activities via AJAX for pagination
20 */
21 public function loadActivities(): void
22 {
23
24 // Verify nonce
25 if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_activity_shortcode_nonce')) {
26 wp_die(esc_html__('Security check failed', 'yatra'), '', ['response' => 403]);
27 }
28
29 // Parse shortcode attributes
30 $atts = $_POST['atts'] ?? [];
31 $page = (int) ($_POST['page'] ?? 1);
32
33 // Add page to attributes for AJAX pagination
34 $atts['current_page'] = $page;
35
36 try {
37 $activityShortcode = new \Yatra\Shortcodes\ActivityShortcode();
38 $activities_data = $activityShortcode->getActivities($atts);
39
40 // Prepare data for template - extract variables for template scope
41 $activities = [
42 'activities' => $activities_data['activities'] ?? [],
43 'max_pages' => $activities_data['max_pages'] ?? 1,
44 'current_page' => $activities_data['current_page'] ?? 1,
45 'total_found' => $activities_data['total_found'] ?? 0
46 ];
47
48 // Extract variables to make them available in template
49 $atts = $atts;
50 $max_pages = $activities_data['max_pages'] ?? 1;
51 $current_page = $activities_data['current_page'] ?? 1;
52 $total_found = $activities_data['total_found'] ?? 0;
53 $columns = (int) $atts['columns'];
54 $column_class = 'yatra-activity-grid-' . min(max($columns, 1), 4);
55
56
57 // Load the template content with variables in scope
58 ob_start();
59 // Extract variables to make them available in template (matching trip shortcode pattern)
60 $activities = $activities_data['activities'] ?? [];
61 $max_pages = $activities_data['max_pages'] ?? 1;
62 $current_page = $activities_data['current_page'] ?? 1;
63 $total_found = $activities_data['total_found'] ?? 0;
64 $columns = (int) $atts['columns'];
65 $column_class = 'yatra-activity-grid-' . min(max($columns, 1), 4);
66
67 include YATRA_PLUGIN_PATH . 'templates/shortcodes/activity.php';
68 $html = ob_get_clean();
69
70 wp_send_json_success([
71 'html' => $html,
72 'current_page' => $activities_data['current_page'] ?? 1,
73 'max_pages' => $activities_data['max_pages'] ?? 1,
74 'total_found' => $activities_data['total_found'] ?? 0
75 ]);
76
77 } catch (\Exception $e) {
78
79
80 wp_send_json_error([
81 'message' => (defined('WP_DEBUG') && WP_DEBUG)
82 ? 'Error loading activities: ' . $e->getMessage()
83 : __('Unable to load activities. Please try again.', 'yatra'),
84 ]);
85 }
86 }
87 }
88