| 1 |
<?php |
| 2 |
|
| 3 |
namespace Bookit\Classes\Admin; |
| 4 |
|
| 5 |
use Bookit\Classes\Base\User; |
| 6 |
use Bookit\Classes\Nonces; |
| 7 |
use Bookit\Classes\Template; |
| 8 |
use Bookit\Classes\Translations; |
| 9 |
use Bookit\Gateways\StripeConnect\Merchant; |
| 10 |
use Bookit\Helpers\FreemiusHelper; |
| 11 |
use DateTimeZone; |
| 12 |
|
| 13 |
class DashboardController { |
| 14 |
|
| 15 |
/** |
| 16 |
* Pro Addon Slug. |
| 17 |
* |
| 18 |
* @since 2.5.0 |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
protected static $proAddon = 'pro'; |
| 23 |
|
| 24 |
protected static $googleCalendarAddon = 'google-calendar'; |
| 25 |
protected static $user = array(); |
| 26 |
|
| 27 |
public static function bookitUser() { |
| 28 |
return User::getUserData(); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Enqueue Admin Styles & Scripts |
| 33 |
*/ |
| 34 |
public static function enqueue_styles_scripts() { |
| 35 |
wp_enqueue_style( 'bookit-dashboard-css', BOOKIT_URL . 'assets/dist/dashboard/css/app.css', array(), BOOKIT_VERSION ); |
| 36 |
wp_enqueue_script( 'bookit-dashboard-js', BOOKIT_URL . 'assets/dist/dashboard/js/app.js', array(), BOOKIT_VERSION ); |
| 37 |
|
| 38 |
$translations = array_merge( Translations::get_admin_translations(), Translations::get_addon_translations(), Translations::get_addons_page_translations() ); |
| 39 |
$settings = SettingsController::get_settings(); |
| 40 |
|
| 41 |
$ajax_data = [ |
| 42 |
'services_url' => admin_url( 'admin.php?page=bookit-services' ), |
| 43 |
'calendar_url' => admin_url( 'admin.php?page=bookit' ), |
| 44 |
'site_url' => get_bloginfo( 'url' ), |
| 45 |
'plugin_url' => BOOKIT_URL, |
| 46 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 47 |
'translations' => $translations, |
| 48 |
'nonces' => Nonces::get_admin_nonces(), |
| 49 |
'bookit_user' => self::bookitUser(), |
| 50 |
'pro_disabled' => bookit_pro_features_disabled(), //todo remove |
| 51 |
'has_feedback' => self::has_feedback(), |
| 52 |
'language' => substr( get_bloginfo( 'language' ), 0, 2 ), |
| 53 |
'timezones' => self::get_timezones(), |
| 54 |
'paypal_mode' => $settings['payments']['paypal']['mode'] ?? 'live', |
| 55 |
'stripe_connect_mode' => ( new Merchant() )->get_mode(), |
| 56 |
]; |
| 57 |
|
| 58 |
wp_localize_script( 'bookit-dashboard-js', 'bookit_window', $ajax_data ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Display Rendered Template |
| 63 |
* @return bool|string |
| 64 |
*/ |
| 65 |
public static function render_addons() { |
| 66 |
wp_enqueue_style( 'bookit-pricing-css', BOOKIT_URL . 'assets/dist/dashboard/css/addons.css', array(), BOOKIT_VERSION ); |
| 67 |
|
| 68 |
$data['translations'] = Translations::get_addons_page_translations(); |
| 69 |
$data['freemius_info'] = FreemiusHelper::get_freemius_info(); |
| 70 |
$data['descriptions'] = array( |
| 71 |
'bookit-pro' => __( 'Let your customers select WooCommerce platform and pay for meetings with ease. Merge your Bookit calendar and Google Calendar with just one click. Now easy to book and schedule appointments.', 'bookit' ), |
| 72 |
); |
| 73 |
return Template::load_template( 'dashboard/bookit-addons', $data, true ); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Check if Feedback already added |
| 78 |
* @return bool |
| 79 |
*/ |
| 80 |
public static function has_feedback() { |
| 81 |
return get_option( 'bookit_feedback_added', false ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Add Feedback |
| 86 |
*/ |
| 87 |
public static function add_feedback() { |
| 88 |
check_ajax_referer( 'bookit_add_feedback', 'nonce' ); |
| 89 |
update_option( 'bookit_feedback_added', true ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Get Timezones. |
| 94 |
* |
| 95 |
* @since 2.5.0 |
| 96 |
* |
| 97 |
* @return array<string> An array of timezones. |
| 98 |
*/ |
| 99 |
public static function get_timezones() { |
| 100 |
$timezones = []; |
| 101 |
$timezone_identifiers = DateTimeZone::listIdentifiers(); |
| 102 |
|
| 103 |
foreach ($timezone_identifiers as $timezone) { |
| 104 |
if (strpos($timezone, '/') !== false) { |
| 105 |
$timezones[] = $timezone; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
return $timezones; |
| 110 |
} |
| 111 |
} |
| 112 |
|