0, // Duration to retrieve 'rows' => 2, // Rows 'cols' => 1, // Columns 'warn' => FALSE, ); public static function tab_setup( $context, $tab ) { /*----------------------------------------* * Control parameters in cookie *----------------------------------------*/ $options = IP_Geo_Block::get_option(); $cookie = $context->get_cookie(); // [0]:Section, [1]:Open a new window, [2]:Duration to retrieve, [3]:Row, [4]:Column self::$controls['time'] = empty( $cookie[ $tab ][2] ) ? self::$controls['time'] : min( 3, max( 0, (int)$cookie[ $tab ][2] ) ); self::$controls['rows'] = empty( $cookie[ $tab ][3] ) ? self::$controls['rows'] : min( 4, max( 1, (int)$cookie[ $tab ][3] ) ); self::$controls['cols'] = empty( $cookie[ $tab ][4] ) ? self::$controls['cols'] : min( 5, max( 1, (int)$cookie[ $tab ][4] ) ); self::$controls['warn'] = ! $options['validation']['reclogs']; /*----------------------------------------* * Blocked by target in logs section *----------------------------------------*/ register_setting( $option_slug = IP_Geo_Block::PLUGIN_NAME, $option_name = IP_Geo_Block::OPTION_NAME ); add_settings_section( $section = IP_Geo_Block::PLUGIN_NAME . '-network', __( 'Blocked by target in logs', 'ip-geo-block' ), array( __CLASS__, 'render_network' ), $option_slug ); /*----------------------------------------* * Chart display layout *----------------------------------------*/ $html = ''; add_settings_field( $option_name.'_chart-size', __( 'Chart display layout', 'ip-geo-block' ), array( $context, 'callback_field' ), $option_slug, $section, array( 'type' => 'html', 'value' => $html, ) ); /*----------------------------------------* * Duration to retrieve *----------------------------------------*/ $time = array( __( 'All', 'ip-geo-block' ), __( 'Latest 1 hour', 'ip-geo-block' ), __( 'Latest 24 hours', 'ip-geo-block' ), __( 'Latest 1 week', 'ip-geo-block' ), ); // make a list of duration $html = "\n"; foreach ( $time as $key => $val ) { $html .= '
  • ' . "\n"; } add_settings_field( $option_name.'_select_duration', __( 'Duration to retrieve', 'ip-geo-block' ), array( $context, 'callback_field' ), $option_slug, $section, array( 'type' => 'html', 'value' => '', ) ); } /** * Render log data * * @param array $args associative array of `id`, `title`, `callback`. */ public static function render_network( $args ) { require_once IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php'; if ( self::$controls['warn'] ) { $context = IP_Geo_Block_Admin::get_instance(); $url = esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME, 'tab' => '0', 'sec' => 5 ), $context->dashboard_url() ) . '#' . IP_Geo_Block::PLUGIN_NAME . '-section-5' ); 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"; } $row = self::$controls['rows'] * 5; $col = self::$controls['cols']; $page = empty( $_REQUEST['p']) ? 0 : (int)$_REQUEST['p']; $start = $page * ( $row * $col ); $count = min( $total = IP_Geo_Block_Admin_Ajax::get_network_count(), $row * $col ); // [0]:site, [1]:comment, [2]:xmlrpc, [3]:login, [4]:admin, [5]:public, [6]:link $json = IP_Geo_Block_Admin_Ajax::restore_network( self::$controls['time'], $start, $count, FALSE ); // Max value on hAxis $max = 0; $num = count( $json ); for ( $i = 0; $i < $num; ++$i ) { $max = max( $max, array_sum( array_slice( $json[ $i ], 1, 5 ) ) ); } // Split the array into chunks $arr = array_chunk( $json, $row ); $num = (int)floor( count( $arr ) / $col ); // Embed array into data attribute as json echo '
    ', "\n"; for ( $i = 0; $i < $col; ++$i ) { if ( isset( $arr[ $i ] ) ) { echo '
    ', '
    ', "\n"; } else { echo '
    '; } } echo '
    ', "\n"; // pagination $url = esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME, 'tab' => 5 ), network_admin_url( 'admin.php' ) ) ); echo '
    ', "\n", '«', ''; $num = (int)ceil( $total / ( $row * $col ) ); for ( $i = 0; $i < $num; ++$i ) { echo '', $i+1, ''; } $num -= 1; echo '', '', '»', '
    ', "\n"; // paginate wrapper } }