| @@ -1,95 +1,131 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Hostinger; |
| 4 | 4 | |
| 5 | - | |
| 6 | -use Hostinger\Admin\PluginSettings; | |
| 7 | -use Hostinger\Admin\Jobs\JobInitializer; | |
| 8 | -use Hostinger\Admin\Proxy; | |
| 9 | -use Hostinger\LlmsTxtGenerator\LlmsTxtFileHelper; | |
| 10 | -use Hostinger\LlmsTxtGenerator\LlmsTxtParser; | |
| 11 | -use Hostinger\Rest\Routes; | |
| 12 | -use Hostinger\Rest\SettingsRoutes; | |
| 5 | +use Hostinger\Loader; | |
| 6 | +use Hostinger\Helper; | |
| 7 | +use Hostinger\Settings; | |
| 8 | +use Hostinger\I18n; | |
| 9 | +use Hostinger\Config; | |
| 10 | +use Hostinger\Cli; | |
| 13 | 11 | use Hostinger\Admin\Assets as AdminAssets; |
| 14 | 12 | use Hostinger\Admin\Hooks as AdminHooks; |
| 15 | 13 | use Hostinger\Admin\Menu as AdminMenu; |
| 14 | +use Hostinger\Admin\Ajax as AdminAjax; | |
| 16 | 15 | use Hostinger\Admin\Redirects as AdminRedirects; |
| 17 | -use Hostinger\WpHelper\Config; | |
| 18 | -use Hostinger\WpHelper\Requests\Client; | |
| 19 | -use Hostinger\WpHelper\Utils; | |
| 20 | -use Hostinger\LlmsTxtGenerator\LlmsTxtGenerator; | |
| 16 | +use Hostinger\Amplitude\Amplitude; | |
| 17 | +use Hostinger\Preview\Assets as PreviewAssets; | |
| 18 | +use Hostinger\Requests\Client; | |
| 19 | +use Hostinger\Admin\Onboarding\Settings as OnboardingSettings; | |
| 20 | +use Hostinger\Surveys\Rest\Rest as SurveysRest; | |
| 21 | +use Hostinger\Surveys\Surveys; | |
| 22 | +use Hostinger\Surveys\Questions as SurveysQuestions; | |
| 23 | +use Hostinger\Admin\Onboarding\AutocompleteSteps; | |
| 21 | 24 | |
| 22 | 25 | defined( 'ABSPATH' ) || exit; |
| 23 | 26 | |
| 24 | 27 | class Bootstrap { |
| 28 | + protected Loader $loader; | |
| 25 | 29 | |
| 26 | - protected Loader $loader; | |
| 27 | - protected Utils $utils; | |
| 28 | - protected Config $config; | |
| 30 | + public function __construct() { | |
| 31 | + $this->loader = new Loader(); | |
| 32 | + } | |
| 29 | 33 | |
| 30 | - public function __construct() { | |
| 31 | - $this->loader = new Loader(); | |
| 32 | - $this->utils = new Utils(); | |
| 33 | - $this->config = new Config(); | |
| 34 | - } | |
| 34 | + public function run(): void { | |
| 35 | + $this->load_dependencies(); | |
| 36 | + $this->set_locale(); | |
| 37 | + $this->loader->run(); | |
| 38 | + } | |
| 35 | 39 | |
| 36 | - public function run(): void { | |
| 37 | - $this->load_dependencies(); | |
| 38 | - $this->set_locale(); | |
| 39 | - $this->loader->run(); | |
| 40 | - } | |
| 40 | + private function load_dependencies(): void { | |
| 41 | + $this->load_onboarding_dependencies(); | |
| 42 | + $this->load_public_dependencies(); | |
| 43 | + $this->amplitude_dependencies(); | |
| 41 | 44 | |
| 42 | - private function load_dependencies(): void { | |
| 43 | - $this->load_public_dependencies(); | |
| 45 | + if ( is_admin() ) { | |
| 46 | + $this->load_admin_dependencies(); | |
| 47 | + if ( ! empty( Helper::get_api_token() ) ) { | |
| 48 | + $this->define_admin_surveys(); | |
| 49 | + } | |
| 50 | + } | |
| 44 | 51 | |
| 45 | - if ( is_admin() ) { | |
| 46 | - $this->load_admin_dependencies(); | |
| 47 | - } | |
| 52 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 53 | + new Cli(); | |
| 54 | + } | |
| 48 | 55 | |
| 49 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 50 | - new Cli(); | |
| 51 | - } | |
| 56 | + if ( get_option( 'hostinger_maintenance_mode', 0 ) ) { | |
| 57 | + require_once HOSTINGER_ABSPATH . 'includes/ComingSoon.php'; | |
| 58 | + } | |
| 59 | + } | |
| 52 | 60 | |
| 53 | - $plugin_settings = new PluginSettings(); | |
| 54 | - $plugin_options = $plugin_settings->get_plugin_settings(); | |
| 61 | + private function set_locale() { | |
| 62 | + $plugin_i18n = new I18n(); | |
| 63 | + $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); | |
| 64 | + } | |
| 55 | 65 | |
| 56 | - if ( $plugin_options->get_maintenance_mode() ) { | |
| 57 | - require_once HOSTINGER_ABSPATH . 'includes/ComingSoon.php'; | |
| 58 | - } | |
| 59 | - } | |
| 66 | + private function load_admin_dependencies(): void { | |
| 67 | + new AdminAssets(); | |
| 68 | + new AdminHooks(); | |
| 69 | + new AdminMenu(); | |
| 70 | + new AdminAjax(); | |
| 71 | + new AdminRedirects(); | |
| 72 | + } | |
| 60 | 73 | |
| 61 | - private function set_locale() { | |
| 62 | - $plugin_i18n = new I18n(); | |
| 63 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); | |
| 64 | - } | |
| 74 | + private function define_admin_surveys(): void { | |
| 75 | + $settings = new Settings(); | |
| 76 | + $helper = new Helper(); | |
| 77 | + $config_handler = new Config(); | |
| 78 | + $survey_questions = new SurveysQuestions(); | |
| 79 | + $client = new Client( | |
| 80 | + $config_handler->get_config_value( 'base_rest_uri', HOSTINGER_REST_URI ), | |
| 81 | + array( | |
| 82 | + Config::TOKEN_HEADER => $helper::get_api_token(), | |
| 83 | + Config::DOMAIN_HEADER => $helper->get_host_info(), | |
| 84 | + ) | |
| 85 | + ); | |
| 86 | + $rest = new SurveysRest( $client ); | |
| 87 | + $surveys = new Surveys( $settings, $helper, $config_handler, $survey_questions, $rest ); | |
| 65 | 88 | |
| 66 | - private function load_admin_dependencies(): void { | |
| 67 | - new AdminAssets(); | |
| 68 | - new AdminHooks( $this->utils ); | |
| 69 | - new AdminMenu(); | |
| 70 | - new AdminRedirects(); | |
| 71 | - new AdminRedirects(); | |
| 72 | - } | |
| 89 | + switch ( true ) { | |
| 90 | + case $surveys->is_woocommerce_survey_enabled(): | |
| 91 | + $survey_function = 'customer_csat_survey'; | |
| 92 | + break; | |
| 73 | 93 | |
| 74 | - private function load_public_dependencies(): void { | |
| 94 | + case $surveys->is_prebuild_website_survey_enabled(): | |
| 95 | + $survey_function = 'prebuild_website_survey'; | |
| 96 | + break; | |
| 75 | 97 | |
| 76 | - $client = new Client( | |
| 77 | - 'https://wh-wordpress-proxy-api.hostinger.io', | |
| 78 | - array( | |
| 79 | - Config::TOKEN_HEADER => $this->utils->getApiToken(), | |
| 80 | - Config::DOMAIN_HEADER => $this->utils->getHostInfo(), | |
| 81 | - ) | |
| 82 | - ); | |
| 98 | + case $surveys->is_ai_onboarding_survey_enabled(): | |
| 99 | + $survey_function = 'customer_ai_csat_survey'; | |
| 100 | + break; | |
| 83 | 101 | |
| 84 | - new JobInitializer( new Proxy( $client, $this->utils ) ); | |
| 85 | - new Hooks(); | |
| 102 | + case $surveys->is_content_generation_survey_enabled(): | |
| 103 | + $survey_function = 'ai_plugin_survey'; | |
| 104 | + break; | |
| 86 | 105 | |
| 87 | - $plugin_settings = new PluginSettings(); | |
| 106 | + case $surveys->is_affiliate_survey_enabled(): | |
| 107 | + $survey_function = 'affiliate_plugin_survey'; | |
| 108 | + break; | |
| 88 | 109 | |
| 89 | - new LlmsTxtGenerator( $plugin_settings, new LlmsTxtFileHelper(), new LlmsTxtParser() ); | |
| 110 | + default: | |
| 111 | + return; // No survey enabled | |
| 112 | + } | |
| 90 | 113 | |
| 91 | - $settings_routes = new SettingsRoutes( $plugin_settings ); | |
| 92 | - $routes = new Routes( $settings_routes ); | |
| 93 | - $routes->init(); | |
| 94 | - } | |
| 114 | + $this->loader->add_action( 'admin_footer', $surveys, $survey_function, 10 ); | |
| 115 | + } | |
| 116 | + | |
| 117 | + private function load_public_dependencies(): void { | |
| 118 | + new PreviewAssets(); | |
| 119 | + new Hooks(); | |
| 120 | + } | |
| 121 | + | |
| 122 | + private function load_onboarding_dependencies(): void { | |
| 123 | + if ( ! OnboardingSettings::all_steps_completed() ) { | |
| 124 | + new AutocompleteSteps(); | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + private function amplitude_dependencies(): void { | |
| 129 | + new Amplitude(); | |
| 130 | + } | |
| 95 | 131 | } |