PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.31
Timetics – Appointment Booking Calendar & Scheduling v1.0.31
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / bootstrap.php

bootstrap.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.31, at bootstrap.php

449 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bootstrap Class
4 *
5 * @package Timetics
6 */
7 namespace Timetics;
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Bootstrap class.
13 *
14 * @since 1.0.0
15 */
16 final class Bootstrap {
17 /**
18 * @var Bootstrap The Actual Timetics instance
19 * @since 1.0.0
20 */
21 private static $instance;
22
23
24 private $file;
25 public $version;
26 private $has_pro;
27
28 /**
29 * Throw Error While Trying To Clone Object
30 *
31 * @since 1.0.0
32 * @return void
33 */
34 public function __clone() {
35 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'timetics' ), '1.0.0' );
36 }
37
38 /**
39 * Disabling Un-serialization Of This Class
40 */
41 public function __wakeup() {
42 _doing_it_wrong( __FUNCTION__, esc_html__( 'Unserializing instances of this class is forbidden.', 'timetics' ), '1.0.0' );
43 }
44
45 /**
46 * The actual TimeTics instance
47 *
48 * @since 1.0.0
49 * @param string $file
50 * @return void
51 */
52 public static function instantiate( $file = '' ) {
53
54 // Return if already instantiated
55 if ( self::instantiated() ) {
56 return self::$instance;
57 }
58
59 self::prepare_instance( $file );
60
61 self::$instance->initialize_constants();
62 self::$instance->define_tables();
63 self::$instance->include_files();
64 self::$instance->initialize_components();
65
66 return self::$instance;
67 }
68
69 /**
70 * Return If The Main Class has Already Been Instantiated Or Not
71 *
72 * @since 1.0.0
73 * @return boolean
74 */
75 private static function instantiated() {
76 if ( ( null !== self::$instance ) && ( self::$instance instanceof Bootstrap ) ) {
77 return true;
78 }
79
80 return false;
81 }
82
83 /**
84 * Prepare Singleton Instance
85 *
86 * @since 1.0.0
87 * @param string $file
88 * @return void
89 */
90 private static function prepare_instance( $file = '' ) {
91 self::$instance = new self();
92 self::$instance->file = $file;
93 self::$instance->version = \Timetics::get_version();
94 }
95
96 /**
97 * Assets Directory URL
98 *
99 * @since 1.0.0
100 * @return void
101 */
102 public function get_assets_url() {
103 return trailingslashit( TIMETICS_PLUGIN_URL . 'assets' );
104 }
105
106 /**
107 * Assets Directory Path
108 *
109 * @since 1.0.0
110 * @return void
111 */
112 public function get_assets_dir() {
113 return trailingslashit( TIMETICS_PLUGIN_DIR . 'assets' );
114 }
115
116 /**
117 * Plugin Directory URL
118 *
119 * @return void
120 */
121 public function get_plugin_url() {
122 return trailingslashit( plugin_dir_url( TIMETICS_PLUGIN_FILE ) );
123 }
124
125 /**
126 * Plugin Directory Path
127 *
128 * @return void
129 */
130 public function get_plugin_dir() {
131 return \Timetics::get_plugin_dir();
132 }
133
134 /**
135 * Plugin Basename
136 *
137 * @return void
138 */
139 public function get_plugin_basename() {
140 return plugin_basename( TIMETICS_PLUGIN_FILE );
141 }
142
143 /**
144 * Setup Plugin Constants
145 *
146 * @since 1.0.0
147 * @return void
148 */
149 private function initialize_constants() {
150 // Plugin Version
151 self::$instance->define( 'TIMETICS_VERSION', \Timetics::get_version() );
152
153 // Plugin Main File
154 self::$instance->define( 'TIMETICS_PLUGIN_FILE', $this->file );
155
156 // Plugin File Basename
157 self::$instance->define( 'TIMETICS_PLUGIN_BASE', $this->get_plugin_basename() );
158
159 // Plugin Main Directory Path
160 self::$instance->define( 'TIMETICS_PLUGIN_DIR', $this->get_plugin_dir() );
161
162 // Plugin Main Directory URL
163 self::$instance->define( 'TIMETICS_PLUGIN_URL', $this->get_plugin_url() );
164
165 // Plugin Assets Directory URL
166 self::$instance->define( 'TIMETICS_ASSETS_URL', $this->get_assets_url() );
167
168 // Plugin Assets Directory Path
169 self::$instance->define( 'TIMETICS_ASSETS_DIR', $this->get_assets_dir() );
170
171
172 }
173
174 /**
175 * Define constant if not already set.
176 *
177 * @since 1.0.0
178 * @param string $name Constant name.
179 * @param string|bool $value Constant value.
180 */
181 private function define( $name, $value ) {
182 if ( ! defined( $name ) ) {
183 define( $name, $value );
184 }
185 }
186
187 /**
188 * Define DB Tables Required For This Plugin
189 *
190 * @since 1.0.0
191 * @return void
192 */
193 private function define_tables() {
194 // To Be Implemented
195 }
196
197 /**
198 * Include All Required Files
199 *
200 * @since 1.0.0
201 * @return void
202 */
203 private function include_files() {
204 // require_once TIMETICS_PLUGIN_DIR . 'includes/post-types.php';
205 // require_once TIMETICS_PLUGIN_DIR . 'includes/widgets/manifest.php';
206 // require_once TIMETICS_PLUGIN_DIR . 'includes/template-functions.php';
207 // require_once TIMETICS_PLUGIN_DIR . 'includes/shortcodes.php';
208 // require_once TIMETICS_PLUGIN_DIR . 'includes/install.php';
209
210 /**
211 * Core helpers.
212 */
213 require_once TIMETICS_PLUGIN_DIR . 'utils/global-helper.php';
214 require_once TIMETICS_PLUGIN_DIR . 'core/staffs/calendars/CalendarSyncFacade.php';
215 require_once TIMETICS_PLUGIN_DIR . 'core/staffs/calendars/CalendarSyncFactory.php';
216 require_once TIMETICS_PLUGIN_DIR . 'core/staffs/calendars/CalendarSyncInterface.php';
217 require_once TIMETICS_PLUGIN_DIR . 'core/staffs/calendars/GoogleCalendarSync.php';
218 }
219
220 /**
221 * Initialize All Components
222 *
223 * @since 1.0.0
224 * @return void
225 */
226 private function initialize_components() {
227
228 // Register scripts and styles first
229 if ( $this->is_request( 'admin' ) ) {
230 add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
231 }
232
233 if ( $this->is_request( 'frontend' ) ) {
234 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
235 }
236
237 // Register admin menu
238 Core\Admin\Menu::instance()->init();
239 Core\Base::instance()->init();
240 Core\Services\Hooks::instance()->init();
241 Base\Custom_Endpoint::instance()->init();
242
243 global $current_screen;
244 $this->has_pro = class_exists('TimeticsPro');
245
246 $this->handle_buy_pro_module();
247
248 if ( function_exists('WC') ) {
249 Core\Integrations\Woocommerce\Hooks::instance()->init();
250 }
251 }
252
253 /**
254 * demo url for set pro button
255 *
256 * @return void
257 */
258 public function demo_url(){
259 return "https://arraytics.com/timetics/";
260 }
261
262 /**
263 * Register scripts and styles for admin
264 *
265 * @return void
266 */
267 public function admin_scripts( $handle ) {
268 if ( 'toplevel_page_timetics' !== $handle ) {
269 return;
270 }
271 global $wp_locale;
272
273 wp_enqueue_media();
274 wp_enqueue_style( 'wp-color-picker' );
275 wp_enqueue_style( 'timetics-admin-style', TIMETICS_ASSETS_URL . 'css/admin.css', [], TIMETICS_VERSION, 'all' );
276 wp_enqueue_style( 'timetics-vendor', TIMETICS_ASSETS_URL . 'css/vendor.css', [], TIMETICS_VERSION, 'all' );
277 wp_enqueue_script( 'timetics-flatpickr-scripts', TIMETICS_ASSETS_URL . 'js/vendors/flatpickr.js', [ 'wp-plugins', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data' ], TIMETICS_VERSION, true );
278 wp_enqueue_script( 'timetics-packages', TIMETICS_ASSETS_URL . 'js/packages.js', [ 'timetics-flatpickr-scripts' ], TIMETICS_VERSION, true );
279
280 $calendar_locale = timetics_get_option('calendar_locale');
281 if (!empty($calendar_locale)) {
282 wp_enqueue_script( 'calendar-locale', TIMETICS_ASSETS_URL . "js/local/{$calendar_locale}.js", [ 'jquery', 'wp-plugins', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data' ], TIMETICS_VERSION, true );
283 }
284
285 wp_enqueue_script( 'timetics-dashboard-scripts', TIMETICS_ASSETS_URL . 'js/dashboard.js', [ 'wp-plugins', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data', 'wp-color-picker' ], TIMETICS_VERSION, true );
286
287
288 $localize_obj = array(
289 'site_url' => site_url(),
290 'admin_url' => admin_url(),
291 'nonce' => wp_create_nonce( 'wp_rest' ),
292 'timezone' => timetics_get_timezone_list(),
293 'stripe_pub_key' => timetics_get_option( 'stripe_pub_key' ),
294 'date_format' => get_option( 'date_format' ),
295 'date_format_string' => date_i18n( get_option( 'date_format' ) ),
296 'time_format' => get_option( 'time_format' ),
297 'time_format_string' => date_i18n( get_option( 'time_format' ) ),
298 'start_of_week' => get_option( 'start_of_week', 0 ),
299
300 'default_timezone' => timetics_get_default_timezone(),
301 'currency_list' => timetics_get_currencies(),
302 'current_user_id' => get_current_user_id(),
303 'timeticsPro' => class_exists('TimeticsPro') ? true : false,
304 'demo_url' => $this->demo_url(),
305 'current_user' => timetics_get_current_user(),
306 );
307
308 $localize_obj = apply_filters( 'timetics_admin_localize_data', $localize_obj );
309
310 wp_localize_script( 'timetics-dashboard-scripts', 'timetics', $localize_obj );
311 }
312
313 /**
314 * Register scripts and styles for frontend
315 *
316 * @return void
317 */
318 public function frontend_scripts() {
319 wp_register_style( 'timetics-vendor', TIMETICS_ASSETS_URL . 'css/vendor.css', [], TIMETICS_VERSION, 'all' );
320 wp_register_style( 'timetics-frontend', TIMETICS_ASSETS_URL . 'css/frontend.css', [], TIMETICS_VERSION, 'all' );
321
322 wp_register_script( 'timetics-flatpickr-scripts', TIMETICS_ASSETS_URL . 'js/vendors/flatpickr.js', [ 'wp-plugins', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data' ], TIMETICS_VERSION, true );
323 wp_enqueue_script( 'timetics-packages', TIMETICS_ASSETS_URL . 'js/packages.js', [ 'timetics-flatpickr-scripts' ], TIMETICS_VERSION, true );
324
325 wp_register_script( 'timetics-frontend-scripts', TIMETICS_ASSETS_URL . 'js/frontend.js', [ 'jquery', 'wp-plugins', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data' ], TIMETICS_VERSION, true );
326
327 $calendar_locale = timetics_get_option('calendar_locale');
328 if (!empty($calendar_locale)) {
329 wp_register_script( 'calendar-locale', "https://npmcdn.com/flatpickr/dist/l10n/{$calendar_locale}.js", [ 'jquery', 'wp-plugins', 'wp-i18n', 'wp-element', 'wp-dom', 'wp-data' ], TIMETICS_VERSION, true );
330 }
331
332 // load text domain
333 wp_set_script_translations( 'timetics-frontend-scripts', 'timetics', TIMETICS_PLUGIN_DIR . 'languages/' );
334
335 global $wp_locale;
336
337 $stripe_pub_key = timetics_get_option( 'stripe_pub_key' );
338 $stripe_secret_key = timetics_get_option( 'stripe_secret_key' );
339 $stripe_configure = $stripe_pub_key && $stripe_secret_key;
340
341 $localize_obj = array(
342 'site_url' => site_url(),
343 'nonce' => wp_create_nonce( 'wp_rest' ),
344 'date_format' => get_option( 'date_format' ),
345 'time_format' => get_option( 'time_format' ),
346 'stripe_pub_key' => $stripe_pub_key,
347 'currency' => apply_filters( 'timetics_currency', timetics_get_option( 'currency', 'USD' ) ),
348 'stripe_configure' => $stripe_configure,
349 'current_user_id' => get_current_user_id(),
350 'start_of_week' => get_option( 'start_of_week', 0 ),
351 'currency_list' => timetics_get_currencies(),
352 'locale_name' => strtolower( str_replace( '_', '-', get_locale() ) )
353
354 );
355
356 $localize_obj = apply_filters( 'timetics_frontned_localize_data', $localize_obj );
357
358 wp_localize_script( 'timetics-frontend-scripts', 'timetics', $localize_obj );
359 }
360
361 /**
362 * What type of request
363 *
364 * @param string $type admin,frontend, ajax, cron
365 * @return boolean
366 */
367 private function is_request( $type ) {
368 switch ( $type ) {
369 case 'admin':
370 return is_admin();
371 case 'ajax':
372 return defined( 'DOING_AJAX' );
373 case 'cron':
374 return defined( 'DOING_CRON' );
375 case 'frontend':
376 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! $this->is_rest_api_request();
377 }
378 }
379
380 /**
381 * Returns if the request is non-legacy REST API request.
382 *
383 * @return boolean
384 */
385 private function is_rest_api_request() {
386 $server_request = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : false;
387
388 if ( ! $server_request ) {
389 return false;
390 }
391
392 $rest_prefix = trailingslashit( rest_get_url_prefix() );
393 $is_rest_request = ( false !== strpos( $server_request, $rest_prefix ) );
394
395 return apply_filters( 'timetics_is_rest_api_request', $is_rest_request );
396 }
397
398
399 /**
400 * Show buy-pro menu if pro plugin not active
401 *
402 * @return void
403 */
404 public function handle_buy_pro_module() {
405 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
406
407
408 if ( 'timetics' !== $page ) {
409 return;
410 }
411
412
413 /**
414 * Show banner (codename: jhanda)
415 */
416 $filter_string = 'timetics,timetics-free-only';
417
418 if( $this->has_pro ) {
419
420 $filter_string .= ',timetics-pro';
421 $filter_string = str_replace(',timetics-free-only', '', $filter_string);
422
423 }
424
425
426 \Wpmet\Libs\Banner::instance('timetics')
427 ->is_test(true)
428 ->set_filter(ltrim($filter_string, ','))
429 ->set_api_url('https://demo.themewinter.com/public/jhanda')
430 ->set_plugin_screens('timetics')
431 ->set_plugin_screens('toplevel_page_timetics')
432 ->call();
433 // show get-help and upgrade-to-premium menu.
434 // $this->handle_get_help_and_upgrade_menu();
435 }
436
437 }
438
439 /**
440 * Returns The Instance Of Timetics.
441 * The main function that is responsible for returning Timetics instance.
442 *
443 * @since 1.0.0
444 * @return Timetics
445 */
446 function timetics() {
447 return Bootstrap::instantiate();
448 }
449