<?php

if (!function_exists('add_action')) {

  die('Please don\'t open this file directly!');

}





define('SSP_SETTING_VER', '1.0');

define('SSP_SETTING_OPTIONS_KEY', 'ssp_setting');



class ssp_setting {



  // init plugin

public static function init() {

    // does the user have enough privilages to use the plugin?

    if (is_admin() && current_user_can('administrator')) {

      add_filter('sn_tabs', array(__CLASS__, 'sn_tabs'));



      // enqueue scripts

      add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'));



      // check and set default settings

      self::default_settings(false);



      // settings registration

      add_action('admin_init', array(__CLASS__, 'register_settings'));

    } // if admin

  } // init



  // check if we're on the SN page

public static function is_plugin_page() {

    $current_screen = get_current_screen();



    if ($current_screen->id == 'toplevel_page_secure-scan-pro') {

      return true;

    } else {

      return false;

    }

  } // is_plugin_page





  // enqueue CSS and JS scripts on plugin's admin page

public static function enqueue_scripts() {

    if (self::is_plugin_page()) {

      $plugin_url = plugin_dir_url(__FILE__);



      wp_enqueue_style('wp-jquery-ui-dialog');

      wp_enqueue_script('jquery-ui-dialog');

    } // if

  } // enqueue_scripts





  // add new tab

public static function sn_tabs($tabs) {

    $schedule_tab = array('id' => 'sn_setting', 'class' => '', 'label' => 'Settings', 'callback' => array(__CLASS__, 'setting_page'));

    $done = 0;



    for ($i = 0; $i < sizeof($tabs); $i++) {

      if ($tabs[$i]['id'] == 'sn_setting') {

        $tabs[$i] = $schedule_tab;

        $done = 1;

        break;

      }

    } // for



    if (!$done) {

      $tabs[] = $schedule_tab;

    }



    return $tabs;

  } // sn_tabs



  // check if proper Core Scanner version exists

  function check_cs_version() {

    return true;

  } // check_cs_version





  // check if core scanner add-on is active

  function is_core_scanner_active() {

    return true;

  } // is_core_scanner_active





  // set default options

public static function default_settings($force = false) {

    $defaults = array('xml_rpc_disable' => '0');



    $options = get_option(SSP_SETTING_OPTIONS_KEY);



    if ($force || !$options) {

      update_option(SSP_SETTING_OPTIONS_KEY, $defaults);

    }

  } // default_settings





  // sanitize settings on save

  function sanitize_settings($values) {

      $old_options = get_option(SSP_SETTING_OPTIONS_KEY);

      if(isset($values) && isset($values['xml_rpc_disable']) && $values['xml_rpc_disable'] !== 0) {

          $values['xml_rpc_disable'] = 1;

      } else {

	  $values = array();

	  $values['xml_rpc_disable'] = 0;

      }

      

      return array_merge($old_options, $values);

  } // sanitize_settings



  // all settings are saved in one option key

public static function register_settings() {

    register_setting(SSP_SETTING_OPTIONS_KEY, SSP_SETTING_OPTIONS_KEY, array(__CLASS__, 'sanitize_settings'));

  } // register_settings





  // display results

public static function setting_page() {

    if (!current_user_can('administrator')) {

      echo 'Cheating, are you?';

      return;

    }



    $options = get_option(SSP_SETTING_OPTIONS_KEY);

    $xml_rpc_disable = $options['xml_rpc_disable'];

    $xml_rpc_checked = $xml_rpc_disable==1?'checked':'';





    echo '<form action="options.php" method="post">';



    settings_fields('ssp_setting');



    echo '<table class="form-table"><tbody>';



    echo '<tr valign="top" id="ssp-xml-rpc-enable">

    <th scope="row"><label for="xml_rpc_disable_to">Disable XML-RPC</label></th>

    <td><input style ="width:0px" type="checkbox" class="regular-text" id="xml_rpc_disable_to" name="ssp_setting[xml_rpc_disable]" '.$xml_rpc_checked.'  value="'.$xml_rpc_disable.'" />';

    echo '</td></tr>';



    echo '<tr valign="top"><td colspan="2">';

    echo '<p class="submit"><input type="submit" value="Save Changes" class="button-primary" name="Submit" />';

    echo '</td></tr>';



    echo '</table>';

    echo '</form>';



  } // core_page



} // ssp_setting class

?>