PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
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 10.1.3, at includes/_news/wpbc_news.php

184 lines 5.9 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 ?><div class="wpbc_message_wrapper <?php echo 'wpbc__version__' . $version ?>"><?php
49
50 // Send Ajax request to get info about the notifications
51 wp_nonce_field('wpbc_ajax_message_top_nonce', "wpbc_ajax_message_top_nonce" , true , true );
52
53 ?><script type="text/javascript">
54 jQuery(document).ready(function(){
55
56 var wpbc_ajax_sent_timer = setTimeout( function (){
57
58 console.log( '== Before Ajax Send - SHOW_MESSAGE_TOP ==' );
59
60 jQuery.ajax({
61 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
62 type:'POST',
63 success: function (data, textStatus){
64
65 // console.log( 'AJAX _ SHOW_MESSAGE_TOP', data );
66 if ( textStatus == 'success' ) {
67 jQuery( '.wpbc_message_wrapper' ).html( data[ 'ajx_show_content' ] );
68 }
69 console.log( '== Response - SHOW_MESSAGE_TOP ==' );
70 },
71 error: function (XMLHttpRequest, textStatus, errorThrown){
72 console.log( 'Ajax sending Error:', XMLHttpRequest, textStatus, errorThrown );
73 },
74 data:{
75 action : 'SHOW_MESSAGE_TOP',
76 wpbc_nonce: document.getElementById( 'wpbc_ajax_message_top_nonce' ).value
77 }
78 });
79 }, 2000 );
80
81 });
82 </script><?php
83
84 ?></div><?php
85
86 }
87 add_bk_action('wpbc_h1_header_content_end', 'wpbc_show_message_top');
88
89
90 /**
91 * Send Ajax request for getting message in top header
92 *
93 * @return void
94 */
95 function wpbc_ajax__get_message_top(){
96
97
98 $ajax_errors = new WPBC_AJAX_ERROR_CATCHING();
99
100 // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),
101 $action_name = 'wpbc_ajax_message_top_nonce';
102 $nonce_post_key = 'wpbc_nonce';
103 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
104
105 // $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id();
106
107 // Check if there were some errors --------------------------------------------------------------------------------
108 $error_messages = $ajax_errors->get_error_messages();
109
110 $top_message = wpbc_send_request__get_top_message();
111
112 //------------------------------------------------------------------------------------------------------------------
113 // 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.
114 wp_send_json( array(
115 'ajx_show_content' => $top_message,
116 'ajx_error_messages' => $error_messages
117 ) );
118 }
119 // Ajax Handlers.
120 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
121
122
123 /**
124 * Get top message
125 *
126 * @return array|false|mixed|string|string[]
127 */
128 function wpbc_send_request__get_top_message(){
129
130 $is_apply_in_demo = true;
131
132 $v=array();
133 if (class_exists('wpdev_bk_personal')) $v[] = 'wpdev_bk_personal';
134 if (class_exists('wpdev_bk_biz_s')) $v[] = 'wpdev_bk_biz_s';
135 if (class_exists('wpdev_bk_biz_m')) $v[] = 'wpdev_bk_biz_m';
136 if (class_exists('wpdev_bk_biz_l')) $v[] = 'wpdev_bk_biz_l';
137 if (class_exists('wpdev_bk_multiuser')) $v[] = 'wpdev_bk_multiuser';
138
139 $obc_settings = array();
140 $ver = get_bk_option( 'bk_version_data' );
141 if ( $ver !== false ) { $obc_settings = array( 'subscription_key'=>wp_json_encode($ver) ); }
142
143 $params = array( 'action' => 'get_top_message' );
144
145 $request = new WP_Http();
146 $result = $request->request( OBC_CHECK_URL . 'info/message_top/'
147 // 'http://real.wpbookingcalendar.com/info/message_top/'
148 , array(
149 'method' => 'POST',
150 'timeout' => 15,
151 'body' => $params
152 )
153 );
154 if ( ! is_wp_error( $result ) && ( $result['response']['code'] == '200' ) && ( true ) ) {
155
156 $string = ( $result['body'] ); //$string = str_replace( "'", '&#039;', $string );
157
158 $shortcodes_arr = wpbc_get_shortcodes_in_text__as_unique_replace( $string , array( 'wpbc_dismiss' ) );
159 $string = $shortcodes_arr['content'];
160 $is_panel_visible = false;
161 foreach ( $shortcodes_arr['shortcodes'] as $shortcode_text_to_replace => $shortcode_params_arr ) {
162
163 if ( isset( $shortcode_params_arr['params']['id'] ) ) {
164
165 ob_start();
166 ob_clean();
167
168 $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
169
170 $new_html = ob_get_contents();
171 ob_end_clean();
172
173 $string = str_replace( '[' . $shortcode_text_to_replace . ']', $new_html, $string );
174 }
175 }
176
177 if ( $is_panel_visible ) {
178 //$string = str_replace( 'script', 'ajax_script', $string );
179 return $string;
180 }
181 }
182
183 return '';
184 }