PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/blog.old/wp-content/plugins/jetpack/class.jetpack-debugger.php

https://github.com/chopsuei3/oscc
PHP | 366 lines | 314 code | 50 blank | 2 comment | 11 complexity | f088f8fbe10d8a474859ec198a04d218 MD5 | raw file
  1. <?php
  2. class Jetpack_Debugger {
  3. private static function is_jetpack_support_open() {
  4. try {
  5. $response = wp_remote_request( "http://jetpack.me/is-support-open" );
  6. $body = wp_remote_retrieve_body( $response );
  7. $json = json_decode( $body );
  8. return ( ( bool )$json->is_support_open );
  9. }
  10. catch ( Exception $e ) {
  11. return true;
  12. }
  13. }
  14. public static function jetpack_increase_timeout($time) {
  15. $time = 20; //seconds
  16. return $time;
  17. }
  18. public static function jetpack_debug_display_handler() {
  19. if ( ! current_user_can( 'manage_options' ) )
  20. wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
  21. global $current_user;
  22. get_currentuserinfo();
  23. $user_id = get_current_user_id();
  24. $user_tokens = Jetpack_Options::get_option( 'user_tokens' );
  25. if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
  26. $user_token = $user_tokens[$user_id];
  27. } else {
  28. $user_token = '[this user has no token]';
  29. }
  30. unset( $user_tokens );
  31. $debug_info = "\r\n";
  32. foreach ( array(
  33. 'CLIENT_ID' => 'id',
  34. 'BLOG_TOKEN' => 'blog_token',
  35. 'MASTER_USER' => 'master_user',
  36. 'CERT' => 'fallback_no_verify_ssl_certs',
  37. 'TIME_DIFF' => 'time_diff',
  38. 'VERSION' => 'version',
  39. 'OLD_VERSION' => 'old_version',
  40. 'PUBLIC' => 'public',
  41. ) as $label => $option_name ) {
  42. $debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
  43. }
  44. $debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
  45. $debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
  46. $debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
  47. $debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
  48. $debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
  49. $debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
  50. $debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
  51. $debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
  52. $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
  53. $debug_raw_info = '';
  54. $tests = array();
  55. $tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
  56. $tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
  57. $tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
  58. $tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
  59. $identity_crisis_message = '';
  60. if ( $identity_crisis = Jetpack::check_identity_crisis( true ) ) {
  61. foreach( $identity_crisis as $key => $value ) {
  62. $identity_crisis_message .= sprintf( __( 'Your `%1$s` option is set up as `%2$s`, but your WordPress.com connection lists it as `%3$s`!', 'jetpack' ), $key, (string) get_option( $key ), $value ) . "\r\n";
  63. }
  64. $identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
  65. } else {
  66. $identity_crisis = 'PASS';
  67. }
  68. $tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
  69. $tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
  70. $self_xml_rpc_url = home_url( 'xmlrpc.php' );
  71. $args = array();
  72. $testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
  73. add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
  74. $tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
  75. $tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
  76. remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
  77. ?>
  78. <div class="wrap">
  79. <h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
  80. <h3><?php _e( "Testing your site's compatibily with Jetpack...", 'jetpack' ); ?></h3>
  81. <div class="jetpack-debug-test-container">
  82. <?php
  83. ob_start();
  84. foreach ( $tests as $test_name => $test_info ) :
  85. if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
  86. false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) ) ||
  87. '200' != $response_code ) ) {
  88. $debug_info .= $test_name . ": FAIL\r\n";
  89. ?>
  90. <div class="jetpack-test-error">
  91. <p>
  92. <a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
  93. <span class="noticon noticon-collapse"></span>
  94. </a>
  95. </p>
  96. <pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
  97. <?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
  98. </div><?php
  99. } else {
  100. $debug_info .= $test_name . ": PASS\r\n";
  101. }
  102. $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 ) );
  103. ?>
  104. <?php endforeach;
  105. $html = ob_get_clean();
  106. if ( '' == trim( $html ) ) {
  107. echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
  108. }
  109. else {
  110. echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
  111. echo $html;
  112. }
  113. $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
  114. ?>
  115. </div>
  116. <div class="entry-content">
  117. <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
  118. <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
  119. <ol>
  120. <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">Jetpack support pages</a> or <a href="%4$s">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ), 'http://jetpack.me/known-issues/', 'http://jetpack.me/known-issues/', 'http://jetpack.me/support/', 'http://wordpress.org/support/plugin/jetpack' ); ?></li>
  121. <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>
  122. <li><b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b> <?php esc_html_e( "If your problem isn't known or caused by a plugin, try activating Twenty Twelve (the default WordPress theme). If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?></li>
  123. <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' ) ); ?>
  124. <ul>
  125. <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>
  126. <li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
  127. </ul>
  128. </li>
  129. </ol>
  130. <p class="jetpack-show-contact-form"><?php _e( 'If none of these help you find a solution, <a href="#">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' ); ?>
  131. </p>
  132. </div>
  133. <div id="contact-message" style="display:none">
  134. <?php if ( self::is_jetpack_support_open() ): ?>
  135. <form id="contactme" method="post" action="http://jetpack.me/contact-support/">
  136. <input type="hidden" name="action" value="submit">
  137. <input type="hidden" name="jetpack" value="needs-service">
  138. <input type="hidden" name="contact_form" id="contact_form" value="1">
  139. <input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
  140. <input type="hidden" name="subject" id="subject" value="from: <?php echo esc_attr( site_url() ); ?> Jetpack contact form">
  141. <div class="formbox">
  142. <label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
  143. <textarea name="message" cols="40" rows="7" id="did"></textarea>
  144. </div>
  145. <div id="name_div" class="formbox">
  146. <label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
  147. <span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
  148. <input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name , 'jetpack'); ?>" size="40">
  149. </div>
  150. <div id="email_div" class="formbox">
  151. <label class="h" for="your_email"><?php esc_html_e( 'E-mail', 'jetpack' ); ?></label>
  152. <span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
  153. <input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email , 'jetpack'); ?>" size="40">
  154. </div>
  155. <div id="toggle_debug_info" class="formbox">
  156. <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>
  157. </div>
  158. <div id="debug_info_div" class="formbox" style="display:none">
  159. <label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
  160. <textarea name="debug_info" cols="40" rows="7" id="debug_info"><?php echo esc_attr( $debug_info ); ?></textarea>
  161. </div>
  162. <div style="clear: both;"></div>
  163. <div id="blog_div" class="formbox">
  164. <div id="submit_div" class="contact-support">
  165. <input type="submit" name="submit" value="Contact Support">
  166. </div>
  167. </div>
  168. <div style="clear: both;"></div>
  169. </form>
  170. <?php endif; ?>
  171. </div>
  172. </div>
  173. <?php
  174. }
  175. public static function jetpack_debug_admin_head() {
  176. ?>
  177. <style type="text/css">
  178. .jetpack-debug-test-container {
  179. margin-top: 20px;
  180. margin-bottom: 30px;
  181. }
  182. .jetpack-tests-succed {
  183. font-size: large;
  184. color: #8BAB3E;
  185. }
  186. .jetpack-test-details {
  187. margin: 4px 6px;
  188. padding: 10px;
  189. overflow: auto;
  190. display: none;
  191. }
  192. .jetpack-test-error {
  193. margin-bottom: 10px;
  194. background: #FFEBE8;
  195. border: solid 1px #C00;
  196. border-radius: 3px;
  197. }
  198. .jetpack-test-error p {
  199. margin: 0;
  200. padding: 0;
  201. }
  202. .jetpack-test-error a.jetpack-test-heading {
  203. padding: 4px 6px;
  204. display: block;
  205. text-decoration: none;
  206. color: inherit;
  207. }
  208. .jetpack-test-error .noticon {
  209. float: right;
  210. }
  211. form#contactme {
  212. border: 1px solid #dfdfdf;
  213. background: #eaf3fa;
  214. padding: 20px;
  215. margin: 10px;
  216. background-color: #eaf3fa;
  217. border-radius: 5px;
  218. font-size: 15px;
  219. font-family: "Open Sans", "Helvetica Neue", sans-serif;
  220. }
  221. form#contactme label.h {
  222. color: #444;
  223. display: block;
  224. font-weight: bold;
  225. margin: 0 0 7px 10px;
  226. text-shadow: 1px 1px 0 #fff;
  227. }
  228. .formbox {
  229. margin: 0 0 25px 0;
  230. }
  231. .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea {
  232. border: 1px solid #e5e5e5;
  233. border-radius: 11px;
  234. box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
  235. color: #666;
  236. font-size: 14px;
  237. padding: 10px;
  238. width: 97%;
  239. }
  240. .formbox .contact-support input[type="submit"] {
  241. float: right;
  242. margin: 0 !important;
  243. border-radius: 20px !important;
  244. cursor: pointer;
  245. font-size: 13pt !important;
  246. height: auto !important;
  247. margin: 0 0 2em 10px !important;
  248. padding: 8px 16px !important;
  249. background-color: #ddd;
  250. border: 1px solid rgba(0,0,0,0.05);
  251. border-top-color: rgba(255,255,255,0.1);
  252. border-bottom-color: rgba(0,0,0,0.15);
  253. color: #333;
  254. font-weight: 400;
  255. display: inline-block;
  256. text-align: center;
  257. text-decoration: none;
  258. }
  259. .formbox span.errormsg {
  260. margin: 0 0 10px 10px;
  261. color: #d00;
  262. display: none;
  263. }
  264. .formbox.error span.errormsg {
  265. display: block;
  266. }
  267. #contact-message ul {
  268. margin: 0 0 20px 10px;
  269. }
  270. #contact-message li {
  271. margin: 0 0 10px 10px;
  272. list-style: disc;
  273. display: list-item;
  274. }
  275. </style>
  276. <script type="text/javascript">
  277. jQuery( document ).ready( function($) {
  278. $('#debug_info').prepend('jQuery version: ' + jQuery.fn.jquery + "\r\n");
  279. $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
  280. $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
  281. return false;
  282. } );
  283. $( '.jetpack-show-contact-form a' ).on( 'click', function() {
  284. $('#contact-message').slideToggle();
  285. return false;
  286. } );
  287. $( '#toggle_debug_info a' ).on( 'click', function() {
  288. $('#debug_info_div').slideToggle();
  289. return false;
  290. } );
  291. $('form#contactme').on("submit", function(e){
  292. var form = $(this);
  293. var message = form.find('#did');
  294. var name = form.find('#your_name');
  295. var email = form.find('#your_email')
  296. var validation_error = false;
  297. if( !name.val() ) {
  298. name.parents('.formbox').addClass('error');
  299. validation_error = true;
  300. }
  301. if( !email.val() ) {
  302. email.parents('.formbox').addClass('error');
  303. validation_error = true;
  304. }
  305. if ( validation_error ) {
  306. return false;
  307. }
  308. message.val(message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_info').val() );
  309. return true;
  310. });
  311. } );
  312. </script>
  313. <?php
  314. }
  315. }