| @@ -2,9 +2,8 @@ | ||
| 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; | |
| 7 | 6 | use Elementor\Core\Base\Module as BaseModule; |
| 8 | 7 | use Elementor\Plugin; |
| 9 | 8 | |
| 10 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -62,8 +61,14 @@ | ||
| 62 | 61 | 'exitTo' => admin_url( 'admin.php?page=elementor' ), |
| 63 | 62 | 'elementorAiCurrentContext' => $this->get_elementor_ai_current_context(), |
| 64 | 63 | ]; |
| 65 | 64 | |
| 65 | + $connect_auth = $this->get_connect_auth(); | |
| 66 | + | |
| 67 | + if ( $connect_auth ) { | |
| 68 | + $settings['connectAuth'] = $connect_auth; | |
| 69 | + } | |
| 70 | + | |
| 66 | 71 | Plugin::$instance->app->set_settings( 'site-builder', $settings ); |
| 67 | 72 | } |
| 68 | 73 | |
| 69 | 74 | private function get_elementor_ai_current_context(): array { |
| @@ -87,15 +92,63 @@ | ||
| 87 | 92 | if ( ! $this->is_experiment_active() ) { |
| 88 | 93 | return null; |
| 89 | 94 | } |
| 90 | 95 | |
| 91 | - $connect_auth = ( new Connect_Auth_Service() )->get_connect_auth(); | |
| 96 | + $connect_auth = $this->get_connect_auth(); | |
| 92 | 97 | |
| 93 | 98 | if ( ! $connect_auth ) { |
| 94 | - return []; | |
| 99 | + return null; | |
| 95 | 100 | } |
| 96 | 101 | |
| 97 | 102 | return [ |
| 98 | 103 | '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, | |
| 99 | 152 | ]; |
| 100 | 153 | } |
| 101 | 154 | } |