| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @package Booking Calendar |
| 4 |
* @category Booking Calendar Widgets |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site https://wpbookingcalendar.com/ |
| 8 |
* @email info@wpbookingcalendar.com |
| 9 |
* |
| 10 |
* @modified 2024-10-08 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit, if accessed directly // FixIn: 10.6.2.1. |
| 14 |
|
| 15 |
// BookingWidget Class |
| 16 |
class BookingWidget extends WP_Widget { |
| 17 |
|
| 18 |
function __construct() { |
| 19 |
parent::__construct( false, $name = 'Booking Calendar' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** @see WP_Widget::widget */ |
| 23 |
function widget($args, $instance) { |
| 24 |
|
| 25 |
extract( $args ); |
| 26 |
|
| 27 |
// FixIn: 6.1.1.11. |
| 28 |
$booking_widget_title = ( isset( $instance['booking_widget_title'] ) ) |
| 29 |
? apply_filters( 'widget_title', $instance['booking_widget_title'] ) |
| 30 |
: __( 'Booking Calendar', 'booking' ); |
| 31 |
if ( function_exists( 'icl_translate' ) ) { |
| 32 |
$booking_widget_title = icl_translate( 'wpml_custom', 'wpbc_custom_widget_booking_title1', $booking_widget_title ); |
| 33 |
} |
| 34 |
|
| 35 |
$booking_widget_show = ( isset( $instance['booking_widget_show'] ) ) |
| 36 |
? $instance['booking_widget_show'] |
| 37 |
: 'booking_form'; |
| 38 |
|
| 39 |
$resource_id = ( isset( $instance['booking_widget_type'] ) ) |
| 40 |
? intval( $instance['booking_widget_type'] ) |
| 41 |
: 1; |
| 42 |
$resource_id = ( empty( $resource_id ) ) ? 1 : $resource_id; |
| 43 |
|
| 44 |
$booking_widget_calendar_count = ( isset( $instance['booking_widget_calendar_count'] ) ) |
| 45 |
? intval( $instance['booking_widget_calendar_count'] ) |
| 46 |
: 1; |
| 47 |
$booking_widget_last_field = ( isset( $instance['booking_widget_last_field'] ) ) |
| 48 |
? $instance['booking_widget_last_field'] |
| 49 |
: ''; |
| 50 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 51 |
echo $before_widget ; |
| 52 |
|
| 53 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 54 |
if ( isset( $_GET['booking_hash'] ) ) { |
| 55 |
esc_html_e( 'You need to use special shortcode [bookingedit] for booking editing.', 'booking' ); |
| 56 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 57 |
echo $after_widget ; |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
if ( $booking_widget_title != '' ) { |
| 62 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 63 |
echo $before_title . wp_kses_post( $booking_widget_title ) . $after_title ; |
| 64 |
} |
| 65 |
|
| 66 |
echo "<div class='widget_wpdev_booking wpdevelop months_num_in_row_1'>"; // FixIn: 8.4.2.3. |
| 67 |
|
| 68 |
if ( $booking_widget_show == 'booking_form' ) { |
| 69 |
$my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id ); |
| 70 |
make_bk_action( 'wpdevbk_add_form', $resource_id, $booking_widget_calendar_count, true, $my_booking_form_name ); |
| 71 |
|
| 72 |
} else { |
| 73 |
echo "<div class='wpbc_only_calendar wpbc_container'>"; // FixIn: 8.0.1.2. |
| 74 |
echo "<div id='calendar_booking_unselectable" . esc_attr( $resource_id ) . "'></div>"; // FixIn: 6.1.1.13. |
| 75 |
do_action( 'wpdev_bk_add_calendar', $resource_id, $booking_widget_calendar_count ); |
| 76 |
echo '</div>'; |
| 77 |
} |
| 78 |
|
| 79 |
if ( $booking_widget_last_field !== '' ) { |
| 80 |
echo '<br/>' . esc_js( $booking_widget_last_field ); |
| 81 |
} |
| 82 |
echo "</div>"; |
| 83 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 84 |
echo $after_widget; |
| 85 |
} |
| 86 |
|
| 87 |
/** @see WP_Widget::update */ |
| 88 |
function update( $new_instance, $old_instance ) { |
| 89 |
$instance = $old_instance; |
| 90 |
|
| 91 |
$instance['booking_widget_title'] = sanitize_textarea_field( $new_instance['booking_widget_title'] ); |
| 92 |
$instance['booking_widget_show'] = sanitize_textarea_field( $new_instance['booking_widget_show'] ); |
| 93 |
$instance['booking_widget_type'] = ( empty( $new_instance['booking_widget_type'] ) ? 1 : intval( $new_instance['booking_widget_type'] ) ); |
| 94 |
$instance['booking_widget_calendar_count'] = intval( $new_instance['booking_widget_calendar_count'] ); |
| 95 |
$instance['booking_widget_last_field'] = $new_instance['booking_widget_last_field']; |
| 96 |
|
| 97 |
return $instance; |
| 98 |
} |
| 99 |
|
| 100 |
/** @see WP_Widget::form */ |
| 101 |
function form($instance) { |
| 102 |
|
| 103 |
if ( isset( $instance['booking_widget_title'] ) ) { |
| 104 |
$booking_widget_title = esc_attr( $instance['booking_widget_title'] ); |
| 105 |
} else { |
| 106 |
$booking_widget_title = ''; |
| 107 |
} |
| 108 |
if ( isset( $instance['booking_widget_show'] ) ) { |
| 109 |
$booking_widget_show = esc_attr( $instance['booking_widget_show'] ); |
| 110 |
} else { |
| 111 |
$booking_widget_show = ''; |
| 112 |
} |
| 113 |
if ( ( class_exists( 'wpdev_bk_personal' ) ) && ( isset( $instance['booking_widget_type'] ) ) ) { |
| 114 |
$resource_id = intval( $instance['booking_widget_type'] ); |
| 115 |
} else { |
| 116 |
$resource_id = 1; |
| 117 |
} |
| 118 |
if ( isset( $instance['booking_widget_calendar_count'] ) ) { |
| 119 |
$booking_widget_calendar_count = esc_attr( $instance['booking_widget_calendar_count'] ); |
| 120 |
} else { |
| 121 |
$booking_widget_calendar_count = 1; |
| 122 |
} |
| 123 |
if ( isset( $instance['booking_widget_last_field'] ) ) { |
| 124 |
$booking_widget_last_field = esc_attr( $instance['booking_widget_last_field'] ); |
| 125 |
} else { |
| 126 |
$booking_widget_last_field = ''; |
| 127 |
} |
| 128 |
?> |
| 129 |
|
| 130 |
<p> |
| 131 |
<label for="<?php echo esc_attr( $this->get_field_id('booking_widget_title') ); ?>"><?php esc_html_e('Title' ,'booking'); ?>:</label><br/> |
| 132 |
<input value="<?php echo esc_attr( $booking_widget_title ); ?>" |
| 133 |
name="<?php echo esc_attr( $this->get_field_name('booking_widget_title') ); ?>" |
| 134 |
id="<?php echo esc_attr( $this->get_field_id('booking_widget_title') ); ?>" |
| 135 |
type="text" class="widefat" style="width:100%;line-height: 1.5em;" /> |
| 136 |
</p> |
| 137 |
|
| 138 |
<p> |
| 139 |
<label for="<?php echo esc_attr( $this->get_field_id('booking_widget_show') ); ?>"><?php esc_html_e('Show' ,'booking'); ?>:</label><br/> |
| 140 |
<select |
| 141 |
name="<?php echo esc_attr( $this->get_field_name('booking_widget_show') ); ?>" |
| 142 |
id="<?php echo esc_attr( $this->get_field_id('booking_widget_show') ); ?>" style="width:100%;line-height: 1.5em;"> |
| 143 |
<option <?php if($booking_widget_show == 'booking_form') echo "selected"; ?> value="booking_form"><?php esc_html_e('Booking form with calendar' ,'booking'); ?></option> |
| 144 |
<option <?php if($booking_widget_show == 'booking_calendar') echo "selected"; ?> value="booking_calendar"><?php esc_html_e('Only availability calendar' ,'booking'); ?></option> |
| 145 |
</select> |
| 146 |
</p> |
| 147 |
|
| 148 |
|
| 149 |
<?php |
| 150 |
if ( class_exists('wpdev_bk_personal')) { |
| 151 |
$types_list = wpbc_get_br_as_objects(); ?> |
| 152 |
<p> |
| 153 |
<label for="<?php echo esc_attr( $this->get_field_id('booking_widget_type') ); ?>"><?php esc_html_e('Booking resource' ,'booking'); ?>:</label><br/> |
| 154 |
<!--input id="calendar_type" name="calendar_type" class="input" type="text" --> |
| 155 |
<select |
| 156 |
name="<?php echo esc_attr( $this->get_field_name('booking_widget_type') ); ?>" |
| 157 |
id="<?php echo esc_attr( $this->get_field_id('booking_widget_type') ); ?>" |
| 158 |
style="width:100%;line-height: 1.5em;"> |
| 159 |
<?php foreach ($types_list as $tl) { ?> |
| 160 |
<option <?php if($resource_id == $tl->id ) echo "selected"; ?> |
| 161 |
style="<?php if (isset($tl->parent)) if ($tl->parent == 0 ) { echo 'font-weight:600;'; } else { echo 'font-size:11px;padding-left:20px;'; } ?>" |
| 162 |
value="<?php echo esc_attr( $tl->id ); ?>"><?php echo esc_html( $tl->title ); ?></option> |
| 163 |
<?php } ?> |
| 164 |
</select> |
| 165 |
|
| 166 |
</p> |
| 167 |
<?php } ?> |
| 168 |
|
| 169 |
<p> |
| 170 |
<label for="<?php echo esc_attr( $this->get_field_id('booking_widget_calendar_count') ); ?>"><?php esc_html_e('Visible months' ,'booking'); ?>:</label><br/> |
| 171 |
|
| 172 |
<select style="width:100%;line-height: 1.5em;" |
| 173 |
name="<?php echo esc_attr( $this->get_field_name('booking_widget_calendar_count') ); ?>" |
| 174 |
id="<?php echo esc_attr( $this->get_field_id('booking_widget_calendar_count') ); ?>" |
| 175 |
> |
| 176 |
<?php foreach ( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ) as $tl ) { ?> |
| 177 |
<option |
| 178 |
<?php if ( $booking_widget_calendar_count == $tl ) { echo "selected"; } ?> |
| 179 |
style="font-weight:600;" |
| 180 |
value="<?php echo esc_attr( $tl ); ?>"><?php echo esc_html( $tl ); ?></option> |
| 181 |
<?php } ?> |
| 182 |
</select> |
| 183 |
</p> |
| 184 |
|
| 185 |
<p> |
| 186 |
<label for="<?php echo esc_attr( $this->get_field_id('booking_widget_last_field') ); ?>"><?php esc_html_e('Footer' ,'booking'); ?>:</label><br/> |
| 187 |
<input value="<?php echo esc_attr( $booking_widget_last_field ); ?>" |
| 188 |
name="<?php echo esc_attr( $this->get_field_name('booking_widget_last_field') ); ?>" |
| 189 |
id="<?php echo esc_attr( $this->get_field_id('booking_widget_last_field') ); ?>" |
| 190 |
type="text" style="width:100%;line-height: 1.5em;" /><br/> |
| 191 |
<em style="font-size:11px;"><?php |
| 192 |
/* translators: 1: ... */ |
| 193 |
echo wp_kses_post( sprintf( __( 'Example: %1$sMake booking here%2$s', 'booking' ), "<code><a href='" . get_site_url() . "'>", '</a></code>' ) ); ?></em> |
| 194 |
</p> |
| 195 |
|
| 196 |
<p style="font-size:10px;"><?php |
| 197 |
|
| 198 |
/* translators: 1: ... */ |
| 199 |
echo wp_kses_post( sprintf( __( '%1$sImportant!!!%2$s Please note, if you show booking calendar (inserted into post/page) with widget at the same page, then the last will not be visible.', 'booking' ), '<strong>', '</strong>' ) ); |
| 200 |
|
| 201 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 202 |
|
| 203 |
?><em><?php |
| 204 |
/* translators: 1: ... */ |
| 205 |
echo wp_kses_post( sprintf( __( '%1$sSeveral widgets are supported at %2$spaid versions%3$s.', 'booking' ), '<span style="">', '<a href="https://wpbookingcalendar.com/" target="_blank" style="text-decoration:none;color:#3A5670;">', '</a>', '</span>' ) ); |
| 206 |
?></em> <?php |
| 207 |
} |
| 208 |
?></p><?php |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
function register_wpbc_widget() { |
| 214 |
// FixIn: 8.1.3.18. |
| 215 |
register_widget( "BookingWidget" ); |
| 216 |
} |
| 217 |
add_action( 'widgets_init', 'register_wpbc_widget' ); |