HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/uptime-monitor-plus/includes/class-admin.php
<?php
defined('ABSPATH') || exit;

/**
 * Admin page handler for UptimeMonitor+.
 */
class UptimeMonitorPlus_Admin {

    /**
     * Render the admin page.
     */
    public function render_page() {
        if ( ! current_user_can( 'manage_options' ) ) {
            wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'uptime-monitor-plus' ) );
        }

        $api_token = get_option( 'uptimemonitorplus_api_token', '' );

        if ( empty( $api_token ) ) {
            $this->render_login_page();
        } else {
            $this->render_detail_page();
        }
    }

    /**
     * Render the login form.
     */
    private function render_login_page() {
        $this->enqueue_admin_assets();
        include UPTIMEMONITORPLUS_PLUGIN_DIR . 'templates/login.php';
    }

    /**
     * Render the detail/dashboard page.
     */
    private function render_detail_page() {
        $this->enqueue_admin_assets();
        include UPTIMEMONITORPLUS_PLUGIN_DIR . 'templates/detail.php';
    }

    /**
     * Enqueue admin CSS and JS.
     */
    private function enqueue_admin_assets() {
        wp_enqueue_style(
            'uptimemonitorplus-admin',
            UPTIMEMONITORPLUS_PLUGIN_URL . 'assets/css/admin.css',
            array(),
            UPTIMEMONITORPLUS_VERSION
        );

        // Chart.js as local asset (not CDN)
        wp_enqueue_script(
            'uptimemonitorplus-chartjs',
            UPTIMEMONITORPLUS_PLUGIN_URL . 'assets/js/chart.min.js',
            array(),
            '4.4.8',
            true
        );

        wp_enqueue_script(
            'uptimemonitorplus-admin',
            UPTIMEMONITORPLUS_PLUGIN_URL . 'assets/js/admin.js',
            array( 'jquery', 'uptimemonitorplus-chartjs' ),
            UPTIMEMONITORPLUS_VERSION,
            true
        );

        wp_localize_script( 'uptimemonitorplus-admin', 'uptimemonitorplus', array(
            'ajax_url' => admin_url( 'admin-ajax.php' ),
            'nonce'    => wp_create_nonce( 'uptimemonitorplus_nonce' ),
            'strings'  => array(
                'loginSuccess'       => __( 'Login successful. Registering domain...', 'uptime-monitor-plus' ),
                'loginFailed'        => __( 'Login failed. Please try again.', 'uptime-monitor-plus' ),
                'invalidCredentials' => __( 'Invalid email or password', 'uptime-monitor-plus' ),
                'emailNotVerified'   => __( 'Verify your email before logging in', 'uptime-monitor-plus' ),
                'siteLinked'         => __( 'Site successfully linked to UptimeMonitor+', 'uptime-monitor-plus' ),
                'domainLimitReached' => __( 'You have reached the domain limit of your plan', 'uptime-monitor-plus' ),
                'domainAlreadyExists' => __( 'This domain is already registered with another account', 'uptime-monitor-plus' ),
                'disconnectConfirm'  => __( 'Are you sure you want to disconnect the plugin?', 'uptime-monitor-plus' ),
                'sessionExpired'     => __( 'Session expired. Please log in again.', 'uptime-monitor-plus' ),
                'apiError'           => __( 'Unable to contact UptimeMonitor+', 'uptime-monitor-plus' ),
                'refresh'            => __( 'Refresh', 'uptime-monitor-plus' ),
                'justNow'            => __( 'just now', 'uptime-monitor-plus' ),
                'minutesAgo'         => __( 'minutes ago', 'uptime-monitor-plus' ),
                'hoursAgo'           => __( 'hours ago', 'uptime-monitor-plus' ),
                'daysAgo'            => __( 'days ago', 'uptime-monitor-plus' ),
                'responseTimeMs'     => __( 'Response Time (ms)', 'uptime-monitor-plus' ),
                'noErrors'           => __( 'No errors in the selected period', 'uptime-monitor-plus' ),
                'noChecks'           => __( 'No checks found', 'uptime-monitor-plus' ),
                'loadMore'           => __( 'Load more', 'uptime-monitor-plus' ),
                'checksForDate'      => __( 'Checks for', 'uptime-monitor-plus' ),
                'up'                 => __( 'UP', 'uptime-monitor-plus' ),
                'down'               => __( 'DOWN', 'uptime-monitor-plus' ),
                'calendarDays'       => __( 'Mon,Tue,Wed,Thu,Fri,Sat,Sun', 'uptime-monitor-plus' ),
                'sslValid'           => __( 'Valid', 'uptime-monitor-plus' ),
                'sslExpiring'        => __( 'Expiring', 'uptime-monitor-plus' ),
                'sslExpired'         => __( 'Expired', 'uptime-monitor-plus' ),
                'sslChainValid'      => __( 'Valid', 'uptime-monitor-plus' ),
                'sslChainInvalid'    => __( 'Invalid', 'uptime-monitor-plus' ),
                'noIncidents'        => __( 'No incidents recorded', 'uptime-monitor-plus' ),
                'incidentOngoing'    => __( 'Ongoing', 'uptime-monitor-plus' ),
                'incidentPageInfo'   => __( 'Page %1$s of %2$s', 'uptime-monitor-plus' ),
                'notifSaved'         => __( 'Notification settings saved', 'uptime-monitor-plus' ),
                'notifError'         => __( 'Error saving notification settings', 'uptime-monitor-plus' ),
                'invalidEmail'       => __( 'Invalid email address', 'uptime-monitor-plus' ),
                'statusConnected'    => __( 'Connected', 'uptime-monitor-plus' ),
                'statusDisconnected' => __( 'Disconnected', 'uptime-monitor-plus' ),
            ),
            'wp_timezone'          => wp_timezone_string(),
        ) );
    }
}