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

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

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