*/ class AIO_Tools_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. * * @since 1.0.0 */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; $this->load_dependencies_frameworks(); add_filter('plugin_action_links_'. AIO_BASE_NAME, [ $this,'aio_add_plugin_page_settings_link'], 10, 2); add_action( 'admin_bar_menu', [ $this, 'aio_add_admin_bar_links' ], 90 ); //add_action( 'init', [ $this, 'aio_set_notices' ] ); $this->create_settings_page(); add_action( 'wp_dashboard_setup', [ $this, 'aio_add_dashboard_widgets' ] ); add_action( 'admin_enqueue_scripts', 'add_thickbox' ); add_action( 'wp_ajax_aio_get_settings', [ $this, 'aio_get_settings_ajax' ] ); add_action( 'wp_ajax_aio_update_settings', [ $this, 'aio_update_settings_ajax' ] ); add_action( 'wp_ajax_aio_get_system_status', [ $this, 'aio_get_system_status_ajax' ] ); add_action( 'wp_ajax_aio_test_telegram_connection', [ $this, 'aio_test_telegram_connection_ajax' ] ); add_action( 'wp_ajax_aio_test_larksuite_connection', [ $this, 'aio_test_larksuite_connection_ajax' ] ); // Load sub-modules require_once AIO_ADMIN_PATH . 'modules/class-aio-security-admin.php'; require_once AIO_ADMIN_PATH . 'modules/class-aio-utility-admin.php'; require_once AIO_ADMIN_PATH . 'modules/class-aio-smtp-admin.php'; new AIO_Security_Admin(); new AIO_Utility_Admin(); new AIO_Smtp_Admin(); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { // Enqueue Phosphor Icons // phpcs:ignore PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent wp_enqueue_style( 'phosphor-icons', 'https://unpkg.com/@phosphor-icons/web@2.1.1/src/regular/style.css', array(), '2.1.1', 'all' ); // phpcs:ignore PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent wp_enqueue_style( 'phosphor-icons-fill', 'https://unpkg.com/@phosphor-icons/web@2.1.1/src/fill/style.css', array(), '2.1.1', 'all' ); wp_enqueue_style( $this->plugin_name, AIO_URL . 'assets/css/aio-tools-admin.css', array(), $this->version, 'all' ); wp_enqueue_style( 'mobile', AIO_URL . 'assets/css/responsive.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts( $hook_suffix ) { if ( strpos( $hook_suffix, 'aio-settings' ) !== false ) { wp_enqueue_media(); } wp_enqueue_script( $this->plugin_name, AIO_URL . 'assets/js/aio-tools-admin.js', array( 'jquery' ), $this->version, true ); wp_localize_script( $this->plugin_name , 'aio_smtp_param', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aio-smtp-check-nonce' ), 'settings_nonce' => wp_create_nonce( 'aio-settings-nonce' ), 'message' => array( 'sending' => __('Sending...','aio-tools'), 'success' => __('Success! Please check your email inbox.','aio-tools'), 'error' => __('The following error occured: ','aio-tools'), 'alertdata' => __('You have entered an invalid email address!','aio-tools'), ), ) ); } public function load_dependencies_frameworks() { require_once AIO_VENDOR_PATH . 'announce4wp/announce4wp-client.php'; } public function create_settings_page() { add_action( 'admin_menu', [ $this, 'aio_add_admin_menu' ] ); } public function aio_add_admin_menu() { $plugin_name = __('AIO Tools', 'aio-tools'); $menu_title = 'AIO Tools'; add_menu_page( $plugin_name, $menu_title, 'manage_options', 'aio-settings', [ $this, 'aio_display_settings_page' ], AIO_URL . 'assets/images/favicon.png', 4 ); add_submenu_page( 'aio-settings', __('Audit Logs', 'aio-tools'), __('Audit Logs', 'aio-tools'), 'manage_options', 'aio-audit-logs', [ $this, 'aio_display_audit_logs_page' ] ); } public function aio_display_audit_logs_page() { require_once AIO_ADMIN_PATH . 'partials/aio-audit-logs-display.php'; } public function aio_display_settings_page() { require_once AIO_ADMIN_PATH . 'partials/aio-tools-admin-display.php'; } public function aio_add_admin_bar_links( WP_Admin_Bar $admin_bar ) { if ( current_user_can( 'manage_options' ) ) { $menu_title = 'AIO Tools'; $admin_bar->add_menu( [ 'id' => 'aio-tools', 'title' => $menu_title, 'href' => admin_url( 'admin.php?page=aio-settings' ), 'meta' => [ 'target' => '_self', 'html' => '', ], ] ); } } public function aio_add_dashboard_widgets() { if ( !current_user_can('manage_options') ) return; $plugin_name = __('AIO Tools', 'aio-tools'); wp_add_dashboard_widget( 'aio_tools_dashboard_widget', $plugin_name . ' - ' . __('Overview', 'aio-tools'), [ $this, 'aio_dashboard_widget_render' ] ); } public function aio_dashboard_widget_render() { $plugin_name = __('AIO Tools', 'aio-tools'); ?>
' . sprintf( __( 'It looks like WP Mail SMTP is active on your site. WP Mail SMTP feature may cause conflict with %1$s.', 'aio-tools' ), AIO_PLUGIN_NAME ) . '', 'warning' ); } } public function aio_add_plugin_page_settings_link( $links ) { $aio_links[] = '' . esc_html__('Settings', 'aio-tools') . ''; return $aio_links + $links; } // SMTP functions moved to class-aio-smtp-admin.php public function aio_get_system_status_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio-tools' ) ); } $theme = wp_get_theme(); $status = [ 'wp_version' => get_bloginfo('version'), 'php_version' => phpversion(), 'theme_name' => $theme->get('Name'), 'plugin_version' => $this->version, 'server' => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : 'Unknown', ]; wp_send_json_success( $status ); } public function aio_get_settings_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio-tools' ) ); } $options = get_option( 'aio_options', [] ); // Hide sensitive data before sending to frontend if (isset($options['txtSmtpPassword']) && !empty($options['txtSmtpPassword'])) { $options['txtSmtpPassword'] = '********'; } if (isset($options['txtOAuthClientSecret']) && !empty($options['txtOAuthClientSecret'])) { $options['txtOAuthClientSecret'] = '********'; } wp_send_json_success( $options ); } // Moved functions out to sub-modules public function aio_update_settings_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio-tools' ) ); } // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash $raw_settings = isset($_POST['settings']) ? $_POST['settings'] : ''; $params = json_decode(wp_unslash($raw_settings), true); if ( !is_array($params) && !empty($raw_settings) ) { $params = json_decode($raw_settings, true); } if ( !is_array($params) ) { $params = []; } if ( is_array($params) ) { $sanitized_params = []; foreach ($params as $key => $value) { if (in_array($key, ['optHeader', 'optFooter', 'txtTawktoScript', 'txtChativeScript'])) { if ( current_user_can( 'unfiltered_html' ) ) { $sanitized_params[$key] = $value; } else { $sanitized_params[$key] = wp_kses_post($value); } } else if (is_array($value)) { $sanitized_params[$key] = $this->aio_sanitize_array_recursive($value); } else { // Strict validation for specific fields if (in_array($key, ['txtSmtpPort', 'optLimitLoginMax', 'optLimitLoginDuration', 'optHeartbeatInterval', 'optRevisionsLimit', 'optAutosaveInterval'])) { $sanitized_params[$key] = absint($value); } else { $sanitized_params[$key] = sanitize_text_field($value); } if (in_array($key, ['txtSmtpPassword', 'txtOAuthClientSecret'])) { if (empty($sanitized_params[$key]) || $sanitized_params[$key] === '********') { // Keep old password $old_options = get_option('aio_options', []); $sanitized_params[$key] = isset($old_options[$key]) ? $old_options[$key] : ''; } else { $sanitized_params[$key] = AIO_Crypto::encrypt($sanitized_params[$key]); } } } } update_option( 'aio_options', $sanitized_params ); wp_send_json_success( [ 'message' => __( 'Settings saved successfully', 'aio-tools' ) ] ); } else { wp_send_json_error( __( 'Invalid data', 'aio-tools' ) ); } } private function aio_sanitize_array_recursive($array) { $sanitized = []; foreach ($array as $key => $value) { if (is_array($value)) { $sanitized[$key] = $this->aio_sanitize_array_recursive($value); } else { $sanitized[$key] = sanitize_text_field($value); } } return $sanitized; } public function aio_test_telegram_connection_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio-tools' ) ); } $token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; $chat_id = isset( $_POST['chat_id'] ) ? sanitize_text_field( wp_unslash( $_POST['chat_id'] ) ) : ''; if ( empty( $token ) || empty( $chat_id ) ) { wp_send_json_error( __( 'Please provide both Bot Token and Chat ID.', 'aio-tools' ) ); } $url = "https://api.telegram.org/bot{$token}/sendMessage"; $message = "🎉 " . __( 'AIO Tools: Connection Successful!', 'aio-tools' ) . "\n"; $message .= __( 'Your Telegram notification settings are configured correctly.', 'aio-tools' ) . "\n"; $message .= __( 'Domain:', 'aio-tools' ) . " " . ( isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '' ) . "\n"; $message .= __( 'Time:', 'aio-tools' ) . " " . current_time( 'Y-m-d H:i:s' ); $response = wp_remote_post( $url, [ 'body' => [ 'chat_id' => $chat_id, 'text' => $message, 'parse_mode' => 'HTML' ], 'timeout' => 15 ] ); if ( is_wp_error( $response ) ) { wp_send_json_error( $response->get_error_message() ); } $status_code = wp_remote_retrieve_response_code( $response ); $body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( $status_code == 200 && isset( $body['ok'] ) && $body['ok'] === true ) { wp_send_json_success( __( 'Test message sent successfully!', 'aio-tools' ) ); } else { $error_msg = isset( $body['description'] ) ? $body['description'] : __( 'Unknown error', 'aio-tools' ); wp_send_json_error( sprintf( __( 'Telegram API Error: %s', 'aio-tools' ), $error_msg ) ); } } public function aio_test_larksuite_connection_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio-tools' ) ); } $webhook = isset( $_POST['webhook'] ) ? sanitize_url( wp_unslash( $_POST['webhook'] ) ) : ''; if ( empty( $webhook ) ) { wp_send_json_error( __( 'Please provide the Webhook URL.', 'aio-tools' ) ); } $message = "🎉 AIO Tools: Connection Successful!\n"; $message .= "Your Larksuite notification settings are configured correctly.\n"; $message .= "Domain: " . ( isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '' ) . "\n"; $message .= "Time: " . current_time( 'Y-m-d H:i:s' ); $body = [ 'msg_type' => 'post', 'content' => [ 'post' => [ 'vi_vn' => [ 'title' => __( 'AIO Tools Connection Test', 'aio-tools' ), 'content' => [ [ [ 'tag' => 'text', 'text' => $message ] ] ] ] ] ] ]; $response = wp_remote_post( $webhook, [ 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => wp_json_encode( $body ), 'timeout' => 15 ] ); if ( is_wp_error( $response ) ) { wp_send_json_error( $response->get_error_message() ); } $status_code = wp_remote_retrieve_response_code( $response ); $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( $status_code == 200 && isset( $response_body['code'] ) && $response_body['code'] === 0 ) { wp_send_json_success( __( 'Test message sent successfully!', 'aio-tools' ) ); } else { $error_msg = isset( $response_body['msg'] ) ? $response_body['msg'] : __( 'Unknown error', 'aio-tools' ); wp_send_json_error( sprintf( __( 'Larksuite API Error: %s', 'aio-tools' ), $error_msg ) ); } } private function aio_get_email_message_html() { ob_start(); ?>
|