Completed
Push — add/crowdsignal-shortcode ( 65c42e...1b4a63 )
by Kuba
14:46 queued 06:22
created

class.jetpack-debugger.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class Jetpack_Debugger {
4
5
	private static function is_jetpack_support_open() {
6
		try {
7
			$url = add_query_arg( 'ver', JETPACK__VERSION, 'https://jetpack.com/is-support-open/' );
8
			$response = wp_remote_request( esc_url_raw( $url ) );
9
			if ( is_wp_error( $response ) ) {
10
				return false;
11
			}
12
			$body = wp_remote_retrieve_body( $response );
13
			$json = json_decode( $body );
14
			return ( ( bool ) $json->is_support_open );
15
		}
16
		catch ( Exception $e ) {
17
			return true;
18
		}
19
	}
20
21
	private static function what_jetpack_plan() {
22
		$plan = Jetpack::get_active_plan();
23
		$plan = ! empty( $plan['class'] ) ? $plan['class'] : 'undefined';
24
		return 'JetpackPlan' . $plan;
25
	}
26
27
	static function seconds_to_time( $seconds ) {
28
		$units = array(
29
			"week"   => 7*24*3600,
30
			"day"    =>   24*3600,
31
			"hour"   =>      3600,
32
			"minute" =>        60,
33
			"second" =>         1,
34
		);
35
		// specifically handle zero
36
		if ( $seconds == 0 ) return "0 seconds";
37
		$human_readable = "";
38
		foreach ( $units as $name => $divisor ) {
39
			if ( $quot = intval( $seconds / $divisor) ) {
40
				$human_readable .= "$quot $name";
41
				$human_readable .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
42
				$seconds -= $quot * $divisor;
43
			}
44
		}
45
		return substr( $human_readable, 0, -2 );
46
	}
47
48
	public static function jetpack_increase_timeout() {
49
		return 30; // seconds
50
	}
51
52
	public static function disconnect_and_redirect() {
53
		$can_disconnect = isset( $_GET['disconnect'] ) && $_GET['disconnect'] && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' );
54
		if ( $can_disconnect ) {
55
			if ( Jetpack::is_active() ) {
56
				Jetpack::disconnect();
57
				wp_safe_redirect( Jetpack::admin_url() );
58
				exit;
59
			}
60
		}
61
	}
62
63
	public static function run_self_test() {
64
		$self_xml_rpc_url = site_url( 'xmlrpc.php' );
65
66
		$testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
67
68
		add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
69
70
		$response = wp_remote_get( $testsite_url . $self_xml_rpc_url );
71
72
		remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
73
74
		return $response;
75
76
	}
77
78
	public static function jetpack_debug_display_handler() {
79
		if ( ! current_user_can( 'manage_options' ) )
80
			wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
81
82
		$current_user = wp_get_current_user();
83
84
		$user_id = get_current_user_id();
85
		$user_tokens = Jetpack_Options::get_option( 'user_tokens' );
86
		if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
87
			$user_token = $user_tokens[$user_id];
88
		} else {
89
			$user_token = '[this user has no token]';
90
		}
91
		unset( $user_tokens );
92
93
		$debug_info = "\r\n";
94
		foreach ( array(
95
			'CLIENT_ID'   => 'id',
96
			'BLOG_TOKEN'  => 'blog_token',
97
			'MASTER_USER' => 'master_user',
98
			'CERT'        => 'fallback_no_verify_ssl_certs',
99
			'TIME_DIFF'   => 'time_diff',
100
			'VERSION'     => 'version',
101
			'OLD_VERSION' => 'old_version',
102
			'PUBLIC'      => 'public',
103
		) as $label => $option_name ) {
104
			$debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
105
		}
106
107
		$debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
108
		$debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
109
		$debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
110
		$debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
111
		$debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
112
		$debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
113
		$debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
114
		$debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
115
		$debug_info .= "\r\n" . esc_html( "PLAN: " . self::what_jetpack_plan() );
116
117
		$debug_info .= "\r\n";
118
119
		$debug_info .= "\r\n" .  "-- SYNC Status -- ";
120
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
121
		$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
122
		if ( $sync_module ) {
123
			$sync_statuses = $sync_module->get_status();
124
			$human_readable_sync_status = array();
125
			foreach( $sync_statuses  as $sync_status => $sync_status_value ) {
126
				$human_readable_sync_status[ $sync_status ] =
127
					in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ) )
128
						? date( 'r', $sync_status_value ) : $sync_status_value ;
129
			}
130
			$debug_info .= "\r\n". sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) );
131
		}
132
133
		require_once JETPACK__PLUGIN_DIR. 'sync/class.jetpack-sync-sender.php';
134
135
		$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
136
137
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
138
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
139
140
		$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
141
142
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
143
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
144
145
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
146
		$idc_urls = array(
147
			'home'       => Jetpack_Sync_Functions::home_url(),
148
			'siteurl'    => Jetpack_Sync_Functions::site_url(),
149
			'WP_HOME'    => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '',
150
			'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '',
151
		);
152
		$debug_info .= "\r\n". esc_html( sprintf(  'Sync IDC URLs: %s', json_encode( $idc_urls ) ) );
153
		$debug_info .= "\r\n". esc_html( sprintf(  'Sync error IDC option: %s', json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) );
154
		$debug_info .= "\r\n". esc_html( sprintf(  'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) );
155
156
		$debug_info .= "\r\n";
157
158
		foreach ( array (
159
					  'HTTP_HOST',
160
					  'SERVER_PORT',
161
					  'HTTPS',
162
					  'GD_PHP_HANDLER',
163
					  'HTTP_AKAMAI_ORIGIN_HOP',
164
					  'HTTP_CF_CONNECTING_IP',
165
					  'HTTP_CLIENT_IP',
166
					  'HTTP_FASTLY_CLIENT_IP',
167
					  'HTTP_FORWARDED',
168
					  'HTTP_FORWARDED_FOR',
169
					  'HTTP_INCAP_CLIENT_IP',
170
					  'HTTP_TRUE_CLIENT_IP',
171
					  'HTTP_X_CLIENTIP',
172
					  'HTTP_X_CLUSTER_CLIENT_IP',
173
					  'HTTP_X_FORWARDED',
174
					  'HTTP_X_FORWARDED_FOR',
175
					  'HTTP_X_IP_TRAIL',
176
					  'HTTP_X_REAL_IP',
177
					  'HTTP_X_VARNISH',
178
					  'REMOTE_ADDR'
179
				  ) as $header ) {
180
			if ( isset( $_SERVER[ $header ] ) ) {
181
				$debug_info .= "\r\n" . esc_html( $header . ": " . $_SERVER[ $header ] );
182
			}
183
		}
184
185
		$debug_info .= "\r\n" . esc_html( "PROTECT_TRUSTED_HEADER: " . json_encode( get_site_option( 'trusted_ip_header' ) ) );
186
187
		$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
188
		$debug_raw_info = '';
189
190
191
		$tests = array();
192
193
		$tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
194
		$tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
195
196
		$tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
197
		$tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
198
199
		$identity_crisis_message = '';
200
		if ( $identity_crisis = Jetpack::check_identity_crisis() ) {
201
			$identity_crisis_message .= sprintf(
202
				__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
203
				$identity_crisis['home'],
204
				$identity_crisis['wpcom_home']
205
			);
206
			$identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
207
		} else {
208
			$identity_crisis = 'PASS';
209
		}
210
		$tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
211
		$tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
212
213
		$tests['SELF']['result'] = self::run_self_test();
214
215
		if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ){
216
			$tests['SELF']['fail_message'] = esc_html__( 'Your site did not get a response from our debugging service in the expected timeframe. If you are not experiencing other issues, this could be due to a slow connection between your site and our server.', 'jetpack' );
217
		} else {
218
			$tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
219
		}
220
221
		?>
222
		<div class="wrap">
223
			<h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2>
224
			<?php if ( isset( $can_disconnect ) && $can_disconnect ) : ?>
0 ignored issues
show
The variable $can_disconnect seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
225
				<div id="message" class="updated notice notice-success is-dismissible"><p><?php esc_html_e( 'This site was successfully disconnected.', 'jetpack' ) ?> <a href="<?php echo esc_url( Jetpack::admin_url() ); ?>"><?php esc_html_e( 'Go to connection screen.', 'jetpack' ); ?></a></p>
226
					<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'jetpack' ); ?></span></button></div>
227
			<?php else: ?>
228
				<h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
229
				<div class="jetpack-debug-test-container">
230
					<?php
231
					ob_start();
232
					foreach ( $tests as $test_name => $test_info ) :
233
						if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
234
								false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) )  ||
235
								'200' != $response_code ) ) {
0 ignored issues
show
The variable $response_code does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
236
							$debug_info .= $test_name . ": FAIL\r\n";
237
							?>
238
							<div class="jetpack-test-error">
239
							<p>
240
								<a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
241
									<span class="noticon noticon-collapse"></span>
242
								</a>
243
							</p>
244
						<pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
245
							<?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
246
							</div><?php
247
						} else {
248
							$debug_info .= $test_name . ": PASS\r\n";
249
						}
250
						$debug_raw_info .= "\r\n\r\n" . $test_name . "\r\n" . esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) );
251
						?>
252
					<?php endforeach;
253
					$html = ob_get_clean();
254
255
					if ( '' == trim( $html ) ) {
256
						echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
257
					} else {
258
						echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
259
						echo $html;
260
					}
261
					$debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
262
					?>
263
				</div>
264
			<?php endif; ?>
265
266
			<div class="entry-content">
267
				<h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
268
				<h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
269
				<ol>
270
					<li><b><em><?php esc_html_e( 'A known issue.', 'jetpack' ); ?></em></b>  <?php echo sprintf( __( 'Some themes and plugins have <a href="%1$s" target="_blank">known conflicts</a> with Jetpack – check the <a href="%2$s" target="_blank">list</a>. (You can also browse the <a href="%3$s" target="_blank">Jetpack support pages</a> or <a href="%4$s" target="_blank">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ), 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/', 'https://wordpress.org/support/plugin/jetpack' ); ?></li>
271
					<li><b><em><?php esc_html_e( 'An incompatible plugin.', 'jetpack' ); ?></em></b>  <?php esc_html_e( "Find out by disabling all plugins except Jetpack. If the problem persists, it's not a plugin issue. If the problem is solved, turn your plugins on one by one until the problem pops up again – there's the culprit! Let us know, and we'll try to help.", 'jetpack' ); ?></li>
272
					<li>
273
						<b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
274
						<?php
275
							$default_theme = wp_get_theme( WP_DEFAULT_THEME );
276
277
							if ( $default_theme->exists() ) {
278
								/* translators: %s is the name of a theme */
279
								echo esc_html( sprintf( __( "If your problem isn't known or caused by a plugin, try activating %s (the default WordPress theme).", 'jetpack' ), $default_theme->get( 'Name' ) ) );
280
							} else {
281
								esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
282
							}
283
						?>
284
						<?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
285
					</li>
286
					<li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b>  <?php echo sprintf( __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ), site_url( 'xmlrpc.php' ) ); ?>
287
						<ul>
288
							<li>- <?php esc_html_e( "If it's not by itself, a theme or plugin is displaying extra characters. Try steps 2 and 3.", 'jetpack' ); ?></li>
289
							<li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
290
						</ul>
291
					</li>
292
					<?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?>
293
						<li>
294
							<strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong>
295
							<?php
296
							echo wp_kses(
297
								sprintf(
298
									__( 'Jetpack works by connecting to WordPress.com for a lot of features. Sometimes, when the connection gets messed up, you need to disconnect and reconnect to get things working properly. <a href="%s">Disconnect from WordPress.com</a>', 'jetpack' ),
299
									wp_nonce_url(
300
										Jetpack::admin_url( array( 'page' => 'jetpack-debugger', 'disconnect' => true ) ),
301
										'jp_disconnect',
302
										'nonce'
303
									)
304
								),
305
								array( 'a' => array( 'href'  => array(), 'class' => array() ) )
306
							);
307
							?>
308
						</li>
309
					<?php endif; ?>
310
				</ol>
311
				<?php if ( self::is_jetpack_support_open() ): ?>
312
				<p class="jetpack-show-contact-form"><?php echo sprintf( __( 'If none of these help you find a solution, <a href="%s">click here to contact Jetpack support</a>. Tell us as much as you can about the issue and what steps you\'ve tried to resolve it, and one of our Happiness Engineers will be in touch to help.', 'jetpack' ), Jetpack::admin_url( array( 'page' => 'jetpack-debugger', 'contact' => true ) ) ); ?>
313
				</p>
314
				<?php endif; ?>
315
				<hr />
316
				<?php if ( Jetpack::is_active() ) : ?>
317
					<div id="connected-user-details">
318
						<h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3>
319
						<p><?php printf(
320
							/* translators: %s is an e-mail address */
321
							__( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ),
322
							esc_html( Jetpack::get_master_user_email() )
323
						); ?></p>
324
					</div>
325
				<?php else : ?>
326
					<div id="dev-mode-details">
327
						<p><?php printf(
328
							__( 'Would you like to use Jetpack on your local development site? You can do so thanks to <a href="%s">Jetpack\'s development mode</a>.', 'jetpack' ),
329
							'https://jetpack.com/support/development-mode/'
330
						); ?></p>
331
					</div>
332
				<?php endif; ?>
333
				<?php if (
334
					current_user_can( 'jetpack_manage_modules' )
335
					&& ( Jetpack::is_development_mode() || Jetpack::is_active() )
336
				) {
337
					printf(
338
						'<p><a href="%1$s">%2$s</a></p>',
339
						Jetpack::admin_url( 'page=jetpack_modules' ),
340
						esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
341
					);
342
				} ?>
343
			</div>
344
			<div id="contact-message" <?php if( ! isset( $_GET['contact'] ) ) {?>  style="display:none" <?php } ?>>
345
			<?php if ( self::is_jetpack_support_open() ): ?>
346
				<form id="contactme" method="post" action="https://jetpack.com/contact-support/">
347
					<input type="hidden" name="action" value="submit">
348
					<input type="hidden" name="jetpack" value="needs-service">
349
350
					<input type="hidden" name="contact_form" id="contact_form" value="1">
351
					<input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
352
					<?php
353
						$subject_line = sprintf(
354
							/* translators: %s is the URL of the site */
355
							_x( 'from: %s Jetpack contact form', 'Support request email subject line', 'jetpack' ),
356
							esc_attr( site_url() )
357
						);
358
359
						if ( Jetpack::is_development_version() ) {
360
							$subject_line = 'BETA ' . $subject_line;
361
						}
362
363
						$subject_line_input = printf(
0 ignored issues
show
$subject_line_input is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
364
							'<input type="hidden" name="subject" id="subject" value="%s"">',
365
							$subject_line
366
						);
367
					?>
368
					<div id="category_div" class="formbox">
369
						<label class="h" for="category"><?php esc_html_e( 'What do you need help with?', 'jetpack' ); ?></label>
370
						<ul>
371
						<?php
372
						/**
373
						 * Set up an array of ticket categories.
374
						 * (reasons why a user would contact us.)
375
						 */
376
						$categories = array(
377
							'Connection' => esc_html__( "I'm having trouble connecting Jetpack to WordPress.com.", 'jetpack' ),
378
							'Billing'    => esc_html__( 'I have an issue with a current plan.', 'jetpack' ),
379
							'Presales'   => esc_html__( 'I have questions about buying a plan.', 'jetpack' ),
380
							'Backups'    => esc_html__( 'I need help with backing up my site.', 'jetpack' ),
381
							'Restores'   => esc_html__( 'I have a problem restoring my site.', 'jetpack' ),
382
							'Security'   => esc_html__( 'I have security concerns / my site is hacked.', 'jetpack' ),
383
							'Priority'   => esc_html__( "My site is down / I can't access my site.", 'jetpack' ),
384
							/* translators: Last item in a list of reasons to contact Jetpack support. */
385
							'Other'      => esc_html__( 'Something Else', 'jetpack' ),
386
						);
387
388
						foreach ( $categories as $value => $label ) { ?>
389
							<li><label for="<?php echo esc_attr( $value ); ?>">
390
								<input
391
									id="<?php echo esc_attr( $value ); ?>"
392
									name="category"
393
									type="radio"
394
									value="<?php echo esc_attr( $value ); ?>"
395
									<?php checked( esc_attr( $value ), 'Other' ); ?>
396
								/>
397
								<?php echo esc_html( $label ); ?>
398
							</label></li>
399
						<?php } ?>
400
						</ul>
401
					</div>
402
403
					<div class="formbox">
404
						<label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
405
						<textarea name="message" cols="40" rows="7" id="did"></textarea>
406
					</div>
407
408
					<div id="name_div" class="formbox">
409
						<label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
410
			  			<span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
411
						<input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name, 'jetpack'); ?>" size="40">
412
					</div>
413
414
					<div id="email_div" class="formbox">
415
						<label class="h" for="your_email"><?php esc_html_e( 'Email', 'jetpack' ); ?></label>
416
			  			<span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
417
						<input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email, 'jetpack'); ?>" size="40">
418
					</div>
419
420
					<div id="toggle_debug_form_info" class="formbox">
421
						<p><?php _e( 'The test results and some other useful debug information will be sent to the support team. Please feel free to <a href="#">review/modify</a> this information.', 'jetpack' ); ?></p>
422
					</div>
423
424
					<div id="debug_info_form_div" class="formbox" style="display:none">
425
						<label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
426
			  			<textarea name="debug_info" cols="40" rows="7" id="debug_form_info"><?php echo esc_attr( $debug_info ); ?></textarea>
427
					</div>
428
429
					<div style="clear: both;"></div>
430
431
					<div id="blog_div" class="formbox">
432
						<div id="submit_div" class="contact-support">
433
						<input type="submit" name="submit" value="<?php esc_html_e( 'Submit &#187;', 'jetpack' ); ?>">
434
						</div>
435
					</div>
436
					<div style="clear: both;"></div>
437
				</form>
438
			<?php endif; ?>
439
		</div> <!-- contact-message, hidden by default. -->
440
		<hr />
441
		<div id="toggle_debug_info"><a href="#"><?php _e( 'View Advanced Debug Results', 'jetpack' ); ?></a></div>
442
			<div id="debug_info_div" style="display:none">
443
			<h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
444
			<div id="debug_info"><pre><?php echo esc_html( $debug_info ) ; ?></pre></div>
445
		</div>
446
		</div>
447
	<?php
448
	}
449
450
	public static function jetpack_debug_admin_head() {
451
452
		Jetpack_Admin_Page::load_wrapper_styles();
453
		?>
454
		<style type="text/css">
455
456
			.jetpack-debug-test-container {
457
				margin-top: 20px;
458
				margin-bottom: 30px;
459
			}
460
461
			.jetpack-tests-succed {
462
				font-size: large;
463
				color: #8BAB3E;
464
			}
465
466
			.jetpack-test-details {
467
				margin: 4px 6px;
468
				padding: 10px;
469
				overflow: auto;
470
				display: none;
471
			}
472
473
			.jetpack-test-error {
474
				margin-bottom: 10px;
475
				background: #FFEBE8;
476
				border: solid 1px #C00;
477
				border-radius: 3px;
478
			}
479
480
			.jetpack-test-error p {
481
				margin: 0;
482
				padding: 0;
483
			}
484
485
			.jetpack-test-error a.jetpack-test-heading {
486
				padding: 4px 6px;
487
				display: block;
488
				text-decoration: none;
489
				color: inherit;
490
			}
491
492
			.jetpack-test-error .noticon {
493
				float: right;
494
			}
495
496
			form#contactme {
497
				border: 1px solid #dfdfdf;
498
				background: #eaf3fa;
499
				padding: 20px;
500
				margin: 10px;
501
				background-color: #eaf3fa;
502
				border-radius: 5px;
503
				font-size: 15px;
504
			}
505
506
			form#contactme label.h {
507
				color: #444;
508
				display: block;
509
				font-weight: bold;
510
				margin: 0 0 7px 10px;
511
				text-shadow: 1px 1px 0 #fff;
512
			}
513
514
			.formbox {
515
				margin: 0 0 25px 0;
516
			}
517
518
			.formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
519
				border: 1px solid #e5e5e5;
520
				border-radius: 11px;
521
				box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
522
				color: #666;
523
				font-size: 14px;
524
				padding: 10px;
525
				width: 97%;
526
			}
527
			#debug_info_div {
528
				border-radius: 0;
529
				margin-top: 16px;
530
				background: #FFF;
531
				padding: 16px;
532
			}
533
			.formbox .contact-support input[type="submit"] {
534
				float: right;
535
				margin: 0 !important;
536
				border-radius: 20px !important;
537
				cursor: pointer;
538
				font-size: 13pt !important;
539
				height: auto !important;
540
				margin: 0 0 2em 10px !important;
541
				padding: 8px 16px !important;
542
				background-color: #ddd;
543
				border: 1px solid rgba(0,0,0,0.05);
544
				border-top-color: rgba(255,255,255,0.1);
545
				border-bottom-color: rgba(0,0,0,0.15);
546
				color: #333;
547
				font-weight: 400;
548
				display: inline-block;
549
				text-align: center;
550
				text-decoration: none;
551
			}
552
553
			.formbox span.errormsg {
554
				margin: 0 0 10px 10px;
555
				color: #d00;
556
				display: none;
557
			}
558
559
			.formbox.error span.errormsg {
560
				display: block;
561
			}
562
563
			#contact-message ul {
564
				margin: 0 0 20px 10px;
565
			}
566
567
			#contact-message li {
568
				margin: 0 0 10px 10px;
569
				list-style: disc;
570
				display: list-item;
571
			}
572
573
			#debug_info_div, #toggle_debug_info, #debug_info_div p {
574
				font-size: 12px;
575
			}
576
577
			#category_div ul li {
578
				list-style-type: none;
579
			}
580
581
		</style>
582
		<script type="text/javascript">
583
		jQuery( document ).ready( function($) {
584
585
			$( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
586
			$( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
587
588
			$( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
589
				$( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
590
				return false;
591
			} );
592
593
			$( '.jetpack-show-contact-form a' ).on( 'click', function() {
594
				$( '#contact-message' ).slideToggle();
595
				return false;
596
			} );
597
598
			$( '#toggle_debug_info a' ).on( 'click', function() {
599
				$( '#debug_info_div' ).slideToggle();
600
				return false;
601
			} );
602
603
			$( '#toggle_debug_form_info a' ).on( 'click', function() {
604
				$( '#debug_info_form_div' ).slideToggle();
605
				return false;
606
			} );
607
608
			$( 'form#contactme' ).on( "submit", function(e){
609
				var form = $( this );
610
				var message = form.find( '#did' );
611
				var name = form.find( '#your_name' );
612
				var email = form.find( '#your_email' )
613
				var validation_error = false;
614
				if( !name.val() ) {
615
					name.parents( '.formbox' ).addClass( 'error' );
616
					validation_error = true;
617
				}
618
				if( !email.val() ) {
619
					email.parents( '.formbox' ).addClass( 'error' );
620
					validation_error = true;
621
				}
622
				if ( validation_error ) {
623
					return false;
624
				}
625
				message.val( message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_form_info').val()  );
626
				return true;
627
	    	});
628
629
		} );
630
		</script>
631
		<?php
632
	}
633
}
634