174 lines
6.1 KiB
PHP
174 lines
6.1 KiB
PHP
<?php
|
||
/**
|
||
* The admin-specific functionality of the module.
|
||
* @package OCVM
|
||
* @subpackage OCVM/admin
|
||
*/
|
||
|
||
/**
|
||
* The admin-specific functionality of the module.
|
||
*
|
||
* Defines the module name, version, and two examples hooks for how to
|
||
* enqueue the admin-specific stylesheet and JavaScript.
|
||
*
|
||
* @package OCVM
|
||
* @subpackage OCVM/admin
|
||
* @author one.com
|
||
*/
|
||
class OCVMAdmin {
|
||
|
||
|
||
/**
|
||
* The ID of this module.
|
||
* @access private
|
||
* @var string $OCVM The ID of this module.
|
||
*/
|
||
private $OCVM;
|
||
|
||
/**
|
||
* The version of this module.
|
||
* @access private
|
||
* @var string $version The current version of this module.
|
||
*
|
||
*/
|
||
private $version;
|
||
|
||
const page_slug = 'onecom-wp-vulnerability-monitor';
|
||
const menu_name = 'Vulnerability Monitor';
|
||
|
||
private $settings;
|
||
private string $folder;
|
||
private string $extension;
|
||
|
||
/**
|
||
* Initialize the class and set its properties.
|
||
* @param string $OCVM The name of this module.
|
||
* @param string $version The version of this module.
|
||
*/
|
||
public function __construct( $OCVM, $version ) {
|
||
$this->OCVM = $OCVM;
|
||
$this->version = $version;
|
||
|
||
// Get latest settings
|
||
$this->settings = new OCVMSettings();
|
||
|
||
$this->folder = ( SCRIPT_DEBUG || SCRIPT_DEBUG === 'true' ) ? '' : 'min-';
|
||
$this->extension = ( SCRIPT_DEBUG || SCRIPT_DEBUG === 'true' ) ? '' : '.min';
|
||
}
|
||
|
||
/**
|
||
* Add admin menu entry
|
||
*/
|
||
public function add_menu() {
|
||
add_submenu_page(
|
||
$this->settings::text_domain,
|
||
__( 'Vulnerability Monitor', 'onecom-wp' ),
|
||
'<span id="onecom_vulnerability_monitor">' . __( self::menu_name, 'onecom-wp' ) . '</span>',
|
||
'manage_options',
|
||
'onecom-wp-vulnerability-monitor',
|
||
array( $this, 'vm_page_callback' ),
|
||
-1
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Admin page callback
|
||
*/
|
||
public function vm_page_callback() {
|
||
require_once $this->settings->module_path . DIRECTORY_SEPARATOR . 'templates/vulnerability-monitor-admin-page.php';
|
||
}
|
||
|
||
/**
|
||
* Register the stylesheets for the admin area. */
|
||
public function enqueue_styles( $hook_suffix ) {
|
||
|
||
/**
|
||
* This function is provided for demonstration purposes only.
|
||
*
|
||
* An instance of this class should be passed to the run() function
|
||
* defined in OCVMLoader as all of the hooks are defined
|
||
* in that particular class.
|
||
*
|
||
* The OCVMLoader will then create the relationship
|
||
* between the defined hooks and the functions defined in this
|
||
* class.
|
||
*/
|
||
|
||
//Enqueue css only on HM page
|
||
if ( $hook_suffix === 'one-com_page_onecom-wp-health-monitor' ) {
|
||
wp_enqueue_style( 'ocvm-tagEditorStyle', plugin_dir_url( __DIR__ ) . 'assets/' . $this->folder . 'css/jquery.tag-editor' . $this->extension . '.css', array(), '', 'all' );
|
||
wp_enqueue_style( 'ocvm-DataTablesStyle', plugin_dir_url( __DIR__ ) . 'assets/min-css/jquery.dataTables.min.css', array(), $this->version, 'all' );
|
||
}
|
||
|
||
/**
|
||
* Enqueue Google fonts in all admin pages if Vulnerabilities Notifications are getting displayed
|
||
* More conditions can be added if google fonts needed for other notices as well
|
||
*/
|
||
$ocvmNotices = new OCVMNotifications();
|
||
$ocvmNotices->prepareNotifications();
|
||
if ( ( is_countable( $ocvmNotices->notices ) && count( $ocvmNotices->notices ) ) || $hook_suffix === 'one-com_page_onecom-wp-health-monitor' ) {
|
||
wp_enqueue_style( 'oc_sh_fonts', ONECOM_WP_URL . 'assets/css/onecom-fonts.css', array(), $this->version, 'all' );
|
||
wp_enqueue_style( $this->OCVM, plugin_dir_url( __DIR__ ) . 'assets/' . $this->folder . 'css/ocvm-admin' . $this->extension . '.css', array(), $this->version, 'all' );
|
||
}
|
||
|
||
// Localize the script for translation
|
||
wp_localize_script(
|
||
'oc_sh_js',
|
||
'vm_log_strings',
|
||
array(
|
||
'showing' => __( 'Showing', 'onecom-wp' ),
|
||
'to' => __( 'to', 'onecom-wp' ),
|
||
'of' => __( 'of', 'onecom-wp' ),
|
||
'entries' => __( 'entries', 'onecom-wp' ),
|
||
)
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Register the JavaScript for the admin area.
|
||
*/
|
||
public function enqueue_scripts( $hook_suffix ) {
|
||
|
||
/**
|
||
* This function is provided for demonstration purposes only.
|
||
*
|
||
* An instance of this class should be passed to the run() function
|
||
* defined in OCVMLoader as all of the hooks are defined
|
||
* in that particular class.
|
||
*
|
||
* The OCVMLoader will then create the relationship
|
||
* between the defined hooks and the functions defined in this
|
||
* class.
|
||
*/
|
||
|
||
if ( $hook_suffix === 'one-com_page_onecom-wp-health-monitor' ) {
|
||
wp_enqueue_script( 'ocvm-DataTablesScript', plugin_dir_url( __DIR__ ) . 'assets/min-js/jquery.dataTables.min.js', array( 'jquery' ), '', false );
|
||
}
|
||
|
||
wp_enqueue_script( 'ocvm-caretScript', plugin_dir_url( __DIR__ ) . 'assets/js/jquery.caret.min.js', array( 'jquery', 'media-upload', 'thickbox', 'wp-util', 'jquery-migrate' ), '', false );
|
||
wp_enqueue_script( 'ocvm-tageditorScript', plugin_dir_url( __DIR__ ) . 'assets/js/jquery.tag-editor.min.js', array( 'jquery' ), '', false );
|
||
wp_enqueue_script( $this->OCVM, plugin_dir_url( __DIR__ ) . 'assets/' . $this->folder . 'js/ocvm-admin' . $this->extension . '.js', array( 'jquery', 'ocvm-caretScript', 'ocvm-tageditorScript' ), $this->version, false );
|
||
//create object for localize into script
|
||
$popupBodylist = array(
|
||
__( 'Update instantly to the latest and most secure version', 'onecom-wp' ),
|
||
__( 'Track exploited vulnerabilities in real time', 'onecom-wp' ),
|
||
__( 'Unlock your website’s full vulnerability log', 'onecom-wp' ),
|
||
);
|
||
|
||
$popupContent = array(
|
||
'title' => sprintf( __( 'Repair vulnerabilities automatically with Managed WordPress', 'onecom-wp' ) ),
|
||
'top-desc' => sprintf( __( 'Tired of fixing vulnerabilities manually? Enjoy automated repairs in the background with Managed WordPress.', 'onecom-wp' ) ),
|
||
'footer-desc' => __( 'Managed WordPress includes other great features like Update Manager and priority support so you can skip the line when you need our help.', 'onecom-wp' ),
|
||
'bodylist' => $popupBodylist,
|
||
);
|
||
|
||
$ocvmObj = array(
|
||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||
'adminurl' => admin_url(),
|
||
'isPremium' => (int) $this->settings->isPremium(),
|
||
'popupContent' => $popupContent,
|
||
);
|
||
wp_localize_script( $this->OCVM, 'ocvmObj', $ocvmObj );
|
||
}
|
||
}
|