get_cookie();
$options = IP_Geo_Block::get_option();
$plugin_slug = IP_Geo_Block::PLUGIN_NAME;
register_setting(
$option_slug = IP_Geo_Block::PLUGIN_NAME,
$option_name = IP_Geo_Block::OPTION_NAME
);
/*----------------------------------------*
* Validation logs
*----------------------------------------*/
add_settings_section(
$section = $plugin_slug . '-logs',
array( __( 'Validation logs', 'ip-geo-block' ), '' . __( 'Help', 'ip-geo-block' ) . '' ),
( $options['validation']['reclogs'] ?
array( __CLASS__, 'validation_logs' ) :
array( __CLASS__, 'warn_accesslog' )
),
$option_slug
);
if ( $options['validation']['reclogs'] ):
if ( extension_loaded( 'pdo_sqlite' ) ):
$html = '
';
// Live update
add_settings_field(
$option_name.'_live-log',
__( 'Live update', 'ip-geo-block' ) . '',
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'html',
'option' => $option_name,
'field' => 'live-log',
'value' => $html,
'class' => isset( $cookie[ $tab ][1] ) && $cookie[ $tab ][1] === 'o' ? '' : 'ip-geo-block-hide',
)
);
endif; // extension_loaded( 'pdo_sqlite' )
// make a list of target (same as in tab-accesslog.php)
$target = array(
'comment' => __( 'Comment post', 'ip-geo-block' ),
'xmlrpc' => __( 'XML-RPC', 'ip-geo-block' ),
'login' => __( 'Login form', 'ip-geo-block' ),
'admin' => __( 'Admin area', 'ip-geo-block' ),
'public' => __( 'Public facing pages', 'ip-geo-block' ),
);
$html = "\n".'' . "\n";
foreach ( $target as $key => $val ) {
$html .= '' . "\n";
}
// Select target
add_settings_field(
$option_name.'_select_target',
__( 'Select target', 'ip-geo-block' ),
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'html',
'option' => $option_name,
'field' => 'select_target',
'value' => '',
)
);
// Search in logs
add_settings_field(
$option_name.'_search_filter',
__( 'Search in logs', 'ip-geo-block' ),
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'text',
'option' => $option_name,
'field' => 'search_filter',
'value' => isset( $_GET['s'] ) ? esc_html( $_GET['s'] ) : '', // preset filter
'after' => ''. __( 'Reset', 'ip-geo-block' ) . '',
)
);
// Preset filters
$filters = has_filter( $plugin_slug . '-logs-preset' ) ? apply_filters( $plugin_slug . '-logs-preset', array() ) : $context->preset_filters();
if ( ! empty( $filters ) ) {
// allowed tags and attributes
$allow_tags = array(
'span' => array(
'class' => 1,
'title' => 1,
)
);
$html = '';
foreach ( $filters as $filter ) {
$html .= '- ' . IP_Geo_Block_Util::kses( $filter['title'], $allow_tags ) . '
';
}
add_settings_field(
$option_name.'_logs_preset',
'' . __( 'Preset filters', 'ip-geo-block' ) . '
',
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'html',
'option' => $option_name,
'field' => 'logs_preset',
'value' => $html,
)
);
}
// Bulk action
add_settings_field(
$option_name.'_bulk_action',
__( 'Bulk action', 'ip-geo-block' ),
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'select',
'option' => $option_name,
'field' => 'bulk_action',
'value' => 0,
'list' => array(
0 => NULL,
'bulk-action-ip-erase' => __( 'Remove entries by IP address', 'ip-geo-block' ),
'bulk-action-ip-white' => __( 'Add IP address to “Whitelist”', 'ip-geo-block' ),
'bulk-action-ip-black' => __( 'Add IP address to “Blacklist”', 'ip-geo-block' ), ) + ( $options['Maxmind']['use_asn'] <= 0 ? array() : array(
'bulk-action-as-white' => __( 'Add AS number to “Whitelist”', 'ip-geo-block' ),
'bulk-action-as-black' => __( 'Add AS number to “Blacklist”', 'ip-geo-block' ),
) ),
'after' => ''. __( 'Apply', 'ip-geo-block' ) . '' . '',
)
);
// Clear logs
add_settings_field(
$option_name.'_clear_all',
__( 'Clear logs', 'ip-geo-block' ),
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'button',
'option' => $option_name,
'field' => 'clear_all',
'value' => __( 'Clear all', 'ip-geo-block' ),
'after' => '',
'class' => empty( $cookie[ $tab ][1] ) || $cookie[ $tab ][1] !== 'o' ? '' : 'ip-geo-block-hide',
)
);
// Export logs
add_settings_field(
$option_name.'_export_logs',
__( 'Export logs', 'ip-geo-block' ),
array( $context, 'callback_field' ),
$option_slug,
$section,
array(
'type' => 'none',
'before' => ''. __( 'Export csv', 'ip-geo-block' ) . '',
'after' => '',
'class' => empty( $cookie[ $tab ][1] ) || $cookie[ $tab ][1] !== 'o' ? '' : 'ip-geo-block-hide',
)
);
endif; // $options['validation']['reclogs']
}
/**
* Function that fills the section with the desired content.
*
*/
private static function dashboard_url() {
$options = IP_Geo_Block::get_option();
$context = IP_Geo_Block_Admin::get_instance();
return $context->dashboard_url( $options['network_wide'] );
}
public static function validation_logs() {
echo '', "\n";
}
public static function warn_accesslog() {
$url = esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME, 'tab' => '0', 'sec' => 3 ), self::dashboard_url() ) . '#' . IP_Geo_Block::PLUGIN_NAME . '-section-3' );
echo '', sprintf( __( '[ %sRecord “Validation logs”%s ] is disabled.', 'ip-geo-block' ), '', '' ), '
', "\n";
echo '', __( 'Please set the proper condition to record and analyze the validation logs.', 'ip-geo-block' ), '
', "\n";
}
}