| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | namespace Elementor\App\Modules\SiteBuilder; |
| 3 | 3 | |
| 4 | 4 | use Elementor\App\Modules\SiteBuilder\Connect\App; |
| 5 | 5 | use Elementor\App\Modules\SiteBuilder\Rest\Rest_Api; |
| 6 | +use Elementor\App\Modules\SiteBuilder\Services\Connect_Auth_Service; | |
| 6 | 7 | use Elementor\Core\Base\Module as BaseModule; |
| 7 | 8 | use Elementor\Plugin; |
| 8 | 9 | |
| 9 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -61,14 +62,8 @@ | ||
| 61 | 62 | 'exitTo' => admin_url( 'admin.php?page=elementor' ), |
| 62 | 63 | 'elementorAiCurrentContext' => $this->get_elementor_ai_current_context(), |
| 63 | 64 | ]; |
| 64 | 65 | |
| 65 | - $connect_auth = $this->get_connect_auth(); | |
| 66 | - | |
| 67 | - if ( $connect_auth ) { | |
| 68 | - $settings['connectAuth'] = $connect_auth; | |
| 69 | - } | |
| 70 | - | |
| 71 | 66 | Plugin::$instance->app->set_settings( 'site-builder', $settings ); |
| 72 | 67 | } |
| 73 | 68 | |
| 74 | 69 | private function get_elementor_ai_current_context(): array { |
| @@ -92,63 +87,15 @@ | ||
| 92 | 87 | if ( ! $this->is_experiment_active() ) { |
| 93 | 88 | return null; |
| 94 | 89 | } |
| 95 | 90 | |
| 96 | - $connect_auth = $this->get_connect_auth(); | |
| 91 | + $connect_auth = ( new Connect_Auth_Service() )->get_connect_auth(); | |
| 97 | 92 | |
| 98 | 93 | if ( ! $connect_auth ) { |
| 99 | - return null; | |
| 94 | + return []; | |
| 100 | 95 | } |
| 101 | 96 | |
| 102 | 97 | return [ |
| 103 | 98 | 'siteKey' => $connect_auth['siteKey'], |
| 104 | - ]; | |
| 105 | - } | |
| 106 | - | |
| 107 | - private function get_connect_auth(): ?array { | |
| 108 | - if ( ! Plugin::instance()->common ) { | |
| 109 | - return null; | |
| 110 | - } | |
| 111 | - | |
| 112 | - $connect = Plugin::instance()->common->get_component( 'connect' ); | |
| 113 | - | |
| 114 | - if ( ! $connect ) { | |
| 115 | - return null; | |
| 116 | - } | |
| 117 | - | |
| 118 | - $app = $connect->get_app( 'library' ); | |
| 119 | - | |
| 120 | - if ( ! $app || ! $app->is_connected() ) { | |
| 121 | - return null; | |
| 122 | - } | |
| 123 | - | |
| 124 | - $access_token = $app->get( 'access_token' ); | |
| 125 | - $client_id = $app->get( 'client_id' ); | |
| 126 | - $home_url = trailingslashit( home_url() ); | |
| 127 | - $site_key = $app->get_site_key(); | |
| 128 | - $access_token_secret = $app->get( 'access_token_secret' ); | |
| 129 | - | |
| 130 | - $connect_data = [ | |
| 131 | - 'access-token' => $access_token, | |
| 132 | - 'app' => 'library', | |
| 133 | - 'client-id' => $client_id, | |
| 134 | - 'home-url' => $home_url, | |
| 135 | - 'site-key' => $site_key, | |
| 136 | - ]; | |
| 137 | - | |
| 138 | - ksort( $connect_data ); | |
| 139 | - | |
| 140 | - $signature = hash_hmac( | |
| 141 | - 'sha256', | |
| 142 | - wp_json_encode( $connect_data, JSON_NUMERIC_CHECK ), | |
| 143 | - $access_token_secret | |
| 144 | - ); | |
| 145 | - | |
| 146 | - return [ | |
| 147 | - 'signature' => $signature, | |
| 148 | - 'accessToken' => $access_token, | |
| 149 | - 'clientId' => $client_id, | |
| 150 | - 'homeUrl' => $home_url, | |
| 151 | - 'siteKey' => $site_key, | |
| 152 | 99 | ]; |
| 153 | 100 | } |
| 154 | 101 | } |