← All changes
|
app/Services/Integrations/Elementor/ElementorIntegration.php
+40
-8
1.5.23
→
2.5.0
View file →
| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace FluentBooking\App\Services\Integrations\Elementor; |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | use FluentBooking\App\Models\Calendar; |
| 7 | +use FluentBooking\App\Models\CalendarSlot; | |
| 7 | 8 | use FluentBooking\App\App; |
| 8 | 9 | |
| 9 | 10 | class ElementorIntegration |
| 10 | 11 | { |
| @@ -18,9 +19,10 @@ | ||
| 18 | 19 | add_action('elementor/editor/before_enqueue_scripts', [$this, 'editorScripts']); |
| 19 | 20 | add_action('elementor/editor/after_enqueue_scripts', [$this, 'editorScripts']); |
| 20 | 21 | |
| 21 | 22 | add_action('wp_ajax_get_calendar_events', [$this, 'ajaxGetCalendarEvents']); |
| 22 | - add_action('wp_ajax_nopriv_get_calendar_events', [$this, 'ajaxGetCalendarEvents']); | |
| 23 | + | |
| 24 | + add_action('wp_ajax_get_event_hash', [$this, 'ajaxGetEventHash']); | |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | public function editorScripts() |
| 26 | 28 | { |
| @@ -59,9 +61,9 @@ | ||
| 59 | 61 | |
| 60 | 62 | public function addElementorCategory() |
| 61 | 63 | { |
| 62 | 64 | \Elementor\Plugin::instance()->elements_manager->add_category('fluentbooking', [ |
| 63 | - 'title' => __('FluentBooking', 'fluent-booking-pro'), | |
| 65 | + 'title' => __('FluentBooking', 'fluent-booking'), | |
| 64 | 66 | ], 1); |
| 65 | 67 | } |
| 66 | 68 | |
| 67 | 69 | /** |
| @@ -92,26 +94,55 @@ | ||
| 92 | 94 | $this->registerFluentBookingCustomGroupSelect($controls_manager); |
| 93 | 95 | } |
| 94 | 96 | |
| 95 | 97 | public function ajaxGetCalendarEvents() { |
| 96 | - if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'calendar_events_nonce')) { | |
| 97 | - wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking-pro')]); | |
| 98 | + if (!isset($_POST['security']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['security'])), 'calendar_events_nonce')) { | |
| 99 | + wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking')]); | |
| 98 | 100 | exit; |
| 99 | 101 | } |
| 100 | 102 | |
| 103 | + if (!current_user_can('edit_posts')) { | |
| 104 | + wp_send_json_error(['message' => __('You do not have permission to perform this action', 'fluent-booking')]); | |
| 105 | + exit; | |
| 106 | + } | |
| 107 | + | |
| 101 | 108 | if (!isset($_POST['cal_id'])) { |
| 102 | - wp_send_json_error(['message' => __('No calendar ID provided', 'fluent-booking-pro')]); | |
| 109 | + wp_send_json_error(['message' => __('No calendar ID provided', 'fluent-booking')]); | |
| 103 | 110 | } |
| 104 | 111 | |
| 105 | 112 | $calId = intval($_POST['cal_id']); |
| 106 | - $events = []; // Fetch events using your getCalendarEvents method or similar | |
| 113 | + $events = []; | |
| 107 | 114 | |
| 108 | - // Example of fetching events (you need to replace this with your actual method) | |
| 109 | 115 | $events = $this->getCalendarEvents($calId); |
| 110 | 116 | |
| 111 | 117 | wp_send_json_success($events); |
| 112 | 118 | } |
| 113 | 119 | |
| 120 | + public function ajaxGetEventHash() { | |
| 121 | + if (!isset($_POST['security']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['security'])), 'calendar_events_nonce')) { | |
| 122 | + wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking')]); | |
| 123 | + exit; | |
| 124 | + } | |
| 125 | + | |
| 126 | + if (!current_user_can('edit_posts')) { | |
| 127 | + wp_send_json_error(['message' => __('You do not have permission to perform this action', 'fluent-booking')]); | |
| 128 | + exit; | |
| 129 | + } | |
| 130 | + | |
| 131 | + $eventId = isset($_POST['event_id']) ? intval($_POST['event_id']) : null; | |
| 132 | + | |
| 133 | + $event = CalendarSlot::find($eventId); | |
| 134 | + | |
| 135 | + if (!$event) { | |
| 136 | + wp_send_json_error(['message' => __('Event not found', 'fluent-booking')]); | |
| 137 | + exit; | |
| 138 | + } | |
| 139 | + | |
| 140 | + $eventHash = $event->hash; | |
| 141 | + | |
| 142 | + wp_send_json_success(['hash' => $eventHash]); | |
| 143 | + } | |
| 144 | + | |
| 114 | 145 | public function registerWidgets() |
| 115 | 146 | { |
| 116 | 147 | \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendarEvent()); |
| 117 | 148 | \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalBookings()); |
| @@ -126,9 +157,10 @@ | ||
| 126 | 157 | $filePath = __DIR__ . $relativePath; |
| 127 | 158 | if (file_exists($filePath)) { |
| 128 | 159 | require_once($filePath); |
| 129 | 160 | } else { |
| 130 | - throw new \Exception(sprintf(__("File not found: %s", "fluent-booking-pro"), $filePath)); | |
| 161 | + /* translators: %s: File path */ | |
| 162 | + throw new \Exception(esc_html(sprintf(__('File not found: %s', 'fluent-booking'), $filePath))); | |
| 131 | 163 | } |
| 132 | 164 | } |
| 133 | 165 | |
| 134 | 166 | private function registerFluentBookingCustomGroupSelect($controls_manager) |