PluginProbe
Booking Calendar / 11.4
Booking Calendar v11.4
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 10.11.3 10.11.4 All 201 releases
booking / core / lib / wpdev-booking-widget.php

wpdev-booking-widget.php in Booking Calendar 11.4, at core/lib/wpdev-booking-widget.php

226 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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'] ) ) ? apply_filters( 'widget_title', $instance['booking_widget_title'] ) : __( 'Booking Calendar', 'booking' );
29 if ( function_exists( 'icl_translate' ) ) {
30 $booking_widget_title = icl_translate( 'wpml_custom', 'wpbc_custom_widget_booking_title1', $booking_widget_title );
31 }
32
33 $booking_widget_show = ( isset( $instance['booking_widget_show'] ) ) ? $instance['booking_widget_show'] : 'booking_form';
34
35 $resource_id = ( isset( $instance['booking_widget_type'] ) ) ? intval( $instance['booking_widget_type'] ) : 1;
36 $resource_id = ( empty( $resource_id ) ) ? 1 : $resource_id;
37
38 $booking_widget_calendar_count = ( isset( $instance['booking_widget_calendar_count'] ) ) ? intval( $instance['booking_widget_calendar_count'] ) : 1;
39 $booking_widget_last_field = ( isset( $instance['booking_widget_last_field'] ) ) ? $instance['booking_widget_last_field'] : '';
40 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
41 echo $before_widget ;
42
43 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
44 if ( isset( $_GET['booking_hash'] ) ) {
45 esc_html_e( 'You need to use special shortcode [bookingedit] for booking editing.', 'booking' );
46 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
47 echo $after_widget ;
48 return;
49 }
50
51 if ( $booking_widget_title != '' ) {
52 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
53 echo $before_title . wp_kses_post( $booking_widget_title ) . $after_title ;
54 }
55
56 echo "<div class='widget_wpdev_booking wpdevelop months_num_in_row_1'>"; // FixIn: 8.4.2.3.
57
58 if ( 'booking_form' === $booking_widget_show ) {
59
60 $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
61
62 // Parse, sanitize and normilize shortcode paramaters.
63 $shortcode_params = array(
64 'is_echo' => 1,
65 'resource_id' => $resource_id,
66 'cal_count' => $booking_widget_calendar_count,
67 'custom_booking_form' => $my_booking_form_name,
68 );
69
70 $shortcode_result = WPBC_FE_Render::render_booking_form( $shortcode_params );
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
76 WPBC_FE_Render::render_calendar_only(
77 array(
78 'resource_id' => $resource_id,
79 'cal_count' => $booking_widget_calendar_count,
80 'is_echo' => 1,
81 )
82 );
83
84 echo '</div>';
85 }
86
87 if ( $booking_widget_last_field !== '' ) {
88 echo '<br/>' . esc_js( $booking_widget_last_field );
89 }
90 echo "</div>";
91 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
92 echo $after_widget;
93 }
94
95 /** @see WP_Widget::update */
96 function update( $new_instance, $old_instance ) {
97 $instance = $old_instance;
98
99 $instance['booking_widget_title'] = sanitize_textarea_field( $new_instance['booking_widget_title'] );
100 $instance['booking_widget_show'] = sanitize_textarea_field( $new_instance['booking_widget_show'] );
101 $instance['booking_widget_type'] = ( empty( $new_instance['booking_widget_type'] ) ? 1 : intval( $new_instance['booking_widget_type'] ) );
102 $instance['booking_widget_calendar_count'] = intval( $new_instance['booking_widget_calendar_count'] );
103 $instance['booking_widget_last_field'] = $new_instance['booking_widget_last_field'];
104
105 return $instance;
106 }
107
108 /** @see WP_Widget::form */
109 function form($instance) {
110
111 if ( isset( $instance['booking_widget_title'] ) ) {
112 $booking_widget_title = esc_attr( $instance['booking_widget_title'] );
113 } else {
114 $booking_widget_title = '';
115 }
116 if ( isset( $instance['booking_widget_show'] ) ) {
117 $booking_widget_show = esc_attr( $instance['booking_widget_show'] );
118 } else {
119 $booking_widget_show = '';
120 }
121 if ( ( class_exists( 'wpdev_bk_personal' ) ) && ( isset( $instance['booking_widget_type'] ) ) ) {
122 $resource_id = intval( $instance['booking_widget_type'] );
123 } else {
124 $resource_id = 1;
125 }
126 if ( isset( $instance['booking_widget_calendar_count'] ) ) {
127 $booking_widget_calendar_count = esc_attr( $instance['booking_widget_calendar_count'] );
128 } else {
129 $booking_widget_calendar_count = 1;
130 }
131 if ( isset( $instance['booking_widget_last_field'] ) ) {
132 $booking_widget_last_field = esc_attr( $instance['booking_widget_last_field'] );
133 } else {
134 $booking_widget_last_field = '';
135 }
136 ?>
137
138 <p>
139 <label for="<?php echo esc_attr( $this->get_field_id('booking_widget_title') ); ?>"><?php esc_html_e('Title' ,'booking'); ?>:</label><br/>
140 <input value="<?php echo esc_attr( $booking_widget_title ); ?>"
141 name="<?php echo esc_attr( $this->get_field_name('booking_widget_title') ); ?>"
142 id="<?php echo esc_attr( $this->get_field_id('booking_widget_title') ); ?>"
143 type="text" class="widefat" style="width:100%;line-height: 1.5em;" />
144 </p>
145
146 <p>
147 <label for="<?php echo esc_attr( $this->get_field_id('booking_widget_show') ); ?>"><?php esc_html_e('Show' ,'booking'); ?>:</label><br/>
148 <select
149 name="<?php echo esc_attr( $this->get_field_name('booking_widget_show') ); ?>"
150 id="<?php echo esc_attr( $this->get_field_id('booking_widget_show') ); ?>" style="width:100%;line-height: 1.5em;">
151 <option <?php if($booking_widget_show == 'booking_form') echo "selected"; ?> value="booking_form"><?php esc_html_e('Booking form with calendar' ,'booking'); ?></option>
152 <option <?php if($booking_widget_show == 'booking_calendar') echo "selected"; ?> value="booking_calendar"><?php esc_html_e('Only availability calendar' ,'booking'); ?></option>
153 </select>
154 </p>
155
156
157 <?php
158 if ( class_exists('wpdev_bk_personal')) {
159 $types_list = wpbc_get_br_as_objects(); ?>
160 <p>
161 <label for="<?php echo esc_attr( $this->get_field_id('booking_widget_type') ); ?>"><?php esc_html_e('Booking resource' ,'booking'); ?>:</label><br/>
162 <!--input id="calendar_type" name="calendar_type" class="input" type="text" -->
163 <select
164 name="<?php echo esc_attr( $this->get_field_name('booking_widget_type') ); ?>"
165 id="<?php echo esc_attr( $this->get_field_id('booking_widget_type') ); ?>"
166 style="width:100%;line-height: 1.5em;">
167 <?php foreach ($types_list as $tl) { ?>
168 <option <?php if($resource_id == $tl->id ) echo "selected"; ?>
169 style="<?php if (isset($tl->parent)) if ($tl->parent == 0 ) { echo 'font-weight:600;'; } else { echo 'font-size:11px;padding-left:20px;'; } ?>"
170 value="<?php echo esc_attr( $tl->id ); ?>"><?php echo esc_html( $tl->title ); ?></option>
171 <?php } ?>
172 </select>
173
174 </p>
175 <?php } ?>
176
177 <p>
178 <label for="<?php echo esc_attr( $this->get_field_id('booking_widget_calendar_count') ); ?>"><?php esc_html_e('Visible months' ,'booking'); ?>:</label><br/>
179
180 <select style="width:100%;line-height: 1.5em;"
181 name="<?php echo esc_attr( $this->get_field_name('booking_widget_calendar_count') ); ?>"
182 id="<?php echo esc_attr( $this->get_field_id('booking_widget_calendar_count') ); ?>"
183 >
184 <?php foreach ( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ) as $tl ) { ?>
185 <option
186 <?php if ( $booking_widget_calendar_count == $tl ) { echo "selected"; } ?>
187 style="font-weight:600;"
188 value="<?php echo esc_attr( $tl ); ?>"><?php echo esc_html( $tl ); ?></option>
189 <?php } ?>
190 </select>
191 </p>
192
193 <p>
194 <label for="<?php echo esc_attr( $this->get_field_id('booking_widget_last_field') ); ?>"><?php esc_html_e('Footer' ,'booking'); ?>:</label><br/>
195 <input value="<?php echo esc_attr( $booking_widget_last_field ); ?>"
196 name="<?php echo esc_attr( $this->get_field_name('booking_widget_last_field') ); ?>"
197 id="<?php echo esc_attr( $this->get_field_id('booking_widget_last_field') ); ?>"
198 type="text" style="width:100%;line-height: 1.5em;" /><br/>
199 <em style="font-size:11px;"><?php
200 /* translators: 1: ... */
201 echo wp_kses_post( sprintf( __( 'Example: %1$sMake booking here%2$s', 'booking' ), "<code>&lt;a href='" . get_site_url() . "'&gt;", '&lt;/a&gt;</code>' ) ); ?></em>
202 </p>
203
204 <p style="font-size:10px;"><?php
205
206 /* translators: 1: ... */
207 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>' ) );
208
209 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
210
211 ?><em><?php
212 /* translators: 1: ... */
213 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>' ) );
214 ?></em> <?php
215 }
216 ?></p><?php
217 }
218 }
219
220
221 function wpbc_register_wpbc_widget() {
222 // FixIn: 8.1.3.18.
223 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
224 register_widget( "BookingWidget" );
225 }
226 add_action( 'widgets_init', 'wpbc_register_wpbc_widget' );