PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/content/plugins/w3-total-cache/Support_AdminActions.php

https://gitlab.com/karlen/ayo_wp
PHP | 202 lines | 136 code | 32 blank | 34 comment | 18 complexity | 0be47fb4e719a60023cd5cdd569005ae MD5 | raw file
  1. <?php
  2. namespace W3TC;
  3. class Support_AdminActions {
  4. /**
  5. * Send support request action
  6. *
  7. * @return void
  8. */
  9. function w3tc_support_send_details() {
  10. $c = Dispatcher::config();
  11. $post = array();
  12. foreach ( $_GET as $p => $v )
  13. $post[$p] = $v;
  14. $post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
  15. $post['version'] = W3TC_VERSION;
  16. $license_level = 'community';
  17. if ( Util_Environment::is_w3tc_pro( $c ) )
  18. $license_level = 'pro';
  19. elseif ( Util_Environment::is_w3tc_enterprise( $c ) )
  20. $license_level = 'enterprise';
  21. $post['license_level'] = $license_level . ' ' .
  22. $c->get_string( 'plugin.license_key' );
  23. /**
  24. * Add attachments
  25. */
  26. $attachments = array();
  27. $attach_files = array(
  28. /**
  29. * Attach WP config file
  30. */
  31. Util_Environment::wp_config_path(),
  32. /**
  33. * Attach .htaccess files
  34. */
  35. Util_Rule::get_pgcache_rules_core_path(),
  36. Util_Rule::get_pgcache_rules_cache_path(),
  37. Util_Rule::get_browsercache_rules_cache_path(),
  38. Util_Rule::get_browsercache_rules_no404wp_path(),
  39. Util_Rule::get_minify_rules_core_path(),
  40. Util_Rule::get_minify_rules_cache_path()
  41. );
  42. /**
  43. * Attach config files
  44. */
  45. if ( $handle = opendir( W3TC_CONFIG_DIR ) ) {
  46. while ( ( $entry = @readdir( $handle ) ) !== false ) {
  47. if ( $entry == '.' || $entry == '..' || $entry == 'index.html' )
  48. continue;
  49. $attach_file[] = W3TC_CONFIG_DIR . '/' . $entry;
  50. }
  51. closedir( $handle );
  52. }
  53. foreach ( $attach_files as $attach_file ) {
  54. if ( $attach_file && file_exists( $attach_file ) &&
  55. !in_array( $attach_file, $attachments ) ) {
  56. $attachments[] = array(
  57. 'filename' => basename( $attach_file ),
  58. 'content' => file_get_contents( $attach_file )
  59. );
  60. }
  61. }
  62. /**
  63. * Attach server info
  64. */
  65. $server_info = print_r( $this->get_server_info(), true );
  66. $server_info = str_replace( "\n", "\r\n", $server_info );
  67. $attachments[] = array(
  68. 'filename' => 'server_info.txt',
  69. 'content' => $server_info
  70. );
  71. /**
  72. * Attach phpinfo
  73. */
  74. ob_start();
  75. phpinfo();
  76. $php_info = ob_get_contents();
  77. ob_end_clean();
  78. $attachments[] = array(
  79. 'filename' => 'php_info.html',
  80. 'content' => $php_info
  81. );
  82. /**
  83. * Attach self-test
  84. */
  85. ob_start();
  86. $this->self_test();
  87. $self_test = ob_get_contents();
  88. ob_end_clean();
  89. $attachments[] = array(
  90. 'filename' => 'self_test.html',
  91. 'content' => $self_test
  92. );
  93. $post['attachments'] = $attachments;
  94. $response = wp_remote_post( W3TC_SUPPORT_REQUEST_URL, array(
  95. 'body' => $post,
  96. 'timeout' => $c->get_integer( 'timelimit.email_send' )
  97. ) );
  98. if ( !is_wp_error( $response ) )
  99. $result = $response['response']['code'] == 200 && $response['body'] == 'ok';
  100. else {
  101. $result = false;
  102. }
  103. echo $result ? 'ok' : 'error';
  104. }
  105. /**
  106. * Self test action
  107. */
  108. private function self_test() {
  109. include W3TC_INC_DIR . '/lightbox/self_test.php';
  110. }
  111. /**
  112. * Returns server info
  113. *
  114. * @return array
  115. */
  116. private function get_server_info() {
  117. global $wp_version, $wp_db_version, $wpdb;
  118. $wordpress_plugins = get_plugins();
  119. $wordpress_plugins_active = array();
  120. foreach ( $wordpress_plugins as $wordpress_plugin_file => $wordpress_plugin ) {
  121. if ( is_plugin_active( $wordpress_plugin_file ) ) {
  122. $wordpress_plugins_active[$wordpress_plugin_file] = $wordpress_plugin;
  123. }
  124. }
  125. $mysql_version = $wpdb->get_var( 'SELECT VERSION()' );
  126. $mysql_variables_result = (array) $wpdb->get_results( 'SHOW VARIABLES', ARRAY_N );
  127. $mysql_variables = array();
  128. foreach ( $mysql_variables_result as $mysql_variables_row ) {
  129. $mysql_variables[$mysql_variables_row[0]] = $mysql_variables_row[1];
  130. }
  131. $server_info = array(
  132. 'w3tc' => array(
  133. 'version' => W3TC_VERSION,
  134. 'server' => ( !empty( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown' ),
  135. 'dir' => W3TC_DIR,
  136. 'cache_dir' => W3TC_CACHE_DIR,
  137. 'blog_id' => Util_Environment::blog_id(),
  138. 'home_domain_root_url' => Util_Environment::home_domain_root_url(),
  139. 'home_url_maybe_https' => Util_Environment::home_url_maybe_https(),
  140. 'site_path' => Util_Environment::site_path(),
  141. 'document_root' => Util_Environment::document_root(),
  142. 'site_root' => Util_Environment::site_root(),
  143. 'site_url_uri' => Util_Environment::site_url_uri(),
  144. 'home_url_host' => Util_Environment::home_url_host(),
  145. 'home_url_uri' => Util_Environment::home_url_uri(),
  146. 'network_home_url_uri' => Util_Environment::network_home_url_uri(),
  147. 'host_port' => Util_Environment::host_port(),
  148. 'host' => Util_Environment::host(),
  149. 'wp_config_path' => Util_Environment::wp_config_path()
  150. ),
  151. 'wp' => array(
  152. 'version' => $wp_version,
  153. 'db_version' => $wp_db_version,
  154. 'abspath' => ABSPATH,
  155. 'home' => get_option( 'home' ),
  156. 'siteurl' => get_option( 'siteurl' ),
  157. 'email' => get_option( 'admin_email' ),
  158. 'upload_info' => (array) Util_Http::upload_info(),
  159. 'theme' => Util_Theme::get_current_theme(),
  160. 'wp_cache' => ( ( defined( 'WP_CACHE' ) && WP_CACHE ) ? 'true' : 'false' ),
  161. 'plugins' => $wordpress_plugins_active
  162. ),
  163. 'mysql' => array(
  164. 'version' => $mysql_version,
  165. 'variables' => $mysql_variables
  166. )
  167. );
  168. return $server_info;
  169. }
  170. }