Changeset 1370621
- Timestamp:
- 03/14/2016 11:21:06 AM (10 years ago)
- File:
-
- 1 edited
-
intercom/trunk/bootstrap.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
intercom/trunk/bootstrap.php
r1326441 r1370621 6 6 Author: Bob Long 7 7 Author URI: https://www.intercom.io 8 Version: 2. 4.18 Version: 2.5.0 9 9 */ 10 10 … … 14 14 private $secret_key = ""; 15 15 16 public function __construct($data, $secret_key )16 public function __construct($data, $secret_key, $secure_mode) 17 17 { 18 18 $this->raw_data = $data; 19 19 $this->secret_key = $secret_key; 20 $this->secure_mode = $secure_mode; 20 21 } 21 22 … … 23 24 { 24 25 $secret_key = $this->getSecretKey(); 25 if (empty($secret_key)) 26 $secure_mode = $this->getSecureMode(); 27 if (empty($secret_key) || !$secure_mode) 26 28 { 27 29 return $this->emptySecureModeHashComponent(); … … 52 54 { 53 55 return $this->secret_key; 56 } 57 58 private function getSecureMode() 59 { 60 return $this->secure_mode; 54 61 } 55 62 … … 79 86 } 80 87 88 public function getAuthUrl() { 89 return "https://wordpress_auth.intercom.io/confirm?state=".get_site_url()."::".wp_create_nonce('intercom-oauth'); 90 } 91 81 92 public function htmlUnclosed() 82 93 { … … 84 95 $app_id = WordPressEscaper::escAttr($settings['app_id']); 85 96 $secret = WordPressEscaper::escAttr($settings['secret']); 86 87 if (empty($secret)) { 88 $secret_row_style = 'display: none;'; 89 $secret_link_style = ''; 97 $secure_mode = WordPressEscaper::escAttr($settings['secure_mode']); 98 $auth_url = $this->getAuthUrl(); 99 100 if($secure_mode) { 101 $secure_mode_state = "checked disabled"; 102 } 103 if (empty($app_id) || empty($secret)) { 104 $app_id_row_style = 'display: none;'; 105 $app_id_link_style = ''; 90 106 } else { 91 $secret_row_style = ''; 92 $secret_link_style = 'display: none;'; 93 } 94 107 $app_id_row_style = ''; 108 $app_id_link_style = 'display: none;'; 109 } 95 110 $dismissable_message = ''; 96 111 if ($_GET['saved']) { 97 $dismissable_message = $this->dismissibleMessage('App ID saved.'); 98 } 99 100 if ($_GET['appId']) { 101 $app_id = WordPressEscaper::escAttr($_GET['appId']); 102 $dismissable_message = $this->dismissibleMessage('We’ve copied your new Intercom app ID below. Click to save changes and then close this window to finish signing up for Intercom.'); 103 } 112 $dismissable_message = $this->dismissibleMessage('Successfully authenticated'); 113 } 114 if ($_GET['enable_secure_mode']) { 115 $dismissable_message = $this->dismissibleMessage('Secure Mode successfully enabled'); 116 } 117 $onboarding_markup = $this->getOnboardingLinkIfNoAppId(); 104 118 105 119 return <<<END 106 <div class="wrap"> 107 <h1>Intercom Settings</h1> 108 $dismissable_message 109 <form method="post" action=""> 110 <table class="form-table"> 111 <tbody> 112 <tr> 113 <th scope="row"><label for="intercom_app_id">App ID</label></th> 114 <td><input id="intercom_app_id" name="intercom[app_id]" type="text" value="$app_id" placeholder="App ID"></td> 115 </tr> 116 <tr id="intercom_secret_key_row" style="$secret_row_style"> 117 <th scope="row"><label for="intercom_secret">Secret Key (optional)</label></th> 118 <td><input id="intercom_secret" name="intercom[secret]" type="text" value="$secret" placeholder="Secret Key"></td> 119 </tr> 120 </tbody> 121 </table> 122 <p class="submit"> 123 <input name="intercom-submit" type="submit" value="Save Changes" class="button button-primary"> 124 <a id="intercom_secret_key_show_link" style="$secret_link_style margin-left: 20px" href="javascript: jQuery('#intercom_secret_key_row').show(); jQuery('#intercom_secret_key_show_link').hide(); jQuery('#intercom_secret').focus(); void(0);">Add your Intercom secret key (optional)</a> 125 </p> 120 121 <link rel="stylesheet" property='stylesheet' href="https://marketing.intercomassets.com/assets/redesign-ead0ee66f7c89e2930e04ac1b7e423494c29e8e681382f41d0b6b8a98b4591e1.css"> 122 <style> 123 #wpcontent { 124 background-color: #ffffff; 125 } 126 </style> 127 128 <div class="wrap"> 129 $dismissable_message 130 131 <section id="main_content" style="padding-top: 70px;"> 132 <div class="container"> 133 <div class="cta"> 134 135 <div class="sp__2--lg sp__2--xlg"></div> 136 137 <div id="oauth_content" style="$app_id_link_style"> 138 <div class="t__h1 c__red">Get started with Intercom</div> 139 140 <div class="cta__desc"> 141 Chat with visitors to your website in real-time, capture them as leads, and convert them to customers. Install Intercom on your WordPress site in a couple of clicks. 142 </div> 143 144 <div id="get_intercom_btn_container" style="position:relative;margin-top:30px;"> 145 <a href="$auth_url"> 146 <img src="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png" srcset="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png 1x, https://static.intercomassets.com/assets/oauth/[email protected] 2x, https://static.intercomassets.com/assets/oauth/[email protected] 3x"/> 147 </a> 148 </div> 149 $onboarding_markup 150 </div> 151 152 <div id="app_id_and_secret_content" style="$app_id_row_style"> 153 <div class="t__h1 c__red">Intercom has been installed</div> 154 155 <div class="cta__desc"> 156 Intercom is now set up and ready to go. You can now chat with your existing and potential new customers, send them targeted messages, and get feedback. 157 <br/> 158 <br/> 159 <a href="https://app.intercom.io/a/apps/$app_id" target="_blank">Click here to access your Intercom Team Inbox.</a> 160 <br/> 161 <br/> 162 Need help? <a href="https://docs.intercom.io/for-converting-visitors-to-users" target="_blank">Visit our documentation</a> for best practices, tips, and much more. 163 <br/> 164 <br/> 165 166 <div> 167 <div style="font-size:0.87em"> 168 Learn more about our products : <a href="https://www.intercom.io/live-chat"target="_blank">Acquire</a>, <a href="https://www.intercom.io/customer-engagement" target="_blank">Engage</a>, <a href="https://www.intercom.io/customer-feedback" target="_blank">Learn</a> and <a href="https://www.intercom.io/customer-support" target="_blank">Support</a>. 169 </div> 170 <form method="post" action="" name="enable_secure_mode"> 171 <table class="form-table" align="center" style="margin-top: 16px; width: inherit;"> 172 <tbody> 173 <tr> 174 <th scope="row" style="text-align: center; vertical-align: middle;"><label for="intercom_app_id">App ID</label></th> 175 <td><input id="intercom_app_id" disabled name="intercom[app_id]" type="text" value="$app_id" placeholder="App ID"></td> 176 </tr> 177 <tr id="intercom_secure_mode"> 178 <th scope="row" style="text-align: center; vertical-align: middle;"><label for="intercom_secure">Secure Mode</label></th> 179 <td><input id="intercom-secure-mode" name="enable_secure_mode" type="checkbox" $secure_mode_state></td> 180 </tr> 181 </tbody> 182 </table> 183 126 184 END; 127 185 } … … 129 187 public function htmlClosed() 130 188 { 131 $ onboarding_markup = $this->getOnboardingLinkIfNoAppId();189 $auth_url = $this->getAuthUrl(); 132 190 return <<<END 133 134 </form>$onboarding_markup 135 </div> 191 </form> 192 <p style="font-size:0.86em">Secure mode allows you to make sure that conversations between you and your users are kept private.<br/> 193 Once you enabled secure mode you cannot disable it.<br/> 194 <a href="https://docs.intercom.io/configuring-intercom/enable-secure-mode" target="_blank">Learn more about Secure Mode</a> 195 </p> 196 <br/> 197 <div style="font-size:0.8em">If the intercom application assiocated with your store is incorrect, please <a href="$auth_url">click here</a> to reconnect with Intercom, to choose a new application.</div> 198 </div> 199 </div> 200 </div> 201 </div> 202 </div> 203 </section> 204 </div> 205 <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script> 206 <script type="text/javascript"> 207 $('#intercom-secure-mode').unbind('click').click(function() { 208 $('#intercom-secure-mode').prop('checked', false); 209 if(confirm('Are you sure you want to enable secure mode for Intercom ?')) { 210 $('#intercom-secure-mode').prop('value', true); 211 $('#intercom-secure-mode').prop('checked', true); 212 $('form[name="enable_secure_mode"]').submit(); 213 } 214 }); 215 </script> 136 216 END; 137 217 } … … 169 249 public function html() 170 250 { 171 return $this->source(); 172 } 173 251 return $this->shutdown_on_logout() . $this->source(); 252 } 253 254 255 private function shutdown_on_logout() 256 { 257 return <<<HTML 258 <script data-cfasync="false"> 259 var logout_link = document.querySelectorAll('a[href*="wp-login.php?action=logout"]'); 260 if (logout_link) { 261 for(var i=0; i < logout_link.length; i++) { 262 logout_link[i].addEventListener( "click", function() { 263 Intercom('shutdown'); 264 }); 265 } 266 } 267 </script> 268 269 HTML; 270 } 174 271 private function source() 175 272 { … … 192 289 private $wordpress_user = NULL; 193 290 194 public function __construct($raw_data, $secret = NULL, $ wordpress_user = NULL, $constants = array('ICL_LANGUAGE_CODE' => 'language_override'))291 public function __construct($raw_data, $secret = NULL, $secure_mode = false, $wordpress_user = NULL, $constants = array('ICL_LANGUAGE_CODE' => 'language_override')) 195 292 { 196 293 $this->raw_data = $this->validateRawData($raw_data); 197 294 $this->secret = $secret; 295 $this->secure_mode = $secure_mode; 198 296 $this->wordpress_user = $wordpress_user; 199 297 $this->constants = $constants; … … 215 313 $user = new IntercomUser($this->wordpress_user, $this->raw_data); 216 314 $settings = $user->buildSettings(); 217 $secureModeCalculator = new SecureModeCalculator($settings, $this->secret );315 $secureModeCalculator = new SecureModeCalculator($settings, $this->secret, $this->secure_mode); 218 316 $result = array_merge($settings, $secureModeCalculator->secureModeComponent()); 219 317 $result = $this->mergeConstants($result); … … 331 429 array("app_id" => WordPressEscaper::escJS($options['app_id'])), 332 430 WordPressEscaper::escJS($options['secret']), 431 WordPressEscaper::escJS($options['secure_mode']), 333 432 wp_get_current_user() 334 433 ); … … 355 454 } 356 455 $options = get_option('intercom'); 357 $settings_page = new SettingsPage(array("app_id" => $options['app_id'], "secret" => $options['secret'] ));456 $settings_page = new SettingsPage(array("app_id" => $options['app_id'], "secret" => $options['secret'], "secure_mode" => $options['secure_mode'])); 358 457 echo $settings_page->htmlUnclosed(); 359 458 wp_nonce_field('intercom-update'); … … 363 462 function intercom_settings() { 364 463 register_setting('intercom', 'intercom'); 365 if (isset($_POST['_wpnonce']) and wp_verify_nonce($_POST[ '_wpnonce'], 'intercom-update') 366 and isset($_POST[ 'intercom-submit' ] ) and current_user_can('manage_options')) { 367 $validator = new Validator($_POST["intercom"], function($x) { return wp_kses(trim($x), array()); }); 368 update_option("intercom", array("app_id" => $validator->validAppId(), "secret" => $validator->validSecret())); 464 if (isset($_GET['state']) && wp_verify_nonce($_GET[ 'state'], 'intercom-oauth') && current_user_can('manage_options') && isset($_GET['app_id']) && isset($_GET['secret']) ) { 465 $validator = new Validator($_GET, function($x) { return wp_kses(trim($x), array()); }); 466 update_option("intercom", array("app_id" => $validator->validAppId(), "secret" => $validator->validSecret(), "secure_mode" => false)); 369 467 wp_safe_redirect(admin_url('options-general.php?page=intercom&saved=1')); 468 } 469 if ( current_user_can('manage_options') && wp_verify_nonce($_POST[ '_wpnonce'],'intercom-update') && isset($_POST['enable_secure_mode'])) { 470 $options = get_option('intercom'); 471 $options["secure_mode"] = true; 472 update_option("intercom", $options); 473 } 474 } 475 // Enable Secure Mode for customers who already copy/pasted their secret_key before the Oauth2 release. 476 function patch_oauth() { 477 $options = get_option('intercom'); 478 if ($options["secret"] && !isset($options["secure_mode"])) { 479 $options["secure_mode"] = true; 480 update_option("intercom", $options); 370 481 } 371 482 } … … 375 486 add_action('admin_menu', 'add_intercom_settings_page'); 376 487 add_action('network_admin_menu', 'add_intercom_settings_page'); 488 add_action('admin_init', 'patch_oauth'); 377 489 add_action('admin_init', 'intercom_settings'); 378 490 }
Note: See TracChangeset
for help on using the changeset viewer.