options = get_option( $this->option_name ); ?>

options = get_option( $this->option_name ); $lines =(!isset($_GET['lines'])) ? '10': $_GET['lines']; $error_type = isset( $this->options['error_type'] ) ? $this->options['error_type'] : $this->defaults['error_type'] ; $error_log_path = isset( $this->options[ 'error_log_path' ] ) ? $this->options[ 'error_log_path' ] : $this->defaults[ 'error_log_path' ] ; $error_log_name = isset( $this->options[ 'error_log_name' ] ) ? $this->options[ 'error_log_name' ] : $this->defaults[ 'error_log_name' ] ; $file = $error_log_path.$error_log_name ; $file_exists = ( !empty( $file ) && file_exists( $file ) ) ? TRUE : FALSE ; ?>

()

        
            
    axlw_tail($file, $lines); $output = explode("\n", $output); // Latest first $output = array_reverse($output); foreach ($output as $out) { if(trim($out)!=''){ echo '
  1. '.htmlspecialchars($out).'
  2. '; } } ?>
option_name, // Option name array( $this, 'sanitize' ) // Sanitize ); add_settings_section( 'axlw_general_section', // ID __( 'General Settings', 'authentication-and-xmlrpc-log-writer' ), // Title array( $this, 'print_section_info' ), // Callback 'axlw-setting-admin' // Page ); add_settings_field( 'error_type', // ID __( 'Error Type', 'authentication-and-xmlrpc-log-writer' ), // Title array( $this, 'error_type_callback' ), // Callback 'axlw-setting-admin', // Page 'axlw_general_section' // Section ); add_settings_field( 'error_log_path', __( 'CUSTOM Error Log Path (only for CUSTOM error type)', 'authentication-and-xmlrpc-log-writer' ), array( $this, 'error_log_path_callback' ), 'axlw-setting-admin', 'axlw_general_section' ); add_settings_field( 'error_log_name', __( 'CUSTOM Error Log Name (only for CUSTOM error type)', 'authentication-and-xmlrpc-log-writer' ), array( $this, 'error_log_name_callback' ), 'axlw-setting-admin', 'axlw_general_section' ); add_settings_field( 'error_log_timezone', __( 'TIMEZONE', 'authentication-and-xmlrpc-log-writer' ), array( $this, 'error_log_timezone_callback' ), 'axlw-setting-admin', 'axlw_general_section' ); // Register the logviewer style wp_register_style( 'axlw_logviewer_style', plugins_url('style/admin-style-min.css', __FILE__) ); } /** * Sanitize each setting field as needed * * @param array $input Contains all settings fields as array keys */ public function sanitize( $input ) { $new_input = array(); if( isset( $input['error_type'] ) ) { $new_input['error_type'] = sanitize_text_field( $input['error_type'] ); // Cannot be blank if( empty( $new_input['error_type'] ) ) { add_settings_error( $this->option_name.'[error_type]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'Please select a valid VALUE for Error Type', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_type'] = $this->defaults['error_type']; } // Verify the value if( $new_input['error_type'] != "SYSTEM" && $new_input['error_type'] != "APACHE" && $new_input['error_type'] != "CUSTOM" ) { add_settings_error( $this->option_name.'[error_type]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'Please select a valid VALUE for Error Type', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_type'] = $this->defaults['error_type']; } } else { // Set it to the default value $new_input['error_type'] = $this->defaults['error_type']; } if( isset( $input['error_log_path'] ) ) { $new_input['error_log_path'] = sanitize_text_field( $input['error_log_path'] ); // Cannot be blank if( empty( $new_input['error_log_path'] ) ) { add_settings_error( $this->option_name.'[error_log_path]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'Please enter a valid VALUE for CUSTOM Error Log Path', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_log_path'] = $this->defaults['error_log_path']; } // Verify if dir exists and i writable if( !is_dir( $new_input['error_log_path'] ) or !is_writable( $new_input['error_log_path'] ) ) { add_settings_error( $this->option_name.'[error_log_path]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'CUSTOM Error Log Path not exist or is not writable', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_log_path'] = $this->defaults['error_log_path']; } } else { // Set it to the default value $new_input['error_log_path'] = $this->defaults['error_log_path']; } if( isset( $input['error_log_name'] ) ) { $new_input['error_log_name'] = sanitize_text_field( $input['error_log_name'] ); // Cannot be blank if( empty( $new_input['error_log_name'] ) ) { add_settings_error( $this->option_name.'[error_log_name]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'Please enter a valid VALUE for CUSTOM Error Log Name', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_log_name'] = $this->defaults['error_log_name']; } } else { // Set it to the default value $new_input['error_log_name'] = $this->defaults['error_log_name']; } if( isset( $input['error_log_timezone'] ) ) { $new_input['error_log_timezone'] = sanitize_text_field( $input['error_log_timezone'] ); // Cannot be blank if( empty( $new_input['error_log_timezone'] ) ) { add_settings_error( $this->option_name.'[error_log_timezone]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'Please enter a valid VALUE for TIMEZONE', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_log_timezone'] = $this->defaults['error_log_timezone']; } // Verify the value if( function_exists( "timezone_identifiers_list" ) ) { $zones = timezone_identifiers_list() ; if( empty( $zones ) or !in_array( $new_input['error_log_timezone'], $zones ) ) { add_settings_error( $this->option_name.'[error_log_timezone]', // Setting title esc_attr( 'settings_updated' ), // Error ID __( 'Please select a valid VALUE for TIMEZONE', 'authentication-and-xmlrpc-log-writer' ), // Error message 'error' // Type of message ); $new_input['error_log_timezone'] = $this->defaults['error_log_timezone']; } } } else { // Set it to the default value $new_input['error_log_timezone'] = $this->defaults['error_log_timezone']; } return $new_input; } /** * Print the Section text */ public function print_section_info() { print __( 'Enter your settings below:', 'authentication-and-xmlrpc-log-writer' ); } /** * Get the settings option array and print one of its values */ public function error_type_callback() { $selected = isset( $this->options['error_type'] ) ? $this->options['error_type'] : $this->defaults['error_type'] ; $select_options = array( 'SYSTEM' => array( 'SYSTEM', 'log will be written by SYSLOG' ), 'APACHE' => array( 'APACHE', 'log will be written by APACHE error log' ), 'CUSTOM' => array( 'CUSTOM', 'log will be written into setted CUSTOM Error Log Path' ) ) ; print '' ; // Desciption text print ' '.__( 'use this to set where the log will be written', 'authentication-and-xmlrpc-log-writer' ).' ' ; } /** * Get the settings option array and print one of its values */ public function error_log_path_callback() { printf( '', isset( $this->options['error_log_path'] ) ? esc_attr( $this->options['error_log_path']) : esc_attr( $this->defaults['error_log_path']) ); // Desciption text print ' '.__( 'this path will be used in CUSTOM mode. This path must exist and must be writable. E.g. ', 'authentication-and-xmlrpc-log-writer' ).'/your/custom/path/' ; } /** * Get the settings option array and print one of its values */ public function error_log_name_callback() { printf( '', isset( $this->options['error_log_name'] ) ? esc_attr( $this->options['error_log_name']) : esc_attr( $this->defaults['error_log_name']) ); } /** * Get the settings option array and print one of its values */ public function error_log_timezone_callback() { if( !function_exists( "timezone_identifiers_list" ) ) { printf( '', isset( $this->options['error_log_timezone'] ) ? esc_attr( $this->options['error_log_timezone']) : esc_attr( $this->defaults['error_log_timezone']) ); } else { $zones = timezone_identifiers_list() ; $selected = isset( $this->options['error_log_timezone'] ) ? $this->options['error_log_timezone'] : $this->defaults['error_log_timezone'] ; print '' ; } // Desciption text print ' '.__( 'Used to prevent WP timezone bug. Use your current server timezone.', 'authentication-and-xmlrpc-log-writer' ).'' ; } public function axlw_tail($filename, $lines = 10, $buffer = 4096) { // Open the file $f = fopen($filename, "rb"); // Jump to last character fseek($f, -1, SEEK_END); // Read it and adjust line number if necessary // (Otherwise the result would be wrong if file doesn't end with a blank line) if(fread($f, 1) != "\n") $lines -= 1; // Start reading $output = ''; $chunk = ''; // While we would like more while(ftell($f) > 0 && $lines >= 0) { // Figure out how far back we should jump $seek = min(ftell($f), $buffer); // Do the jump (backwards, relative to where we are) fseek($f, -$seek, SEEK_CUR); // Read a chunk and prepend it to our output $chunk = fread($f, $seek) ; $output = $chunk.$output; // Jump back to where we started reading fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR); // Decrease our line counter $lines -= substr_count($chunk, "\n"); } // While we have too many lines // (Because of buffer size we might have read too many) while($lines++ < 0) { // Find first newline and remove all text before that $output = substr($output, strpos($output, "\n") + 1); } // Close file and return fclose($f); return $output; } public function axlw_logwiewer_admin_styles() { /* * It will be called only on your plugin admin page, enqueue our stylesheet here */ wp_enqueue_style( 'axlw_logviewer_style' ); } } if( is_admin() ) $axlw_settings_page = new axLogWriterSettingsPage();