PluginProbe
Booking Calendar / 10.11.2
Booking Calendar v10.11.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 / publish / wpbc-publish-shortcode.php

wpbc-publish-shortcode.php in Booking Calendar 10.11.2, at includes/publish/wpbc-publish-shortcode.php

378 lines 17.4 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 Publish Booking Calendar shortcodes into the Pages
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2023-12-27
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.15.5.
16
17
18 /**
19 * Get prepared (for WP Blocks) shortcode of booking form for inserting into the post or page
20 *
21 * @param int $resource_id
22 *
23 * @return string
24 */
25 function wpbc_get_prepared_shortcode( $resource_id = 1 ) {
26
27 $resource_id = intval( $resource_id );
28
29 $shortcode = '';
30 if ( ! empty( $resource_id ) ) {
31
32 // $shortcode .= '<!-- wp:booking/booking {"wpbc_shortcode":"[booking resource_id=' . $resource_id . ' nummonths=1]"} -->';
33 // $shortcode .= '<div class="wp-block-booking-booking">[booking resource_id=' . $resource_id . ' nummonths=1]</div>';
34 // $shortcode .= '<!-- /wp:booking/booking -->';
35
36 $shortcode .= '<!-- wp:shortcode -->';
37 $shortcode .= '[booking resource_id=' . $resource_id . ' nummonths=1]';
38 $shortcode .= '<!-- /wp:shortcode -->';
39 }
40
41 return $shortcode;
42 }
43
44
45 /**
46 * Submit | Update checking
47 *
48 * @param $page_name
49 *
50 * @return false|void
51 */
52 function wpbc_check_for_submit__page_resource_publish( $page_name ) {
53
54 if (
55 ( 'resources' !== $page_name )
56 // && ( 'wpbc-ajx_booking_setup_wizard' !== $page_name )
57 ){
58 return false;
59 }
60
61 // Check $_POST
62
63 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
64 if ( ( isset( $_POST['action'] ) ) && ( 'wpbc_page_resource_publish' === $_POST['action'] ) ) {
65
66 if ( wpbc_is_this_demo() ) {
67 wpbc_show_notice__for_page_resource_publish( 'This operation is restricted in the demo version.', 'warning' );
68 return;
69 }
70
71 $nonce_gen_time = check_admin_referer( 'set_resource_publish_check' ); // It stops show anything on submitting, if it not refers to the original page
72
73 $add_shortcode_result_arr = false;
74
75 // CREATE NEW PAGE
76 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
77 if ( ( 'create' === $_POST['wpbc_page_resource_publish_what'] )
78 && ( ! empty($_POST['create_page_for_resource_publish'] ) )
79 && ( ! empty($_POST['wpbc_page_resource_publish_resource_id'] ) )
80 ){
81 $shortcode_resource_id = intval( $_POST['wpbc_page_resource_publish_resource_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
82 $page_name = sanitize_text_field( wp_unslash( $_POST['create_page_for_resource_publish'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
83
84 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
85 if ( ! empty( $_POST['wpbc_page_resource_publish_resource_shortcode'] ) ) {
86 //$insert_shortcode = WPBC_Settings_API::validate_textarea_post_static( 'wpbc_page_resource_publish_resource_shortcode' );
87 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
88 $insert_shortcode = wp_kses( trim( stripslashes( $_POST[ 'wpbc_page_resource_publish_resource_shortcode' ] ) ),
89 array_merge( array( // 'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true )
90 // , 'script' => array( 'type' => true ) // Allow JS
91 ),
92 wp_kses_allowed_html( 'post' )
93 )
94 );
95 $insert_shortcode = '<!-- wp:shortcode -->' . $insert_shortcode .'<!-- /wp:shortcode -->';
96 } else {
97 // auto_generated_shortcode
98 $insert_shortcode = wpbc_get_prepared_shortcode( $shortcode_resource_id );
99 }
100
101
102 // Add shortcode to specific Page with POST ID
103 $add_shortcode_result_arr = wpbc_add_shortcode_into_page( array(
104 'shortcode' => $insert_shortcode,
105 'check_exist_shortcode' => '[WPBC_' . microtime() . '_WPBC]', // Just add Fake shortcode, so we always add new shortcode to the page
106
107 'page_post_name' => sanitize_title( $page_name ),
108 'post_title' => esc_html( $page_name ),
109 'resource_id' => $shortcode_resource_id
110 ) );
111 }
112
113 // ADD TO EXIST PAGE
114 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
115 if ( ( 'edit' === $_POST['wpbc_page_resource_publish_what'] )
116 && ( ! empty($_POST['select_page_for_resource_publish'] ) )
117 && ( ! empty($_POST['wpbc_page_resource_publish_resource_id'] ) )
118 ){
119 $shortcode_resource_id = intval( $_POST['wpbc_page_resource_publish_resource_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
120 $page_id = intval( $_POST['select_page_for_resource_publish'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
121
122 // Add shortcode to specific Page with POST ID
123 $check_exist_shortcode_arr = array(
124 '[booking resource_id=' . $shortcode_resource_id . ' ',
125 '[booking resource_id=' . $shortcode_resource_id . ']',
126 '[booking type=' . $shortcode_resource_id . ' ',
127 '[booking type=' . $shortcode_resource_id . ']'
128 );
129 if ( 1 === $shortcode_resource_id ) {
130 $check_exist_shortcode_arr[] = '[booking]';
131 }
132
133
134 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
135 if ( ! empty( $_POST['wpbc_page_resource_publish_resource_shortcode'] ) ) {
136 //$insert_shortcode = WPBC_Settings_API::validate_textarea_post_static( 'wpbc_page_resource_publish_resource_shortcode' );
137 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
138 $insert_shortcode = wp_kses( trim( stripslashes( $_POST[ 'wpbc_page_resource_publish_resource_shortcode' ] ) ),
139 array_merge( array( // 'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true )
140 // , 'script' => array( 'type' => true ) // Allow JS
141 ),
142 wp_kses_allowed_html( 'post' )
143 )
144 );
145 $insert_shortcode = '<!-- wp:shortcode -->' . $insert_shortcode .'<!-- /wp:shortcode -->';
146 } else {
147 // auto_generated_shortcode
148 $insert_shortcode = wpbc_get_prepared_shortcode( $shortcode_resource_id );
149 }
150
151 $add_shortcode_result_arr = wpbc_add_shortcode_into_page( array(
152 'shortcode' => $insert_shortcode,
153 'page_id' => $page_id,
154 'check_exist_shortcode' => $check_exist_shortcode_arr, //'[WPBC_' . microtime() . '_WPBC]' // Just add Fake shortcode, so we always add new shortcode to the page
155 'resource_id' => $shortcode_resource_id
156 ) );
157 }
158
159 // Show Result Message
160 if (
161 ( ! empty( $add_shortcode_result_arr ) )
162 && ( $add_shortcode_result_arr['result'] )
163 && ( ! empty( $add_shortcode_result_arr['relative_url'] ) )
164 ){
165 $relative_post_url = $add_shortcode_result_arr['relative_url'];
166 $post_title = trim( $relative_post_url, '/' );
167 $post_obj = get_page_by_path( $relative_post_url );
168 if ( ! empty( $post_obj ) ) {
169 $post_title = $post_obj->post_title;
170 }
171 wpbc_show_notice__for_page_resource_publish( $add_shortcode_result_arr['message']
172 // . ' ' . '<a href="' . esc_url( wpbc_make_link_absolute( $relative_post_url ) ) . '">' . $post_title . '</a>'
173 );
174
175 } elseif ( false === $add_shortcode_result_arr ) {
176 wpbc_show_notice__for_page_resource_publish( 'Error: You may not have chosen the correct page name.', 'error' );
177 wpbc_show_notice__for_page_resource_publish(
178 /* translators: 1: ... */
179 sprintf( __( 'Find more information at the %1$sFAQ page%2$s', 'booking' ),
180 '<a href="https://wpbookingcalendar.com/faq/#shortcodes">', '</a>'
181 ), 'info');
182 }else {
183 wpbc_show_notice__for_page_resource_publish( $add_shortcode_result_arr['message'], 'error' );
184 wpbc_show_notice__for_page_resource_publish(
185 /* translators: 1: ... */
186 sprintf( __( 'Find more information at the %1$sFAQ page%2$s', 'booking' ),
187 '<a href="https://wpbookingcalendar.com/faq/#shortcodes">', '</a>'
188 ), 'info');
189 }
190
191 }
192 }
193 add_action( 'wpbc_hook_settings_page_before_content_table', 'wpbc_check_for_submit__page_resource_publish' ,10, 1);
194
195
196 function wpbc_show_notice__for_page_resource_publish( $message, $message_type = 'success' ) {
197 ?>
198 <div class="wpbc-settings-notice notice-<?php echo esc_attr( $message_type ); ?>" style="text-align:left;font-size: 1rem;margin-top:20px;">
199 <strong><?php
200 if ( ( 'error' == $message_type ) ) {
201 echo esc_html__( 'Error', 'booking' ) . '! ';
202 } ?></strong> <?php
203 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
204 echo $message;
205 ?>
206 </div>
207 <?php
208 }
209
210
211 /** Publish Layout - Modal Window structure */
212 function wpbc_write_content_for_modal__page_resource_publish( $page_name ) {
213
214 if (
215 ( 'resources' !== $page_name ) &&
216 ( 'wpbc-ajx_booking_setup_wizard' !== $page_name )
217 // && ( 'wpbc-ajx_booking' !== $page_name ) // FixIn: 10.6.6.2.
218 ){
219 return false;
220 }
221
222 ?><span class="wpdevelop"><?php
223
224 ?><div id="wpbc_modal__resource_publish" class="modal wpbc_popup_modal" tabindex="-1" role="dialog">
225 <style type="text/css">
226 #wpbc_modal__resource_publish .modal-header .modal-title {
227 font-weight: 600;
228 }
229 .wpbc_popup_modal .form-table input[type="radio"]{
230 margin: -4px 4px 0 0;
231 }
232 .wpbc_publish_wizard_steps {
233 display: none;
234 }
235 .wpbc_publish_wizard_step_1 {
236 display: block;
237 }
238 .wpbc_publish_wizard_steps .wpbc_publish_wizard_inner_header {
239 line-height: 1.75em;
240 text-align: center;
241 font-size: 16px;
242 font-weight: 400;
243 max-width: 30em;
244 margin: 0 auto;
245 margin-bottom: 15px;
246 }
247 .wpbc_publish_wizard_steps__buttons,
248 .wpbc_publish_wizard_steps__inputs {
249 display: flex;
250 flex-flow: row wrap;
251 justify-content: center;
252 align-items: center;
253 margin:10px 0;
254 }
255 #wpbc_modal__resource_publish .wpbc_publish_wizard_steps__buttons a{
256 margin: 0 10px;
257 }
258 #wpbc_modal__resource_publish .modal-footer {
259 display: none;
260 text-align: center;
261 }
262 .wp-core-ui .wpbc_page .wpbc_publish_wizard_steps__inputs input[type='text'],
263 .wpbc_publish_wizard_steps__inputs input[type='text'],
264 .wpbc_publish_wizard_steps__inputs select {
265 width: Min(100%,25em);
266 max-width: Min(100%,25em);
267 margin: 5px 10px 10px;
268 min-height: 30px;
269 }
270 .wpbc_publish_wizard_steps__inputs input[type='submit'] {
271 margin: 5px 10px 10px;
272 }
273 </style>
274 <div class="modal-dialog modal-lg0">
275 <div class="modal-content">
276 <div class="modal-header">
277 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
278 <h4 class="modal-title"><?php esc_html_e( 'Insert into page', 'booking' ); ?></h4>
279 </div>
280 <div class="modal-body">
281 <div id="wpbc_content_for_js_resource_publish">
282 <?php
283 if ( wpbc_is_this_demo() ) {
284 wpbc_show_notice__for_page_resource_publish( 'In the demo versions such operation is not allowed.', 'warning' );
285 } else {
286 ?>
287 <form method="post" action="">
288 <input type="hidden" name="action" value="wpbc_page_resource_publish" />
289 <input type="hidden" id="wpbc_page_resource_publish_resource_id" name="wpbc_page_resource_publish_resource_id" value="" />
290 <input type="hidden" id="wpbc_page_resource_publish_resource_shortcode" name="wpbc_page_resource_publish_resource_shortcode" value="" />
291 <input type="hidden" id="wpbc_page_resource_publish_what" name="wpbc_page_resource_publish_what" value="" />
292 <?php
293 wp_nonce_field( 'set_resource_publish_check' );
294 ?>
295 <div class="wpbc_publish_wizard_steps wpbc_publish_wizard_step_1">
296 <div class="wpbc_publish_wizard_inner_header"><?php esc_html_e('Choose whether to embed your booking form in an existing page or create a new one.', 'booking'); ?></div>
297 <div class="wpbc_publish_wizard_steps__buttons">
298 <a href="javascript:void(0)" class="button button-secondary"
299 onclick="javascript:jQuery( '.wpbc_publish_wizard_steps').hide();
300 jQuery( '.wpbc_publish_wizard_step_2').show();
301 jQuery( '#wpbc_modal__resource_publish .modal-footer').show();
302 jQuery( '#wpbc_page_resource_publish_resource_shortcode' ).val( jQuery( '#booking_resource_shortcode_' + jQuery( '#wpbc_page_resource_publish_resource_id' ).val() ).val() );
303 jQuery( '#wpbc_page_resource_publish_what' ).val( 'edit' );"
304 ><?php esc_html_e('Embed in Existing Page', 'booking' ); ?></a>
305 <a href="javascript:void(0)" class="button button-secondary"
306 onclick="javascript:jQuery( '.wpbc_publish_wizard_steps').hide();
307 jQuery( '.wpbc_publish_wizard_step_3').show();
308 jQuery( '#wpbc_modal__resource_publish .modal-footer').show();
309 jQuery( '#wpbc_page_resource_publish_resource_shortcode' ).val( jQuery( '#booking_resource_shortcode_' + jQuery( '#wpbc_page_resource_publish_resource_id' ).val() ).val() );
310 jQuery( '#wpbc_page_resource_publish_what' ).val( 'create' );"
311 ><?php esc_html_e('Create New Page','booking'); ?></a>
312 </div>
313 </div>
314 <div class="wpbc_publish_wizard_steps wpbc_publish_wizard_step_2">
315 <div class="wpbc_publish_wizard_inner_header"><?php esc_html_e('Select the page where you want to embed your booking form.', 'booking'); ?></div>
316 <div class="wpbc_publish_wizard_steps__inputs">
317 <?php
318 wp_dropdown_pages(
319 array(
320 'name' => 'select_page_for_resource_publish',
321 'show_option_none' => '&mdash; ' . esc_html__( 'Select', 'booking' ) . ' &mdash;',
322 'option_none_value' => '0',
323 'selected' => 0,//$privacy_policy_page_id,
324 'post_status' => array( 'draft', 'publish' ),
325 )
326 );
327 submit_button( __( 'Use This Page', 'booking' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) );
328 ?>
329 </div>
330 </div>
331 <div class="wpbc_publish_wizard_steps wpbc_publish_wizard_step_3">
332 <div class="wpbc_publish_wizard_inner_header"><?php esc_html_e('Provide a name for your new page.', 'booking'); ?></div>
333 <div class="wpbc_publish_wizard_steps__inputs">
334 <input id="create_page_for_resource_publish" name="create_page_for_resource_publish" type="text" value=""
335 placeholder="<?php echo esc_attr( __( 'Enter Page Name', 'booking' ) ); ?>"/>
336 <?php
337 submit_button( __( 'Create Page', 'booking' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) );
338 ?>
339 </div>
340 </div>
341 </form>
342 <?php } ?>
343 </div>
344 </div>
345 <div class="modal-footer">
346 <!--a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal"><?php esc_html_e('Close' ,'booking'); ?></a-->
347 <a id="wpbc_modal__go_back_button" class="button button-secondary"
348 href="javascript:void(0);"
349 onclick="javascript:jQuery( '.wpbc_publish_wizard_steps').hide();
350 jQuery( '.wpbc_publish_wizard_step_1').show();
351 jQuery( '#wpbc_modal__resource_publish .modal-footer').hide();"
352 ><i class="menu_icon icon-1x wpbc_icn_keyboard_arrow_left"></i> <?php esc_html_e('Go Back' ,'booking'); ?></a>
353 </div>
354 </div><!-- /.modal-content -->
355 </div><!-- /.modal-dialog -->
356 </div><!-- /.modal -->
357 <?php
358
359 ?></span><?php
360
361
362 ?><script type="text/javascript">
363 function wpbc_modal_dialog__show__resource_publish( booking_id ){
364
365 if ( 'function' === typeof (jQuery( '#wpbc_modal__resource_publish' ).wpbc_my_modal) ){
366 jQuery( '#wpbc_modal__resource_publish' ).wpbc_my_modal( 'show' );
367 jQuery( '#wpbc_page_resource_publish_resource_id' ).val( booking_id );
368 jQuery( '.wpbc_publish_wizard_steps').hide();
369 jQuery( '.wpbc_publish_wizard_step_1').show();
370 jQuery( '#wpbc_modal__resource_publish .modal-footer').hide();
371 } else {
372 alert( 'Warning! Modal module( wpbc_my_modal ) had not define.' )
373 }
374 }
375 </script><?php
376 }
377 add_action( 'wpbc_hook_settings_page_footer', 'wpbc_write_content_for_modal__page_resource_publish' ,10, 1);
378