forked from ThimPressWP/wp-hotel-booking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-hotel-booking.php
More file actions
389 lines (330 loc) · 11.7 KB
/
wp-hotel-booking.php
File metadata and controls
389 lines (330 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
/*
Plugin Name: WP Hotel Booking
Plugin URI: http://thimpress.com/
Description: Full of professional features for a booking room system
Author: ThimPress
Version: 1.7.8
Author URI: http://thimpress.com
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
define( 'WPHB_FILE', __FILE__ );
define( 'WPHB_PLUGIN_PATH', dirname( __FILE__ ) );
define( 'WPHB_PLUGIN_URL', plugins_url( '', __FILE__ ) );
define( 'WPHB_VERSION', '1.7.8' );
define( 'WPHB_BLOG_ID', get_current_blog_id() );
/**
* Class WP_Hotel_Booking
*/
class WP_Hotel_Booking {
/**
* Hold the instance of main class
*
* @var object
*/
protected static $_instance = null;
/**
* Plugin path
*
* @var string
*/
protected $_plugin_path = null;
/**
* Plugin URL
*
* @var string
*/
protected $_plugin_url = null;
public $cart = null;
public $user = null;
/**
* Construction
*/
public function __construct() {
if ( self::$_instance ) {
return self::$_instance;
}
$this->includes();
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_print_scripts', array( $this, 'global_js' ) );
add_action( 'template_redirect', 'hb_handle_purchase_request', 999 );
register_activation_hook( plugin_basename( __FILE__ ), array( $this, 'install' ) );
register_activation_hook( plugin_basename( __FILE__ ), array( $this, 'uninstall' ) );
add_action( 'init', array( $this, 'init' ), 20 );
// create new blog in multisite
add_action( 'wpmu_new_blog', array( $this, 'create_new_blog' ), 10, 6 );
// multisite delete table in multisite
add_filter( 'wpmu_drop_tables', array( $this, 'delete_blog_table' ) );
}
public function init() {
// cart
$this->cart = WPHB_Cart::instance();
// user
$this->user = hb_get_current_user();
}
// install hook
public function install() {
return WPHB_Install::install();
}
// uninstall hook
public function uninstall() {
return WPHB_Install::uninstall();
}
// create new blog table
public function create_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
return WPHB_Install::create_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta );
}
// delete table when delete blog, multisite
public function delete_blog_table( $tables ) {
return WPHB_Install::delete_tables( $tables );
}
/**
* Include a file
*
* @param string
* @param bool
* @param array
*/
public function _include( $file, $root = true, $args = array(), $unique = true ) {
if ( $root ) {
$file = $this->plugin_path( $file );
}
if ( is_array( $args ) ) {
extract( $args );
}
if ( file_exists( $file ) ) {
if ( $unique ) {
require_once $file;
} else {
require $file;
}
}
}
/**
* Get the full path of a file
*
* @param string
*
* @return string
*/
public function locate( $file ) {
return $this->_plugin_path . '/' . $file;
}
/**
* Includes common files and libraries
*/
public function includes() {
$this->_include( 'includes/class-wphb-autoloader.php' );
$this->_include( 'includes/class-wphb-template-loader.php' );
$this->_include( 'includes/class-wphb-ajax.php' );
$this->_include( 'includes/class-wphb-install.php' );
if ( is_admin() ) {
$this->admin_includes();
}
$this->_include( 'includes/class-wphb-settings.php' );
$this->_include( 'includes/class-wphb-comments.php' );
$this->_include( 'includes/wphb-template-hooks.php' );
$this->_include( 'includes/wphb-template-functions.php' );
$this->_include( 'includes/wphb-widget-functions.php' );
if ( ! is_admin() ) {
$this->frontend_includes();
}
$this->_include( 'includes/class-wphb-post-types.php' );
$this->_include( 'includes/wphb-core-functions.php' );
$this->_include( 'includes/wphb-functions.php' );
$this->_include( 'includes/class-wphb-resizer.php' );
// booking
$this->_include( 'includes/booking/wphb-booking-functions.php' );
$this->_include( 'includes/booking/wphb-booking-hooks.php' );
$this->_include( 'includes/booking/class-wphb-booking.php' );
// users
$this->_include( 'includes/user/wphb-user-functions.php' );
$this->_include( 'includes/user/class-wphb-user.php' );
$this->_include( 'includes/class-wphb-roles.php' );
// products
$this->_include( 'includes/products/class-wphb-abstract-product.php' );
$this->_include( 'includes/products/class-wphb-product-room.php' );
// end products
$this->_include( 'includes/room/wphb-room-functions.php' );
$this->_include( 'includes/room/class-wphb-room.php' );
// // addon
if ( apply_filters( 'hotel_booking_enable_currency_addon', true ) ) {
$this->_include( 'includes/plugins/wp-hotel-booking-currencies/wp-hotel-booking-currencies.php' );
}
$this->_include( 'includes/plugins/wp-hotel-booking-extra/wp-hotel-booking-extra.php' );
// // end addon
$this->_include( 'includes/class-wphb-sessions.php' );
// cart
$this->_include( 'includes/cart/wphb-cart-functions.php' );
$this->_include( 'includes/cart/class-wphb-cart.php' );
$this->_include( 'includes/gateways/class-wphb-payment-gateway-base.php' );
$this->_include( 'includes/wphb-webhooks.php' );
}
public function frontend_includes() {
// shortcodes
$this->_include( 'includes/shortcodes/class-wphb-abstract-shortcodes.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-cart.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-account.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-checkout.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-lastest-reviews.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-best-reviews.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-rooms.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-mini-cart.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking-slider.php' );
$this->_include( 'includes/shortcodes/class-wphb-shortcode-hotel-booking.php' );
// end shortcodes
if ( ! class_exists( 'Aq_Resize' ) ) {
$this->_include( 'includes/aq_resizer.php' );
}
}
public function admin_includes() {
$this->_include( 'includes/admin/class-wphb-admin.php' );
}
// load payments addons
public function plugins_loaded() {
// load text domain
$this->load_text_domain();
}
/**
* Get the path of the plugin with sub path
*
* @param string $sub
*
* @return string
*/
public function plugin_path( $sub = '' ) {
if ( ! $this->_plugin_path ) {
$this->_plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
}
return $this->_plugin_path . '/' . $sub;
}
/**
* Get the url of the plugin with sub path
*
* @param string $sub
*
* @return string
*/
public function plugin_url( $sub = '' ) {
if ( ! $this->_plugin_url ) {
$this->_plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
}
return $this->_plugin_url . '/' . $sub;
}
/**
* Load language for the plugin
*/
public function load_text_domain() {
// prefix
$prefix = basename( dirname( plugin_basename( __FILE__ ) ) );
$locale = get_locale();
$dir = $this->plugin_path( 'languages' );
$mofile = false;
$globalFile = WP_LANG_DIR . '/plugins/' . $prefix . '-' . $locale . '.mo';
$pluginFile = $dir . '/' . $prefix . '-' . $locale . '.mo';
if ( file_exists( $globalFile ) ) {
$mofile = $globalFile;
} else if ( file_exists( $pluginFile ) ) {
$mofile = $pluginFile;
}
if ( $mofile ) {
// In themes/plugins/mu-plugins directory
load_textdomain( 'wp-hotel-booking', $mofile );
}
}
/**
* Enqueue assets for the plugin
*/
public function enqueue_assets() {
$dependencies = array(
'jquery',
'jquery-ui-sortable',
'jquery-ui-datepicker',
'wp-util'
);
wp_register_style( 'wp-hotel-booking-libaries-style', $this->plugin_url( 'assets/css/libraries.css' ) );
// select2
wp_register_script( 'wp-admin-hotel-booking-select2', $this->plugin_url( 'assets/js/select2.min.js' ) );
if ( is_admin() ) {
$dependencies = array_merge( $dependencies, array( 'backbone' ) );
wp_register_style( 'wp-admin-hotel-booking', $this->plugin_url( 'assets/css/admin.tp-hotel-booking.min.css' ) );
wp_register_script( 'wp-admin-hotel-booking', $this->plugin_url( 'assets/js/admin.hotel-booking.js' ), $dependencies );
wp_localize_script( 'wp-admin-hotel-booking', 'hotel_booking_i18n', hb_admin_i18n() );
wp_register_script( 'wp-admin-hotel-booking-moment', $this->plugin_url( 'assets/js/moment.min.js' ), $dependencies );
wp_register_script( 'wp-admin-hotel-booking-fullcalendar', $this->plugin_url( 'assets/js/fullcalendar.min.js' ), $dependencies );
wp_register_style( 'wp-admin-hotel-booking-fullcalendar', $this->plugin_url( 'assets/css/fullcalendar.min.css' ) );
} else {
wp_register_style( 'wp-hotel-booking', $this->plugin_url( 'assets/css/hotel-booking.min.css' ) );
wp_register_script( 'wp-hotel-booking', $this->plugin_url( 'assets/js/hotel-booking.min.js' ), $dependencies, false, true );
wp_localize_script( 'wp-hotel-booking', 'hotel_booking_i18n', hb_i18n() );
// rooms slider widget
wp_register_script( 'wp-hotel-booking-gallery', $this->plugin_url( 'includes/libraries/camera/js/gallery.min.js' ), $dependencies );
// owl carousel
wp_register_script( 'wp-hotel-booking-owl-carousel', $this->plugin_url( 'includes/libraries/owl-carousel/owl.carousel.min.js' ), $dependencies );
}
if ( is_admin() ) {
wp_enqueue_style( 'wp-admin-hotel-booking' );
wp_enqueue_script( 'wp-admin-hotel-booking' );
wp_enqueue_script( 'backbone' );
// report
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
/* fullcalendar */
wp_enqueue_script( 'wp-admin-hotel-booking-moment' );
wp_enqueue_style( 'wp-admin-hotel-booking-fullcalendar' );
wp_enqueue_script( 'wp-admin-hotel-booking-fullcalendar' );
} else {
wp_enqueue_style( 'wp-hotel-booking' );
wp_enqueue_script( 'wp-hotel-booking' );
// rooms slider widget
wp_enqueue_script( 'wp-hotel-booking-owl-carousel' );
// room galleria
wp_enqueue_script( 'wp-hotel-booking-gallery' );
}
wp_enqueue_style( 'wp-hotel-booking-libaries-style' );
// select2
wp_enqueue_script( 'wp-admin-hotel-booking-select2' );
// wp_enqueue_script( 'colorpicker' );
}
/**
* Output global js settings
*/
public function global_js() {
$upload_dir = wp_upload_dir();
$upload_base_url = $upload_dir['baseurl'];
$min_booking_date = get_option( 'tp_hotel_booking_minimum_booking_day' ) ? get_option( 'tp_hotel_booking_minimum_booking_day' ) : 1;
?>
<script type="text/javascript">
var hotel_settings = {
ajax: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
settings: <?php echo WPHB_Settings::instance()->toJson( apply_filters( 'hb_settings_fields', array( 'review_rating_required' ) ) ); ?>,
upload_base_url: '<?php echo esc_js( $upload_base_url ) ?>',
meta_key: {
prefix: '_hb_'
},
nonce: '<?php echo wp_create_nonce( 'hb_booking_nonce_action' ); ?>',
timezone: '<?php echo current_time( 'timestamp' ) ?>',
min_booking_date: <?php echo $min_booking_date; ?>
}
</script>
<?php
}
/**
* Create an instance of the plugin if it is not created
*
* @static
* @return object|WP_Hotel_Booking
*/
static function instance() {
if ( ! self::$_instance ) {
self::$_instance = new self();
}
return self::$_instance;
}
}
$GLOBALS['wp_hotel_booking'] = WP_Hotel_Booking::instance();