-
- $text
- - -END; - } - - public function getAuthUrl() { - return "https://wordpress_auth.intercom.io/confirm?state=".get_site_url()."::".wp_create_nonce('intercom-oauth'); - } - - public function htmlUnclosed() - { - $settings = $this->getSettings(); - $styles = $this->getStyles(); - $app_id = WordPressEscaper::escAttr($settings['app_id']); - $secret = WordPressEscaper::escAttr($settings['secret']); - $secure_mode = WordPressEscaper::escAttr($settings['secure_mode']); - $auth_url = $this->getAuthUrl(); - $dismissable_message = ''; - if (isset($_GET['appId'])) { - // Copying app_id from setup guide - $app_id = WordPressEscaper::escAttr($_GET['appId']); - $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."); - } - if (isset($_GET['saved'])) { - $dismissable_message = $this->dismissibleMessage("Your app id has been successfully saved. You can now close this window to finish signing up for Intercom."); - } - if (isset($_GET['authenticated'])) { - $dismissable_message = $this->dismissibleMessage('You successfully authenticated with Intercom'); - } - if (isset($_GET['enable_secure_mode'])) { - $dismissable_message = $this->dismissibleMessage('Secure Mode successfully enabled'); - } - $onboarding_markup = $this->getOnboardingLinkIfNoAppId(); - - return <<
-
- Need an Intercom account? Get started.
'; - } else { - return ''; - } - } -} - -class Snippet -{ - private $snippet_settings = ""; - - public function __construct($snippet_settings) - { - $this->snippet_settings = $snippet_settings; - } - public function html() - { - return $this->shutdown_on_logout() . $this->source(); - } - - - private function shutdown_on_logout() - { - return << - var logout_link = document.querySelectorAll('a[href*="wp-login.php?action=logout"]'); - if (logout_link) { - for(var i=0; i < logout_link.length; i++) { - logout_link[i].addEventListener( "click", function() { - Intercom('shutdown'); - }); - } - } - - -HTML; - } - private function source() - { - $snippet_json = $this->snippet_settings->json(); - $app_id = $this->snippet_settings->appId(); - - return << - window.intercomSettings = $snippet_json; - - -HTML; - } -} - -class SnippetSettings -{ - private $raw_data = array(); - private $secret = NULL; - private $wordpress_user = NULL; - - public function __construct($raw_data, $secret = NULL, $secure_mode = false, $wordpress_user = NULL, $constants = array('ICL_LANGUAGE_CODE' => 'language_override')) - { - $this->raw_data = $this->validateRawData($raw_data); - $this->secret = $secret; - $this->secure_mode = $secure_mode; - $this->wordpress_user = $wordpress_user; - $this->constants = $constants; - } - - public function json() - { - return json_encode($this->getRawData()); - } - - public function appId() - { - $raw_data = $this->getRawData(); - return $raw_data["app_id"]; - } - - private function getRawData() - { - $user = new IntercomUser($this->wordpress_user, $this->raw_data); - $settings = $user->buildSettings(); - $secureModeCalculator = new SecureModeCalculator($settings, $this->secret, $this->secure_mode); - $result = array_merge($settings, $secureModeCalculator->secureModeComponent()); - $result = $this->mergeConstants($result); - return $result; - } - - private function mergeConstants($settings) { - foreach($this->constants as $key => $value) { - if (defined($key)) { - $const_val = WordPressEscaper::escJS(constant($key)); - $settings = array_merge($settings, array($value => $const_val)); - } - } - return $settings; - } - - private function validateRawData($raw_data) - { - if (!array_key_exists("app_id", $raw_data)) { - throw new Exception("app_id is required"); - } - return $raw_data; - } -} - -class WordPressEscaper -{ - public static function escAttr($value) - { - if (function_exists('esc_attr')) { - return esc_attr($value); - } else { - if (getenv('INTERCOM_PLUGIN_TEST') == '1') { - return $value; - } - } - } - - public static function escJS($value) - { - if (function_exists('esc_js')) { - return esc_js($value); - } else { - if (getenv('INTERCOM_PLUGIN_TEST') == '1') { - return $value; - } - } - } -} - -class IntercomUser -{ - private $wordpress_user = NULL; - private $settings = array(); - - public function __construct($wordpress_user, $settings) - { - $this->wordpress_user = $wordpress_user; - $this->settings = $settings; - } - - public function buildSettings() - { - if (empty($this->wordpress_user)) - { - return $this->settings; - } - if (!empty($this->wordpress_user->user_email)) - { - $this->settings["email"] = WordPressEscaper::escJS($this->wordpress_user->user_email); - } - if (!empty($this->wordpress_user->display_name)) - { - $this->settings["name"] = WordPressEscaper::escJS($this->wordpress_user->display_name); - } - return $this->settings; - } -} - -class Validator -{ - private $inputs = array(); - private $validation; - - public function __construct($inputs, $validation) - { - $this->input = $inputs; - $this->validation = $validation; - } - - public function validAppId() - { - return $this->validate($this->input["app_id"]); - } - - public function validSecret() - { - return $this->validate($this->input["secret"]); - } - - private function validate($x) - { - return call_user_func($this->validation, $x); - } -} - -if (getenv('INTERCOM_PLUGIN_TEST') != '1') { - if (!defined('ABSPATH')) exit; -} - -function add_intercom_snippet() -{ - $options = get_option('intercom'); - $snippet_settings = new SnippetSettings( - array("app_id" => WordPressEscaper::escJS($options['app_id'])), - WordPressEscaper::escJS($options['secret']), - WordPressEscaper::escJS($options['secure_mode']), - wp_get_current_user() - ); - $snippet = new Snippet($snippet_settings); - echo $snippet->html(); -} - -function add_intercom_settings_page() -{ - add_options_page( - 'Intercom Settings', - 'Intercom', - 'manage_options', - 'intercom', - 'render_intercom_options_page' - ); -} - -function render_intercom_options_page() -{ - if (!current_user_can('manage_options')) - { - wp_die('You do not have sufficient permissions to access Intercom settings'); - } - $options = get_option('intercom'); - $settings_page = new IntercomSettingsPage(array("app_id" => $options['app_id'], "secret" => $options['secret'], "secure_mode" => $options['secure_mode'])); - echo $settings_page->htmlUnclosed(); - wp_nonce_field('intercom-update'); - echo $settings_page->htmlClosed(); -} - -function intercom_settings() { - register_setting('intercom', 'intercom'); - if (isset($_GET['state']) && wp_verify_nonce($_GET[ 'state'], 'intercom-oauth') && current_user_can('manage_options') && isset($_GET['app_id']) && isset($_GET['secret']) ) { - $validator = new Validator($_GET, function($x) { return wp_kses(trim($x), array()); }); - $secure_mode = isset($_GET['enable_secure_mode']); - update_option("intercom", array("app_id" => $validator->validAppId(), "secret" => $validator->validSecret(), "secure_mode" => $secure_mode)); - $redirect_to = $secure_mode ? 'options-general.php?page=intercom&enable_secure_mode=1' : 'options-general.php?page=intercom&authenticated=1'; - wp_safe_redirect(admin_url($redirect_to)); - } - if ( current_user_can('manage_options') && isset($_POST[ '_wpnonce']) && wp_verify_nonce($_POST[ '_wpnonce'],'intercom-update') && isset($_POST['enable_secure_mode'])) { - $options = get_option('intercom'); - $options["secure_mode"] = true; - update_option("intercom", $options); - wp_safe_redirect(admin_url('options-general.php?page=intercom&enable_secure_mode=1')); - } - if (current_user_can('manage_options') && isset($_POST['app_id']) && isset($_POST[ '_wpnonce']) && wp_verify_nonce($_POST[ '_wpnonce'],'intercom-update')) { - $options = array(); - $options["app_id"] = WordPressEscaper::escAttr($_POST['app_id']); - update_option("intercom", $options); - wp_safe_redirect(admin_url('options-general.php?page=intercom&saved=1')); - } -} -// Enable Secure Mode for customers who already copy/pasted their secret_key before the Oauth2 release. -function patch_oauth() { - $options = get_option('intercom'); - if ($options["secret"] && !isset($options["secure_mode"])) { - $options["secure_mode"] = true; - update_option("intercom", $options); - } -} - -if (getenv('INTERCOM_PLUGIN_TEST') != '1') { - add_action('wp_footer', 'add_intercom_snippet'); - add_action('admin_menu', 'add_intercom_settings_page'); - add_action('network_admin_menu', 'add_intercom_settings_page'); - add_action('admin_init', 'patch_oauth'); - add_action('admin_init', 'intercom_settings'); -} diff --git a/wordpress/wp-content/plugins/intercom/phpunit.xml.dist b/wordpress/wp-content/plugins/intercom/phpunit.xml.dist deleted file mode 100644 index d289b73377082ad105168077eb6c58526b7293c3..0000000000000000000000000000000000000000 --- a/wordpress/wp-content/plugins/intercom/phpunit.xml.dist +++ /dev/null @@ -1,9 +0,0 @@ - - -
-
-Once authenticated, if you have enabled [Acquire](https://www.intercom.io/live-chat), the Intercom widget will automatically appear on your site.
-
-
-
-NB: This plugin injects a Javascript snippet on your website frontend containing dynamic user data. Some caching solutions will cache entire pages and should not be used with this plugin. Doing so may cause conversations to be delivered to the wrong user.
-
-# Users
-
-If a `$current_user` is present, we use their email as an identifier in the widget.
-We recommend to enable the [secure mode](https://docs.intercom.io/configuring-intercom/enable-secure-mode) in the settings page.
-Otherwise the widget operates in [Acquire mode](https://www.intercom.io/live-chat) (if available). This allows you to talk with anonymous visitors on your WordPress site.
-
-# Contributing
-
-* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
-* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
-* Fork the project.
-* Start a feature/bugfix branch.
-* Commit and push until you are happy with your contribution.
-* Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
diff --git a/wordpress/wp-content/plugins/intercom/readme.txt b/wordpress/wp-content/plugins/intercom/readme.txt
deleted file mode 100644
index 062ba818ce56eb4d95a1a99af22de04754ba8585..0000000000000000000000000000000000000000
--- a/wordpress/wp-content/plugins/intercom/readme.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-=== Plugin Name ===
-Contributors: bobintercom
-License: Apache 2.0
-Tags: intercom, customer, chat
-Requires at least: 4.2.0
-Tested up to: 4.2.4
-
-The official WordPress plugin, built by Intercom. Chat with your website visitors in real-time, capture them as leads, and convert them to customers.
-
-== Description ==
-
-[Intercom](https://www.intercom.io/) is a fundamentally new way for internet businesses to communicate with customers, personally, at scale. It's a customer communication platform with a suite of integrated products for every team – including sales, marketing, product, and support. Our products enable targeted communication with customers on your website, inside your web and mobile apps, and by email.
-
-With this plugin, you can add the Intercom Messenger to your website in just a few clicks and start chatting to customers and visitors to your website right away ([Acquire](https://www.intercom.io/live-chat) subscription required).
-
-Your logged-in customers will be tracked in Intercom as users, and visitors who aren’t customers (or aren’t logged in) will be tracked as leads.
-
-== Installation ==
-
-Installing Intercom on your WordPress site takes just a few minutes.
-
-If you aren’t already an Intercom customer, you can find full instructions on signing up and installing Intercom using the WordPress plugin [here](https://docs.intercom.io/install-on-your-product-or-site/other-ways-to-get-started/install-intercom-on-your-wordpress-site).
-
-If you’re already an Intercom customer, you can find instructions in the in-app [setup guide](https://app.intercom.io/a/apps/_/guide/web_integration/web_integration_users). The first thing you’ll need to do is install and activate the plugin - you must be using WordPress v4.2.0 or higher and have the ability to install plugins in order to use this method.
-
-Note: This plugin injects a Javascript snippet on your website frontend containing dynamic user data. Some caching solutions will cache entire pages and should not be used with this plugin. Doing so may cause conversations to be delivered to the wrong user.
diff --git a/wordpress/wp-content/plugins/intercom/screenshots/settings.png b/wordpress/wp-content/plugins/intercom/screenshots/settings.png
deleted file mode 100644
index fd8dd155dd0ce80c8d136fc5bf4f106aac065448..0000000000000000000000000000000000000000
Binary files a/wordpress/wp-content/plugins/intercom/screenshots/settings.png and /dev/null differ
diff --git a/wordpress/wp-content/plugins/intercom/screenshots/widget.png b/wordpress/wp-content/plugins/intercom/screenshots/widget.png
deleted file mode 100644
index 9f1ad73f8d1dd193647471568c4975dbb684cf14..0000000000000000000000000000000000000000
Binary files a/wordpress/wp-content/plugins/intercom/screenshots/widget.png and /dev/null differ
diff --git a/wordpress/wp-content/plugins/intercom/test/SecureModeCalulatorTest.php b/wordpress/wp-content/plugins/intercom/test/SecureModeCalulatorTest.php
deleted file mode 100644
index 0c65ee276760fdc39128b895d07b577786ed9d6a..0000000000000000000000000000000000000000
--- a/wordpress/wp-content/plugins/intercom/test/SecureModeCalulatorTest.php
+++ /dev/null
@@ -1,31 +0,0 @@
- "test@intercom.io");
- $calculator = new SecureModeCalculator($data, "s3cre7");
- $this->assertEquals(array("user_hash" => "844240a2deab99438ade8e7477aa832e22adb0e1eb1ad7754ff8d4054fb63869"), $calculator->secureModeComponent());
- }
-
- public function testHashUserId()
- {
- $data = array("user_id" => "abcdef", "email" => "test@intercom.io");
- $calculator = new SecureModeCalculator($data, "s3cre7");
- $this->assertEquals(array("user_hash" => "532cd9cd6bfa49528cf2503db0743bb72456bda2cb7424d2894c5b11f6cad6cf"), $calculator->secureModeComponent());
- }
-
- public function testEmpty()
- {
- $data = array();
- $calculator = new SecureModeCalculator($data, "s3cre7");
- $this->assertEquals(array(), $calculator->secureModeComponent());
- }
-
- public function testNoSecureMode()
- {
- $data = array("email" => "test@intercom.io");
- $calculator = new SecureModeCalculator($data, "");
- $this->assertEquals(array(), $calculator->secureModeComponent());
- }
-}
diff --git a/wordpress/wp-content/plugins/intercom/test/SettingsPageTest.php b/wordpress/wp-content/plugins/intercom/test/SettingsPageTest.php
deleted file mode 100644
index b7d82e342af319cdd368a903fdd4799fdee42e49..0000000000000000000000000000000000000000
--- a/wordpress/wp-content/plugins/intercom/test/SettingsPageTest.php
+++ /dev/null
@@ -1,57 +0,0 @@
- NULL, "secret" => NULL));
- $expectedHtml = <<Need an Intercom account? Get started.
-