Advertisement
dedotombo

WP Cassify - Modified admin-menu.php

Oct 3rd, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 74.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace wp_cassify;
  4.  
  5. class WP_Cassify_Admin_Page {
  6.  
  7.     public $wp_cassify_plugin_datas;
  8.     public $wp_cassify_plugin_directory;
  9.     public $wp_cassify_network_activated;
  10.     public $wp_cassify_plugin_options_list;
  11.     public $wp_cassify_default_login_servlet;
  12.     public $wp_cassify_default_logout_servlet;
  13.     public $wp_cassify_default_service_validate_servlet;
  14.     public $wp_cassify_default_ssl_cipher_values = array();
  15.     public $wp_cassify_default_ssl_check_certificate;
  16.     public $wp_cassify_default_xpath_query_to_extact_cas_user;
  17.     public $wp_cassify_default_xpath_query_to_extact_cas_attributes;
  18.     public $wp_cassify_default_notifications_options;
  19.     public $wp_cassify_default_expirations_options;
  20.     public $wp_cassify_default_allow_deny_order;
  21.     public $wp_cassify_wordpress_user_meta_list;
  22.        
  23.     private $wp_cassify_admin_page_slug;
  24.     private $wp_cassify_multisite_admin_page_slug;
  25.    
  26.     private $wp_cassify_admin_page_hook;
  27.        
  28.     /**
  29.      * Constructor
  30.      */
  31.     public function __construct() {
  32.     }
  33.    
  34.     public function init_parameters(
  35.         $wp_cassify_plugin_datas,
  36.         $wp_cassify_plugin_directory,
  37.         $wp_cassify_network_activated,
  38.         $wp_cassify_plugin_options_list,
  39.         $wp_cassify_default_protocol_version_values,
  40.         $wp_cassify_default_login_servlet,
  41.         $wp_cassify_default_logout_servlet,
  42.         $wp_cassify_default_service_validate_servlet,
  43.         $wp_cassify_default_ssl_cipher_values,
  44.         $wp_cassify_default_ssl_check_certificate,
  45.         $wp_cassify_default_xpath_query_to_extact_cas_user,
  46.         $wp_cassify_default_xpath_query_to_extact_cas_attributes,
  47.         $wp_cassify_default_notifications_options,
  48.         $wp_cassify_default_expirations_options,
  49.         $wp_cassify_default_allow_deny_order,
  50.         $wp_cassify_wordpress_user_meta_list
  51.     ) {
  52.         $this->wp_cassify_plugin_datas = $wp_cassify_plugin_datas;
  53.         $this->wp_cassify_plugin_directory = $wp_cassify_plugin_directory;
  54.         $this->wp_cassify_network_activated = $wp_cassify_network_activated;
  55.         $this->wp_cassify_plugin_options_list = $wp_cassify_plugin_options_list;
  56.         $this->wp_cassify_default_protocol_version_values = $wp_cassify_default_protocol_version_values;
  57.         $this->wp_cassify_default_ssl_check_certificate = $wp_cassify_default_ssl_check_certificate;
  58.         $this->wp_cassify_default_login_servlet = $wp_cassify_default_login_servlet;
  59.         $this->wp_cassify_default_logout_servlet = $wp_cassify_default_logout_servlet;
  60.         $this->wp_cassify_default_service_validate_servlet = $wp_cassify_default_service_validate_servlet;
  61.         $this->wp_cassify_default_ssl_cipher_values = $wp_cassify_default_ssl_cipher_values;
  62.         $this->wp_cassify_default_xpath_query_to_extact_cas_user = $wp_cassify_default_xpath_query_to_extact_cas_user;
  63.         $this->wp_cassify_default_xpath_query_to_extact_cas_attributes = $wp_cassify_default_xpath_query_to_extact_cas_attributes;
  64.         $this->wp_cassify_default_notifications_options = $wp_cassify_default_notifications_options;
  65.         $this->wp_cassify_default_expirations_options = $wp_cassify_default_expirations_options;
  66.         $this->wp_cassify_default_allow_deny_order = $wp_cassify_default_allow_deny_order;
  67.         $this->wp_cassify_wordpress_user_meta_list = $wp_cassify_wordpress_user_meta_list;
  68.        
  69.         $this->wp_cassify_admin_page_slug = 'options-general.php';
  70.         $this->wp_cassify_multisite_admin_page_slug = 'settings.php';
  71.        
  72.         // Add the actions
  73.         if ( $this->wp_cassify_network_activated ) {
  74.             add_action( 'network_admin_menu', array( $this , 'wp_cassify_create_network_menu' ) );
  75.         }
  76.         else {
  77.             add_action( 'admin_menu', array( $this , 'wp_cassify_create_menu' ) );
  78.         }
  79.     }  
  80.    
  81.     /**
  82.      *  Add admin menu options
  83.      */
  84.     public function wp_cassify_create_menu() {
  85.  
  86.         $this->wp_cassify_admin_page_hook = add_options_page( $this->wp_cassify_plugin_datas['Name'] . ' Options',
  87.             $this->wp_cassify_plugin_datas['Name'],
  88.             'manage_options',
  89.             'wp-cassify.php' ,
  90.             array( $this, 'wp_cassify_options' )
  91.          );
  92.          
  93.         // Add javascript needed by metaboxes
  94.         add_action( 'admin_init', array( $this , 'wp_cassify_add_metaboxes_js' ) );          
  95.          
  96.         // Call export plugin configurations settings function
  97.         add_action( 'load-'. $this->wp_cassify_admin_page_hook, array( $this , 'wp_cassify_export_configuration_options_settings' ) );
  98.  
  99.         // Call import plugin configurations settings function
  100.         add_action( 'load-'. $this->wp_cassify_admin_page_hook, array( $this , 'wp_cassify_import_configuration_options_settings' ) );
  101.          
  102.         // Register differents metaboxes on admin screen.
  103.         add_action( 'load-'. $this->wp_cassify_admin_page_hook, array( $this, 'wp_cassify_register_metaboxes' ) );  
  104.        
  105.         // Add custom javascript functions specific to this plugin
  106.         add_action( 'load-'. $this->wp_cassify_admin_page_hook, array( $this , 'wp_cassify_add_custom_js' ) );
  107.     }
  108.    
  109.     /**
  110.      *  Add admin menu options if plugin is activate over the network
  111.      */        
  112.     public function wp_cassify_create_network_menu() {
  113.  
  114.         $this->wp_cassify_admin_page_hook = add_submenu_page(
  115.             'settings.php',
  116.             $this->wp_cassify_plugin_datas['Name'] . ' Options',
  117.             $this->wp_cassify_plugin_datas['Name'],
  118.             'manage_options',
  119.             'wp-cassify.php' ,
  120.             array( $this, 'wp_cassify_options' )
  121.          );
  122.  
  123.         // Call register settings function
  124.         add_action( 'admin_init', array( $this , 'wp_cassify_register_plugin_settings' ) );
  125.  
  126.         // Call register settings function
  127.         add_action( 'admin_init', array( $this , 'wp_cassify_register_plugin_settings' ) );
  128.  
  129.         // Add javascript needed by metaboxes
  130.         add_action( 'admin_init', array( $this , 'wp_cassify_add_metaboxes_js' ) );
  131.        
  132.         // Register differents metaboxes on admin screen.
  133.         add_action( 'load-'. $this->wp_cassify_admin_page_hook, array( $this, 'wp_cassify_register_metaboxes' ) );  
  134.        
  135.         // Add custom javascript functions specific to this plugin
  136.         add_action( 'load-'. $this->wp_cassify_admin_page_hook, array( $this , 'wp_cassify_add_custom_js' ) ); 
  137.     }
  138.    
  139.     /**
  140.      * Add javascript needed by metaboxes
  141.      */
  142.      public function wp_cassify_add_metaboxes_js() {
  143.        
  144.         // Ensure, that the needed javascripts been loaded to allow drag/drop, expand/collapse and hide/show of boxes
  145.         wp_enqueue_script( 'common' );
  146.         wp_enqueue_script( 'wp-lists' );
  147.         wp_enqueue_script( 'postbox' );    
  148.      }
  149.    
  150.     /**
  151.      * Add js functions to admin option page.
  152.      */
  153.     public function wp_cassify_add_custom_js() {   
  154.  
  155.         wp_register_script(
  156.             'wp_cassify_custom_js',
  157.             $this->wp_cassify_plugin_directory . 'js/functions.js',
  158.             array( 'jquery' ),
  159.             '1.0',
  160.             TRUE
  161.         );
  162.        
  163.         wp_localize_script( 'wp_cassify_custom_js', 'wp_cassify_screen_data', $this->wp_cassify_get_screen_data() );
  164.         wp_enqueue_script( 'wp_cassify_custom_js' );
  165.        
  166.         // Add jQuery Datepicker control
  167.         wp_enqueue_script( 'jquery-ui-datepicker', false, array( 'jquery' ) );
  168.         wp_enqueue_style( 'jquery-ui-style', $this->wp_cassify_plugin_directory . 'css/jquery-ui.min.css' );
  169.     }  
  170.    
  171.     /**
  172.      * Get the last form submit button id clicked by user.
  173.      * @return $screen_data
  174.      */
  175.     public function wp_cassify_get_screen_data() {
  176.        
  177.         $screen_data = array();
  178.        
  179.         if ( ( isset( $_POST[ 'action' ] ) ) && ( $_POST[ 'action' ] == 'update' ) ) {    
  180.  
  181.             // Check security tocken
  182.             if (! wp_verify_nonce( $_POST[ 'wp_cassify_admin_form' ], 'admin_form' ) ) {
  183.                 die( 'Security Check !' );
  184.             }
  185.            
  186.             $posted_values = array_values( $_POST );
  187.  
  188.             if ( in_array( 'Save options', $posted_values ) ) {
  189.                 $screen_data[ 'scrollToId' ] = sanitize_text_field( array_search( 'Save options',  $_POST ) );
  190.             }
  191.            
  192.             if ( in_array( 'Send test message', $posted_values ) ) {   
  193.                 $screen_data[ 'scrollToId' ] = sanitize_text_field( array_search( 'Send test message',  $_POST ) );
  194.             }          
  195.         }
  196.        
  197.         return $screen_data;
  198.     }  
  199.    
  200.     /**
  201.      * Register the differents metaboxes availables on admin screen.
  202.      */
  203.     public function wp_cassify_register_metaboxes() {
  204.  
  205.         add_meta_box(
  206.             'wp_cassify_metabox_general_settings',
  207.             'General Settings',
  208.             array( $this, 'wp_cassify_add_metabox_general_settings' ),
  209.             $this->wp_cassify_admin_page_hook,
  210.             'normal',
  211.             'high'
  212.         );
  213.        
  214.         add_meta_box(
  215.             'wp_cassify_metabox_urls_settings',
  216.             'Urls Settings',
  217.             array( $this, 'wp_cassify_add_metabox_urls_settings' ),
  218.             $this->wp_cassify_admin_page_hook,
  219.             'normal',
  220.             'high'
  221.         ); 
  222.  
  223.         add_meta_box(
  224.             'wp_cassify_metabox_attributes_extraction_settings',
  225.             'Attributes Extraction Settings',
  226.             array( $this, 'wp_cassify_add_metabox_attributes_extraction_settings' ),
  227.             $this->wp_cassify_admin_page_hook,
  228.             'normal',
  229.             'high'
  230.         ); 
  231.  
  232.         add_meta_box(
  233.             'wp_cassify_metabox_authorization_rules_settings',
  234.             'Authorization Rules Settings',
  235.             array( $this, 'wp_cassify_add_metabox_authorization_rules_settings' ),
  236.             $this->wp_cassify_admin_page_hook,
  237.             'normal',
  238.             'high'
  239.         );
  240.  
  241.         add_meta_box(
  242.             'wp_cassify_metabox_users_roles_settings',
  243.             'Users Roles Settings',
  244.             array( $this, 'wp_cassify_add_metabox_users_roles_settings' ),
  245.             $this->wp_cassify_admin_page_hook,
  246.             'normal',
  247.             'high'
  248.         );
  249.  
  250.         add_meta_box(
  251.             'wp_cassify_metabox_users_attributes_synchronization_settings',
  252.             'Users Attributes Synchronization Settings',
  253.             array( $this, 'wp_cassify_add_metabox_users_attributes_synchronization_settings' ),
  254.             $this->wp_cassify_admin_page_hook,
  255.             'normal',
  256.             'high'
  257.         );
  258.        
  259.         add_meta_box(
  260.             'wp_cassify_metabox_notifications_settings',
  261.             'Notifications Settings',
  262.             array( $this, 'wp_cassify_add_metabox_notifications_settings' ),
  263.             $this->wp_cassify_admin_page_hook,
  264.             'normal',
  265.             'high'
  266.         ); 
  267.        
  268.         add_meta_box(
  269.             'wp_cassify_metabox_notifications_rules_settings',
  270.             'Notifications Rules Settings',
  271.             array( $this, 'wp_cassify_add_metabox_notifications_rules_settings' ),
  272.             $this->wp_cassify_admin_page_hook,
  273.             'normal',
  274.             'high'
  275.         ); 
  276.        
  277.         add_meta_box(
  278.             'wp_cassify_metabox_expirations_rules_settings',
  279.             'Expirations Rules Settings',
  280.             array( $this, 'wp_cassify_add_metabox_expirations_rules_settings' ),
  281.             $this->wp_cassify_admin_page_hook,
  282.             'normal',
  283.             'high'
  284.         ); 
  285.        
  286.         add_meta_box(
  287.             'wp_cassify_metabox_debug_settings',
  288.             'Debug Settings',
  289.             array( $this, 'wp_cassify_add_metabox_debug_settings' ),
  290.             $this->wp_cassify_admin_page_hook,
  291.             'normal',
  292.             'high'
  293.         );         
  294.        
  295.         add_meta_box(
  296.             'wp_cassify_metabox_backup_restore_configuration_settings',
  297.             'Backup / Restore configuration settings',
  298.             array( $this, 'wp_cassify_add_metabox_backup_restore_configuration_settings' ),
  299.             $this->wp_cassify_admin_page_hook,
  300.             'normal',
  301.             'high'
  302.         );     
  303.        
  304.         // Side boxes
  305.         add_meta_box(
  306.             'wp_cassify_metabox_plugin_brand',
  307.             'WP Cassify',
  308.             array( $this, 'wp_cassify_add_metabox_plugin_brand' ),
  309.             $this->wp_cassify_admin_page_hook,
  310.             'side',
  311.             'high'
  312.         ); 
  313.        
  314.         add_meta_box(
  315.             'wp_cassify_metabox_online_documentation',
  316.             'Online Documentation',
  317.             array( $this, 'wp_cassify_add_metabox_online_documentation' ),
  318.             $this->wp_cassify_admin_page_hook,
  319.             'side',
  320.             'high'
  321.         );     
  322.     }
  323.    
  324.     /**
  325.      * Display html output for metabox Plugin Brand.
  326.      */
  327.     public function wp_cassify_add_metabox_plugin_brand() {
  328. ?>
  329.     <div class="wp_cassify_brand"><img src="<?php echo $this->wp_cassify_plugin_directory . '/images/wp-cassify-logo.png'; ?>" /></div>
  330. <?php                  
  331.     }  
  332.    
  333.     /**
  334.      * Display html output for metabox Online documentation.
  335.      */
  336.     public function wp_cassify_add_metabox_online_documentation() {
  337. ?>
  338.         <ul>
  339.             <li><a href="https://wpcassify.wordpress.com/wp-cassify-plugin-documentation/" target="_blank">Full options documentation</a></li>
  340.             <li><a href="https://wpcassify.wordpress.com/getting-started/" target="_blank">Screencasts</a></li>
  341.             <li><a href="https://wordpress.org/plugins/wp-cassify/faq/">FAQ</a></li>
  342.             <li><a href="https://wordpress.org/support/plugin/wp-cassify">Support</a></li>
  343.         </ul>
  344. <?php                  
  345.     }
  346.    
  347.     /**
  348.      * Display html output for metabox General Settings.
  349.      */
  350.     public function wp_cassify_add_metabox_general_settings() {
  351.        
  352.         $wp_cassify_protocol_version = WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_protocol_version' );
  353.  
  354.         if (! empty( $wp_cassify_protocol_version ) ) {
  355.             $wp_cassify_default_protocol_version_selected = $wp_cassify_protocol_version;
  356.         }
  357.         else {
  358.             $wp_cassify_default_protocol_version_selected = $this->wp_cassify_default_protocol_version_values[ '3' ]; // Default version 3.
  359.         }
  360.  
  361.         $is_disabled = FALSE;
  362.  
  363.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_disable_authentication' ) == 'disabled' ) {
  364.             $is_disabled = TRUE;
  365.         }
  366.         else {
  367.             $is_disabled = FALSE;
  368.         }
  369.  
  370.         $create_user_if_not_exist = FALSE; 
  371.  
  372.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_create_user_if_not_exist' ) == 'create_user_if_not_exist' ) {
  373.             $create_user_if_not_exist = TRUE;
  374.         }
  375.         else {
  376.             $create_user_if_not_exist = FALSE;
  377.         }
  378.  
  379.         $enable_gateway_mode = FALSE;  
  380.  
  381.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_enable_gateway_mode' ) == 'enable_gateway_mode' ) {
  382.             $enable_gateway_mode = TRUE;
  383.         }
  384.         else {
  385.             $enable_gateway_mode = FALSE;
  386.         }
  387.  
  388.         $enable_sso = FALSE;   
  389.  
  390.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_enable_sso' ) == 'enable_sso' ) {
  391.             $enable_sso = TRUE;
  392.         }
  393.         else {
  394.             $enable_sso = FALSE;
  395.         }
  396.        
  397.         $wp_cassify_ssl_cipher = WP_Cassify_Utils::wp_cassify_get_option(
  398.             $this->wp_cassify_network_activated,
  399.             'wp_cassify_ssl_cipher'
  400.         );
  401.  
  402.         if ( isset( $wp_cassify_ssl_cipher ) ) {
  403.             $wp_cassify_ssl_cipher_selected = $wp_cassify_ssl_cipher;
  404.         }
  405.         else {
  406.             $wp_cassify_ssl_cipher_selected = '0';
  407.         }
  408.        
  409.         $is_ssl_check_certificate_enabled = FALSE;
  410.  
  411.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_ssl_check_certificate' ) == 'enabled' ) {
  412.             $is_ssl_check_certificate_enabled = TRUE;
  413.         }
  414.         else {
  415.             $is_ssl_check_certificate_enabled = FALSE;
  416.         }      
  417. ?>
  418.         <table class="optiontable form-table">
  419.             <tr valign="top">
  420.                 <th scope="row"><label for="wp_cassify_base_url">CAS Server base url</label></th>
  421.                 <td>
  422.                     <input type="text" id="wp_cassify_base_url" name="wp_cassify_base_url" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_base_url' ) ); ?>" size="40" class="regular-text post_form" />
  423.                     <br /><span class="description">Example : https://you-cas-server/cas/ </span>
  424.                 </td>
  425.             </tr>
  426.             <tr valign="top">
  427.                 <th scope="row">CAS Version protocol</th>
  428.                 <td>
  429.                     <select id="wp_cassify_protocol_version" name="wp_cassify_protocol_version" class="post_form">
  430.                         <?php foreach ( $this->wp_cassify_default_protocol_version_values as $wp_cassify_default_protocol_version_key => $wp_cassify_default_protocol_version_value ) { ?>
  431.                             <?php if ( $wp_cassify_default_protocol_version_value == $wp_cassify_default_protocol_version_selected ) { ?>
  432.                                 <option value="<?php echo $wp_cassify_default_protocol_version_key; ?>" selected><?php echo $wp_cassify_default_protocol_version_value; ?></option>
  433.                             <?php } else { ?>
  434.                                 <option value="<?php echo $wp_cassify_default_protocol_version_key; ?>"><?php echo $wp_cassify_default_protocol_version_value; ?></option>
  435.                             <?php } ?>                     
  436.                         <?php } ?>
  437.                     </select>
  438.                     <br /><span class="description">Default value : <?php echo $this->wp_cassify_default_protocol_version_values[ '3' ]; ?></span>
  439.                 </td>
  440.             </tr>
  441.             <tr valign="top">
  442.                 <th scope="row">Disable CAS Authentication</th>
  443.                 <?php if ( $is_disabled ) { ?>
  444.                 <td><input type="checkbox" id="wp_cassify_disable_authentication" name="wp_cassify_disable_authentication" class="post_form" value="disabled" checked /></td>
  445.                 <?php } else { ?>
  446.                 <td><input type="checkbox" id="wp_cassify_disable_authentication" name="wp_cassify_disable_authentication" class="post_form" value="disabled" /></td>
  447.                 <?php }?>
  448.             </tr>
  449.             <tr valign="top">
  450.                 <th scope="row">Create user if not exist</th>
  451.                 <?php if ( $create_user_if_not_exist ) { ?>
  452.                 <td><input type="checkbox" id="wp_cassify_create_user_if_not_exist" name="wp_cassify_create_user_if_not_exist" class="post_form" value="create_user_if_not_exist" checked /><br /><span class="description">Create wordpress user account if not exist.</span></td>
  453.                 <?php } else { ?>
  454.                 <td><input type="checkbox" id="wp_cassify_create_user_if_not_exist" name="wp_cassify_create_user_if_not_exist" class="post_form" value="create_user_if_not_exist" /><br /><span class="description">Create wordpress user account if not exist.</span></td>
  455.                 <?php }?>
  456.             </tr>
  457.             <tr valign="top">
  458.                 <th scope="row">Enable Gateway Mode</th>
  459.                 <?php if ( $enable_gateway_mode ) { ?>
  460.                 <td><input type="checkbox" id="wp_cassify_enable_gateway_mode" name="wp_cassify_enable_gateway_mode" class="post_form" value="enable_gateway_mode" checked /><br /><span class="description">Enable support for auto-login (Gateway Mode).</span></td>
  461.                 <?php } else { ?>
  462.                 <td><input type="checkbox" id="wp_cassify_enable_gateway_mode" name="wp_cassify_enable_gateway_mode" class="post_form" value="enable_gateway_mode" /><br /><span class="description">Enable support for auto-login (Gateway Mode).</span></td>
  463.                 <?php }?>
  464.             </tr>
  465.             <tr valign="top">
  466.                 <th scope="row">Enable SSO</th>
  467.                 <?php if ( $enable_sso ) { ?>
  468.                 <td><input type="checkbox" id="wp_cassify_enable_sso" name="wp_cassify_enable_sso" class="post_form" value="enable_sso" checked /><br /><span class="description">Enable support for central logout (Single Sign Out).</span></td>
  469.                 <?php } else { ?>
  470.                 <td><input type="checkbox" id="wp_cassify_enable_sso" name="wp_cassify_enable_sso" class="post_form" value="enable_sso" /><br /><span class="description">Enable support for central logout (Single Sign Out).</span></td>
  471.                 <?php }?>
  472.             </tr>
  473.             <tr valign="top">
  474.                 <th scope="row">SSL Cipher used for query CAS Server with HTTPS Webrequest to validate service ticket</th>
  475.                 <td>
  476.                     <select id="wp_cassify_ssl_cipher" name="wp_cassify_ssl_cipher" class="post_form">
  477.                         <?php foreach ( $this->wp_cassify_default_ssl_cipher_values as $cipher_id => $cipher_name ) { ?>
  478.                             <?php if ( $cipher_id == $wp_cassify_ssl_cipher_selected ) { ?>
  479.                                 <option value="<?php echo $cipher_id; ?>" selected><?php echo $cipher_name; ?></option>
  480.                             <?php } else { ?>
  481.                                 <option value="<?php echo $cipher_id; ?>"><?php echo $cipher_name; ?></option>
  482.                             <?php } ?>                     
  483.                         <?php } ?>
  484.                     </select>
  485.                     <br /><span class="description">Default value : <?php echo $this->wp_cassify_default_ssl_cipher_values[ '0' ]; ?></span>
  486.                 </td>
  487.             </tr>
  488.             <tr valign="top">
  489.                 <th scope="row">Enable SSL Certificate Check</th>
  490.                 <?php if ( $is_ssl_check_certificate_enabled ) { ?>
  491.                 <td><input type="checkbox" name="wp_cassify_ssl_check_certificate" class="post_form" value="enabled" checked /></td>
  492.                 <?php } else { ?>
  493.                 <td><input type="checkbox" name="wp_cassify_ssl_check_certificate" class="post_form" value="enabled" /></td>
  494.                 <?php }?>
  495.             </tr>      
  496.         </table>
  497.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_general_settings', FALSE, array( 'id' => 'wp_cassify_save_options_general_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  498. <?php      
  499.     }
  500.    
  501.     /**
  502.      * Display html output for metabox Url Settings.
  503.      */    
  504.     public function wp_cassify_add_metabox_urls_settings() {
  505. ?>
  506.         <table class="optiontable form-table">
  507.             <tr valign="top">
  508.                 <th scope="row"><label for="wp_cassify_redirect_url_after_logout">Service logout redirect url</label></th>
  509.                 <td>
  510.                     <input type="text" id="wp_cassify_redirect_url_after_logout" name="wp_cassify_redirect_url_after_logout" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_redirect_url_after_logout' ) ); ?>" size="40" class="regular-text post_form" />
  511.                     <br /><span class="description">The blog home url is used when this option is not set .Url where the CAS Server redirect after logout. CAS Server must be configured correctly (see : followServiceRedirects option in JASIG documentation) </span>
  512.                 </td>
  513.             </tr>
  514.             <tr valign="top">
  515.                 <th scope="row"><label for="wp_cassify_override_service_url">Override service callback url</label></th>
  516.                 <td>
  517.                     <input type="text" id="wp_cassify_override_service_url" name="wp_cassify_override_service_url" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_override_service_url' ) ); ?>" size="40" class="regular-text post_form" />
  518.                     <br /><span class="description">In multisite context, use this option if you want override service url parameter before beeing redirected to CAS. For example : https://my-current-domain.org?site={WP_CASSIFY_CURRENT_SERVICE_URL}.
  519.                         Then when you try to access to https://blog1.my-current-domain.org/wp-admin/, you will be redirected to https://my-cas-server.org/cas/login?service=https://my-current-domain.org?site=https://blog1.my-current-domain.org/wp-admin/
  520.                     </span>
  521.                 </td>
  522.             </tr>          
  523.             <tr valign="top">
  524.                 <td colspan="2">Update servlets name only if you have customized your CAS Server.</td>
  525.             </tr>
  526.             <tr valign="top">
  527.                 <th scope="row">Name of the login servlet (Default : <?php echo $this->wp_cassify_default_login_servlet; ?>)</th>
  528.                 <td><input type="text" id="wp_cassify_login_servlet" name="wp_cassify_login_servlet" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_login_servlet' ) ); ?>" size="40" class="regular-text post_form" /></td>
  529.             </tr>
  530.             <tr valign="top">
  531.                 <th scope="row">Name of the logout servlet (Default : <?php echo $this->wp_cassify_default_logout_servlet; ?>)</th>
  532.                 <td><input type="text" id="wp_cassify_logout_servlet" name="wp_cassify_logout_servlet" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_logout_servlet' ) ); ?>" size="40" class="regular-text post_form" /></td>
  533.             </tr>
  534.             <tr valign="top">
  535.                 <th scope="row">Name of the service validate servlet (Default : <?php echo $this->wp_cassify_default_service_validate_servlet; ?>)</th>
  536.                 <td><input type="text" id="wp_cassify_service_validate_servlet" name="wp_cassify_service_validate_servlet" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_service_validate_servlet' ) ); ?>" size="40" class="regular-text post_form" /></td>
  537.             </tr>
  538.         </table>
  539.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_urls_settings', FALSE, array( 'id' => 'wp_cassify_save_options_urls_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>  
  540. <?php
  541.     }
  542.  
  543.     /**
  544.      * Display html output for metabox Attribute extraction Settings.
  545.      */    
  546.     public function wp_cassify_add_metabox_attributes_extraction_settings() {
  547. ?>
  548.         <table class="optiontable form-table">
  549.             <tr valign="top">
  550.                 <th scope="row">Xpath query used to extract cas user id during parsing</th>
  551.                 <td>
  552.                     <input type="text" id="wp_cassify_xpath_query_to_extact_cas_user" name="wp_cassify_xpath_query_to_extact_cas_user" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_xpath_query_to_extact_cas_user' ) ); ?>" size="40" class="regular-text post_form" />
  553.                     <br /><span class="description">(Default : <?php echo $this->wp_cassify_default_xpath_query_to_extact_cas_user; ?>)</span>
  554.                 </td>
  555.             </tr>  
  556.             <tr valign="top">
  557.                 <th scope="row">Xpath query used to extract cas user attributes during parsing</th>
  558.                 <td>
  559.                     <input type="text" id="wp_cassify_xpath_query_to_extact_cas_attributes" name="wp_cassify_xpath_query_to_extact_cas_attributes" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_xpath_query_to_extact_cas_attributes' ) ); ?>" size="40" class="regular-text post_form" />
  560.                     <br /><span class="description">(Default : <?php echo $this->wp_cassify_default_xpath_query_to_extact_cas_attributes; ?>)</span>
  561.                 </td>
  562.             </tr>
  563.             <tr valign="top">
  564.                 <th scope="row">Cas user attributes you want to populate into session.</th>
  565.                 <td>
  566.                     <input type="text" id="wp_cassify_attributes_list" name="wp_cassify_attributes_list" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_attributes_list' ) ); ?>" size="40" class="regular-text post_form" />
  567.                     <br /><span class="description">You must write attribute name separated by comma like this : attribute_1,attribute_2,attribute_3</span>
  568.                 </td>
  569.             </tr>
  570.         </table>
  571.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_attributes_extraction_settings', FALSE, array( 'id' => 'wp_cassify_save_options_extraction_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  572. <?php
  573.     }
  574.    
  575.     /**
  576.      * Display html output for metabox Authorization rules Settings.
  577.      */    
  578.     public function wp_cassify_add_metabox_authorization_rules_settings() {
  579.        
  580.         $wp_cassify_allow_deny_order = WP_Cassify_Utils::wp_cassify_get_option(
  581.             $this->wp_cassify_network_activated,
  582.             'wp_cassify_allow_deny_order'
  583.         );
  584.  
  585.         if (! empty( $wp_cassify_allow_deny_order ) ) {
  586.             $wp_cassify_allow_deny_order_selected = $wp_cassify_allow_deny_order;
  587.         }
  588.         else {
  589.             $wp_cassify_allow_deny_order_selected = $this->wp_cassify_default_allow_deny_order;
  590.         }
  591.  
  592.         $wp_cassify_autorization_rules = unserialize(
  593.             WP_Cassify_Utils::wp_cassify_get_option(
  594.                     $this->wp_cassify_network_activated,
  595.                     'wp_cassify_autorization_rules'
  596.             )
  597.         );
  598.  
  599.         if ( ( is_array( $wp_cassify_autorization_rules ) ) && ( count( $wp_cassify_autorization_rules ) > 0 ) ) {
  600.             foreach ( $wp_cassify_autorization_rules as $rule_key => $rule_value ) {
  601.                 $wp_cassify_autorization_rules_selected[ $rule_key ] = stripslashes( $rule_value );  
  602.             }
  603.         }
  604.         else {
  605.             $wp_cassify_autorization_rules_selected = array();
  606.         }      
  607. ?>
  608.         <table class="optiontable form-table">
  609.             <tr valign="top">
  610.                 <th scope="row">Build authorizaton rules</th>
  611.                 <td>
  612.                     <span class="description">Example rule syntax (Refer to plugin documentation) : (CAS{cas_user_id} -EQ "m.brown") -AND (CAS{email} -CONTAINS "my-university.fr")</span>
  613.                 </td>
  614.             </tr>
  615.             <tr valign="top">
  616.                 <th scope="row">Order Allow/Deny</th>
  617.                 <td>
  618.                     <select name="wp_cassify_allow_deny_order" class="post_form">
  619.                         <?php foreach ( $this->wp_cassify_default_allow_deny_order as $allow_deny_order ) { ?>
  620.                             <?php if ( $allow_deny_order == $wp_cassify_allow_deny_order_selected ) { ?>
  621.                                 <option value="<?php echo $allow_deny_order; ?>" selected><?php echo $allow_deny_order; ?></option>
  622.                             <?php } else { ?>
  623.                                 <option value="<?php echo $allow_deny_order; ?>"><?php echo $allow_deny_order; ?></option>
  624.                             <?php } ?>                     
  625.                         <?php } ?>
  626.                     </select>
  627.                     <br /><span class="description">Default value : <?php echo $this->wp_cassify_default_allow_deny_order[0]; ?></span>
  628.                 </td>
  629.             </tr>
  630.             <tr valign="top">
  631.                 <th scope="row">Autorization rules</th>
  632.                 <td>
  633.                     <select id="wp_cassify_rule_type" name="wp_cassify_rule_type">
  634.                         <option value="ALLOW">Allow</option>
  635.                         <option value="DENY">Deny</option>
  636.                     </select>                  
  637.                     <input type="text" id="wp_cassify_autorization_rule" name="wp_cassify_autorization_rules" class="post_form" value="" size="68" class="regular-text" /><br />
  638.                     <select id="wp_cassify_autorization_rules" name="wp_cassify_autorization_rules[]" class="post_form" multiple="multiple" style="height:100px;width:590px" size="10">
  639.                     <?php if ( ( is_array( $wp_cassify_autorization_rules_selected )  ) && ( count( $wp_cassify_autorization_rules_selected ) > 0 ) ) { ?>
  640.                     <?php   foreach ( $wp_cassify_autorization_rules_selected as $wp_cassify_autorization_rules_selected_key => $wp_cassify_autorization_rules_selected_value ) { ?>
  641.                     <?php       echo "<option value='$wp_cassify_autorization_rules_selected_value'>$wp_cassify_autorization_rules_selected_value</option>"; ?>
  642.                     <?php   } ?>
  643.                     <?php } ?>
  644.                     </select>
  645.                 </td>
  646.             </tr>
  647.             <tr valign="top">
  648.                 <td></td>
  649.                 <td>
  650.                     <span class="description">Double click on rule in list to edit it.</span>
  651.                     <?php submit_button( 'Add Rule', 'secondary', 'wp_cassify_add_rule', FALSE, array( 'id' => 'wp_cassify_add_rule' ) ); ?>
  652.                     <?php submit_button( 'Remove Rule', 'secondary', 'wp_cassify_remove_rule', FALSE, array( 'id' => 'wp_cassify_remove_rule' ) ); ?>
  653.                 </td>
  654.             </tr>
  655.             <tr valign="top">
  656.                 <th scope="row"><label for="wp_cassify_redirect_url_if_not_allowed">User not allowed redirect url</label></th>
  657.                 <td>
  658.                     <input type="text" id="wp_cassify_redirect_url_if_not_allowed" name="wp_cassify_redirect_url_if_not_allowed" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_redirect_url_if_not_allowed' ) ); ?>" size="40" class="regular-text post_form" />
  659.                     <br /><span class="description">Url where to redirect if user is not allowed to connect according to autorization rules below. If it's blog page, this page does not require authenticated access. The blog home url is used when this option is not set.</span>
  660.                 </td>
  661.             </tr>
  662.             <tr valign="top">
  663.                 <th scope="row"><label for="wp_cassify_redirect_url_white_list">White List URL(s)</label></th>
  664.                 <td>
  665.                     <input type="text" id="wp_cassify_redirect_url_white_list" name="wp_cassify_redirect_url_white_list" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_redirect_url_white_list' ) ); ?>" size="40" class="regular-text post_form" />
  666.                     <br /><span class="description">List of URL(s) that don't intercepted by CAS Authentication. Use ';' as URL separator.</span>
  667.                 </td>
  668.             </tr>
  669.         </table>
  670.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_authorization_rules_settings', FALSE, array( 'id' => 'wp_cassify_save_options_authorization_rules_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  671. <?php
  672.     }
  673.    
  674.     /**
  675.      * Display html output for metabox Users roles Settings.
  676.      */    
  677.     public function wp_cassify_add_metabox_users_roles_settings() {
  678.        
  679.         $wp_cassify_user_role_rules = unserialize(
  680.             WP_Cassify_Utils::wp_cassify_get_option(
  681.                     $this->wp_cassify_network_activated,
  682.                     'wp_cassify_user_role_rules'
  683.             )
  684.         );
  685.  
  686.         if ( ( is_array( $wp_cassify_user_role_rules ) ) && ( count( $wp_cassify_user_role_rules ) > 0 ) ) {
  687.             foreach ( $wp_cassify_user_role_rules as $rule_key => $rule_value ) {
  688.                 $wp_cassify_user_role_rules_selected[ $rule_key ] = stripslashes( $rule_value );  
  689.             }
  690.         }
  691.         else {
  692.             $wp_cassify_user_role_rules_selected = array();
  693.         }
  694. ?>
  695.         <table class="optiontable form-table">
  696.             <tr valign="top">
  697.                 <th scope="row">Set Conditionnal Users Roles</th>
  698.                 <td>
  699.                     <span class="description">Example rule syntax (Refer to plugin documentation) : (CAS{cas_user_id} -EQ "m.brown") -AND (CAS{email} -CONTAINS "my-university.fr")</span>
  700.                 </td>
  701.             </tr>              
  702.             <tr valign="top">
  703.                 <th scope="row">Push defaults roles to connected user </th>
  704.                 <td>
  705.                     <select id="wp_cassify_default_user_roles" name="wp_cassify_default_user_roles" class="post_form">
  706.                     <?php $wp_cassify_wordpress_roles = WP_Cassify_Utils::wp_cassify_get_wordpress_roles_names(); ?>
  707.                     <?php foreach ( $wp_cassify_wordpress_roles as $wp_cassify_wordpress_role_key => $wp_cassify_wordpress_role_value ) { ?>
  708.                     <?php       echo "<option value='$wp_cassify_wordpress_role_key'>$wp_cassify_wordpress_role_value</option>"; ?>
  709.                     <?php } ?>
  710.                     </select>
  711.                     <?php if ( $this->wp_cassify_network_activated ) { ?>
  712.                     <?php $blogs = wp_get_sites();?>   
  713.                     <select id="wp_cassify_user_role_blog_id" name="wp_cassify_user_role_blog_id" class="post_form">
  714.                     <?php       echo '<option value="0">(0)&nbsp;ALL BLOGS</option>';   ?>     
  715.                     <?php for( $i = 0; $i <= count( $blogs ) - 1; $i++ ) { ?>
  716.                     <?php       echo '<option value="' . $blogs[ $i ][ 'blog_id' ] . '">(' . $blogs[ $i ][ 'blog_id' ] . ')&nbsp;' . $blogs[ $i ][ 'domain' ] . $blogs[ $i ][ 'path' ] . '</option>';   ?> 
  717.                     <?php } ?>                         
  718.                     </select>
  719.                     <?php } ?>
  720.                     <input type="text" id="wp_cassify_user_role_rule" name="wp_cassify_user_role_rule" class="post_form" value="" size="60" class="regular-text" /><br />
  721.                     <br />
  722.                     <select id="wp_cassify_user_role_rules" name="wp_cassify_user_role_rules[]" class="post_form" multiple="multiple" style="height:100px;width:590px" size="10">
  723.                     <?php if ( ( is_array( $wp_cassify_user_role_rules_selected )  ) && ( count( $wp_cassify_user_role_rules_selected ) > 0 ) ) { ?>
  724.                     <?php   foreach ( $wp_cassify_user_role_rules_selected as $wp_cassify_user_role_rules_selected_key => $wp_cassify_user_role_rules_selected_value ) { ?>
  725.                     <?php       echo "<option value='$wp_cassify_user_role_rules_selected_value'>$wp_cassify_user_role_rules_selected_value</option>"; ?>
  726.                     <?php   } ?>
  727.                     <?php } ?>
  728.                     </select>
  729.                 </td>
  730.             </tr>
  731.             <tr valign="top">
  732.                 <td></td>
  733.                 <td>
  734.                     <span class="description">Double click on rule in list to edit it.</span>
  735.                     <?php submit_button( 'Add Conditional Rule Role', 'secondary', 'wp_cassify_add_user_role_rule', FALSE, array( 'id' => 'wp_cassify_add_user_role_rule' ) ); ?>
  736.                     <?php submit_button( 'Remove Conditional Rule Role', 'secondary', 'wp_cassify_remove_user_role_rule', FALSE, array( 'id' => 'wp_cassify_remove_user_role_rule' ) ); ?>
  737.                 </td>
  738.             </tr>
  739.         </table>
  740.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_users_roles_settings', FALSE, array( 'id' => 'wp_cassify_save_options_users_roles_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  741. <?php
  742.     }  
  743.    
  744.     /**
  745.      * Display html output for metabox Users attributes synchronization Settings.
  746.      */    
  747.     public function wp_cassify_add_metabox_users_attributes_synchronization_settings() {
  748.  
  749.         $wp_cassify_user_attributes_mapping_list = unserialize(
  750.             WP_Cassify_Utils::wp_cassify_get_option(
  751.                     $this->wp_cassify_network_activated,
  752.                     'wp_cassify_user_attributes_mapping_list'
  753.             )
  754.         );
  755.        
  756.         $wp_cassify_user_attributes_mapping_list_selected = array();
  757.         if ( ( is_array( $wp_cassify_user_attributes_mapping_list ) ) && ( count( $wp_cassify_user_attributes_mapping_list ) > 0 ) ) {
  758.             foreach ( $wp_cassify_user_attributes_mapping_list as $wp_cassify_user_attributes_mapping_key => $wp_cassify_user_attributes_mapping_value ) {
  759.                 $wp_cassify_user_attributes_mapping_list_selected[ $wp_cassify_user_attributes_mapping_value ] = $wp_cassify_user_attributes_mapping_value;  
  760.             }
  761.         }
  762.         else {
  763.             $wp_cassify_user_attributes_mapping_list_selected = array();
  764.         }              
  765. ?>
  766.         <table class="optiontable form-table">
  767.             <tr valign="top">
  768.                 <th scope="row" colspan="2">Synchronize Wordpress User metas with CAS User attributes </th>
  769.             </tr>
  770.             <tr valign="top">
  771.                 <th scope="row">Wordpress User Meta</th>
  772.                 <td>
  773.                     <select id="wp_cassify_wordpress_user_meta_list" name="wp_cassify_wordpress_user_meta_list" class="post_form"> ?>
  774.                     <?php foreach ( $this->wp_cassify_wordpress_user_meta_list as $wp_cassify_wordpress_user_meta ) { ?>
  775.                     <?php       echo "<option value='$wp_cassify_wordpress_user_meta'>$wp_cassify_wordpress_user_meta</option>"; ?>
  776.                     <?php } ?>
  777.                     </select>
  778.                     <input type="text" id="wp_cassify_custom_user_meta" name="wp_cassify_custom_user_meta" class="post_form" value="" size="40" class="regular-text" />
  779.                 </td>
  780.             </tr>
  781.             <tr valign="top">
  782.                 <th scope="row">CAS User Attribute</th>
  783.                 <td>
  784.                     <input type="text" id="wp_cassify_cas_user_attribute" name="wp_cassify_cas_user_attribute" class="post_form" value="" size="40" class="regular-text" />
  785.                 </td>
  786.             </tr>
  787.             <tr valign="top">
  788.                 <td>
  789.                 </td>
  790.                 <td>
  791.                     <select id="wp_cassify_user_attributes_mapping_list" name="wp_cassify_user_attributes_mapping_list[]" class="post_form" multiple="multiple" style="height:100px;width:590px" size="10">
  792.                     <?php if ( ( is_array( $wp_cassify_user_attributes_mapping_list_selected )  ) && ( count( $wp_cassify_user_attributes_mapping_list_selected ) > 0 ) ) { ?>
  793.                     <?php   foreach ( $wp_cassify_user_attributes_mapping_list_selected as $wp_cassify_user_attributes_mapping_list_selected_key => $wp_cassify_user_attributes_mapping_list_selected_value ) { ?>
  794.                     <?php       echo "<option value='$wp_cassify_user_attributes_mapping_list_selected_value'>$wp_cassify_user_attributes_mapping_list_selected_value</option>"; ?>
  795.                     <?php   } ?>
  796.                     <?php } ?>
  797.                     </select>
  798.                 </td>
  799.             </tr>
  800.             <tr valign="top">
  801.                 <td></td>
  802.                 <td>
  803.                     <span class="description">Double click on rule in list to edit it.</span>
  804.                     <?php submit_button( 'Add Attribute Mapping', 'secondary', 'wp_cassify_add_user_attribute_mapping', FALSE, array( 'id' => 'wp_cassify_add_user_attribute_mapping' ) ); ?>
  805.                     <?php submit_button( 'Remove Attribute Mapping', 'secondary', 'wp_cassify_remove_user_attribute_mapping', FALSE, array( 'id' => 'wp_cassify_remove_user_attribute_mapping' ) ); ?>
  806.                 </td>
  807.             </tr>
  808.         </table>
  809.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_users_attributes_synchronization_settings', FALSE, array( 'id' => 'wp_cassify_save_options_users_attributes_synchronization_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  810. <?php
  811.     }
  812.    
  813.     /**
  814.      * Display html output for metabox Notifications Settings.
  815.      */    
  816.     public function wp_cassify_add_metabox_notifications_settings() {
  817.  
  818.         $wp_cassify_notifications_smtp_auth_enabled = FALSE;
  819.  
  820.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_auth' ) == 'enabled' ) {
  821.             $wp_cassify_notifications_smtp_auth_enabled = TRUE;
  822.         }
  823.         else {
  824.             $wp_cassify_notifications_smtp_auth_enabled = FALSE;
  825.         }
  826.  
  827.         $wp_cassify_notifications_smtp_port_selected = '';
  828.         $wp_cassify_notifications_smtp_port = WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_port' );
  829.  
  830.         if (! empty( $wp_cassify_notifications_smtp_port ) ) {
  831.             $wp_cassify_notifications_smtp_port_selected = $wp_cassify_notifications_smtp_port;
  832.         }
  833.        
  834.         $wp_cassify_notifications_priority_selected = '3';
  835.         $wp_cassify_notifications_priority = WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_priority' );
  836.  
  837.         if (! empty( $wp_cassify_notifications_priority ) ) {
  838.             $wp_cassify_notifications_priority_selected = $wp_cassify_notifications_priority;
  839.         }
  840.        
  841.         $wp_cassify_notifications_encryption_type_selected = $this->wp_cassify_default_notifications_options[ 'wp_cassify_default_notifications_encryption_type' ][ 'tls' ];
  842.         $wp_cassify_notifications_encryption_type = WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_encryption_type' );
  843.        
  844.         if (! empty( $wp_cassify_notifications_encryption_type ) ) {
  845.             $wp_cassify_notifications_encryption_type_selected = $wp_cassify_notifications_encryption_type;
  846.         }    
  847. ?>
  848.         <table class="optiontable form-table">
  849.             <tr valign="top">
  850.                 <th scope="row">SMTP Host</th>
  851.                 <td>
  852.                     <input type="text" id="wp_cassify_notifications_smtp_host" name="wp_cassify_notifications_smtp_host" class="post_form regular-text" size="40" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_host' ) ); ?>" />
  853.                     <br /><span class="description">IP or FQDN</span>
  854.                 </td>
  855.             </tr>
  856.             <tr valign="top">
  857.                 <th scope="row">SMTP port</th>
  858.                 <td>
  859.                     <select id="wp_cassify_notifications_smtp_port" name="wp_cassify_notifications_smtp_port" class="post_form">
  860.                         <?php foreach ( $this->wp_cassify_default_notifications_options[ 'wp_cassify_default_notifications_smtp_port' ] as $wp_cassify_default_notifications_smtp_port_key => $wp_cassify_default_notifications_smtp_port_value ) { ?>
  861.                             <?php if ( $wp_cassify_default_notifications_smtp_port_value == $wp_cassify_notifications_smtp_port_selected ) { ?>
  862.                                 <option value="<?php echo $wp_cassify_default_notifications_smtp_port_key; ?>" selected><?php echo $wp_cassify_default_notifications_smtp_port_value; ?></option>
  863.                             <?php } else { ?>
  864.                                 <option value="<?php echo $wp_cassify_default_notifications_smtp_port_key; ?>"><?php echo $wp_cassify_default_notifications_smtp_port_value; ?></option>
  865.                             <?php } ?>                     
  866.                         <?php } ?>
  867.                     </select>
  868.                 </td>
  869.             </tr>
  870.             <tr valign="top">
  871.                 <th scope="row">SMTP Authentication</th>
  872.                 <?php if ( $wp_cassify_notifications_smtp_auth_enabled ) { ?>
  873.                 <td><input type="checkbox" id="wp_cassify_notifications_smtp_auth" name="wp_cassify_notifications_smtp_auth" class="post_form" value="enabled" checked /></td>
  874.                 <?php } else { ?>
  875.                 <td><input type="checkbox" id="wp_cassify_notifications_smtp_auth" name="wp_cassify_notifications_smtp_auth" class="post_form" value="enabled" /></td>
  876.                 <?php }?>
  877.             </tr>
  878.             <tr valign="top">
  879.                 <th scope="row">SMTP Authentication type</th>
  880.                 <td>
  881.                     <select id="wp_cassify_notifications_encryption_type" name="wp_cassify_notifications_encryption_type" class="post_form">
  882.                         <?php foreach ( $this->wp_cassify_default_notifications_options[ 'wp_cassify_default_notifications_encryption_type' ] as $wp_cassify_default_notifications_encryption_type_key => $wp_cassify_default_notifications_encryption_type_value ) { ?>
  883.                             <?php if ( $wp_cassify_default_notifications_encryption_type_value == $wp_cassify_notifications_encryption_type_selected ) { ?>
  884.                                 <option value="<?php echo $wp_cassify_default_notifications_encryption_type_key; ?>" selected><?php echo $wp_cassify_default_notifications_encryption_type_value; ?></option>
  885.                             <?php } else { ?>
  886.                                 <option value="<?php echo $wp_cassify_default_notifications_encryption_type_key; ?>"><?php echo $wp_cassify_default_notifications_encryption_type_value; ?></option>
  887.                             <?php } ?>                     
  888.                         <?php } ?>
  889.                     </select>
  890.                 </td>
  891.             </tr>          
  892.             <tr valign="top">
  893.                 <th scope="row">SMTP User</th>
  894.                 <td>
  895.                     <input type="text" id="wp_cassify_notifications_smtp_user" name="wp_cassify_notifications_smtp_user" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_user' ) ); ?>" class="post_form regular-text" size="40" />
  896.                 </td>
  897.             </tr>
  898.             <tr valign="top">
  899.                 <th scope="row">SMTP Password</th>
  900.                 <td>
  901.                     <input type="password" id="wp_cassify_notifications_smtp_password" name="wp_cassify_notifications_smtp_password" class="post_form regular-text" value="" size="40" />
  902.                 </td>
  903.             </tr>
  904.             <tr valign="top">
  905.                 <th scope="row">SMTP Password confirmation</th>
  906.                 <td>
  907.                     <input type="password" id="wp_cassify_notifications_smtp_confirm_password" name="wp_cassify_notifications_smtp_confirm_password" class="post_form regular-text" value="" size="40"  />
  908.                 </td>
  909.             </tr>  
  910.             <tr valign="top">
  911.                 <th scope="row">Salt</th>
  912.                 <td>
  913.                     <input type="text" id="wp_cassify_notifications_salt" name="wp_cassify_notifications_salt" class="post_form regular-text" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_salt' ) ); ?>" size="40" />
  914.                     <br /><span class="description">Salt is used to store user smtp password as encrypted value</span>
  915.                 </td>
  916.             </tr>
  917.             <tr valign="top">
  918.                 <th scope="row">Priority</th>
  919.                 <td>
  920.                     <select id="wp_cassify_notifications_priority" name="wp_cassify_notifications_priority" class="post_form">
  921.                         <?php foreach ( $this->wp_cassify_default_notifications_options[ 'wp_cassify_default_notifications_priority' ] as $wp_cassify_default_notifications_priority_key => $wp_cassify_default_notifications_priority_value ) { ?>
  922.                             <?php if ( $wp_cassify_default_notifications_priority_key == $wp_cassify_notifications_priority_selected ) { ?>
  923.                                 <option value="<?php echo $wp_cassify_default_notifications_priority_key; ?>" selected><?php echo $wp_cassify_default_notifications_priority_value; ?></option>
  924.                             <?php } else { ?>
  925.                                 <option value="<?php echo $wp_cassify_default_notifications_priority_key; ?>"><?php echo $wp_cassify_default_notifications_priority_value; ?></option>
  926.                             <?php } ?>                     
  927.                         <?php } ?>
  928.                     </select>
  929.                 </td>
  930.             </tr>          
  931.             <tr valign="top">
  932.                 <th scope="row">SMTP From</th>
  933.                 <td>
  934.                     <input type="text" id="wp_cassify_notifications_smtp_from" name="wp_cassify_notifications_smtp_from" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_from' ) ); ?>" class="post_form regular-text" size="40" />
  935.                 </td>
  936.             </tr>
  937.                 <tr valign="top">
  938.                 <th scope="row">SMTP To</th>
  939.                 <td>
  940.                     <input type="text" id="wp_cassify_notifications_smtp_to" name="wp_cassify_notifications_smtp_to" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_to' ) ); ?>" class="post_form regular-text" size="40" />
  941.                 </td>
  942.             </tr>      
  943.             <tr valign="top">
  944.                 <th scope="row">Subject prefix</th>
  945.                 <td>
  946.                     <input type="text" id="wp_cassify_notifications_subject_prefix" name="wp_cassify_notifications_subject_prefix" class="post_form regular-text" value="<?php echo esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_subject_prefix' ) ); ?>" size="40" />
  947.                     <br /><span class="description">Prefix of mail notification messages. Default value : <?php echo $this->wp_cassify_default_notifications_options[ 'wp_cassify_default_notifications_subject_prefix' ]; ?></span>
  948.                 </td>
  949.             </tr>
  950.             <tr valign="top">
  951.                 <th scope="row">Send test message</th>
  952.                 <td>
  953.                     To : <input type="text" id="wp_cassify_notifications_send_to_test" name="wp_cassify_notifications_send_to_test" class="post_form regular-text" value="" size="40" />
  954.                     <?php submit_button( 'Send test message', 'secondary', 'wp_cassify_send_notification_test_message', FALSE, array( 'id' => 'wp_cassify_send_notification_test_message', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  955.                 </td>
  956.             </tr>
  957.         </table>
  958.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_notifications_settings', FALSE, array( 'id' => 'wp_cassify_save_options_notifications_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  959. <?php
  960.     }
  961.    
  962.     /**
  963.      * Display html output for metabox Notifications rules Settings.
  964.      */    
  965.     public function wp_cassify_add_metabox_notifications_rules_settings() {
  966.        
  967.         $wp_cassify_notification_rules = unserialize(
  968.             WP_Cassify_Utils::wp_cassify_get_option(
  969.                     $this->wp_cassify_network_activated,
  970.                     'wp_cassify_notification_rules'
  971.             )
  972.         );
  973.  
  974.         if ( ( is_array( $wp_cassify_notification_rules ) ) && ( count( $wp_cassify_notification_rules ) > 0 ) ) {
  975.             foreach ( $wp_cassify_notification_rules as $rule_key => $rule_value ) {
  976.                 $wp_cassify_notification_rules_selected[ $rule_key ] = stripslashes( $rule_value );  
  977.             }
  978.         }
  979.         else {
  980.             $wp_cassify_notification_rules_selected = array();
  981.         }
  982. ?>
  983.         <table class="optiontable form-table">
  984.             <tr valign="top">
  985.                 <th scope="row">Set Conditionnal Notifications Rules</th>
  986.                 <td>
  987.                     <span class="description">Example rule syntax (Refer to plugin documentation) : (CAS{cas_user_id} -EQ "m.brown") -AND (CAS{email} -CONTAINS "my-university.fr")</span>
  988.                 </td>
  989.             </tr>              
  990.             <tr valign="top">
  991.                 <th scope="row">Send mail notification if user match criteria</th>
  992.                 <td>
  993.                     <select id="wp_cassify_notifications_actions" name="wp_cassify_notifications_actions" class="post_form">
  994.                         <?php foreach ( $this->wp_cassify_default_notifications_options[ 'wp_cassify_default_notifications_actions' ] as $wp_cassify_default_notifications_actions_key => $wp_cassify_default_notifications_actions_value ) { ?>
  995.                                 <option value="<?php echo $wp_cassify_default_notifications_actions_key; ?>"><?php echo $wp_cassify_default_notifications_actions_value; ?></option>
  996.                         <?php } ?>
  997.                     </select>
  998.                     <input type="text" id="wp_cassify_notification_rule" name="wp_cassify_notification_rule" class="post_form" value="" size="60" class="regular-text" /><br />
  999.                     <br />
  1000.                     <select id="wp_cassify_notification_rules" name="wp_cassify_notification_rules[]" class="post_form" multiple="multiple" style="height:100px;width:590px" size="10">
  1001.                     <?php if ( ( is_array( $wp_cassify_notification_rules_selected )  ) && ( count( $wp_cassify_notification_rules_selected ) > 0 ) ) { ?>
  1002.                     <?php   foreach ( $wp_cassify_notification_rules_selected as $wp_cassify_notification_rules_selected_key => $wp_cassify_notification_rules_selected_value ) { ?>
  1003.                     <?php       echo "<option value='$wp_cassify_notification_rules_selected_value'>$wp_cassify_notification_rules_selected_value</option>"; ?>
  1004.                     <?php   } ?>
  1005.                     <?php } ?>
  1006.                     </select>
  1007.                     <br />
  1008.                     <span class="description">(*) Theses triggers needs that users attributes presents in notification rule are populated into session to be fired. See "Attributes Extraction Settings" to populate attributes into session.</span>
  1009.                 </td>
  1010.             </tr>
  1011.             <tr valign="top">
  1012.                 <td></td>
  1013.                 <td>
  1014.                     <span class="description">Double click on rule in list to edit it.</span>
  1015.                     <?php submit_button( 'Add Notification Rule', 'secondary', 'wp_cassify_add_notification_rule', FALSE, array( 'id' => 'wp_cassify_add_notification_rule' ) ); ?>
  1016.                     <?php submit_button( 'Remove Notification Rule', 'secondary', 'wp_cassify_remove_notification_rule', FALSE, array( 'id' => 'wp_cassify_remove_notification_rule' ) ); ?>
  1017.                 </td>
  1018.             </tr>  
  1019.         </table>
  1020.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_notifications_rules_settings', FALSE, array( 'id' => 'wp_cassify_save_options_notifications_rules_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  1021. <?php
  1022.     }  
  1023.    
  1024.     /**
  1025.      * Display html output for metabox Expirations rules Settings.
  1026.      */    
  1027.     public function wp_cassify_add_metabox_expirations_rules_settings() {
  1028.        
  1029.         $wp_cassify_expiration_rules = unserialize(
  1030.             WP_Cassify_Utils::wp_cassify_get_option(
  1031.                     $this->wp_cassify_network_activated,
  1032.                     'wp_cassify_expiration_rules'
  1033.             )
  1034.         );
  1035.  
  1036.         if ( ( is_array( $wp_cassify_expiration_rules ) ) && ( count( $wp_cassify_expiration_rules ) > 0 ) ) {
  1037.             foreach ( $wp_cassify_expiration_rules as $rule_key => $rule_value ) {
  1038.                 $wp_cassify_expiration_rules_selected[ $rule_key ] = stripslashes( $rule_value );  
  1039.             }
  1040.         }
  1041.         else {
  1042.             $wp_cassify_expiration_rules_selected = array();
  1043.         }
  1044.        
  1045. ?>
  1046.         <table class="optiontable form-table">
  1047.             <tr valign="top">
  1048.                 <th scope="row">Set Conditionnal Expirations Rules</th>
  1049.                 <td>
  1050.                     <span class="description">Example rule syntax (Refer to plugin documentation) : (CAS{cas_user_id} -EQ "m.brown") -AND (CAS{email} -CONTAINS "my-university.fr")</span>
  1051.                     <input type="text" id="wp_cassify_expiration_rule" name="wp_cassify_expiration_rule" class="post_form" value="" size="60" class="regular-text" />
  1052.                 </td>
  1053.             </tr>              
  1054.             <tr valign="top">
  1055.                 <th scope="row">Expire user account if user match criteria</th>
  1056.                 <td>
  1057.                     <select id="wp_cassify_default_expirations_types" name="wp_cassify_default_expirations_types" class="post_form">
  1058.                         <?php foreach ( $this->wp_cassify_default_expirations_options[ 'wp_cassify_default_expirations_types' ] as $wp_cassify_default_expirations_types_key => $wp_cassify_default_expirations_types_value ) { ?>
  1059.                                 <option value="<?php echo $wp_cassify_default_expirations_types_key; ?>"><?php echo $wp_cassify_default_expirations_types_value; ?></option>
  1060.                         <?php } ?>
  1061.                     </select>
  1062.                     <input type="text" id="wp_cassify_after_user_account_created_time_limit" name="wp_cassify_after_user_account_created_time_limit" class="post_form" value="" size="60" class="regular-text" />
  1063.                     <input type="text" id="wp_cassify_fixed_datetime_limit" name="wp_cassify_fixed_datetime_limit" class="post_form" value="" size="60" class="regular-text" /><br />
  1064.                    
  1065.                     <br />
  1066.                     <select id="wp_cassify_expiration_rules" name="wp_cassify_expiration_rules[]" class="post_form" multiple="multiple" style="height:100px;width:590px" size="10">
  1067.                     <?php if ( ( is_array( $wp_cassify_expiration_rules_selected )  ) && ( count( $wp_cassify_expiration_rules_selected ) > 0 ) ) { ?>
  1068.                     <?php   foreach ( $wp_cassify_expiration_rules_selected as $wp_cassify_expiration_rules_selected_key => $wp_cassify_expiration_rules_selected_value ) { ?>
  1069.                     <?php       echo "<option value='$wp_cassify_expiration_rules_selected_value'>$wp_cassify_expiration_rules_selected_value</option>"; ?>
  1070.                     <?php   } ?>
  1071.                     <?php } ?>
  1072.                     </select>
  1073.                     <br />
  1074.                 </td>
  1075.             </tr>
  1076.             <tr valign="top">
  1077.                 <td></td>
  1078.                 <td>
  1079.                     <span class="description">Double click on rule in list to edit it.</span>
  1080.                     <?php submit_button( 'Add Expiration Rule', 'secondary', 'wp_cassify_add_expiration_rule', FALSE, array( 'id' => 'wp_cassify_add_expiration_rule' ) ); ?>
  1081.                     <?php submit_button( 'Remove Expiration Rule', 'secondary', 'wp_cassify_remove_expiration_rule', FALSE, array( 'id' => 'wp_cassify_remove_expiration_rule' ) ); ?>
  1082.                 </td>
  1083.             </tr>  
  1084.         </table>
  1085.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_expirations_rules_settings', FALSE, array( 'id' => 'wp_cassify_save_options_expirations_rules_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  1086. <?php
  1087.     }
  1088.    
  1089.     /**
  1090.      * Display html output for metabox Debug Settings.
  1091.      */    
  1092.     public function wp_cassify_add_metabox_debug_settings() {
  1093.        
  1094.         $is_enabled = FALSE;
  1095.  
  1096.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_xml_response_dump' ) == 'enabled' ) {
  1097.             $is_enabled = TRUE;
  1098.         }
  1099.         else {
  1100.             $is_enabled = FALSE;
  1101.         }
  1102. ?>
  1103.         <table class="optiontable form-table">
  1104.             <tr valign="top">
  1105.                 <th scope="row">Dump xml CAS server response</th>
  1106.                 <?php if ( $is_enabled ) { ?>
  1107.                 <td><input type="checkbox" id="wp_cassify_xml_response_dump" name="wp_cassify_xml_response_dump" class="post_form" value="enabled" checked /></td>
  1108.                 <?php } else { ?>
  1109.                 <td><input type="checkbox" id="wp_cassify_xml_response_dump" name="wp_cassify_xml_response_dump" class="post_form" value="enabled" /></td>
  1110.                 <?php }?>
  1111.             </tr>  
  1112.             <tr valign="top">
  1113.                 <th scope="row">Last XML CAS server response</th>
  1114.                 <td>
  1115.                     <textarea rows="4" cols="50" id="wp_cassify_xml_response_value" name="wp_cassify_xml_response_value" class="post_form" value="" class="regular-text">
  1116.                         <?php echo ltrim( esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_xml_response_value' ) ) ); ?>
  1117.                     </textarea>
  1118.                 </td>
  1119.             </tr>          
  1120.         </table>
  1121.         <?php submit_button( 'Save options', 'primary', 'wp_cassify_save_options_debug_settings', FALSE, array( 'id' => 'wp_cassify_save_options_debug_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?>
  1122. <?php
  1123.     }
  1124.    
  1125.     /**
  1126.      * Display html output for metabox Backup / Restore configuration settings.
  1127.      */    
  1128.     public function wp_cassify_add_metabox_backup_restore_configuration_settings() {
  1129.        
  1130.         $is_enabled = FALSE;
  1131.  
  1132.         if ( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_xml_response_dump' ) == 'enabled' ) {
  1133.             $is_enabled = TRUE;
  1134.         }
  1135.         else {
  1136.             $is_enabled = FALSE;
  1137.         }
  1138. ?>
  1139.         <table class="optiontable form-table">
  1140.             <tr valign="top">
  1141.                 <td><?php submit_button( 'Backup plugin configuration', 'secondary', 'wp_cassify_backup_plugin_options_settings', FALSE, array( 'id' => 'wp_cassify_backup_plugin_options_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?></td>
  1142.                 <td><?php submit_button( 'Restore plugin configuration', 'secondary', 'wp_cassify_restore_plugin_options_settings', FALSE, array( 'id' => 'wp_cassify_restore_plugin_options_settings', 'data-style' => 'wp_cassify_save_options' ) ); ?></td>
  1143.             </tr>
  1144.             <tr valign="top">
  1145.                 <th scope="row">Import configuration file</th>
  1146.                 <td>
  1147.                     <input type="file" id="wp_cassify_restore_plugin_options_configuration_settings_file" name="wp_cassify_restore_plugin_options_configuration_settings_file" class="post_form" value="" size="60" /><br />
  1148.                 </td>
  1149.             </tr>          
  1150.         </table>
  1151. <?php
  1152.     }  
  1153.    
  1154.     /**
  1155.      *  Register option into database.
  1156.      */
  1157.     public function wp_cassify_register_plugin_settings() {
  1158.  
  1159.         foreach ( $this->wp_cassify_plugin_options_list as $option ) {
  1160.             register_setting( 'wp-cassify-settings-group', $option );
  1161.         }
  1162.     }
  1163.    
  1164.     /**
  1165.      *  Display form to manage plugin options.
  1166.      */
  1167.     public function wp_cassify_options() {
  1168.  
  1169.             if ( !current_user_can( 'manage_options' ) )  {
  1170.                 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  1171.             }
  1172.  
  1173.             if ( $this->wp_cassify_is_options_updated() ) {    
  1174.            
  1175.                 // Check security tocken
  1176.                 if (! wp_verify_nonce ($_POST[ 'wp_cassify_admin_form' ], 'admin_form' ) ) {
  1177.                     die( 'Security Check !' );
  1178.                 }
  1179.                
  1180.                 // General settings
  1181.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_base_url', FALSE, $this->wp_cassify_network_activated );                        
  1182.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_protocol_version', FALSE, $this->wp_cassify_network_activated );
  1183.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_disable_authentication', 'disabled', $this->wp_cassify_network_activated );
  1184.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_create_user_if_not_exist', 'create_user_if_not_exist', $this->wp_cassify_network_activated );
  1185.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_enable_gateway_mode', 'enable_gateway_mode', $this->wp_cassify_network_activated );  
  1186.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_enable_sso', 'enable_sso', $this->wp_cassify_network_activated );
  1187.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_ssl_cipher', TRUE, $this->wp_cassify_network_activated );
  1188.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_ssl_check_certificate', 'enabled', $this->wp_cassify_network_activated );
  1189.  
  1190.                 // Url settings
  1191.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_redirect_url_after_logout', FALSE, $this->wp_cassify_network_activated );
  1192.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_override_service_url', FALSE, $this->wp_cassify_network_activated );
  1193.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_login_servlet', FALSE, $this->wp_cassify_network_activated );
  1194.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_logout_servlet', FALSE, $this->wp_cassify_network_activated );
  1195.                
  1196.                 WP_Cassify_Utils::wp_cassify_update_textfield_manual(
  1197.                     '',
  1198.                     'wp_cassify_service_validate_servlet',
  1199.                     $this->wp_cassify_network_activated
  1200.                 );
  1201.                
  1202.                 // Attributes extraction settings
  1203.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_xpath_query_to_extact_cas_user', FALSE, $this->wp_cassify_network_activated );
  1204.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_xpath_query_to_extact_cas_attributes', FALSE, $this->wp_cassify_network_activated );
  1205.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_attributes_list', FALSE, $this->wp_cassify_network_activated );
  1206.                
  1207.                 // Authorization rules settings
  1208.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_allow_deny_order', FALSE, $this->wp_cassify_network_activated );
  1209.                 WP_Cassify_Utils::wp_cassify_update_multiple_select( $_POST, 'wp_cassify_autorization_rules', $this->wp_cassify_network_activated );
  1210.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_redirect_url_if_not_allowed', FALSE, $this->wp_cassify_network_activated );
  1211.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_redirect_url_white_list', FALSE, $this->wp_cassify_network_activated );
  1212.                
  1213.                 // User roles rules settings
  1214.                 WP_Cassify_Utils::wp_cassify_update_multiple_select( $_POST, 'wp_cassify_user_role_rules', $this->wp_cassify_network_activated );
  1215.                
  1216.                 // User attributes mapping settings
  1217.                 WP_Cassify_Utils::wp_cassify_update_multiple_select( $_POST, 'wp_cassify_user_attributes_mapping_list', $this->wp_cassify_network_activated );
  1218.                
  1219.                 // Notification settings
  1220.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_smtp_host', FALSE, $this->wp_cassify_network_activated );
  1221.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_smtp_port', FALSE, $this->wp_cassify_network_activated );
  1222.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_encryption_type', FALSE, $this->wp_cassify_network_activated );
  1223.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_notifications_smtp_auth', 'enabled', $this->wp_cassify_network_activated );
  1224.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_salt', FALSE, $this->wp_cassify_network_activated );
  1225.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_priority', FALSE, $this->wp_cassify_network_activated );
  1226.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_smtp_user', FALSE, $this->wp_cassify_network_activated );
  1227.  
  1228.                 // Store smtp password as encrypted string
  1229.                 $wp_cassify_notifications_salt = WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_salt' );
  1230.  
  1231.                 if (! empty( $_POST[ 'wp_cassify_notifications_smtp_password' ] ) ) {
  1232.                    
  1233.                     $wp_cassify_notifications_smtp_password = '';
  1234.                    
  1235.                     if (! empty( $wp_cassify_notifications_salt ) ) {
  1236.                         $wp_cassify_notifications_smtp_password = WP_Cassify_Utils::wp_cassify_simple_encrypt(
  1237.                             $_POST[ 'wp_cassify_notifications_smtp_password' ],
  1238.                             $wp_cassify_notifications_salt
  1239.                         );
  1240.                     }
  1241.                     else {
  1242.                         $wp_cassify_notifications_smtp_password = WP_Cassify_Utils::wp_cassify_simple_encrypt(
  1243.                             $_POST[ 'wp_cassify_notifications_smtp_password' ]
  1244.                         );                     
  1245.                     }
  1246.  
  1247.                     if (! empty( $wp_cassify_notifications_smtp_password ) ) {
  1248.                         WP_Cassify_Utils::wp_cassify_update_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_password', $wp_cassify_notifications_smtp_password );
  1249.                     }
  1250.                 }
  1251.  
  1252.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_smtp_from', FALSE, $this->wp_cassify_network_activated );
  1253.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_smtp_to', FALSE, $this->wp_cassify_network_activated );
  1254.                 WP_Cassify_Utils::wp_cassify_update_textfield( $_POST, 'wp_cassify_notifications_subject_prefix', FALSE, $this->wp_cassify_network_activated );
  1255.  
  1256.                 // Notifications rules settings
  1257.                 WP_Cassify_Utils::wp_cassify_update_multiple_select( $_POST, 'wp_cassify_notification_rules', $this->wp_cassify_network_activated );
  1258.                
  1259.                 // Expirations rules settings
  1260.                 WP_Cassify_Utils::wp_cassify_update_multiple_select( $_POST, 'wp_cassify_expiration_rules', $this->wp_cassify_network_activated );             
  1261.  
  1262.                 // Debug settings
  1263.                 WP_Cassify_Utils::wp_cassify_update_checkbox( $_POST, 'wp_cassify_xml_response_dump', 'enabled', $this->wp_cassify_network_activated );
  1264.                
  1265.                 // Send test notification message.
  1266.                 if (! empty( $_POST['wp_cassify_send_notification_test_message'] ) ){
  1267.                    
  1268.                     $wp_cassify_send_notification_to = sanitize_text_field( $_POST[ 'wp_cassify_notifications_send_to_test' ] );
  1269.                     $wp_cassify_notifications_subject_prefix = esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_subject_prefix' ) );
  1270.                     $wp_cassify_send_notification_subject =  $this->wp_cassify_default_notifications_options[ 'wp_cassify_send_notification_default_subject' ];
  1271.                     $wp_cassify_send_notification_message = $this->wp_cassify_default_notifications_options[ 'wp_cassify_send_notification_default_message' ];
  1272.                
  1273.                     if (! empty( $wp_cassify_notifications_subject_prefix ) ) {
  1274.                         $wp_cassify_send_notification_subject = $wp_cassify_notifications_subject_prefix . $wp_cassify_send_notification_subject;
  1275.                     }
  1276.  
  1277.                     $wp_cassify_notifications_smtp_auth = esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_auth' ) );
  1278.                    
  1279.                     $wp_cassify_notifications_smtp_auth_enabled = FALSE;
  1280.                     $wp_cassify_notifications_encryption_type = NULL;
  1281.                    
  1282.                     if ( $wp_cassify_notifications_smtp_auth == 'enabled' ) {
  1283.                         $wp_cassify_notifications_smtp_auth_enabled = TRUE;
  1284.                         $wp_cassify_notifications_encryption_type = esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_encryption_type' ) );
  1285.                     }
  1286.                    
  1287.                     $wp_cassify_notifications_priority = esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_priority' ) );
  1288.  
  1289.                     $wp_cassify_notifications_smtp_user = esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_user' ) );
  1290.                     $wp_cassify_notifications_smtp_password = esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_password' ) );
  1291.                    
  1292.                     if (! empty( $wp_cassify_notifications_salt ) ) {
  1293.                         $wp_cassify_notifications_smtp_password = WP_Cassify_Utils::wp_cassify_simple_decrypt(
  1294.                             $wp_cassify_notifications_smtp_password,
  1295.                             $wp_cassify_notifications_salt
  1296.                         );
  1297.                     }
  1298.                     else {
  1299.                         $wp_cassify_notifications_smtp_password = WP_Cassify_Utils::wp_cassify_simple_decrypt(
  1300.                             $wp_cassify_notifications_smtp_password
  1301.                         );                     
  1302.                     }
  1303.  
  1304.                     $send_result = WP_Cassify_Utils::wp_cassify_sendmail(
  1305.                         esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_from' ) ),
  1306.                         $wp_cassify_send_notification_to,
  1307.                         $wp_cassify_send_notification_subject,
  1308.                         $wp_cassify_send_notification_message,
  1309.                         $wp_cassify_notifications_priority,
  1310.                         esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_host' ) ),
  1311.                         esc_attr( WP_Cassify_Utils::wp_cassify_get_option( $this->wp_cassify_network_activated, 'wp_cassify_notifications_smtp_port' ) ),
  1312.                         $wp_cassify_notifications_smtp_auth_enabled,
  1313.                         $wp_cassify_notifications_encryption_type,
  1314.                         $wp_cassify_notifications_smtp_user,
  1315.                         $wp_cassify_notifications_smtp_password
  1316.                     );
  1317.                    
  1318.                     if ( $send_result == TRUE ) {
  1319. ?>
  1320.                     <div id="message_test_notification" class="updated" >Mail sent successfully.</div>
  1321. <?php
  1322.                     }
  1323.                     else {
  1324. ?>
  1325.                     <div id="message_test_notification" class="error" ><?php echo esc_attr( print_r( $send_result ) ); ?></div>
  1326. <?php  
  1327.                     }
  1328.                 }
  1329.                
  1330.                 // Empty cache when options are updated.
  1331.                 if (function_exists('w3tc_pgcache_flush')) {
  1332.                     w3tc_pgcache_flush();
  1333.  
  1334.                     // Sleep during cache is cleaning.
  1335.                     sleep ( 2 );
  1336.                 }
  1337.             }
  1338.            
  1339.             $post_action_page = NULL;
  1340.            
  1341.             if ( $this->wp_cassify_network_activated ) {
  1342.                 $wp_cassify_post_action_url = $this->wp_cassify_multisite_admin_page_slug . '?page=wp-cassify.php';
  1343.             }
  1344.             else {
  1345.                 $wp_cassify_post_action_url = $this->wp_cassify_admin_page_slug . '?page=wp-cassify.php';
  1346.             }
  1347. ?>
  1348.         <div class="wrap" id="wp-cassify">
  1349.         <h2><?php screen_icon('options-general'); ?><?php echo $this->wp_cassify_plugin_datas[ 'Name' ] ?></h2>
  1350.        
  1351.         <?php if ( $this->wp_cassify_is_options_updated() ) { ?>
  1352.                 <div id="message" class="updated" >Settings saved successfully</div>
  1353.         <?php } ?>
  1354.  
  1355.         <form method="post" action="<?php echo $wp_cassify_post_action_url; ?>" enctype="multipart/form-data">
  1356.             <?php wp_nonce_field( 'admin_form', 'wp_cassify_admin_form' ); // Set security token ?>
  1357.             <?php settings_fields( 'wp-cassify-settings-group' ); ?>
  1358.             <?php do_settings_sections( 'wp-cassify-settings-group' ); ?>
  1359.            
  1360.             <?php if ( $this->wp_cassify_network_activated ) { ?>
  1361.                 <input type="hidden" id="wp_cassify_network_activated" name="wp_cassify_network_activated" value="enabled" />
  1362.             <?php } else { ?>
  1363.                 <input type="hidden" id="wp_cassify_network_activated" name="wp_cassify_network_activated" value="disabled" />
  1364.             <?php } ?>
  1365.  
  1366.            
  1367.             <div id="poststuff" class="metabox-holder columns-2">
  1368.                 <div id="side-info-column" class="inner-sidebar">
  1369.                     <?php do_meta_boxes( $this->wp_cassify_admin_page_hook, 'side', array() ); ?>
  1370.                 </div>
  1371.                 <div id="post-body" class="metabox-holder columns-2">
  1372.                     <div id="post-body-content" class="has-sidebar-content">
  1373.                         <?php do_meta_boxes( $this->wp_cassify_admin_page_hook, 'normal', array() ); ?>
  1374.                     </div>
  1375.                 </div>
  1376.             </div>
  1377.         </form>
  1378.         </div>
  1379.         <?php
  1380.     }
  1381.    
  1382.     /**
  1383.      * Export plugin configuration options settings
  1384.      */
  1385.     public function wp_cassify_export_configuration_options_settings() {
  1386.  
  1387.  
  1388.         if ( !current_user_can( 'manage_options' ) )  {
  1389.             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  1390.         }
  1391.  
  1392.         if ( $this->wp_cassify_is_options_updated() ) {    
  1393.        
  1394.             // Check security tocken
  1395.             if (! wp_verify_nonce ($_POST[ 'wp_cassify_admin_form' ], 'admin_form' ) ) {
  1396.                 die( 'Security Check 1 !' );
  1397.             }
  1398.            
  1399.             if (! empty( $_POST['wp_cassify_backup_plugin_options_settings'] ) ){
  1400.            
  1401.                 $wp_cassify_backup_plugin_options_settings = WP_Cassify_Utils::wp_cassify_export_configuration_options( false );
  1402.    
  1403.                 nocache_headers();
  1404.                 header( 'Content-Type: application/json; charset=utf-8' );
  1405.                 header( 'Content-Disposition: attachment; filename=wpcassify-settings-export-' . date( 'm-d-Y' ) . '.json' );
  1406.                 header( "Expires: 0" );
  1407.                
  1408.                 echo json_encode( $wp_cassify_backup_plugin_options_settings );
  1409.                 exit;          
  1410.             }
  1411.         }
  1412.     }  
  1413.  
  1414.     /**
  1415.      * Import plugin configuration options settings
  1416.      */
  1417.     public function wp_cassify_import_configuration_options_settings() {
  1418.  
  1419.  
  1420.         if ( !current_user_can( 'manage_options' ) )  {
  1421.             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  1422.         }
  1423.  
  1424.         if ( $this->wp_cassify_is_options_updated() ) {    
  1425.        
  1426.             // Check security tocken
  1427.             if (! wp_verify_nonce ($_POST[ 'wp_cassify_admin_form' ], 'admin_form' ) ) {
  1428.                 die( 'Security Check 2 !' );
  1429.             }
  1430.  
  1431.             if (! empty( $_FILES['wp_cassify_restore_plugin_options_configuration_settings_file']['name'] ) ) {
  1432.  
  1433.                 //$extension = end( explode( '.', $_FILES['wp_cassify_restore_plugin_options_configuration_settings_file']['name'] ) );
  1434.                 $extension = explode( '.', $_FILES['wp_cassify_restore_plugin_options_configuration_settings_file']['name'] );
  1435.                 $extension = end( $extension );
  1436.  
  1437.                 if( $extension != 'json' ) {
  1438.                     wp_die( __( 'Please upload a valid .json file' ) );
  1439.                 }
  1440.                
  1441.                 $import_file = $_FILES['wp_cassify_restore_plugin_options_configuration_settings_file']['tmp_name'];
  1442.                
  1443.                 if( empty( $import_file ) ) {
  1444.                     wp_die( __( 'Please upload a file to import' ) );
  1445.                 }
  1446.                
  1447.                 $wp_cassify_import_configuration_options = (array) json_decode( file_get_contents( $import_file ) );
  1448.                
  1449.                 WP_Cassify_Utils::wp_cassify_import_configuration_options(
  1450.                     $wp_cassify_import_configuration_options,
  1451.                     $this->wp_cassify_network_activated
  1452.                 );
  1453.                            
  1454.                 if ( $this->wp_cassify_network_activated ) {
  1455.                     wp_safe_redirect( admin_url( $this->wp_cassify_multisite_admin_page_slug . '?page=wp-cassify.php' ) ); exit;
  1456.                 }
  1457.                 else {
  1458.                     wp_safe_redirect( admin_url( $this->wp_cassify_admin_page_slug . '?page=wp-cassify.php' ) ); exit;
  1459.                 }
  1460.             }
  1461.         }
  1462.     }
  1463.  
  1464.    
  1465.     /**
  1466.      * Detect if form has been submitted.
  1467.      * @return is_updated
  1468.      */
  1469.     private function wp_cassify_is_options_updated() {
  1470.        
  1471.         $is_updated = FALSE;
  1472.         if ( ( isset( $_POST[ 'action' ] ) ) && ( $_POST[ 'action' ] == 'update' ) ) {    
  1473.            
  1474.             $is_updated = TRUE;
  1475.         }
  1476.        
  1477.         return $is_updated;
  1478.     }
  1479. }
  1480. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement