<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
 * Collect site information for display.
 *
 * @package Maintainn Tools.
 * @since 1.0.0
 */

/**
 * Class Maintainn_Tools_System_Info
 *
 * @since 1.0.0
 */
class Maintainn_Tools_System_Info {

	/**
	 * Array of various system information items.
	 *
	 * @var array
	 * @since 1.0.0
	 */
	public $system_info = array();

	/**
	 * Browser data class instance.
	 *
	 * @var Browser
	 * @since 1.0.0
	 */
	protected $browser;

	/**
	 * Copy of WPDB global instance.
	 *
	 * @var WPDB
	 * @since 1.0.0
	 */
	protected $wpdb;

	/**
	 * Maintainn_Tools_System_Info constructor.
	 *
	 * @param Browser $browser Browser() instance.
	 * @param WPDB    $wpdb    $wpdb global instance.
	 */
	public function __construct( Browser $browser, WPDB $wpdb ) {
		$this->browser = $browser;
		$this->wpdb    = $wpdb;
	}

	/**
	 * Populate our browser-based data points.
	 *
	 * @since 1.0.0
	 */
	private function set_browser() {
		$this->system_info['browser']['name']        = $this->browser->getBrowser();
		$this->system_info['browser']['version']     = $this->browser->getVersion();
		$this->system_info['browser']['ua']          = $this->browser->getUserAgent();
		$this->system_info['browser']['platform']    = $this->browser->getPlatform();
		$this->system_info['browser']['client_ip']   = $this->get_client_ip();
		$this->system_info['browser']['client_host'] = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( gethostbyaddr( $_SERVER['REMOTE_ADDR'] ) ) : esc_html__( 'N/A', 'maintainn-tools' );
		$this->system_info['browser']['client_port'] = isset( $_SERVER['REMOTE_PORT'] ) ? sanitize_text_field( $_SERVER['REMOTE_PORT'] ) : esc_html__( 'N/A', 'maintainn-tools' );
	}

	/**
	 * Populate our plugin-based data points.
	 *
	 * @since 1.0.0
	 */
	private function set_plugin_data() {
		if ( is_multisite() ) {
			$network_plugins = wp_get_active_network_plugins();
			$network_active  = get_site_option( 'active_sitewide_plugins', array() );

			$this->system_info['plugins']['network_plugins']        = $network_plugins;
			$this->system_info['plugins']['network_plugin_count']   = count( $network_plugins );
			$this->system_info['plugins']['network_active_plugins'] = $network_active;
		}
	}

	/**
	 * Populate our site-based data points.
	 *
	 * @since 1.0.0
	 */
	private function set_site_info() {
		$page_front = get_option( 'page_on_front' );
		$posts_page = get_option( 'page_for_posts' );

		$this->system_info['site_info']['site_url']       = site_url();
		$this->system_info['site_info']['home_url']       = home_url();
		$this->system_info['site_info']['post_types']     = implode( ', ', get_post_types() );
		$this->system_info['site_info']['post_stati']     = implode( ', ', get_post_stati() );
		$this->system_info['site_info']['show_on_front']  = get_option( 'show_on_front' );
		$this->system_info['site_info']['page_on_front']  = get_the_title( $page_front ) . "#{$page_front}";
		$this->system_info['site_info']['page_for_posts'] = get_the_title( $posts_page ) . "#{$posts_page}";
	}

	/**
	 * Populate our system overview data points.
	 *
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function set_system_overview() {
		$this->system_info['system_overview']                     = array();
		$this->system_info['system_overview']['server_ip']        = isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( $_SERVER['SERVER_ADDR'] ) : esc_html__( 'N/A', 'maintainn-tools' );
		$this->system_info['system_overview']['server_port']      = isset( $_SERVER['SERVER_PORT'] ) ? sanitize_text_field( $_SERVER['SERVER_PORT'] ) : esc_html__( 'N/A', 'maintainn-tools' );
		$this->system_info['system_overview']['server_load']      = $this->get_server_load();
		$this->system_info['system_overview']['server_load_avg']  = $this->get_server_load_avg();
		$this->system_info['system_overview']['php_memory_usage'] = $this->get_memory_usage();
	}

	/**
	 * Get the client IP address.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/inc/widgets-helper.php
	 * @return string IP address.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_client_ip() {
		static $env_vars = array( 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR' );

		foreach ( $env_vars as $var ) {
			if ( isset( $_SERVER[ $var ] ) ) {
				return sanitize_text_field( $_SERVER[ $var ] );
			}
		}

		foreach ( $env_vars as $var ) {
			if ( getenv( $var ) ) {
				return sanitize_text_field( getenv( $var ) );
			}
		}

		return esc_html__( 'N/A', 'maintainn-tools' );
	}

	/**
	 * Get the server load.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/widgets/widget-system-info.php
	 * @return string Load averages separated by commas: 1 minute, 5 minute, 15 minute.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_server_load() {

		if ( ! function_exists( 'sys_getloadavg' ) ) {
			return esc_html__( 'N/A', 'maintainn-tools' );
		}

		$avgs = sys_getloadavg();

		if ( ! is_array( $avgs ) ) {
			return esc_html__( 'N/A', 'maintainn-tools' );
		}

		return implode( ', ', $avgs );
	}

	/**
	 * Get the server load based on CPU count.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/widgets/widget-system-info.php
	 * @return string Load average based on number of CPUs.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_server_load_avg() {
		if ( stristr( PHP_OS, 'win' ) ) {
			if ( ! class_exists( 'COM' ) ) {
				return esc_html__( 'N/A', 'maintainn-tools' );
			}

			$wmi        = new COM( 'Winmgmts://' );
			$server     = $wmi->execquery( 'SELECT LoadPercentage FROM Win32_Processor' );
			$cpu_num    = 0;
			$load_total = 0;

			foreach ( $server as $cpu ) {
				$cpu_num++;
				$load_total += $cpu->loadpercentage;
			}

			$load = round( $load_total / $cpu_num );
		} else {
			if ( ! function_exists( 'sys_getloadavg' ) ) {
				return esc_html__( 'N/A', 'maintainn-tools' );
			}

			$sys_loadavg = sys_getloadavg();
			$sys_load    = ( is_array( $sys_loadavg ) ) ? $sys_loadavg : array( 0 );
			$load        = array_sum( $sys_load ) / count( $sys_load );
		}

		return (string) round( $load, 3 );
	}

	/**
	 * Get the PHP memory usage.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/widgets/widget-system-info.php
	 * @return string Memory usage in percent with size in parentheses.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_memory_usage() {
		$load = function_exists( 'memory_get_usage' ) ? round( memory_get_usage() / 1024 / 1024, 2 ) : 0;

		$limit = (int) ini_get( 'memory_limit' );

		$usage = round( $load / $limit * 100, 0 );

		return $usage . '% (' . $load . 'M ' . esc_html__( 'of ', 'maintainn-tools' ) . $limit . 'M)';
	}

	/**
	 * Populate our WordPress Extra data points.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/widgets/widget-system-info.php
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function set_wp_extra() {
		global $concatenate_scripts, $compress_scripts, $compress_css, $_wp_using_ext_object_cache;

		$this->system_info['wp_extra']                     = array();
		$this->system_info['wp_extra']['remote_post']      = $this->is_remote_post_enabled() ? __( 'Enabled', 'maintainn-tools' ) : __( 'Disabled', 'maintainn-tools' );
		$this->system_info['wp_extra']['enforce_gzip']     = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) ? __( 'Enabled', 'maintainn-tools' ) : __( 'Disabled', 'maintainn-tools' );
		$this->system_info['wp_extra']['query_log']        = ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) ? __( 'Enabled', 'maintainn-tools' ) : __( 'Disabled', 'maintainn-tools' );
		$this->system_info['wp_extra']['no_file_edit']     = ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) ? __( 'Enabled', 'maintainn-tools' ) : __( 'Disabled', 'maintainn-tools' );
		$this->system_info['wp_extra']['auto_update_core'] = ( defined( 'WP_AUTO_UPDATE_CORE' ) && WP_AUTO_UPDATE_CORE ) ? __( 'Enabled', 'maintainn-tools' ) : __( 'Disabled', 'maintainn-tools' );
		$this->system_info['wp_extra']['obj_cache']        = $_wp_using_ext_object_cache ? __( 'Enabled', 'maintainn-tools' ) : __( 'Disabled', 'maintainn-tools' );
		$this->system_info['wp_extra']['time']             = current_time( 'mysql' );
		$this->system_info['wp_extra']['update_method']    = get_filesystem_method( array() ) !== 'direct' ? __( 'FTP/SSH access only', 'maintainn-tools' ) : __( 'Direct access allowed', 'maintainn-tools' );
	}

	/**
	 * Check whether wp_remote_post() is enabled.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/widgets/widget-system-info.php
	 * @return boolean true if enabled, false otherwise.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function is_remote_post_enabled() {

		$test_url = 'https://www.paypal.com/cgi-bin/webscr';
		$request  = array(
			'cmd' => '_notify-validate',
		);

		$params = array(
			'method'    => 'POST',
			'sslverify' => true,
			'timeout'   => 60,
			'body'      => $request,
		);

		$response = wp_remote_post( $test_url, $params );

		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
			return true;
		}
		return false;
	}

	/**
	 * Load MySQL global variables.
	 *
	 * @see https://plugins.trac.wordpress.org/browser/dashboard-widgets-suite/trunk/widgets/widget-system-info.php
	 * @return void
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function set_db_info() {
		$this->set_db_variables();
		$this->system_info['db_info']['uptime']  = $this->get_db_uptime_string();
		$this->system_info['db_info']['charset'] = defined( 'DB_CHARSET' ) ? sanitize_text_field( DB_CHARSET ) : __( 'N/A', 'maintainn-tools' );
	}

	/**
	 * Set DB info that comes from MySQL variables.
	 *
	 * @return void
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function set_db_variables() {
		global $wpdb;

		$results = $wpdb->get_results( 'SHOW GLOBAL VARIABLES' );
		if ( ! $results ) {
			return;
		}

		$db_vars = array(
			'version_comment',
			'hostname',
		);

		$this->system_info['db_info'] = array();

		foreach ( $db_vars as $db_var ) {
			$this->system_info['db_info'][ $db_var ] = __( 'N/A', 'maintainn-tools' );
		}

		foreach ( $results as $result ) {
			// phpcs:disable WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
			if ( in_array( $result->Variable_name, $db_vars, true ) ) {
				$this->system_info['db_info'][ $result->Variable_name ] = $result->Value;
			}
			// phpcs:enable
		}
	}

	/**
	 * Get the uptime from MySQL.
	 *
	 * @return int Uptime in seconds.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_db_uptime() {
		global $wpdb;

		$results = $wpdb->get_results( 'SHOW GLOBAL STATUS' );
		if ( ! $results ) {
			return 0;
		}

		foreach ( $results as $result ) {
			// phpcs:disable WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
			if ( 'Uptime' === $result->Variable_name ) {
				return $result->Value;
			}
			// phpcs:enable
		}
		return 0;
	}

	/**
	 * Get a formatted uptime string from MySQL.
	 *
	 * @return string Formatted uptime string.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	public function get_db_uptime_string() {

		$uptime = $this->get_db_uptime();

		$uptime_seconds = $uptime % 60;
		$uptime_minutes = (int) ( ( $uptime % 3600 ) / 60 );
		$uptime_hours   = (int) ( ( $uptime % 86400 ) / 3600 );
		$uptime_days    = (int) ( $uptime / 86400 );

		if ( $uptime_days > 0 ) {
			/* Translators: Uptime string with days, hours, minutes, seconds */
			return sprintf( esc_html__( '%1$s days, %2$s hours, %3$s minutes, %4$s seconds', 'maintainn-tools' ), $uptime_days, $uptime_hours, $uptime_minutes, $uptime_seconds );
		} elseif ( $uptime_hours > 0 ) {
			/* Translators: Uptime string with hours, minutes, seconds */
			return sprintf( esc_html__( '%1$s hours, %2$s minutes, %3$s seconds', 'maintainn-tools' ), $uptime_hours, $uptime_minutes, $uptime_seconds );
		} elseif ( $uptime_minutes > 0 ) {
			/* Translators: Uptime string with minutes, seconds */
			return sprintf( esc_html__( '%1$s minutes, %2$s seconds', 'maintainn-tools' ), $uptime_minutes, $uptime_seconds );
		}

		/* Translators: Uptime string with seconds */
		return sprintf( esc_html__( '%s seconds', 'maintainn-tools' ), $uptime_seconds );
	}

	/**
	 * Populate our server-based data points.
	 *
	 * @since 1.0.0
	 */
	private function set_server_info() {
		$display_errors      = ini_get( 'display_errors' );

		$this->system_info['server_info']['server_signature']         = $this->get_server_signature();
		$this->system_info['server_info']['apache_modules']           = function_exists( 'apache_get_modules' ) ? implode( ', ', (array) apache_get_modules() ) : __( 'N/A', 'maintainn-tools' );
		$this->system_info['server_info']['web_protocol']             = isset( $_SERVER['SERVER_PROTOCOL'] ) ? sanitize_text_field( $_SERVER['SERVER_PROTOCOL'] ) : __( 'N/A', 'maintainn-tools' );
		$this->system_info['server_info']['http_connection']          = isset( $_SERVER['HTTP_CONNECTION'] ) ? sanitize_text_field( $_SERVER['HTTP_CONNECTION'] ) : __( 'N/A', 'maintainn-tools' );
		$this->system_info['server_info']['server_gateway']           = isset( $_SERVER['GATEWAY_INTERFACE'] ) ? sanitize_text_field( $_SERVER['GATEWAY_INTERFACE'] ) : __( 'N/A', 'maintainn-tools' );
		$this->system_info['server_info']['server_time']              = date( 'Y-m-d H:i:s' );
		$this->system_info['server_info']['wp_memory_limit']          = WP_MEMORY_LIMIT;
		$this->system_info['server_info']['sessions']                 = isset( $_SESSION ) ? __( 'Yes', 'maintainn-tools' ) : __( 'No', 'maintainn-tools' );
		$this->system_info['server_info']['session_name']             = esc_html( ini_get( 'session.name' ) );
		$this->system_info['server_info']['session_cookie_path']      = esc_html( ini_get( 'session.cookie_path' ) );
		$this->system_info['server_info']['session_save_path']        = esc_html( ini_get( 'session.save_path' ) );
		$this->system_info['server_info']['session_use_cookies']      = ini_get( 'session.use_cookies' ) ? __( 'On', 'maintainn-tools' ) : __( 'Off', 'maintainn-tools' );
		$this->system_info['server_info']['session_use_only_cookies'] = ini_get( 'session.use_only_cookies' ) ? __( 'On', 'maintainn-tools' ) : __( 'Off', 'maintainn-tools' );
		$this->system_info['server_info']['display_errors']           = ( ini_get( 'disable_errors' ) ) ? sprintf( __( 'On (%s)', 'maintainn-tools' ), $display_errors ) : __( 'N/A', 'maintainn-tools' );
		$this->system_info['server_info']['fsockopen']                = ( function_exists( 'fsockopen' ) ) ? __( 'On', 'maintainn-tools' ) : __( 'Off', 'maintainn-tools' );
		$this->system_info['server_info']['soap_client']              = ( class_exists( 'SoapClient' ) ) ? __( 'On', 'maintainn-tools' ) : __( 'Off', 'maintainn-tools' );
		$this->system_info['server_info']['disk_space']               = $this->get_disk_space();
	}

	private function set_image_sizes() {
		$sizes = get_intermediate_image_sizes();

		$this->system_info['image_sizes'] = implode( ', ', $sizes );
	}

	/**
	 * Gets disk space.
	 *
	 * @since 2.1.0
	 * @return string Disk space.
	 */
	private function get_disk_space() {
		if ( ! disk_free_space( '/' ) || ! disk_total_space( '/' ) ) {
			return esc_html__( 'N/A', 'maintainn-tools' );
		}

		// translators: %1$s = free disk space. %2$s = total disk space.
		return sprintf( esc_html__( '%1$s / %2$s', 'maintainn-tools' ), size_format( disk_free_space( '/' ), 0 ), size_format( disk_total_space( '/' ), 0 ) );
	}

	/**
	 * Get the server signature.
	 *
	 * @return string Sever signature, 'Disabled' if not set.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_server_signature() {

		if ( isset( $_SERVER['SERVER_SIGNATURE'] ) && trim( $_SERVER['SERVER_SIGNATURE'] ) !== '' ) {
			return sanitize_text_field( $_SERVER['SERVER_SIGNATURE'] );
		}

		return __( 'Disabled', 'maintainn-tools' );
	}

	/**
	 * Load PHP related information.
	 *
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function set_php_info() {
		$this->system_info['php_info'] = array();

		$this->system_info['php_info']['zend_version']   = sanitize_text_field( zend_version() );
		$this->system_info['php_info']['peak_memory']    = $this->get_peak_memory_usage();
		/* Translators: abbreviation for seconds (s). */
		$this->system_info['php_info']['include_path']   = sanitize_text_field( ini_get( 'include_path' ) );
		$this->system_info['php_info']['url_fopen']      = ini_get( 'allow_url_fopen' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['php_info']['file_uploads']   = ini_get( 'file_uploads' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['php_info']['loaded_ext']     = sanitize_text_field( implode( ', ', get_loaded_extensions() ) );
		$this->system_info['php_info']['short_tag']      = ini_get( 'short_open_tag' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
	}

	/**
	 * Get peak memory usage.
	 *
	 * @return string Peak memory usage in bytes (B), kilobytes (K), or megabytes (M).
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_peak_memory_usage() {

		$mem = function_exists( 'memory_get_peak_usage' ) ? memory_get_peak_usage( true ) : 0;

		if ( $mem < 1024 ) {
			/* Translators: abbreviation for bytes (B). */
			$$memory = sprintf( __( '%sB', 'maintainn-tools' ), $mem );
		} elseif ( $mem < 1048576 ) {
			/* Translators: abbreviation for kilobytes (K). */
			$memory = sprintf( __( '%sK', 'maintainn-tools' ), round( $mem / 1024, 2 ) );
		} else {
			/* Translators: abbreviation for megabytes (M). */
			$memory = sprintf( __( '%sM', 'maintainn-tools' ), round( $mem / 1048576, 2 ) );
		}

		return $memory;
	}

	/**
	 * Load security section info.
	 *
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function set_security_info() {
		$this->system_info['sec_info'] = array();

		$this->system_info['sec_info']['register_globals']  = ini_get( 'register_globals' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['sec_info']['allow_url_include'] = ini_get( 'allow_url_include' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['sec_info']['allow_url_fopen']   = ini_get( 'allow_url_fopen' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['sec_info']['magic_quotes']      = get_magic_quotes_gpc() ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['sec_info']['server_signature']  = isset( $_SERVER['SERVER_SIGNATURE'] ) ? $_SERVER['SERVER_SIGNATURE'] : 'n/a';
		$this->system_info['sec_info']['wp_unique_keys']    = $this->get_unique_keys();
		$this->system_info['sec_info']['mod_security']      = $this->get_modsecurity();
		$this->system_info['sec_info']['open_basedir']      = ini_get( 'open_basedir' ) ? esc_html__( 'Enabled', 'maintainn-tools' ) : esc_html__( 'Disabled', 'maintainn-tools' );
		$this->system_info['sec_info']['upload_tmp_dir']    = $this->get_upload_tmp_dir();
		$this->system_info['sec_info']['expose_php']        = ini_get('expose_php');
	}

	/**
	 * Get a span with Enabled/Disabled based on a parameter.
	 *
	 * @param boolean $param The parameter to check to display Enabled (true) or Disabled (false).
	 * @param boolean $enabled_good Whether the Enabled state is a good thing or not, Default true.
	 * @return string Span with Enabled / Disabled and the proper good/bad class color set.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_enabled( $param, $enabled_good = true ) {

		$enabled_class  = $enabled_good ? 'load-color-good' : 'load-color-poor';
		$disabled_class = ! $enabled_good ? 'load-color-good' : 'load-color-poor';

		return $param ?
			"<span class='{$enabled_class}'>". esc_html__( 'Enabled', 'maintainn-tools' ) . '</span>' :
			"<span class='{$disabled_class}'>". esc_html__( 'Disabled', 'maintainn-tools' ) . '</span>';
	}

	/**
	 * Check whether or not the WP keys are set to unique values.
	 *
	 * @return boolean
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_unique_keys() {

		$keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY' );

		foreach ( $keys as $key ) {
			if ( defined( $key ) ) {
				if ( 'put your unique phrase here' === constant( $key ) ) {
					return false;
				}
			} else {
				return false;
			}
		}
		return true;
	}

	/**
	 * Check for the presence of the mod_security module.
	 *
	 * @return string Span with installation status.
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_modsecurity() {

		$mod_security  = '';
		$enabled_good  = esc_html__( 'Enabled', 'maintainn-tools' );
		$disabled_poor = esc_html__( 'Disabled', 'maintainn-tools' );
		$unknown_warn  = esc_html__( 'Not Installed', 'maintainn-tools' );

		if ( function_exists( 'apache_get_modules' ) ) {
			$apache_mods  = apache_get_modules(); // Note: apache_get_modules() does not work if running PHP as CGI.
			$mod_security = in_array( 'mod_security', $apache_mods ) || in_array( 'mod_security2', $apache_mods ) ? $enabled_good : $disabled_poor;

			if ( ! $mod_security && in_array( 'security2_module', $apache_mods ) ) {
				$mod_security = $unknown_warn;
			}
		} else {
			$mod_security = $unknown_warn;
		}

		return $mod_security;
	}

	/**
	 * Get the upload directory.
	 *
	 * @return string
	 * @author Justin Foell <justin.foell@webdevstudios.com>
	 * @since  NEXT
	 */
	private function get_upload_tmp_dir() {

		$dir = ini_get( 'upload_tmp_dir' ) ? ini_get( 'upload_tmp_dir' ) : null;

		if ( function_exists( 'sys_get_temp_dir' ) ) {
			$dir = sys_get_temp_dir();
		} else {
			$vars = array( 'TMP', 'TMPDIR', 'TEMP' );

			foreach ( $vars as $var ) {
				$tmp = getenv( $var );
				if ( ! empty( $tmp ) ) {
					$dir = realpath( $tmp );
				}
			}
		}

		return $dir ? $dir : 'n/a';
	}

	/**
	 * Construct our system_info property and return to user.
	 *
	 * @since 1.0.0
	 *
	 * @return array Array of all our content.
	 */
	public function get_system_info() {
		$this->set_browser();
		$this->set_plugin_data();
		$this->set_site_info();
		$this->set_wp_extra();
		$this->set_system_overview();
		$this->set_db_info();
		$this->set_server_info();
		$this->set_php_info();
		$this->set_security_info();
		$this->set_image_sizes();

		return $this->system_info;
	}
}
