PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.23
Timetics – Appointment Booking Calendar & Scheduling v1.0.23
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.23, at bootstrap.php

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