<?php /**
 * Simple System Info
 *
 * @package     Simple System Info
 * @author      Daniel J Griffiths
 * @since       1.0.0
 */


// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;


// We need to make sure plugin.php is loaded!
require_once ABSPATH . 'wp-admin/includes/plugin.php';


if( !class_exists( 'Simple_System_Info' ) ) {

    /**
     * Main System Info class
     *
     * @author      Daniel J Griffiths
     * @since       1.0.0
     */
    class Simple_System_Info {

        /**
         * Get system info
         *
         * Returns the system info for a WordPress instance
         * 
         * @access      public
         * @author      Daniel J Griffiths
         * @since       1.0.0
         * @global      $wpdb
         * @global      object $wpdb Used to query the database
         * @param       bool $show_inactive Whether or not to show inactive plugins
         * @param       string $id The ID to assign to the returned textarea (Default: system-info-box)
         * @param       string $class The class to assign to the returned textarea (Default: none)
         * @return      string $return A string containing all system info
         */
        public function get( $show_inactive = false, $id = 'system-info-box', $class = null ) {
            global $wpdb;

            if( !defined( 'SSINFO_VERSION' ) )
                define( 'SSINFO_VERSION', '1.0.0' );

            // We need the Browser class!
            if( !class_exists( 'Browser' ) )
                require_once 'browser.php';

            $browser = new Browser();

            // Get theme info for this WordPress version
            if( get_bloginfo( 'version' ) < '3.4' ) {
                $theme_data = wp_get_theme( get_stylesheet_directory() . '/style.css' );
                $theme      = $theme_data['Name'] . ' ' . $theme_data['Version'];
            } else {
                $theme_data = wp_get_theme();
                $theme      = $theme_data->Name . ' ' . $theme_data-&gt;Version;&#13;
            }&#13;
&#13;
            $return = '<textarea readonly onclick="this.focus(); this.select()" id="' . $id . '" . null class="' . $class . '" : title="To copy the system info, click below and press Ctrl+C (PC) or Cmd+C (Mac).">';&#13;
&#13;
            $return .= '### Begin System Info ###' . "\n\n";&#13;
&#13;
            do_action( 'simple_system_info_before' );&#13;
&#13;
            // Start with the basice...&#13;
            $return .= '-- Site Info' . "\n\n";&#13;
            $return .= 'Site URL:                 ' . site_url() . "\n";&#13;
            $return .= 'Home URL:                 ' . home_url() . "\n";&#13;
            $return .= 'Multisite:                ' . ( is_multisite() ? 'Yes' : 'No' ) . "\n";&#13;
&#13;
            if( has_filter( 'ssi_after_site_info' ) )&#13;
                $return .= apply_filters( 'ssi_after_site_info', $return );&#13;
&#13;
            // The local users' browser information, handled by the Browser class&#13;
            $return .= "\n" . '-- User Browser' . "\n\n";&#13;
            $return .= $browser;&#13;
&#13;
            if( has_filter( 'ssi_after_user_browser' ) )&#13;
                $return .= apply_filters( 'ssi_after_user_browser', $return );&#13;
&#13;
            // WordPress configuration&#13;
            $return .= "\n" . '-- WordPress Configuration' . "\n\n";&#13;
            $return .= 'Version:                  ' . get_bloginfo( 'version' ) . "\n";&#13;
            $return .= 'Permalink Structure:      ' . ( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' ) . "\n";&#13;
            $return .= 'Active Theme:             ' . $theme . "\n";&#13;
            $return .= 'Show On Front:            ' . get_option( 'show_on_front' ) . "\n";&#13;
&#13;
            // Only show page specs if frontpage is set to 'page'&#13;
            if( get_option( 'show_on_front' ) == 'page' ) {&#13;
                $front_page_id = get_option( 'page_on_front' );&#13;
                $blog_page_id = get_option( 'page_for_posts' );&#13;
&#13;
                $return .= 'Page On Front:            ' . ( $front_page_id != 0 ? get_the_title( $front_page_id ) . ' (#' . $front_page_id . ')' : 'Unset' ) . "\n";&#13;
                $return .= 'Page For Posts:           ' . ( $blog_page_id != 0 ? get_the_title( $blog_page_id ) . ' (#' . $blog_page_id . ')' : 'Unset' ) . "\n";&#13;
            }&#13;
&#13;
            // Make sure wp_remote_post() is working&#13;
            $request['cmd'] = '_notify-validate';&#13;
&#13;
            $params = array(&#13;
                'sslverify'     =&gt; false,&#13;
                'timeout'       =&gt; 60,&#13;
                'user-agent'    =&gt; 'SSInfo/' . SSINFO_VERSION,&#13;
                'body'          =&gt; $request&#13;
            );&#13;
&#13;
            $response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );&#13;
&#13;
            if( !is_wp_error( $response ) &amp;&amp; $response['response']['code'] &gt;= 200 &amp;&amp; $response['response']['code'] prefix ) . '   Status: ' . ( strlen( $wpdb-&gt;prefix ) &gt; 16 ? 'ERROR: Too long' : 'Acceptable' ) . "\n";&#13;
            $return .= 'WP_DEBUG:                 ' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ) . "\n";&#13;
            $return .= 'Memory Limit:             ' . WP_MEMORY_LIMIT . "\n";&#13;
&#13;
            if( has_filter( 'ssi_after_wordpress_config' ) )&#13;
                $return .= apply_filters( 'ssi_after_wordpress_config', $return );&#13;
&#13;
            // WordPress active plugins&#13;
            $return .= "\n" . '-- WordPress Active Plugins' . "\n\n";&#13;
&#13;
            $plugins = get_plugins();&#13;
            $active_plugins = get_option( 'active_plugins', array() );&#13;
&#13;
            foreach( $plugins as $plugin_path =&gt; $plugin ) {&#13;
                if( !in_array( $plugin_path, $active_plugins ) )&#13;
                    continue;&#13;
&#13;
                //if( $plugin['Name'] !== 'Redux Framework' ) continue;&#13;
&#13;
                $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";&#13;
            }&#13;
&#13;
            if( has_filter( 'ssi_after_wordpress_plugins' ) )&#13;
                $return .= apply_filters( 'ssi_after_wordpress_plugins', $return );&#13;
&#13;
            // WordPress inactive plugins&#13;
            if( $show_inactive == true ) {&#13;
                $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n";&#13;
&#13;
                foreach( $plugins as $plugin_path =&gt; $plugin ) {&#13;
                    if( in_array( $plugin_path, $active_plugins ) )&#13;
                        continue;&#13;
&#13;
                    $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";&#13;
                }&#13;
            }&#13;
&#13;
            if( has_filter( 'ssi_after_wordpress_plugins_inactive' ) )&#13;
                $return .= apply_filters( 'ssi_after_wordpress_plugins_inactive', $return );&#13;
&#13;
            // WordPress Multisite active plugins&#13;
            if( is_multisite() ) {&#13;
                $return .= "\n" . '-- Network Active Plugins' . "\n\n";&#13;
        &#13;
                $plugins = wp_get_active_network_plugins();&#13;
                $active_plugins = get_site_option( 'active_sitewide_plugins', array() );&#13;
&#13;
                foreach( $plugins as $plugin_path ) {&#13;
                    $plugin_base = plugin_basename( $plugin_path );&#13;
&#13;
                    if( !array_key_exists( $plugin_base, $active_plugins ) )&#13;
                        continue;&#13;
&#13;
                    $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";&#13;
                }&#13;
                &#13;
                if( has_filter( 'ssi_after_wordpress_ms_plugins' ) )&#13;
                    $return .= apply_filters( 'ssi_after_wordpress_ms_plugins', $return );&#13;
&#13;
                // WordPress Multisite inactive plugins&#13;
                if( $show_inactive == true ) {&#13;
                    $return .= "\n" . '-- Network Inactive Plugins' . "\n\n";&#13;
        &#13;
                    foreach( $plugins as $plugin_path ) {&#13;
                        $plugin_base = plugin_basename( $plugin_path );&#13;
&#13;
                        if( array_key_exists( $plugin_base, $active_plugins ) )&#13;
                            continue;&#13;
&#13;
                        $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";&#13;
                    }&#13;
                }    &#13;
            }&#13;
            &#13;
            if( has_filter( 'ssi_after_wordpress_ms_plugins_inactive' ) )&#13;
                $return .= apply_filters( 'ssi_after_wordpress_ms_plugins_inactive', $return );&#13;
&#13;
            // Server configuration (really just versioning)&#13;
            $return .= "\n" . '-- Webserver Configuration' . "\n\n";&#13;
            $return .= 'PHP Version:              ' . PHP_VERSION . "\n";&#13;
            $return .= 'MySQL Version:            ' . mysql_get_server_info() . "\n";&#13;
            $return .= 'Webserver Info:           ' . $_SERVER['SERVER_SOFTWARE'] . "\n";&#13;
&#13;
            if( has_filter( 'ssi_after_webserver_config' ) )&#13;
                $return .= apply_filters( 'ssi_after_webserver_config', $return );&#13;
&#13;
            // PHP configs... now we're getting to the important stuff&#13;
            $return .= "\n" . '-- PHP Configuration' . "\n\n";&#13;
            $return .= 'Safe Mode:                ' . ( ini_get( 'safe_mode' ) ? 'Yes' : 'No' ) . "\n";&#13;
            $return .= 'Memory Limit:             ' . ini_get( 'memory_limit' ) . "\n";&#13;
            $return .= 'Upload Max Size:          ' . ini_get( 'upload_max_filesize' ) . "\n";&#13;
            $return .= 'Post Max Size:            ' . ini_get( 'post_max_size' ) . "\n";&#13;
            $return .= 'Upload Max Filesize:      ' . ini_get( 'upload_max_filesize' ) . "\n";&#13;
            $return .= 'Time Limit:               ' . ini_get( 'max_execution_time' ) . "\n";&#13;
            $return .= 'Max Input Vars:           ' . ini_get( 'max_input_vars' ) . "\n";&#13;
            $return .= 'Display Errors:           ' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ) . "\n";&#13;
&#13;
            if( has_filter( 'ssi_after_php_config' ) )&#13;
                $return .= apply_filters( 'ssi_after_php_config', $return );&#13;
&#13;
            // PHP extensions and such&#13;
            $return .= "\n" . '-- PHP Extensions' . "\n\n";&#13;
            $return .= 'cURL:                     ' . ( function_exists( 'curl_init' ) ? 'Supported' : 'Not Supported' ) . "\n";&#13;
            $return .= 'fsockopen:                ' . ( function_exists( 'fsockopen' ) ? 'Supported' : 'Not Supported' ) . "\n";&#13;
            $return .= 'SOAP Client:              ' . ( class_exists( 'SoapClient' ) ? 'Installed' : 'Not Installed' ) . "\n";&#13;
            $return .= 'Suhosin:                  ' . ( extension_loaded( 'suhosin' ) ? 'Installed' : 'Not Installed' ) . "\n";&#13;
&#13;
            if( has_filter( 'ssi_after_php_ext' ) )&#13;
                $return .= apply_filters( 'ssi_after_php_ext', $return );&#13;
&#13;
            // Session stuff&#13;
            $return .= "\n" . '-- Session Configuration' . "\n\n";&#13;
            $return .= 'Session:                  ' . ( isset( $_SESSION ) ? 'Enabled' : 'Disabled' ) . "\n";&#13;
&#13;
            // The rest of this is only relevant is session is enabled&#13;
            if( isset( $_SESSION ) ) {&#13;
                $return .= 'Session Name:             ' . esc_html( ini_get( 'session.name' ) ) . "\n";&#13;
                $return .= 'Cookie Path:              ' . esc_html( ini_get( 'session.cookie_path' ) ) . "\n";&#13;
                $return .= 'Save Path:                ' . esc_html( ini_get( 'session.save_path' ) ) . "\n";&#13;
                $return .= 'Use Cookies:              ' . ( ini_get( 'session.use_cookies' ) ? 'On' : 'Off' ) . "\n";&#13;
                $return .= 'Use Only Cookies:         ' . ( ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off' ) . "\n";&#13;
            }&#13;
&#13;
            if( has_filter( 'ssi_after_session_config' ) )&#13;
                $return .= apply_filters( 'ssi_after_session_config', $return );&#13;
&#13;
            do_action( 'ssi_after' );&#13;
            &#13;
            $return .= "\n" . '### End System Info ###';&#13;
&#13;
            $return .= '</textarea>';&#13;
        &#13;
            return $return;&#13;
        }&#13;
    }&#13;
}&#13;
