<?php
/**
 * Name: System Summary
 * Description: Display comprehensive server and WordPress information in dashboard widget including PHP version, MySQL version, memory limits, server software, and WordPress environment details for troubleshooting
 * Category: Utilities
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "Add Useful Functionality",
 *     "description": "Extend WordPress with helpful tools that make site management easier."
 *   },
 *   {
 *     "title": "Save Time",
 *     "description": "Automate or simplify tasks that would otherwise require manual work or additional tools."
 *   }
 * ]
 * Added: 2025-07-14
 * Tags: system, server, info, dashboard, php, mysql
 * WhereToFind: {
 *   "location": "Dashboard widget",
 *   "url": "",
 *   "instructions": "System Summary widget shows server and PHP info",
 *   "newTab": false
 * }
 */

// Prevent direct access
if (!defined('ABSPATH')) exit;

class SwitchboardSystemSummary {
    
    public function __construct() {
        add_action('wp_dashboard_setup', [$this, 'add_dashboard_widget']);
    }
    
    public function add_dashboard_widget() {
        wp_add_dashboard_widget(
            'switchboard_system_summary',
            'System Summary <span class="switchboard-badge">SWITCHBOARD</span>',
            [$this, 'display_widget']
        );
    }
    
    public function display_widget() {
        global $wpdb;
        
        $php_version = phpversion();
        $mysql_version = $wpdb->db_version();
        $wp_version = get_bloginfo('version');
        $server_software = isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : 'Unknown';
        $max_upload = ini_get('upload_max_filesize') ?: 'Unknown';
        $max_post = ini_get('post_max_size') ?: 'Unknown';
        $memory_limit = ini_get('memory_limit') ?: 'Unknown';
        $max_execution = ini_get('max_execution_time') ?: 'Unknown';
        
        ?>
        <style>
        .system-summary-table { width: 100%; }
        .system-summary-table td { padding: 8px 0; border-bottom: 1px solid #f0f0f0; }
        .system-summary-table td:first-child { font-weight: 600; width: 40%; }
        .system-summary-table tr:last-child td { border-bottom: none; }
        </style>
        <table class="system-summary-table">
            <tr>
                <td><?php esc_html_e('WordPress Version', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($wp_version); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('PHP Version', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($php_version); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('MySQL Version', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($mysql_version); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('Server Software', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($server_software); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('Memory Limit', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($memory_limit); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('Max Upload Size', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($max_upload); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('Max Post Size', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($max_post); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e('Max Execution Time', 'wpswitchboard'); ?></td>
                <td><?php echo esc_html($max_execution); ?>s</td>
            </tr>
        </table>
        <?php
    }

    /**
     * Register data locations for cleanup system
     *
     * @return array Data storage locations
     */
    public function register_data_locations() {
        return [
            'options' => [],
            'option_patterns' => [],
            'tables' => [],
            'post_meta' => [],
            'user_meta' => [],
        ];
    }
}

// Initialize and register with data system
$switchboard_instance = new SwitchboardSystemSummary();
Switchboard_Data_Registry::get_instance()->auto_register($switchboard_instance, __FILE__);
