PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / core / wpbm-ajax.php

wpbm-ajax.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0, at core/wpbm-ajax.php

154 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Manager
5 * @subpackage Ajax Responder
6 * @category Items
7 *
8 * @author wpdevelop
9 * @link http://oplugins.com/
10 * @email info@oplugins.com
11 *
12 * @modified 2014.05.26
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 ////////////////////////////////////////////////////////////////////////////////
18 // S u p p o r t f u n c t i o n s f o r A j a x ///////////////
19 ////////////////////////////////////////////////////////////////////////////////
20
21 // Verify the nonce.
22 function wpbm_check_nonce_in_admin_panel( $action_check = 'wpbm_ajax_admin_nonce' ){
23
24 $nonce = ( isset( $_REQUEST[ 'wpbm_nonce' ] ) ) ? $_REQUEST[ 'wpbm_nonce' ] : '';
25
26 if ( '' === $nonce ) return false; // Its was request from some other plugin
27
28 if ( ! wp_verify_nonce( $nonce, $action_check ) ) { // This nonce is not valid.
29 ?>
30 <script type="text/javascript">
31 jQuery("#ajax_respond").after( "<div class='wpdevelop'><div class='alert alert-warning alert-danger'><?php
32 printf(__('%sError!%s Request do not pass security check! Please refresh the page and try one more time.' , 'booking-manager'),'<strong>','</strong>');
33 ?></div></div>" );
34 if ( jQuery("#ajax_message").length )
35 jQuery("#ajax_message").slideUp();
36 </script>
37 <?php
38 die;
39 }
40 return true; //FixIn: 7.2.1.10
41 }
42
43
44 // Check and (re)Load specific Locale for the Ajax request - based on "admin_init" hook
45 function wpbm_check_locale_for_ajax() {
46
47 add_wpbm_filter( 'wpbm_check_for_active_language', 'wpbm_check_for_active_language' ); // Add Hook for ability to check the content for active lanaguges
48
49 if ( isset( $_POST[ 'wpbm_active_locale' ] ) ) { // Reload locale according request parameter
50 global $l10n;
51 if ( isset( $l10n[ 'booking-manager' ] ) )
52 unset( $l10n[ 'booking-manager' ] );
53
54 if ( ! defined( 'WPBM_RELOAD' ) )
55 define( 'WPBM_RELOAD', esc_js( $_POST[ 'wpbm_active_locale' ] ) );
56
57 // Reload locale settings, its required for the correct dates format
58 if ( isset( $l10n[ 'default' ] ) )
59 unset( $l10n[ 'default' ] ); // Unload locale
60 add_filter( 'locale', 'wpbm_get_locale', 999 ); // Set filter to load the locale of the Booking Manager
61 load_default_textdomain(); // Load default locale
62 global $wp_locale;
63 $wp_locale = new WP_Locale(); // Reload class
64
65 wpbm_load_locale( WPBM_RELOAD );
66 }
67 }
68
69
70 ////////////////////////////////////////////////////////////////////////////////
71 // A j a x H o o k s f o r s p e c i f i c A c t i o n s /////
72 ////////////////////////////////////////////////////////////////////////////////
73
74
75 function wpbm_ajax_WPBM_USER_SAVE_WINDOW_STATE() {
76
77 // if ( ! wpbm_check_nonce_in_admin_panel() ) return false;
78 // update_user_option($_POST['user_id'],'wpbm_win_' . $_POST['window'] ,$_POST['is_closed']);
79
80 if ( ! wpbm_check_nonce_in_admin_panel() ) return false;
81 update_user_option( (int) $_POST['user_id'], 'wpbm_win_' . esc_attr( $_POST['window'] ) , (int) $_POST['is_closed'] );
82 wp_send_json_success();
83 }
84
85
86 /** Save Custom User Data */
87 function wpbm_ajax_WPBM_USER_SAVE_CUSTOM_DATA() {
88
89 if ( ! wpbm_check_nonce_in_admin_panel() ) return false;
90 /* Exmaple of $_POST:
91 [data_name] => add_wpbm_calendar_options
92 [data_value] => calendar_months_count=1&calendar_months_num_in_1_row=1&calendar_width=500px&calendar_cell_height
93 */
94 $post_param = explode( '&', $_POST['data_value'] ); // "&" was set by jQuery.param( data_params ) in client side.
95 $data_to_save = array();
96 foreach ( $post_param as $param ) {
97 $param_data = explode( '=', $param );
98
99 $data_to_save[ $param_data[0] ] = ( isset( $param_data[1] ) ) ? esc_attr( $param_data[1] ) : '';
100 }
101 /* Exmaple:
102 Array
103 (
104 [calendar_months_count] => 1
105 [calendar_months_num_in_1_row] => 1
106 [calendar_width] => 500px
107 [calendar_cell_height] =>
108 )
109 */
110
111 // Save Custom User Data
112 update_user_option( (int) $_POST['user_id'], 'wpbm_custom_' . esc_attr( $_POST['data_name'] ) , serialize( $data_to_save ) );
113
114 ?> <script type="text/javascript">
115 var my_message = '<?php echo html_entity_decode( esc_js( __('Saved' , 'booking-manager') ),ENT_QUOTES) ; ?>';
116 wpbm_admin_show_message( my_message, 'success', 1000 );
117 <?php if ( ! empty( $_POST['is_reload'] ) == 1 ) { ?>
118 setTimeout(function ( ) {location.reload(true);} ,1500);
119 <?php } ?>
120 </script> <?php
121 die();
122
123 }
124
125
126 ////////////////////////////////////////////////////////////////////////////////
127 // R u n A j a x //////////////////////////////////
128 ////////////////////////////////////////////////////////////////////////////////
129 if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) {
130
131 // Reload Locale if its required
132 add_action( 'admin_init', 'wpbm_check_locale_for_ajax' );
133
134 // Hooks list
135 $actions_list = array(
136 'WPBM_USER_SAVE_WINDOW_STATE' => 'admin'
137 ,'WPBM_USER_SAVE_CUSTOM_DATA' => 'admin'
138
139 , 'WPBM_LISTING_ICS_URL' => 'admin'
140 );
141
142 foreach ($actions_list as $action_name => $action_where) {
143
144 if ( ( isset($_POST['action']) ) && ( $_POST['action'] == $action_name ) ){
145
146 if ( ( $action_where == 'admin' ) || ( $action_where == 'both' ) )
147 add_action( 'wp_ajax_' . $action_name, 'wpbm_ajax_' . $action_name); // Admin & Client (logged in usres)
148
149 if ( ( $action_where == 'both' ) || ( $action_where == 'client' ) )
150 add_action( 'wp_ajax_nopriv_' . $action_name, 'wpbm_ajax_' . $action_name); // Client (not logged in)
151 }
152 }
153 }
154