nitropack
Last commit date
nitropack-sdk
5 years ago
view
5 years ago
advanced-cache.php
5 years ago
constants.php
5 years ago
diagnostics.php
5 years ago
functions.php
5 years ago
integrations.php
5 years ago
main.php
5 years ago
readme.txt
5 years ago
uninstall.php
6 years ago
wp-cli.php
5 years ago
diagnostics.php
154 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or die( 'Someone made a boo boo!' ); |
| 4 | |
| 5 | if (!function_exists('get_plugins')) { |
| 6 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 7 | } |
| 8 | |
| 9 | $np_diag_functions = array( |
| 10 | 'general-info-status' => 'npdiag_get_general_info', |
| 11 | 'active-plugins-status' => 'npdiag_get_active_plugins', |
| 12 | 'conflicting-plugins-status' => 'npdiag_get_conflicting_plugins', |
| 13 | 'user-config-status' => 'npdiag_get_user_config', |
| 14 | 'dir-info-status' => 'npdiag_get_dir_info', |
| 15 | 'getexternalcache' => 'npdiag_get_third_party_cache' |
| 16 | |
| 17 | ); |
| 18 | |
| 19 | function npdiag_helper_trailingslashit($string) { |
| 20 | return rtrim( $string, '/\\' ) . '/'; |
| 21 | } |
| 22 | |
| 23 | function npdiag_get_general_info() { |
| 24 | global $wp_version; |
| 25 | if (null !== $nitro = get_nitropack_sdk()) { |
| 26 | $probe_result = "OK"; |
| 27 | try { |
| 28 | $nitro->fetchConfig(); |
| 29 | } catch (\Exception $e) { |
| 30 | $probe_result = 'Error: ' . $e->getMessage(); |
| 31 | } |
| 32 | } else { |
| 33 | $probe_result = 'Error: Cannot get SDK instance'; |
| 34 | } |
| 35 | |
| 36 | $info = array( |
| 37 | 'Nitro_WP_version' => !empty($wp_version) ? $wp_version : get_bloginfo('version'), |
| 38 | 'Nitro_Version' => defined('NITROPACK_VERSION') ? NITROPACK_VERSION : 'Undefined', |
| 39 | 'Nitro_API_Connection' => $probe_result, |
| 40 | 'Nitro_SDK_Version' => defined('NitroPack\SDK\Nitropack::VERSION') ? NitroPack\SDK\Nitropack::VERSION : 'Undefined', |
| 41 | 'Advanced_Cache_Version' => defined('NITROPACK_ADVANCED_CACHE_VERSION') ? NITROPACK_ADVANCED_CACHE_VERSION : 'Undefined', |
| 42 | 'Nitro_Absolute_Path' => defined('ABSPATH') ? ABSPATH : 'Undefined', |
| 43 | 'Nitro_Plugin_Direcotry' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__), |
| 44 | 'Nitro_Data_Directory' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : 'Undefined', |
| 45 | 'Nitro_Config_File' => defined('NITROPACK_CONFIG_FILE') ? NITROPACK_CONFIG_FILE : 'Undefined' |
| 46 | ); |
| 47 | |
| 48 | if (defined("NITROPACK_VERSION") && defined("NITROPACK_ADVANCED_CACHE_VERSION") && NITROPACK_VERSION == NITROPACK_ADVANCED_CACHE_VERSION && nitropack_is_dropin_cache_allowed()) { |
| 49 | $info['Nitro_Cache_Method'] = 'drop-in'; |
| 50 | } elseif ( defined('EZOIC_INTEGRATION_VERSION') ) { |
| 51 | $info['Nitro_Cache_Method'] = 'plugin-ezoic'; |
| 52 | } else { |
| 53 | $info['Nitro_Cache_Method'] = 'plugin'; |
| 54 | } |
| 55 | |
| 56 | return $info; |
| 57 | } |
| 58 | |
| 59 | function npdiag_get_active_plugins() { |
| 60 | if (is_admin()) { |
| 61 | $info = array(); |
| 62 | $raw_installed_list = get_plugins(); |
| 63 | $raw_active_list = get_option('active_plugins'); |
| 64 | foreach ($raw_installed_list as $pkey => $pval) { |
| 65 | if ( in_array($pkey, $raw_active_list) ) { |
| 66 | $info[$pval['Name']] = $pval['Version']; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return $info; |
| 72 | } |
| 73 | |
| 74 | function npdiag_get_user_config() { |
| 75 | if (defined('NITROPACK_CONFIG_FILE')) { |
| 76 | if (file_exists(NITROPACK_CONFIG_FILE)) { |
| 77 | $info = json_decode(file_get_contents(NITROPACK_CONFIG_FILE)); |
| 78 | if (!$info) { |
| 79 | $info = 'Config found, but unable to get contents.'; |
| 80 | } |
| 81 | } else { |
| 82 | $info = 'Config file not found.'; |
| 83 | } |
| 84 | } else { |
| 85 | $info = 'Config file constant is not defined.'; |
| 86 | } |
| 87 | |
| 88 | return $info; |
| 89 | } |
| 90 | |
| 91 | function npdiag_get_dir_info() { |
| 92 | $siteConfig = nitropack_get_site_config(); |
| 93 | $siteID = !empty($siteConfig['siteId']) ? $siteConfig['siteId'] : get_option('nitropack-siteId'); |
| 94 | // DoI = Directories of Interest |
| 95 | $DoI = array( |
| 96 | 'WP_Content_Dir_Writable' => defined('WP_CONTENT_DIRR') ? WP_CONTENT_DIR : (defined('ABSPATH') ? ABSPATH . '/wp-content' : 'Undefined'), |
| 97 | 'Nitro_Data_Dir_Writable' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack', |
| 98 | 'Nitro_siteID_Dir_Writable' => npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack/' . $siteID, |
| 99 | 'Nitro_Plugin_Dir_Writable' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__) |
| 100 | ); |
| 101 | |
| 102 | $info = array(); |
| 103 | foreach ($DoI as $doi_dir => $dpath) { |
| 104 | if (is_dir($dpath)) { |
| 105 | $info[$doi_dir] = is_writeable($dpath) ? true : false; |
| 106 | } else if (is_file($dpath)) { |
| 107 | $info[$doi_dir] = "$dpath is a file not a directory"; |
| 108 | } else { |
| 109 | $info[$doi_dir] = 'Directory not found'; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return $info; |
| 114 | } |
| 115 | |
| 116 | function npdiag_get_third_party_cache() { |
| 117 | $info = "Get info about other caching solutions' residual cache. Placeholder for now."; |
| 118 | return $info; |
| 119 | } |
| 120 | |
| 121 | function npdiag_get_conflicting_plugins() { |
| 122 | $info = nitropack_get_conflicting_plugins(); |
| 123 | if ( !empty($info) ) { |
| 124 | return $info; |
| 125 | } else { |
| 126 | return $info = 'None detected'; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | function nitropack_generate_report() { |
| 131 | global $np_diag_functions; |
| 132 | try { |
| 133 | $ar = !empty($_POST["toggled"]) ? $_POST["toggled"] : NULL; |
| 134 | if ( $ar !== NULL) { |
| 135 | $diag_data = array('report-time-stamp' => date("Y-m-d H:i:s")); |
| 136 | foreach ($ar as $func_name => $func_allowed) { |
| 137 | if ((boolean)$func_allowed) { |
| 138 | $diag_data[$func_name] = call_user_func($np_diag_functions[$func_name]); |
| 139 | } |
| 140 | } |
| 141 | $str = json_encode($diag_data, JSON_PRETTY_PRINT); |
| 142 | $filename = 'nitropack_diag_file.txt'; |
| 143 | header('Content-Disposition: attachment; filename="'.$filename.'"'); |
| 144 | header("Content-Type: text/plain"); |
| 145 | header("Content-Length: " . strlen($str)); |
| 146 | echo $str; |
| 147 | exit; |
| 148 | } |
| 149 | } catch (\Exception $e) { |
| 150 | //exception handling here |
| 151 | } |
| 152 | |
| 153 | } |
| 154 |