Completed
Push — test-gdpr-linter ( db411a...bd8f31 )
by
unknown
51:47 queued 42:38
created

class.jetpack-debugger.php (4 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
// Tracking tracking tracking, let's trigger the linter elsewhere 4!
4
5
class Jetpack_Debugger {
6
7
	private static function is_jetpack_support_open() {
8
		try {
9
			$url = add_query_arg( 'ver', JETPACK__VERSION, 'https://jetpack.com/is-support-open/' );
10
			$response = wp_remote_request( esc_url_raw( $url ) );
11
			if ( is_wp_error( $response ) ) {
12
				return false;
13
			}
14
			$body = wp_remote_retrieve_body( $response );
15
			$json = json_decode( $body );
16
			return ( ( bool ) $json->is_support_open );
17
		}
18
		catch ( Exception $e ) {
19
			return true;
20
		}
21
	}
22
23
	private static function what_jetpack_plan() {
24
		$plan = Jetpack::get_active_plan();
25
		$plan = ! empty( $plan['class'] ) ? $plan['class'] : 'undefined';
26
		return 'JetpackPlan' . $plan;
27
	}
28
29
	static function seconds_to_time( $seconds ) {
30
		$units = array(
31
			"week"   => 7*24*3600,
32
			"day"    =>   24*3600,
33
			"hour"   =>      3600,
34
			"minute" =>        60,
35
			"second" =>         1,
36
		);
37
		// specifically handle zero
38
		if ( $seconds == 0 ) return "0 seconds";
39
		$human_readable = "";
40
		foreach ( $units as $name => $divisor ) {
41
			if ( $quot = intval( $seconds / $divisor) ) {
42
				$human_readable .= "$quot $name";
43
				$human_readable .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
44
				$seconds -= $quot * $divisor;
45
			}
46
		}
47
		return substr( $human_readable, 0, -2 );
48
	}
49
50
	public static function jetpack_increase_timeout() {
51
		return 30; // seconds
52
	}
53
54
	public static function disconnect_and_redirect() {
55
		$can_disconnect = isset( $_GET['disconnect'] ) && $_GET['disconnect'] && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' );
56
		if ( $can_disconnect ) {
57
			if ( Jetpack::is_active() ) {
58
				Jetpack::disconnect();
59
				wp_safe_redirect( Jetpack::admin_url() );
60
				exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method disconnect_and_redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
61
			}
62
		}
63
	}
64
65
	public static function jetpack_debug_display_handler() {
66
		if ( ! current_user_can( 'manage_options' ) )
67
			wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
68
69
		$current_user = wp_get_current_user();
70
71
		$user_id = get_current_user_id();
72
		$user_tokens = Jetpack_Options::get_option( 'user_tokens' );
73
		if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
74
			$user_token = $user_tokens[$user_id];
75
		} else {
76
			$user_token = '[this user has no token]';
77
		}
78
		unset( $user_tokens );
79
80
		$debug_info = "\r\n";
81
		foreach ( array(
82
			'CLIENT_ID'   => 'id',
83
			'BLOG_TOKEN'  => 'blog_token',
84
			'MASTER_USER' => 'master_user',
85
			'CERT'        => 'fallback_no_verify_ssl_certs',
86
			'TIME_DIFF'   => 'time_diff',
87
			'VERSION'     => 'version',
88
			'OLD_VERSION' => 'old_version',
89
			'PUBLIC'      => 'public',
90
		) as $label => $option_name ) {
91
			$debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
92
		}
93
94
		$debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
95
		$debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
96
		$debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
97
		$debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
98
		$debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
99
		$debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
100
		$debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
101
		$debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
102
		$debug_info .= "\r\n" . esc_html( "PLAN: " . self::what_jetpack_plan() );
103
104
		$debug_info .= "\r\n";
105
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
106
		$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
107
		$sync_statuses = $sync_module->get_status();
108
		$human_readable_sync_status = array();
109
		foreach( $sync_statuses  as $sync_status => $sync_status_value ) {
110
			$human_readable_sync_status[ $sync_status ] =
111
				in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ) )
112
				? date( 'r', $sync_status_value ) : $sync_status_value ;
113
		}
114
115
		$debug_info .= "\r\n". sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) );
116
117
		require_once JETPACK__PLUGIN_DIR. 'sync/class.jetpack-sync-sender.php';
118
119
		$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
120
121
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
122
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
123
124
		$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
125
126
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
127
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
128
129
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
130
		$idc_urls = array(
131
			'home'       => Jetpack_Sync_Functions::home_url(),
132
			'siteurl'    => Jetpack_Sync_Functions::site_url(),
133
			'WP_HOME'    => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '',
134
			'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '',
135
		);
136
		$debug_info .= "\r\n". esc_html( sprintf(  'Sync IDC URLs: %s', json_encode( $idc_urls ) ) );
137
		$debug_info .= "\r\n". esc_html( sprintf(  'Sync error IDC option: %s', json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) );
138
		$debug_info .= "\r\n". esc_html( sprintf(  'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) );
139
140
		$debug_info .= "\r\n";
141
142
		foreach ( array (
143
					  'HTTP_HOST',
144
					  'SERVER_PORT',
145
					  'HTTPS',
146
					  'GD_PHP_HANDLER',
147
					  'HTTP_AKAMAI_ORIGIN_HOP',
148
					  'HTTP_CF_CONNECTING_IP',
149
					  'HTTP_CLIENT_IP',
150
					  'HTTP_FASTLY_CLIENT_IP',
151
					  'HTTP_FORWARDED',
152
					  'HTTP_FORWARDED_FOR',
153
					  'HTTP_INCAP_CLIENT_IP',
154
					  'HTTP_TRUE_CLIENT_IP',
155
					  'HTTP_X_CLIENTIP',
156
					  'HTTP_X_CLUSTER_CLIENT_IP',
157
					  'HTTP_X_FORWARDED',
158
					  'HTTP_X_FORWARDED_FOR',
159
					  'HTTP_X_IP_TRAIL',
160
					  'HTTP_X_REAL_IP',
161
					  'HTTP_X_VARNISH',
162
					  'REMOTE_ADDR'
163
				  ) as $header ) {
164
			if ( isset( $_SERVER[ $header ] ) ) {
165
				$debug_info .= "\r\n" . esc_html( $header . ": " . $_SERVER[ $header ] );
166
			}
167
		}
168
169
		$debug_info .= "\r\n" . esc_html( "PROTECT_TRUSTED_HEADER: " . json_encode( get_site_option( 'trusted_ip_header' ) ) );
170
171
		$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
172
		$debug_raw_info = '';
173
174
175
		$tests = array();
176
177
		$tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
178
		$tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
179
180
		$tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
181
		$tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
182
183
		$identity_crisis_message = '';
184
		if ( $identity_crisis = Jetpack::check_identity_crisis() ) {
185
			$identity_crisis_message .= sprintf(
186
				__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
187
				$identity_crisis['home'],
188
				$identity_crisis['wpcom_home']
189
			);
190
			$identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
191
		} else {
192
			$identity_crisis = 'PASS';
193
		}
194
		$tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
195
		$tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
196
197
		$self_xml_rpc_url = site_url( 'xmlrpc.php' );
198
199
		$testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
200
201
		add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
202
203
		$tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
204
		if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ){
205
			$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' );
206
		} else {
207
			$tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
208
		}
209
210
		remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
211
212
		?>
213
		<div class="wrap">
214
			<h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
215
			<?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...
216
				<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>
217
					<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'jetpack' ); ?></span></button></div>
218
			<?php else: ?>
219
				<h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
220
				<div class="jetpack-debug-test-container">
221
					<?php
222
					ob_start();
223
					foreach ( $tests as $test_name => $test_info ) :
224
						if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
225
								false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) )  ||
226
								'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...
227
							$debug_info .= $test_name . ": FAIL\r\n";
228
							?>
229
							<div class="jetpack-test-error">
230
							<p>
231
								<a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
232
									<span class="noticon noticon-collapse"></span>
233
								</a>
234
							</p>
235
						<pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
236
							<?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
237
							</div><?php
238
						} else {
239
							$debug_info .= $test_name . ": PASS\r\n";
240
						}
241
						$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 ) );
242
						?>
243
					<?php endforeach;
244
					$html = ob_get_clean();
245
246
					if ( '' == trim( $html ) ) {
247
						echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
248
					} else {
249
						echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
250
						echo $html;
251
					}
252
					$debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
253
					?>
254
				</div>
255
			<?php endif; ?>
256
257
			<div class="entry-content">
258
				<h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
259
				<h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
260
				<ol>
261
					<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>
262
					<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>
263
					<li>
264
						<b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
265
						<?php
266
							$default_theme = wp_get_theme( WP_DEFAULT_THEME );
267
268
							if ( $default_theme->exists() ) {
269
								/* translators: %s is the name of a theme */
270
								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' ) ) );
271
							} else {
272
								esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
273
							}
274
						?>
275
						<?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
276
					</li>
277
					<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' ) ); ?>
278
						<ul>
279
							<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>
280
							<li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
281
						</ul>
282
					</li>
283
					<?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?>
284
						<li>
285
							<strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong>
286
							<?php
287
							echo wp_kses(
288
								sprintf(
289
									__( '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' ),
290
									wp_nonce_url(
291
										Jetpack::admin_url( array( 'page' => 'jetpack-debugger', 'disconnect' => true ) ),
292
										'jp_disconnect',
293
										'nonce'
294
									)
295
								),
296
								array( 'a' => array( 'href'  => array(), 'class' => array() ) )
297
							);
298
							?>
299
						</li>
300
					<?php endif; ?>
301
				</ol>
302
				<?php if ( self::is_jetpack_support_open() ): ?>
303
				<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 ) ) ); ?>
304
				</p>
305
				<?php endif; ?>
306
				<hr />
307
				<?php if ( Jetpack::is_active() ) : ?>
308
					<div id="connected-user-details">
309
						<h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3>
310
						<p><?php printf(
311
							/* translators: %s is an e-mail address */
312
							__( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ),
313
							esc_html( Jetpack::get_master_user_email() )
314
						); ?></p>
315
					</div>
316
				<?php else : ?>
317
					<div id="dev-mode-details">
318
						<p><?php printf(
319
							__( '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' ),
320
							'https://jetpack.com/support/development-mode/'
321
						); ?></p>
322
					</div>
323
				<?php endif; ?>
324
				<?php if (
325
					current_user_can( 'jetpack_manage_modules' )
326
					&& ( Jetpack::is_development_mode() || Jetpack::is_active() )
327
				) {
328
					printf(
329
						'<p><a href="%1$s">%2$s</a></p>',
330
						Jetpack::admin_url( 'page=jetpack_modules' ),
331
						esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
332
					);
333
				} ?>
334
			</div>
335
			<div id="contact-message" <?php if( ! isset( $_GET['contact'] ) ) {?>  style="display:none" <?php } ?>>
336
			<?php if ( self::is_jetpack_support_open() ): ?>
337
				<form id="contactme" method="post" action="https://jetpack.com/contact-support/">
338
					<input type="hidden" name="action" value="submit">
339
					<input type="hidden" name="jetpack" value="needs-service">
340
341
					<input type="hidden" name="contact_form" id="contact_form" value="1">
342
					<input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
343
					<?php
344
						$subject_line = sprintf(
345
							/* translators: %s is the URL of the site */
346
							_x( 'from: %s Jetpack contact form', 'Support request email subject line', 'jetpack' ),
347
							esc_attr( site_url() )
348
						);
349
350
						if ( Jetpack::is_development_version() ) {
351
							$subject_line = 'BETA ' . $subject_line;
352
						}
353
354
						$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...
355
							'<input type="hidden" name="subject" id="subject" value="%s"">',
356
							$subject_line
357
						);
358
					?>
359
					<div id="category_div" class="formbox">
360
						<label class="h" for="category"><?php esc_html_e( 'What do you need help with?', 'jetpack' ); ?></label>
361
						<ul>
362
						<?php
363
						/**
364
						 * Set up an array of ticket categories.
365
						 * (reasons why a user would contact us.)
366
						 */
367
						$categories = array(
368
							'Connection' => esc_html__( "I'm having trouble connecting Jetpack to WordPress.com.", 'jetpack' ),
369
							'Billing'    => esc_html__( 'I have an issue with a current plan.', 'jetpack' ),
370
							'Presales'   => esc_html__( 'I have questions about buying a plan.', 'jetpack' ),
371
							'Backups'    => esc_html__( 'I need help with backing up my site.', 'jetpack' ),
372
							'Restores'   => esc_html__( 'I have a problem restoring my site.', 'jetpack' ),
373
							'Security'   => esc_html__( 'I have security concerns / my site is hacked.', 'jetpack' ),
374
							'Priority'   => esc_html__( "My site is down / I can't access my site.", 'jetpack' ),
375
							/* translators: Last item in a list of reasons to contact Jetpack support. */
376
							'Other'      => esc_html__( 'Something Else', 'jetpack' ),
377
						);
378
379
						foreach ( $categories as $value => $label ) { ?>
380
							<li><label for="<?php echo esc_attr( $value ); ?>">
381
								<input
382
									id="<?php echo esc_attr( $value ); ?>"
383
									name="category"
384
									type="radio"
385
									value="<?php echo esc_attr( $value ); ?>"
386
									<?php checked( esc_attr( $value ), 'Other' ); ?>
387
								/>
388
								<?php echo esc_html( $label ); ?>
389
							</label></li>
390
						<?php } ?>
391
						</ul>
392
					</div>
393
394
					<div class="formbox">
395
						<label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
396
						<textarea name="message" cols="40" rows="7" id="did"></textarea>
397
					</div>
398
399
					<div id="name_div" class="formbox">
400
						<label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
401
			  			<span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
402
						<input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name, 'jetpack'); ?>" size="40">
403
					</div>
404
405
					<div id="email_div" class="formbox">
406
						<label class="h" for="your_email"><?php esc_html_e( 'Email', 'jetpack' ); ?></label>
407
			  			<span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
408
						<input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email, 'jetpack'); ?>" size="40">
409
					</div>
410
411
					<div id="toggle_debug_form_info" class="formbox">
412
						<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>
413
					</div>
414
415
					<div id="debug_info_form_div" class="formbox" style="display:none">
416
						<label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
417
			  			<textarea name="debug_info" cols="40" rows="7" id="debug_form_info"><?php echo esc_attr( $debug_info ); ?></textarea>
418
					</div>
419
420
					<div style="clear: both;"></div>
421
422
					<div id="blog_div" class="formbox">
423
						<div id="submit_div" class="contact-support">
424
						<input type="submit" name="submit" value="<?php esc_html_e( 'Submit &#187;', 'jetpack' ); ?>">
425
						</div>
426
					</div>
427
					<div style="clear: both;"></div>
428
				</form>
429
			<?php endif; ?>
430
		</div> <!-- contact-message, hidden by default. -->
431
		<hr />
432
		<div id="toggle_debug_info"><a href="#"><?php _e( 'View Advanced Debug Results', 'jetpack' ); ?></a></div>
433
			<div id="debug_info_div" style="display:none">
434
			<h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
435
			<div id="debug_info"><pre><?php echo esc_html( $debug_info ) ; ?></pre></div>
436
		</div>
437
		</div>
438
	<?php
439
	}
440
441
	public static function jetpack_debug_admin_head() {
442
		?>
443
		<style type="text/css">
444
445
			.jetpack-debug-test-container {
446
				margin-top: 20px;
447
				margin-bottom: 30px;
448
			}
449
450
			.jetpack-tests-succed {
451
				font-size: large;
452
				color: #8BAB3E;
453
			}
454
455
			.jetpack-test-details {
456
				margin: 4px 6px;
457
				padding: 10px;
458
				overflow: auto;
459
				display: none;
460
			}
461
462
			.jetpack-test-error {
463
				margin-bottom: 10px;
464
				background: #FFEBE8;
465
				border: solid 1px #C00;
466
				border-radius: 3px;
467
			}
468
469
			.jetpack-test-error p {
470
				margin: 0;
471
				padding: 0;
472
			}
473
474
			.jetpack-test-error a.jetpack-test-heading {
475
				padding: 4px 6px;
476
				display: block;
477
				text-decoration: none;
478
				color: inherit;
479
			}
480
481
			.jetpack-test-error .noticon {
482
				float: right;
483
			}
484
485
			form#contactme {
486
				border: 1px solid #dfdfdf;
487
				background: #eaf3fa;
488
				padding: 20px;
489
				margin: 10px;
490
				background-color: #eaf3fa;
491
				border-radius: 5px;
492
				font-size: 15px;
493
			}
494
495
			form#contactme label.h {
496
				color: #444;
497
				display: block;
498
				font-weight: bold;
499
				margin: 0 0 7px 10px;
500
				text-shadow: 1px 1px 0 #fff;
501
			}
502
503
			.formbox {
504
				margin: 0 0 25px 0;
505
			}
506
507
			.formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
508
				border: 1px solid #e5e5e5;
509
				border-radius: 11px;
510
				box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
511
				color: #666;
512
				font-size: 14px;
513
				padding: 10px;
514
				width: 97%;
515
			}
516
			#debug_info_div {
517
				border-radius: 0;
518
				margin-top: 16px;
519
				background: #FFF;
520
				padding: 16px;
521
			}
522
			.formbox .contact-support input[type="submit"] {
523
				float: right;
524
				margin: 0 !important;
525
				border-radius: 20px !important;
526
				cursor: pointer;
527
				font-size: 13pt !important;
528
				height: auto !important;
529
				margin: 0 0 2em 10px !important;
530
				padding: 8px 16px !important;
531
				background-color: #ddd;
532
				border: 1px solid rgba(0,0,0,0.05);
533
				border-top-color: rgba(255,255,255,0.1);
534
				border-bottom-color: rgba(0,0,0,0.15);
535
				color: #333;
536
				font-weight: 400;
537
				display: inline-block;
538
				text-align: center;
539
				text-decoration: none;
540
			}
541
542
			.formbox span.errormsg {
543
				margin: 0 0 10px 10px;
544
				color: #d00;
545
				display: none;
546
			}
547
548
			.formbox.error span.errormsg {
549
				display: block;
550
			}
551
552
			#contact-message ul {
553
				margin: 0 0 20px 10px;
554
			}
555
556
			#contact-message li {
557
				margin: 0 0 10px 10px;
558
				list-style: disc;
559
				display: list-item;
560
			}
561
562
			#debug_info_div, #toggle_debug_info, #debug_info_div p {
563
				font-size: 12px;
564
			}
565
566
			#category_div ul li {
567
				list-style-type: none;
568
			}
569
570
		</style>
571
		<script type="text/javascript">
572
		jQuery( document ).ready( function($) {
573
574
			$( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
575
			$( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
576
577
			$( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
578
				$( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
579
				return false;
580
			} );
581
582
			$( '.jetpack-show-contact-form a' ).on( 'click', function() {
583
				$( '#contact-message' ).slideToggle();
584
				return false;
585
			} );
586
587
			$( '#toggle_debug_info a' ).on( 'click', function() {
588
				$( '#debug_info_div' ).slideToggle();
589
				return false;
590
			} );
591
592
			$( '#toggle_debug_form_info a' ).on( 'click', function() {
593
				$( '#debug_info_form_div' ).slideToggle();
594
				return false;
595
			} );
596
597
			$( 'form#contactme' ).on( "submit", function(e){
598
				var form = $( this );
599
				var message = form.find( '#did' );
600
				var name = form.find( '#your_name' );
601
				var email = form.find( '#your_email' )
602
				var validation_error = false;
603
				if( !name.val() ) {
604
					name.parents( '.formbox' ).addClass( 'error' );
605
					validation_error = true;
606
				}
607
				if( !email.val() ) {
608
					email.parents( '.formbox' ).addClass( 'error' );
609
					validation_error = true;
610
				}
611
				if ( validation_error ) {
612
					return false;
613
				}
614
				message.val( message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_form_info').val()  );
615
				return true;
616
	    	});
617
618
		} );
619
		</script>
620
		<?php
621
	}
622
}
623