PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 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 All 205 releases
booking / includes / publish / wpbc-publish-shortcode.php

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

393 lines 18.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 Publish Booking Calendar shortcodes into the Pages
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email [email protected]
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 ){
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_booking_form_publishing_restricted() ) {
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 * Render feedback from the Booking Resource publishing workflow.
197 *
198 * The shared publisher is also used outside the Resources catalog, so catalog
199 * spacing is applied only while the new catalog renderer owns the request.
200 *
201 * @param string $message Escaped or deliberately prepared notice markup.
202 * @param string $message_type Notice type used by the Booking Calendar notice styles.
203 *
204 * @return void
205 */
206 function wpbc_show_notice__for_page_resource_publish( $message, $message_type = 'success' ) {
207 $notice_style = 'text-align:left;font-size:1rem;margin-top:20px;';
208
209 if ( function_exists( 'wpbc_catalog_booking_resources_is_page' ) && wpbc_catalog_booking_resources_is_page() ) {
210 $notice_style = 'text-align:left;font-size:1rem;margin:0 0 40px;';
211 }
212 ?>
213 <div class="wpbc-settings-notice notice-<?php echo esc_attr( $message_type ); ?>" style="<?php echo esc_attr( $notice_style ); ?>">
214 <strong><?php
215 if ( ( 'error' == $message_type ) ) {
216 echo esc_html__( 'Error', 'booking' ) . '! ';
217 } ?></strong> <?php
218 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
219 echo $message;
220 ?>
221 </div>
222 <?php
223 }
224
225
226 /** Publish Layout - Modal Window structure */
227 function wpbc_write_content_for_modal__page_resource_publish( $page_name ) {
228
229 if (
230 ( 'resources' !== $page_name ) &&
231 ( ! wpbc_is_builder_booking_form_page() )
232 // && ( 'wpbc-ajx_booking' !== $page_name ) // FixIn: 10.6.6.2.
233 ){
234 return false;
235 }
236
237 ?><span class="wpdevelop"><?php
238
239 ?><div id="wpbc_modal__resource_publish" class="modal wpbc_popup_modal" tabindex="-1" role="dialog">
240 <style type="text/css">
241 #wpbc_modal__resource_publish .modal-header .modal-title {
242 font-weight: 600;
243 }
244 .wpbc_popup_modal .form-table input[type="radio"]{
245 margin: -4px 4px 0 0;
246 }
247 .wpbc_publish_wizard_steps {
248 display: none;
249 }
250 .wpbc_publish_wizard_step_1 {
251 display: block;
252 }
253 .wpbc_publish_wizard_steps .wpbc_publish_wizard_inner_header {
254 line-height: 1.75em;
255 text-align: center;
256 font-size: 16px;
257 font-weight: 400;
258 max-width: 30em;
259 margin: 0 auto;
260 margin-bottom: 15px;
261 }
262 .wpbc_publish_wizard_steps__buttons,
263 .wpbc_publish_wizard_steps__inputs {
264 display: flex;
265 flex-flow: row wrap;
266 justify-content: center;
267 align-items: center;
268 margin:10px 0;
269 }
270 #wpbc_modal__resource_publish .wpbc_publish_wizard_steps__buttons a{
271 margin: 0 10px;
272 }
273 #wpbc_modal__resource_publish .modal-footer {
274 display: none;
275 text-align: center;
276 }
277 .wp-core-ui .wpbc_page .wpbc_publish_wizard_steps__inputs input[type='text'],
278 .wpbc_publish_wizard_steps__inputs input[type='text'],
279 .wpbc_publish_wizard_steps__inputs select {
280 width: Min(100%,25em);
281 max-width: Min(100%,25em);
282 margin: 5px 10px 10px;
283 min-height: 30px;
284 }
285 .wpbc_publish_wizard_steps__inputs input[type='submit'] {
286 margin: 5px 10px 10px;
287 }
288 </style>
289 <div class="modal-dialog modal-lg0">
290 <div class="modal-content">
291 <div class="modal-header">
292 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
293 <h4 class="modal-title"><?php esc_html_e( 'Insert into page', 'booking' ); ?></h4>
294 </div>
295 <div class="modal-body">
296 <div id="wpbc_content_for_js_resource_publish">
297 <?php
298 if ( wpbc_is_booking_form_publishing_restricted() ) {
299 wpbc_show_notice__for_page_resource_publish( 'In the demo versions such operation is not allowed.', 'warning' );
300 } else {
301 ?>
302 <form method="post" action="">
303 <input type="hidden" name="action" value="wpbc_page_resource_publish" />
304 <input type="hidden" id="wpbc_page_resource_publish_resource_id" name="wpbc_page_resource_publish_resource_id" value="" />
305 <input type="hidden" id="wpbc_page_resource_publish_resource_shortcode" name="wpbc_page_resource_publish_resource_shortcode" value="" />
306 <input type="hidden" id="wpbc_page_resource_publish_what" name="wpbc_page_resource_publish_what" value="" />
307 <?php
308 wp_nonce_field( 'set_resource_publish_check' );
309 ?>
310 <div class="wpbc_publish_wizard_steps wpbc_publish_wizard_step_1">
311 <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>
312 <div class="wpbc_publish_wizard_steps__buttons">
313 <a href="javascript:void(0)" class="button button-secondary"
314 onclick="javascript:jQuery( '.wpbc_publish_wizard_steps').hide();
315 jQuery( '.wpbc_publish_wizard_step_2').show();
316 jQuery( '#wpbc_modal__resource_publish .modal-footer').show();
317 jQuery( '#wpbc_page_resource_publish_resource_shortcode' ).val( jQuery( '#booking_resource_shortcode_' + jQuery( '#wpbc_page_resource_publish_resource_id' ).val() ).val() );
318 jQuery( '#wpbc_page_resource_publish_what' ).val( 'edit' );"
319 ><?php esc_html_e('Embed in Existing Page', 'booking' ); ?></a>
320 <a href="javascript:void(0)" class="button button-secondary"
321 onclick="javascript:jQuery( '.wpbc_publish_wizard_steps').hide();
322 jQuery( '.wpbc_publish_wizard_step_3').show();
323 jQuery( '#wpbc_modal__resource_publish .modal-footer').show();
324 jQuery( '#wpbc_page_resource_publish_resource_shortcode' ).val( jQuery( '#booking_resource_shortcode_' + jQuery( '#wpbc_page_resource_publish_resource_id' ).val() ).val() );
325 jQuery( '#wpbc_page_resource_publish_what' ).val( 'create' );"
326 ><?php esc_html_e('Create New Page','booking'); ?></a>
327 </div>
328 </div>
329 <div class="wpbc_publish_wizard_steps wpbc_publish_wizard_step_2">
330 <div class="wpbc_publish_wizard_inner_header"><?php esc_html_e('Select the page where you want to embed your booking form.', 'booking'); ?></div>
331 <div class="wpbc_publish_wizard_steps__inputs">
332 <?php
333 wp_dropdown_pages(
334 array(
335 'name' => 'select_page_for_resource_publish',
336 'show_option_none' => '&mdash; ' . esc_html__( 'Select', 'booking' ) . ' &mdash;',
337 'option_none_value' => '0',
338 'selected' => 0,//$privacy_policy_page_id,
339 'post_status' => array( 'draft', 'publish' ),
340 )
341 );
342 submit_button( __( 'Use This Page', 'booking' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) );
343 ?>
344 </div>
345 </div>
346 <div class="wpbc_publish_wizard_steps wpbc_publish_wizard_step_3">
347 <div class="wpbc_publish_wizard_inner_header"><?php esc_html_e('Provide a name for your new page.', 'booking'); ?></div>
348 <div class="wpbc_publish_wizard_steps__inputs">
349 <input id="create_page_for_resource_publish" name="create_page_for_resource_publish" type="text" value=""
350 placeholder="<?php echo esc_attr( __( 'Enter Page Name', 'booking' ) ); ?>"/>
351 <?php
352 submit_button( __( 'Create Page', 'booking' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) );
353 ?>
354 </div>
355 </div>
356 </form>
357 <?php } ?>
358 </div>
359 </div>
360 <div class="modal-footer">
361 <!--a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal"><?php esc_html_e('Close' ,'booking'); ?></a-->
362 <a id="wpbc_modal__go_back_button" class="button button-secondary"
363 href="javascript:void(0);"
364 onclick="javascript:jQuery( '.wpbc_publish_wizard_steps').hide();
365 jQuery( '.wpbc_publish_wizard_step_1').show();
366 jQuery( '#wpbc_modal__resource_publish .modal-footer').hide();"
367 ><i class="menu_icon icon-1x wpbc_icn_keyboard_arrow_left"></i> <?php esc_html_e('Go Back' ,'booking'); ?></a>
368 </div>
369 </div><!-- /.modal-content -->
370 </div><!-- /.modal-dialog -->
371 </div><!-- /.modal -->
372 <?php
373
374 ?></span><?php
375
376
377 ?><script type="text/javascript">
378 function wpbc_modal_dialog__show__resource_publish( booking_id ){
379
380 if ( 'function' === typeof (jQuery( '#wpbc_modal__resource_publish' ).wpbc_my_modal) ){
381 jQuery( '#wpbc_modal__resource_publish' ).wpbc_my_modal( 'show' );
382 jQuery( '#wpbc_page_resource_publish_resource_id' ).val( booking_id );
383 jQuery( '.wpbc_publish_wizard_steps').hide();
384 jQuery( '.wpbc_publish_wizard_step_1').show();
385 jQuery( '#wpbc_modal__resource_publish .modal-footer').hide();
386 } else {
387 alert( 'Warning! Modal module( wpbc_my_modal ) had not define.' )
388 }
389 }
390 </script><?php
391 }
392 add_action( 'wpbc_hook_settings_page_footer', 'wpbc_write_content_for_modal__page_resource_publish' ,10, 1);
393