PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.65
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.65
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / admin / class-adminconstants.php

class-adminconstants.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.65, at public/admin/class-adminconstants.php

214 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\admin;
4
5 use Leadin\data\Filters;
6 use Leadin\admin\Links;
7 use Leadin\admin\Routing;
8 use Leadin\auth\OAuth;
9 use Leadin\utils\Versions;
10 use Leadin\data\User;
11 use Leadin\data\Portal_Options;
12 use Leadin\admin\Connection;
13 use Leadin\admin\Impact;
14 use Leadin\data\User_Metadata;
15 use Leadin\auth\OAuthCryptoError;
16
17 /**
18 * Class containing all the constants used for admin script localization.
19 */
20 class AdminConstants {
21
22
23
24 /**
25 * Return utm_campaign to add to the signup link.
26 */
27 private static function get_utm_campaign() {
28 $wpe_template = get_option( 'wpe_template' );
29 if ( 'hubspot' === $wpe_template ) {
30 return 'wp-engine-site-template';
31 }
32 }
33
34 /**
35 * Return an array with the utm parameters for signup
36 */
37 private static function get_utm_query_params_array() {
38 $utm_params = array(
39 'utm_source' => 'wordpress-plugin',
40 'utm_medium' => 'marketplaces',
41 );
42
43 $utm_campaign = self::get_utm_campaign();
44 if ( ! empty( $utm_campaign ) ) {
45 $utm_params['utm_campaign'] = $utm_campaign;
46 }
47 return $utm_params;
48 }
49
50 /**
51 * Return a nonce used on the connection class
52 */
53 private static function get_connection_nonce() {
54 return wp_create_nonce( 'hubspot-nonce' );
55 }
56
57 /**
58 * Return an array with the user's pre-fill info for signup
59 */
60 private static function get_signup_prefill_params_array() {
61 $wp_user = wp_get_current_user();
62 $user_info = array(
63 'firstName' => $wp_user->user_firstname,
64 'lastName' => $wp_user->user_lastname,
65 'email' => $wp_user->user_email,
66 'company' => get_bloginfo( 'name' ),
67 );
68
69 return $user_info;
70 }
71
72 /**
73 * Return an array of properties to be included in the signup search string
74 */
75 public static function get_signup_query_params_array() {
76 $signup_params = array();
77 $signup_params['leadinPluginVersion'] = constant( 'LEADIN_PLUGIN_VERSION' );
78 $signup_params['trackConsent'] = User_Metadata::get_track_consent();
79 $user_prefill_params = self::get_signup_prefill_params_array();
80 $signup_params = array_merge( $signup_params, $user_prefill_params );
81 return $signup_params;
82 }
83
84 /**
85 * Return query params array for the iframe.
86 */
87 public static function get_hubspot_query_params_array() {
88 $wp_user = wp_get_current_user();
89 $hubspot_config = array(
90 'l' => get_locale(),
91 'php' => Versions::get_php_version(),
92 'v' => LEADIN_PLUGIN_VERSION,
93 'wp' => Versions::get_wp_version(),
94 'theme' => get_option( 'stylesheet' ),
95 'adminUrl' => admin_url(),
96 'websiteName' => get_bloginfo( 'name' ),
97 'domain' => wp_parse_url( get_site_url(), PHP_URL_HOST ),
98 'wp_user' => $wp_user->first_name ? $wp_user->first_name : $wp_user->user_nicename,
99 'nonce' => self::get_connection_nonce(),
100 'accountName' => Portal_Options::get_account_name(),
101 'hsdio' => Portal_Options::get_device_id(),
102 'portalDomain' => Portal_Options::get_portal_domain(),
103 );
104
105 $utm_params = self::get_utm_query_params_array();
106 $hubspot_config = array_merge( $hubspot_config, $utm_params );
107
108 if ( User::is_admin() ) {
109 $hubspot_config['admin'] = '1';
110 }
111
112 if ( Routing::has_just_connected_with_oauth() ) {
113 $hubspot_config['justConnected'] = true;
114 }
115 if ( Routing::is_new_portal_with_oauth() ) {
116 $hubspot_config['isNewPortal'] = true;
117 }
118
119 if ( ! Connection::is_connected() ) {
120 $signup_params = self::get_signup_query_params_array();
121 $hubspot_config = array_merge( $hubspot_config, $signup_params, Impact::get_params() );
122 }
123
124 return $hubspot_config;
125 }
126
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 /**
144 * Returns a minimal version of leadinConfig, containing the data needed by the background iframe.
145 */
146 public static function get_background_leadin_config() {
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 );
151
152 $background_config = array(
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(),
185 );
186
187 if ( false === $refresh_token ) {
188 $background_config['decryptError'] = OAuthCryptoError::DECRYPT_FAILED;
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
192
193 return $background_config;
194 }
195
196 /**
197 * Returns leadinConfig, containing all the data needed by the leadin javascript.
198 */
199 public static function get_leadin_config() {
200 $leadin_config = self::get_background_leadin_config();
201
202 if ( 'NotConnected' === $leadin_config['connectionStatus'] ) {
203 if ( ! Impact::has_params() ) {
204 $impact_link = Impact::get_affiliate_link();
205 if ( ! empty( $impact_link ) ) {
206 $leadin_config['impactLink'] = Impact::get_affiliate_link();
207 }
208 }
209 }
210
211 return $leadin_config;
212 }
213 }
214