PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / _news / wpbc_news.php

wpbc_news.php in Booking Calendar 11.2, at includes/_news/wpbc_news.php

186 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 Calendar
5 * @subpackage Show news
6 * @category Support
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2023-04-08
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 // FixIn: 9.6.1.8.
18
19 /**
20 * Show message in top header
21 *
22 * @param $page_tag
23 * @param $active_page_tab
24 * @param $active_page_subtab
25 *
26 * @return void
27 */
28 function wpbc_show_message_top( $page_tag, $active_page_tab, $active_page_subtab ) {
29
30 if ( wpbc_is_this_demo() ) {
31 return;
32 }
33
34 $version = wpbc_get_version_type__and_mu();
35 // if ( 'free' != $version ) { return; }
36
37 ?>
38 <style type="text/css">
39 .wpbc_message_wrapper {
40 margin-left: auto;
41 flex: 0 1 auto;
42 }
43 .wpbc_header_news {
44 position: relative;
45 z-index: 99;
46 }
47 </style><?php
48 ?>
49 <div class="wpbc_message_wrapper <?php
50 echo 'wpbc__version__' . esc_attr( $version ); ?>"><?php
51
52 // Send Ajax request to get info about the notifications
53 wp_nonce_field('wpbc_ajax_message_top_nonce', "wpbc_ajax_message_top_nonce" , true , true );
54
55 ?><script type="text/javascript">
56 jQuery(document).ready(function(){
57
58 var wpbc_ajax_sent_timer = setTimeout( function (){
59
60 console.log( '== Before Ajax Send - SHOW_MESSAGE_TOP ==' );
61
62 jQuery.ajax({
63 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
64 type:'POST',
65 success: function (data, textStatus){
66
67 // console.log( 'AJAX _ SHOW_MESSAGE_TOP', data );
68 if ( textStatus == 'success' ) {
69 jQuery( '.wpbc_message_wrapper' ).html( data[ 'ajx_show_content' ] );
70 }
71 console.log( '== Response - SHOW_MESSAGE_TOP ==' );
72 },
73 error: function (XMLHttpRequest, textStatus, errorThrown){
74 console.log( 'Ajax sending Error:', XMLHttpRequest, textStatus, errorThrown );
75 },
76 data:{
77 action : 'SHOW_MESSAGE_TOP',
78 wpbc_nonce: document.getElementById( 'wpbc_ajax_message_top_nonce' ).value
79 }
80 });
81 }, 2000 );
82
83 });
84 </script><?php
85
86 ?></div><?php
87
88 }
89 add_bk_action('wpbc_h1_header_content_end', 'wpbc_show_message_top');
90
91
92 /**
93 * Send Ajax request for getting message in top header
94 *
95 * @return void
96 */
97 function wpbc_ajax__get_message_top(){
98
99
100 $ajax_errors = new WPBC_AJAX_ERROR_CATCHING();
101
102 // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),
103 $action_name = 'wpbc_ajax_message_top_nonce';
104 $nonce_post_key = 'wpbc_nonce';
105 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
106
107 // $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
108
109 // Check if there were some errors --------------------------------------------------------------------------------
110 $error_messages = $ajax_errors->get_error_messages();
111
112 $top_message = wpbc_send_request__get_top_message();
113
114 //------------------------------------------------------------------------------------------------------------------
115 // Send JSON. Its will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) Pass JS OBJ: response_data in "jQuery.post( " function on success.
116 wp_send_json( array(
117 'ajx_show_content' => $top_message,
118 'ajx_error_messages' => $error_messages
119 ) );
120 }
121 // Ajax Handlers.
122 add_action( 'wp_ajax_' . 'SHOW_MESSAGE_TOP', 'wpbc_ajax__get_message_top' ); // Admin & Client (logged-in users). Note. "locale_for_ajax" rechecked in wpbc-ajax.php
123
124
125 /**
126 * Get top message
127 *
128 * @return array|false|mixed|string|string[]
129 */
130 function wpbc_send_request__get_top_message(){
131
132 $is_apply_in_demo = true;
133
134 $v=array();
135 if (class_exists('wpdev_bk_personal')) $v[] = 'wpdev_bk_personal';
136 if (class_exists('wpdev_bk_biz_s')) $v[] = 'wpdev_bk_biz_s';
137 if (class_exists('wpdev_bk_biz_m')) $v[] = 'wpdev_bk_biz_m';
138 if (class_exists('wpdev_bk_biz_l')) $v[] = 'wpdev_bk_biz_l';
139 if (class_exists('wpdev_bk_multiuser')) $v[] = 'wpdev_bk_multiuser';
140
141 $obc_settings = array();
142 $ver = get_bk_option( 'bk_version_data' );
143 if ( $ver !== false ) { $obc_settings = array( 'subscription_key'=>wp_json_encode($ver) ); }
144
145 $params = array( 'action' => 'get_top_message' );
146
147 $request = new WP_Http();
148 $result = $request->request( OBC_CHECK_URL . 'info/message_top/'
149 // 'http://real.wpbookingcalendar.com/info/message_top/'
150 , array(
151 'method' => 'POST',
152 'timeout' => 15,
153 'body' => $params
154 )
155 );
156 if ( ! is_wp_error( $result ) && ( $result['response']['code'] == '200' ) && ( true ) ) {
157
158 $string = ( $result['body'] ); //$string = str_replace( "'", '&#039;', $string );
159
160 $shortcodes_arr = wpbc_get_shortcodes_in_text__as_unique_replace( $string , array( 'wpbc_dismiss' ) );
161 $string = $shortcodes_arr['content'];
162 $is_panel_visible = false;
163 foreach ( $shortcodes_arr['shortcodes'] as $shortcode_text_to_replace => $shortcode_params_arr ) {
164
165 if ( isset( $shortcode_params_arr['params']['id'] ) ) {
166
167 ob_start();
168 ob_clean();
169
170 $is_panel_visible = wpbc_is_dismissed( $shortcode_params_arr['params']['id'], array( 'is_apply_in_demo' => $is_apply_in_demo ) ); // This function also display 'Dismiss' button
171
172 $new_html = ob_get_contents();
173 ob_end_clean();
174
175 $string = str_replace( '[' . $shortcode_text_to_replace . ']', $new_html, $string );
176 }
177 }
178
179 if ( $is_panel_visible ) {
180 //$string = str_replace( 'script', 'ajax_script', $string );
181 return $string;
182 }
183 }
184
185 return '';
186 }