| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @description Booking Manager - Shortcodes |
| 5 | 5 | * |
| 6 | 6 | * @author wpdevelop |
| 7 | - * @link http://oplugins.com/ | |
| 7 | + * @link https://oplugins.com/ | |
| 8 | 8 | * @email info@oplugins.com |
| 9 | 9 | * |
| 10 | 10 | * @modified 2017-07-16 |
| 11 | 11 | */ |
| @@ -23,8 +23,14 @@ | ||
| 23 | 23 | * @return string |
| 24 | 24 | */ |
| 25 | 25 | function wpbm_ics_import_shortcode( $attr ) { |
| 26 | 26 | |
| 27 | + if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { | |
| 28 | + return wpbc_get_preview_for_shortcode( 'booking-manager-import', $attr ); //FixIn: 9.9.0.39 | |
| 29 | + } | |
| 30 | + | |
| 31 | + if ( wpbm_block_shortcodes_if_unpublished() ) { return ''; } // FixIn: 2.1.15.1. | |
| 32 | + | |
| 27 | 33 | ob_start(); |
| 28 | 34 | |
| 29 | 35 | $import_status = wpbm_ics_import_start( $attr ); |
| 30 | 36 | |
| @@ -63,9 +69,15 @@ | ||
| 63 | 69 | * |
| 64 | 70 | * @param array $attr |
| 65 | 71 | */ |
| 66 | 72 | function wpbm_ics_listing_shortcode( $attr ) { |
| 67 | - | |
| 73 | + | |
| 74 | + if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { | |
| 75 | + return wpbc_get_preview_for_shortcode( 'booking-manager-listing', $attr ); //FixIn: 9.9.0.39 | |
| 76 | + } | |
| 77 | + | |
| 78 | + if ( wpbm_block_shortcodes_if_unpublished() ) { return ''; } // FixIn: 2.1.15.1. | |
| 79 | + | |
| 68 | 80 | $listing = wpbm_ics_get_listing( $attr ); |
| 69 | 81 | |
| 70 | 82 | return $listing; |
| 71 | 83 | |
| @@ -70,4 +82,111 @@ | ||
| 70 | 82 | return $listing; |
| 71 | 83 | |
| 72 | 84 | } |
| 73 | 85 | add_shortcode('booking-manager-listing', 'wpbm_ics_listing_shortcode' ); //[booking-manager-listing url='https://calendar.google.com/calendar/ical/pkqi3dnhq1l4j2qu0id3as984k%40group.calendar.google.com/public/basic.ics' from='2016-08-01' until='2018-08-30'] |
| 86 | + | |
| 87 | + | |
| 88 | +//FixIn: 2.0.22.1 | |
| 89 | +// [booking-manager-delete resource_id=5] | |
| 90 | +// [booking-manager-delete resource_id=5 action='delete'] | |
| 91 | +function wpbm_ics_delete_shortcode( $attr ) { | |
| 92 | + | |
| 93 | + if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { | |
| 94 | + return wpbc_get_preview_for_shortcode( 'booking-manager-delete', $attr ); //FixIn: 9.9.0.39 | |
| 95 | + } | |
| 96 | + | |
| 97 | + if ( wpbm_block_shortcodes_if_unpublished() ) { return ''; } // FixIn: 2.1.15.1. | |
| 98 | + | |
| 99 | + ob_start(); | |
| 100 | + | |
| 101 | + if ( ! isset( $attr['resource_id'] ) ) { | |
| 102 | + $attr['resource_id'] = 1; | |
| 103 | + } | |
| 104 | + | |
| 105 | + if ( ! isset( $attr['action'] ) ) { | |
| 106 | + $attr['action'] = 'trash'; | |
| 107 | + } | |
| 108 | + | |
| 109 | + global $wpdb; | |
| 110 | + $is_trash = 1; | |
| 111 | + $resource_id = intval( $attr['resource_id'] ); //FixIn: | |
| 112 | + | |
| 113 | + if ( 'trash' == $attr['action'] ) { | |
| 114 | + | |
| 115 | + $my_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = {$is_trash} WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id}"; | |
| 116 | + | |
| 117 | + if ( false === $wpdb->query( $my_sql ) ) { | |
| 118 | + ?> | |
| 119 | + <script type="text/javascript"> | |
| 120 | + var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during trash booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; | |
| 121 | + wpbc_admin_show_message( my_message, 'error', 30000 ); | |
| 122 | + </script> <?php | |
| 123 | + } | |
| 124 | + } | |
| 125 | + | |
| 126 | + if ( 'delete' == $attr['action'] ) { | |
| 127 | + | |
| 128 | + $bookings_obj_arr = $wpdb->get_results( "SELECT booking_id as ID FROM {$wpdb->prefix}booking WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id} LIMIT 0, 1000" ); | |
| 129 | + | |
| 130 | + $id_arr = array(); | |
| 131 | + foreach ( $bookings_obj_arr as $booking_obj ) { | |
| 132 | + $id_arr[] = $booking_obj->ID; | |
| 133 | + } | |
| 134 | + $string_id = implode( ',', $id_arr ); | |
| 135 | + | |
| 136 | + if ( $string_id != '' ) { | |
| 137 | + | |
| 138 | + // D E L E T E Dates | |
| 139 | + if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$string_id})" ) ) { ?> <script type="text/javascript"> var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during deleting booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; wpbc_admin_show_message( my_message, 'error', 30000 ); </script> <?php die(); } | |
| 140 | + // D E L E T E Bookings | |
| 141 | + if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$string_id})" ) ){ ?> <script type="text/javascript"> var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during deleting booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; wpbc_admin_show_message( my_message, 'error', 30000 ); </script> <?php die(); } | |
| 142 | + } | |
| 143 | + } | |
| 144 | + | |
| 145 | + $echo_results = ob_get_contents(); | |
| 146 | + | |
| 147 | + ob_end_clean(); | |
| 148 | + | |
| 149 | + return ''; | |
| 150 | +} | |
| 151 | +add_shortcode( 'booking-manager-delete', 'wpbm_ics_delete_shortcode' ); | |
| 152 | + | |
| 153 | + | |
| 154 | +/** | |
| 155 | + * Return true if shortcode should NOT run for the current post context. | |
| 156 | + * Allowed statuses are filterable via 'wpbm_shortcode_allowed_statuses' (default: ['publish']). | |
| 157 | + * | |
| 158 | + * @return bool | |
| 159 | + */ | |
| 160 | +function wpbm_block_shortcodes_if_unpublished() { | |
| 161 | + | |
| 162 | + // FixIn: 2.1.15.1. | |
| 163 | + $post = get_post(); | |
| 164 | + if ( ! $post ) { | |
| 165 | + return true; // no post context -> suppress. | |
| 166 | + } | |
| 167 | + | |
| 168 | + // e.g. add 'private'. | |
| 169 | + $allowed_statuses = apply_filters( 'wpbm_shortcode_allowed_statuses', array( 'publish' ) ); | |
| 170 | + | |
| 171 | + // Do not execute the shortcode. | |
| 172 | + if ( ! in_array( $post->post_status, $allowed_statuses, true ) ) { | |
| 173 | + return true; | |
| 174 | + } | |
| 175 | + | |
| 176 | + // Optional: allow front-end preview for editors. | |
| 177 | + /* | |
| 178 | + if ( is_preview() && current_user_can( 'edit_post', $post->ID ) ) { | |
| 179 | + return false; // allow | |
| 180 | + } | |
| 181 | + */ | |
| 182 | + | |
| 183 | + // Optional: suppress in REST/admin universally. | |
| 184 | + /* | |
| 185 | + if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { | |
| 186 | + return true; | |
| 187 | + } | |
| 188 | + */ | |
| 189 | + | |
| 190 | + // Execute the shortcode normally. | |
| 191 | + return false; | |
| 192 | +} | |