PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.1.22
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.1.22
2.1.22 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 All 56 releases
booking-manager / core / any / wpbm-class-dismiss.php

wpbm-class-dismiss.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.1.22, at core/any/wpbm-class-dismiss.php

207 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description Dismiss Class
4 * @category Dismiss panels Class
5 * @author wpdevelop
6 *
7 * @web-site https://oplugins.com/
8 * @email [email protected]
9 *
10 * @modified 2015-11-13
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 /** Dismiss Class
16 * @usage:
17 *
18 * Inline Setting Notice Dismiss'
19 *
20 $notice_id = 'wpbm_upload_help_section';
21 if ( ! wpbm_section_is_dismissed( $notice_id ) ) {
22
23 ?><div id="<?php echo $notice_id; ?>"
24 class="wpbm_system_notice wpbm_is_dismissible wpbm_is_hideable notice-warning wpbm_internal_notice"
25 data-nonce="<?php echo wp_create_nonce( $nonce_name = $notice_id . '_wpbmnonce' ); ?>"
26 data-user-id="<?php echo get_current_user_id(); ?>"
27 ><?php
28 wpbm_x_dismiss_button();
29 ....
30 ?></div><?php
31 *
32 * System Notice
33 *
34 $notice_id = 'wpbm_system_notice_free_instead_paid';
35 if ( ! wpbm_section_is_dismissed( $notice_id ) ) {
36 ?><div id="<?php echo $notice_id; ?>"
37 class="wpbm_system_notice wpbm_is_dismissible wpbm_is_hideable updated notice-warning"
38 data-nonce="<?php echo wp_create_nonce( $nonce_name = $notice_id . '_wpbmnonce' ); ?>"
39 data-user-id="<?php echo get_current_user_id(); ?>"
40 ><?php
41 wpbm_x_dismiss_button();
42 ...
43 ?></div><?php
44 *
45 */
46 final class WPBM_Dismiss {
47
48 static private $instance = NULL; // Define only one instance of this class
49
50 /** Get only one instance of this class
51 *
52 * @return class WPBM_Dismiss
53 */
54 public static function init() {
55
56 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPBM_Dismiss ) ) {
57
58 self::$instance = new WPBM_Dismiss;
59
60 // JS & CSS
61 add_action( 'wpbm_enqueue_js_files', array( self::$instance, 'wpbm_js_load_files' ), 50 );
62 add_action( 'wpbm_enqueue_css_files', array( self::$instance, 'wpbm_enqueue_css_files' ), 50 );
63
64 // Ajax Handlers. Note. "locale_for_ajax" recehcked in wpbm-ajax.php
65 add_action( 'wp_ajax_' . 'WPBM_DISMISS', array( self::$instance, 'wpbm_ajax_' . 'WPBM_DISMISS' ) ); // Admin & Client (logged in usres)
66 //add_action( 'wp_ajax_nopriv_' . 'WPBM_DISMISS', array( self::$instance, 'wpbm_ajax_' . 'WPBM_DISMISS' ) ); // Client (not logged in)
67 }
68
69 return self::$instance;
70 }
71
72
73 /** Ajax Handler
74 * for request like:
75 * action: 'WPBM_DISMISS',
76 user_id: panel_obj.user_id ,
77 nonce: panel_obj.nonce,
78 element_id: panel_obj.id,
79 is_closed: 1
80 *
81 */
82 public function wpbm_ajax_WPBM_DISMISS() {
83
84 $element_id = isset( $_POST['element_id'] ) && is_scalar( $_POST['element_id'] )
85 ? sanitize_text_field( wp_unslash( (string) $_POST['element_id'] ) )
86 : '';
87 if ( '' === $element_id ) {
88 status_header( 400 );
89 wp_send_json_error( array( 'message' => __( 'The dismissible interface element is not valid.', 'booking-manager' ) ) );
90 }
91
92 $action_name = $element_id . '_wpbmnonce';
93 $nonce_post_key = 'nonce';
94
95 // Check Security
96 $result = check_ajax_referer( $action_name, $nonce_post_key );
97
98 $requested_user_id = isset( $_POST['user_id'] ) && is_scalar( $_POST['user_id'] )
99 ? absint( wp_unslash( (string) $_POST['user_id'] ) )
100 : 0;
101 $authorized_user_id = wpbm_get_authorized_user_option_target_id( $requested_user_id );
102 if ( 0 === $authorized_user_id ) {
103 status_header( 403 );
104 wp_send_json_error( array( 'message' => __( 'You can update only your own interface preferences.', 'booking-manager' ) ) );
105 }
106
107 // Save status
108 $is_closed = isset( $_POST['is_closed'] ) && is_scalar( $_POST['is_closed'] )
109 ? (int) wp_unslash( (string) $_POST['is_closed'] )
110 : 0;
111 update_user_option( $authorized_user_id, 'wpbm_win_' . $element_id, $is_closed );
112
113 // FixIn: 2.0.2.1 //Fix: We need to comment this line, because previously its possible that we already sent some messages, and its does not correct json format in this case.
114 //Fix: of showing "parsererror ~ SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"
115 // send JSON
116 // wp_send_json( array( 'response' => 'success' ) ); // Return JS OBJ: response_data = { response: "success" } in "dismiss.js"
117 // This function call wp_die( '', '', array( 'response' => null, ) )
118 wp_die( '', '', array( 'response' => null ) );
119 }
120
121
122 /** JSS */
123 public function wpbm_js_load_files( $where_to_load ) {
124
125 $in_footer = true;
126
127 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
128
129 wp_enqueue_script( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/js/dismiss.js' ), array( 'wpbm-global-vars' ), '1.1', $in_footer );
130 }
131 }
132
133
134 /** CSS */
135 public function wpbm_enqueue_css_files( $where_to_load ) {
136
137 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
138
139 wp_enqueue_style( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/css/dismiss.css' ), array(), WPBM_VERSION_NUM );
140 }
141 }
142
143
144 /** Check if this section dismissed or not.
145 *
146 * @param string $section_html_id
147 * @return boolean
148 */
149 public function is_dismissed( $section_html_id ) {
150
151 if ( '1' == get_user_option( 'wpbm_win_' . $section_html_id ) )
152 return true;
153 else
154 return false;
155 }
156
157 }
158
159
160 function wpbm_dismiss() {
161 return WPBM_Dismiss::init();
162 }
163 wpbm_dismiss(); // Run
164
165
166 /** Check if specific section dismissed or not
167 *
168 * @param type $section_html_id
169 * @return boolean
170 */
171 function wpbm_section_is_dismissed( $section_html_id ) {
172
173 $wpbm_dismiss = wpbm_dismiss();
174
175 return $wpbm_dismiss->is_dismissed( $section_html_id );
176 }
177
178
179 /** Show dismiss X button
180 *
181 * @param string $title
182 * @param array $attributes_arr - array of attributes, like: array( 'class' => 'wpbm_dismiss' )
183 * @param bool $echo
184 * @return string of dismiss button
185 */
186 function wpbm_x_dismiss_button( $title = '&times;', $attributes_arr = array(), $echo = true ) {
187
188 $defaults = array(
189 'style' => ''
190 , 'class' => 'wpbm_dismiss'
191 , 'title' => esc_js( __( 'Close', 'booking-manager' ) )
192 );
193 $attributes_arr = wp_parse_args( $attributes_arr, $defaults );
194
195 $attr_echo = array();
196 foreach ( $attributes_arr as $attr_name => $attr_value ) {
197 $attr_echo[] = esc_attr( $attr_name ) . '="' . esc_attr( $attr_value ) . '"';
198 }
199 $attr_echo = implode( ' ', $attr_echo );
200
201 if ( ! $echo ) { ob_start(); }
202
203 ?><a href="javascript:void(0)" <?php echo $attr_echo; ?> ><?php echo $title; ?></a><?php
204
205 if ( ! $echo ) { return ob_get_clean(); }
206 }
207