| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPSynchro\Utilities; |
| 4 |
|
| 5 |
use WPSynchro\Utilities\CommonFunctions; |
| 6 |
use WPSynchro\API\MasterData; |
| 7 |
use WPSynchro\Utilities\Configuration\PluginConfiguration; |
| 8 |
use WPSynchro\Utilities\Licensing\Licensing; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class for debug information |
| 12 |
*/ |
| 13 |
class DebugInformation |
| 14 |
{ |
| 15 |
private $populated = false; |
| 16 |
private $data_to_show = []; |
| 17 |
private $data_to_json_only = []; |
| 18 |
private function populate() |
| 19 |
{ |
| 20 |
if ($this->populated) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
$commonfunctions = new CommonFunctions(); |
| 25 |
if (CommonFunctions::isPremiumVersion()) { |
| 26 |
$licensing = new Licensing(); |
| 27 |
} |
| 28 |
$plugin_configuration = new PluginConfiguration(); |
| 29 |
|
| 30 |
// WP synchro |
| 31 |
$this->data_to_show['WP Synchro plugin version'] = WPSYNCHRO_VERSION; |
| 32 |
$this->data_to_show['WP Synchro db version'] = get_option('wpsynchro_dbversion'); |
| 33 |
$this->data_to_show['WP Synchro PRO'] = (CommonFunctions::isPremiumVersion() ? 'yes' : 'no'); |
| 34 |
if (CommonFunctions::isPremiumVersion()) { |
| 35 |
$this->data_to_show['WP Synchro PRO validated'] = ($licensing->verifyLicense() ? 'yes' : 'no'); |
| 36 |
$this->data_to_show['WP Synchro license data'] = $licensing->getLicenseState(); |
| 37 |
} |
| 38 |
$this->data_to_show['WP Synchro MU plugin'] = ($plugin_configuration->getMUPluginEnabledState() ? 'yes' : 'no'); |
| 39 |
$this->data_to_show['WP Synchro MU plugin version'] = (defined("WPSYNCHRO_MU_COMPATIBILITY_VERSION") ? WPSYNCHRO_MU_COMPATIBILITY_VERSION : "N/A"); |
| 40 |
|
| 41 |
// WP |
| 42 |
global $wp_version; |
| 43 |
$this->data_to_show['WP Version'] = $wp_version; |
| 44 |
$this->data_to_show['WP SAVEQUERIES used'] = ((defined('SAVEQUERIES') && SAVEQUERIES == true) ? 'yes' : 'no'); |
| 45 |
$this->data_to_show['WP Memory limit'] = WP_MEMORY_LIMIT; |
| 46 |
$this->data_to_show['WP Max memory limit'] = WP_MAX_MEMORY_LIMIT; |
| 47 |
$this->data_to_show['WP multisite enabled'] = (is_multisite() ? 'yes' : 'no'); |
| 48 |
$this->data_to_show['WP option upload_path'] = get_option('upload_path', ""); |
| 49 |
$this->data_to_show['WP option upload_url_path'] = get_option('upload_url_path', ""); |
| 50 |
$this->data_to_show['WP debug enabled'] = (defined('WP_DEBUG') && WP_DEBUG === true ? "yes" : "no"); |
| 51 |
global $wpdb; |
| 52 |
$this->data_to_show['MySQL Version'] = $wpdb->get_var("SELECT VERSION()"); |
| 53 |
|
| 54 |
// Memory limits |
| 55 |
$this->data_to_show['Memory limit'] = number_format($commonfunctions->convertPHPSizeToBytes(ini_get('memory_limit')), 0, ",", ".") . " bytes"; |
| 56 |
$this->data_to_show['Memory usage'] = number_format(memory_get_usage(), 0, ",", ".") . " bytes"; |
| 57 |
|
| 58 |
// PHP |
| 59 |
$this->data_to_show['PHP Version'] = PHP_VERSION; |
| 60 |
$this->data_to_show['PHP max_execution_time'] = intval(ini_get('max_execution_time')); |
| 61 |
$this->data_to_show['PHP post_max_size'] = number_format($commonfunctions->convertPHPSizeToBytes(ini_get('post_max_size')), 0, ",", ".") . " bytes"; |
| 62 |
$this->data_to_show['PHP open_basedir'] = ini_get('open_basedir'); |
| 63 |
|
| 64 |
// MYSQL |
| 65 |
$this->data_to_show['MySQL max_allowed_packet'] = number_format($wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'")->Value, 0, ",", ".") . " bytes"; |
| 66 |
|
| 67 |
// Webserver |
| 68 |
$this->data_to_show['Webserver Version'] = (isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : "N/A"); |
| 69 |
|
| 70 |
// JSON ONLY |
| 71 |
if (!function_exists('get_plugins')) { |
| 72 |
require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 73 |
} |
| 74 |
|
| 75 |
$plugins = get_plugins(); |
| 76 |
$this->data_to_json_only['WP Active plugins'] = []; |
| 77 |
foreach ($plugins as $pluginfile => $plugin) { |
| 78 |
if (is_plugin_active($pluginfile)) { |
| 79 |
$this->data_to_json_only['WP Active plugins'][] = $plugin; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
$this->data_to_json_only['WP MU plugins'] = get_mu_plugins(); |
| 84 |
$this->data_to_json_only['WP dropins'] = get_dropins(); |
| 85 |
$this->data_to_json_only['PHP Extensions'] = get_loaded_extensions(); |
| 86 |
$masterdata_obj = new Masterdata(); |
| 87 |
$this->data_to_json_only['Masterdata Base'] = $masterdata_obj->getBaseSiteData(); |
| 88 |
$this->data_to_json_only['Masterdata Files'] = $masterdata_obj->getFileDetailsData(); |
| 89 |
$this->populated = true; |
| 90 |
} |
| 91 |
|
| 92 |
public function getJSONDebugInformation() |
| 93 |
{ |
| 94 |
$this->populate(); |
| 95 |
$tmp = array_merge($this->data_to_show, $this->data_to_json_only); |
| 96 |
return json_encode((object) $tmp); |
| 97 |
} |
| 98 |
|
| 99 |
public function getAllDebugInformation() |
| 100 |
{ |
| 101 |
$this->populate(); |
| 102 |
return array_merge($this->data_to_show, $this->data_to_json_only); |
| 103 |
} |
| 104 |
} |
| 105 |
|