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 / publish / wpbc-publish-shortcode.php

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

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