| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace Leadin\admin; |
| 3 | 4 | |
| 4 | 5 | use Leadin\data\Filters; |
| 5 | 6 | use Leadin\admin\Links; |
| @@ -10,8 +11,9 @@ | ||
| 10 | 11 | use Leadin\data\Portal_Options; |
| 11 | 12 | use Leadin\admin\Connection; |
| 12 | 13 | use Leadin\admin\Impact; |
| 13 | 14 | use Leadin\data\User_Metadata; |
| 15 | +use Leadin\auth\OAuthCryptoError; | |
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * Class containing all the constants used for admin script localization. |
| 17 | 19 | */ |
| @@ -17,8 +19,9 @@ | ||
| 17 | 19 | */ |
| 18 | 20 | class AdminConstants { |
| 19 | 21 | |
| 20 | 22 | |
| 23 | + | |
| 21 | 24 | /** |
| 22 | 25 | * Return utm_campaign to add to the signup link. |
| 23 | 26 | */ |
| 24 | 27 | private static function get_utm_campaign() { |
| @@ -90,9 +93,9 @@ | ||
| 90 | 93 | 'wp' => Versions::get_wp_version(), |
| 91 | 94 | 'theme' => get_option( 'stylesheet' ), |
| 92 | 95 | 'adminUrl' => admin_url(), |
| 93 | 96 | 'websiteName' => get_bloginfo( 'name' ), |
| 94 | - 'domain' => parse_url( get_site_url(), PHP_URL_HOST ), | |
| 97 | + 'domain' => wp_parse_url( get_site_url(), PHP_URL_HOST ), | |
| 95 | 98 | 'wp_user' => $wp_user->first_name ? $wp_user->first_name : $wp_user->user_nicename, |
| 96 | 99 | 'nonce' => self::get_connection_nonce(), |
| 97 | 100 | 'accountName' => Portal_Options::get_account_name(), |
| 98 | 101 | 'hsdio' => Portal_Options::get_device_id(), |
| @@ -121,44 +124,72 @@ | ||
| 121 | 124 | return $hubspot_config; |
| 122 | 125 | } |
| 123 | 126 | |
| 124 | 127 | /** |
| 128 | + * Returns information about Content embed plugin necessary for user guide to determine if/how to install & activate | |
| 129 | + */ | |
| 130 | + public static function get_content_embed_config() { | |
| 131 | + $content_embed_config = array_merge( | |
| 132 | + array( | |
| 133 | + 'userCanInstall' => current_user_can( 'install_plugins' ), | |
| 134 | + 'userCanActivate' => current_user_can( 'activate_plugins' ), | |
| 135 | + 'nonce' => wp_create_nonce( ContentEmbedInstaller::INSTALL_ARG ), | |
| 136 | + ), | |
| 137 | + ContentEmbedInstaller::is_content_embed_active_installed() | |
| 138 | + ); | |
| 139 | + | |
| 140 | + return $content_embed_config; | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 125 | 144 | * Returns a minimal version of leadinConfig, containing the data needed by the background iframe. |
| 126 | 145 | */ |
| 127 | 146 | public static function get_background_leadin_config() { |
| 128 | - $wp_user_id = get_current_user_id(); | |
| 147 | + $wp_user_id = get_current_user_id(); | |
| 148 | + $portal_id = Portal_Options::get_portal_id(); | |
| 149 | + $refresh_token = OAuth::get_refresh_token(); | |
| 150 | + $is_connected = ! empty( $portal_id ) && ! empty( $refresh_token ); | |
| 129 | 151 | |
| 130 | 152 | $background_config = array( |
| 131 | - 'adminUrl' => admin_url(), | |
| 132 | - 'activationTime' => Portal_Options::get_activation_time(), | |
| 133 | - 'deviceId' => Portal_Options::get_device_id(), | |
| 134 | - 'formsScript' => Filters::apply_forms_script_url_filters(), | |
| 135 | - 'formsScriptPayload' => Filters::apply_forms_payload_filters(), | |
| 136 | - 'meetingsScript' => Filters::apply_meetings_script_url_filters(), | |
| 137 | - 'hublet' => Filters::apply_hublet_filters(), | |
| 138 | - 'hubspotBaseUrl' => Filters::apply_base_url_filters( Connection::is_connected() ), | |
| 139 | - 'leadinPluginVersion' => constant( 'LEADIN_PLUGIN_VERSION' ), | |
| 140 | - 'locale' => get_locale(), | |
| 141 | - 'restUrl' => get_rest_url(), | |
| 142 | - 'restNonce' => wp_create_nonce( 'wp_rest' ), | |
| 143 | - 'redirectNonce' => wp_create_nonce( Routing::REDIRECT_NONCE ), | |
| 144 | - 'phpVersion' => Versions::get_php_version(), | |
| 145 | - 'pluginPath' => constant( 'LEADIN_PATH' ), | |
| 146 | - 'plugins' => get_plugins(), | |
| 147 | - 'portalId' => Portal_Options::get_portal_id(), | |
| 148 | - 'accountName' => Portal_Options::get_account_name(), | |
| 149 | - 'portalDomain' => Portal_Options::get_portal_domain(), | |
| 150 | - 'portalEmail' => get_user_meta( $wp_user_id, 'leadin_email', true ), | |
| 151 | - 'reviewSkippedDate' => User_Metadata::get_skip_review(), | |
| 152 | - 'theme' => get_option( 'stylesheet' ), | |
| 153 | - 'wpVersion' => Versions::get_wp_version(), | |
| 154 | - 'leadinQueryParams' => self::get_hubspot_query_params_array(), | |
| 155 | - 'connectionStatus' => Connection::is_connected() ? 'Connected' : 'NotConnected', | |
| 153 | + 'adminUrl' => admin_url(), | |
| 154 | + 'activationTime' => Portal_Options::get_activation_time(), | |
| 155 | + 'deviceId' => Portal_Options::get_device_id(), | |
| 156 | + 'formsScript' => Filters::apply_forms_script_url_filters(), | |
| 157 | + 'formsScriptPayload' => Filters::apply_forms_payload_filters(), | |
| 158 | + 'meetingsScript' => Filters::apply_meetings_script_url_filters(), | |
| 159 | + 'hublet' => Filters::apply_hublet_filters(), | |
| 160 | + 'hubspotBaseUrl' => Filters::apply_base_url_filters( $is_connected ), | |
| 161 | + 'leadinPluginVersion' => constant( 'LEADIN_PLUGIN_VERSION' ), | |
| 162 | + 'locale' => get_locale(), | |
| 163 | + 'restUrl' => get_rest_url(), | |
| 164 | + 'restNonce' => wp_create_nonce( 'wp_rest' ), | |
| 165 | + 'redirectNonce' => wp_create_nonce( Routing::REDIRECT_NONCE ), | |
| 166 | + 'phpVersion' => Versions::get_php_version(), | |
| 167 | + 'pluginPath' => constant( 'LEADIN_PATH' ), | |
| 168 | + // Returning and empty array to release a hotfix to a security issue ensuring no errors on the frontend | |
| 169 | + // 'plugins' => get_plugins(), | |
| 170 | + 'plugins' => array(), | |
| 171 | + 'portalId' => $portal_id, | |
| 172 | + 'accountName' => Portal_Options::get_account_name(), | |
| 173 | + 'portalDomain' => Portal_Options::get_portal_domain(), | |
| 174 | + 'portalEmail' => get_user_meta( $wp_user_id, 'leadin_email', true ), | |
| 175 | + 'reviewSkippedDate' => User_Metadata::get_skip_review(), | |
| 176 | + 'theme' => get_option( 'stylesheet' ), | |
| 177 | + 'wpVersion' => Versions::get_wp_version(), | |
| 178 | + 'leadinQueryParams' => self::get_hubspot_query_params_array(), | |
| 179 | + 'connectionStatus' => $is_connected ? 'Connected' : 'NotConnected', | |
| 180 | + 'contentEmbed' => self::get_content_embed_config(), | |
| 181 | + 'requiresContentEmbedScope' => is_plugin_active( 'hubspot-content-embed/content-embed.php' ) ? '1' : '0', | |
| 182 | + 'lastAuthorizeTime' => Portal_Options::get_last_authorize_time(), | |
| 183 | + 'lastDeauthorizeTime' => Portal_Options::get_last_deauthorize_time(), | |
| 184 | + 'lastDisconnectTime' => Portal_Options::get_last_disconnect_time(), | |
| 156 | 185 | ); |
| 157 | 186 | |
| 158 | - if ( Connection::is_connected() ) { | |
| 159 | - $background_config['refreshToken'] = OAuth::get_refresh_token(); | |
| 187 | + if ( false === $refresh_token ) { | |
| 188 | + $background_config['decryptError'] = OAuthCryptoError::DECRYPT_FAILED; | |
| 160 | 189 | } |
| 190 | + // refreshToken is no longer included in leadinConfig — PHP exchanges it for | |
| 191 | + // a short-lived access token server-side via the /access-token REST endpoint | |
| 161 | 192 | |
| 162 | 193 | return $background_config; |
| 163 | 194 | } |
| 164 | 195 | |
| @@ -167,9 +198,9 @@ | ||
| 167 | 198 | */ |
| 168 | 199 | public static function get_leadin_config() { |
| 169 | 200 | $leadin_config = self::get_background_leadin_config(); |
| 170 | 201 | |
| 171 | - if ( ! Connection::is_connected() ) { | |
| 202 | + if ( 'NotConnected' === $leadin_config['connectionStatus'] ) { | |
| 172 | 203 | if ( ! Impact::has_params() ) { |
| 173 | 204 | $impact_link = Impact::get_affiliate_link(); |
| 174 | 205 | if ( ! empty( $impact_link ) ) { |
| 175 | 206 | $leadin_config['impactLink'] = Impact::get_affiliate_link(); |
| @@ -178,6 +209,5 @@ | ||
| 178 | 209 | } |
| 179 | 210 | |
| 180 | 211 | return $leadin_config; |
| 181 | 212 | } |
| 182 | - | |
| 183 | 213 | } |