| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @description Booking Manager - Shortcodes |
| 5 |
* |
| 6 |
* @author wpdevelop |
| 7 |
* @link https://oplugins.com/ |
| 8 |
* @email [email protected] |
| 9 |
* |
| 10 |
* @modified 2017-07-16 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
//////////////////////////////////////////////////////////////////////////////////////////// |
| 17 |
// I M P O R T |
| 18 |
//////////////////////////////////////////////////////////////////////////////////////////// |
| 19 |
|
| 20 |
/** Shortcode [] - Import ICS feed and create bookings from this feed. |
| 21 |
* |
| 22 |
* @param array $attr |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
function wpbm_ics_import_shortcode( $attr ) { |
| 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 |
ob_start(); |
| 32 |
|
| 33 |
$import_status = wpbm_ics_import_start( $attr ); |
| 34 |
|
| 35 |
$echo_results = ob_get_contents(); |
| 36 |
|
| 37 |
ob_end_clean(); |
| 38 |
|
| 39 |
if ( ! empty( $attr['silence'] ) ) { //FixIn: m.2.0.1.2 - do not show 'Import XX bookings' message, if paremeter silence=1 in shortcode |
| 40 |
$import_status_echo = ''; |
| 41 |
} else { |
| 42 |
$import_status_echo = sprintf( __( 'Imported %s bookings', 'booking-manager' ), '<strong>' . ( (int) $import_status ) . '</strong>' ); |
| 43 |
} |
| 44 |
|
| 45 |
return $import_status_echo . $echo_results; |
| 46 |
} |
| 47 |
add_shortcode('booking-manager-import', 'wpbm_ics_import_shortcode' ); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
//////////////////////////////////////////////////////////////////////////////////////////// |
| 53 |
// L I S T I N G |
| 54 |
//////////////////////////////////////////////////////////////////////////////////////////// |
| 55 |
// [booking-manager-listing url='https://server.com/feed.ics' from='2017-08-06' until='week' until_offset='4h' max=500] |
| 56 |
// [booking-manager-listing url='https://server.com/feed.ics' from='today' from_offset='5d' until='year-end' until_offset='4h' max=500] |
| 57 |
// 'now' => __( 'Now', 'booking-manager' ) |
| 58 |
// , 'today' => __( '00:00 Today', 'booking-manager' ) |
| 59 |
// , 'week' => __( 'Start of current week', 'booking-manager' ) |
| 60 |
// , 'month-start' => __( 'Start of current month', 'booking-manager' ) |
| 61 |
// , 'month-end' => __( 'End of current month', 'booking-manager' ) |
| 62 |
// , 'year-start' => __( 'Start of current year', 'booking-manager' ) |
| 63 |
// , 'any' => __( 'The start of time', 'booking-manager' ) |
| 64 |
// , 'date' => __( 'Specific date / time', 'booking-manager' ) |
| 65 |
|
| 66 |
/** Shortcode [booking-manager-listing ...] for showing listing from .ics feed |
| 67 |
* |
| 68 |
* @param array $attr |
| 69 |
*/ |
| 70 |
function wpbm_ics_listing_shortcode( $attr ) { |
| 71 |
|
| 72 |
if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { |
| 73 |
return wpbc_get_preview_for_shortcode( 'booking-manager-listing', $attr ); //FixIn: 9.9.0.39 |
| 74 |
} |
| 75 |
|
| 76 |
$listing = wpbm_ics_get_listing( $attr ); |
| 77 |
|
| 78 |
return $listing; |
| 79 |
|
| 80 |
} |
| 81 |
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'] |
| 82 |
|
| 83 |
|
| 84 |
//FixIn: 2.0.22.1 |
| 85 |
// [booking-manager-delete resource_id=5] |
| 86 |
// [booking-manager-delete resource_id=5 action='delete'] |
| 87 |
function wpbm_ics_delete_shortcode( $attr ) { |
| 88 |
|
| 89 |
if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { |
| 90 |
return wpbc_get_preview_for_shortcode( 'booking-manager-delete', $attr ); //FixIn: 9.9.0.39 |
| 91 |
} |
| 92 |
|
| 93 |
ob_start(); |
| 94 |
|
| 95 |
if ( ! isset( $attr['resource_id'] ) ) { |
| 96 |
$attr['resource_id'] = 1; |
| 97 |
} |
| 98 |
|
| 99 |
if ( ! isset( $attr['action'] ) ) { |
| 100 |
$attr['action'] = 'trash'; |
| 101 |
} |
| 102 |
|
| 103 |
global $wpdb; |
| 104 |
$is_trash = 1; |
| 105 |
$resource_id = intval( $attr['resource_id'] ); //FixIn: |
| 106 |
|
| 107 |
if ( 'trash' == $attr['action'] ) { |
| 108 |
|
| 109 |
$my_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = {$is_trash} WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id}"; |
| 110 |
|
| 111 |
if ( false === $wpdb->query( $my_sql ) ) { |
| 112 |
?> |
| 113 |
<script type="text/javascript"> |
| 114 |
var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during trash booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; |
| 115 |
wpbc_admin_show_message( my_message, 'error', 30000 ); |
| 116 |
</script> <?php |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
if ( 'delete' == $attr['action'] ) { |
| 121 |
|
| 122 |
$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" ); |
| 123 |
|
| 124 |
$id_arr = array(); |
| 125 |
foreach ( $bookings_obj_arr as $booking_obj ) { |
| 126 |
$id_arr[] = $booking_obj->ID; |
| 127 |
} |
| 128 |
$string_id = implode( ',', $id_arr ); |
| 129 |
|
| 130 |
if ( $string_id != '' ) { |
| 131 |
|
| 132 |
// D E L E T E Dates |
| 133 |
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(); } |
| 134 |
// D E L E T E Bookings |
| 135 |
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(); } |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
$echo_results = ob_get_contents(); |
| 140 |
|
| 141 |
ob_end_clean(); |
| 142 |
|
| 143 |
return ''; |
| 144 |
} |
| 145 |
add_shortcode( 'booking-manager-delete', 'wpbm_ics_delete_shortcode' ); |
| 146 |
|