Plugin Directory

Changeset 640296


Ignore:
Timestamp:
12/17/2012 01:57:21 AM (13 years ago)
Author:
Bit51
Message:

Added .csv export for 404 logs

Location:
better-wp-security/trunk/inc/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • better-wp-security/trunk/inc/admin/common.php

    r640277 r640296  
    840840        function log404csv() {
    841841
    842 
     842            global $wpdb;
     843
     844            @header( 'Content-type: text/x-csv' );
     845            @header( 'Content-Transfer-Encoding: binary' );
     846            @header( 'Content-Disposition: attachment; filename=404errors.csv' );
     847            @header( 'Cache-Control: no-cache, must-revalidate' );
     848            @header( 'Expires: Thu, 22 Jun 1978 00:28:00 GMT' );
     849
     850            @ini_set( 'auto_detect_line_endings', true );
     851
     852            $headers = array(
     853                'url',
     854                'time',
     855                'host',
     856                'referrer'
     857            );
     858
     859            $errors = $wpdb->get_results( "SELECT url, timestamp, host, referrer, url FROM `" . $wpdb->base_prefix . "bwps_log` WHERE `type` = 2;", ARRAY_A );
     860
     861            array_unshift( $errors, $headers );
     862
     863            foreach ( $errors as $error ) {
     864
     865                foreach ( $error as $attr ) {
     866
     867                    echo $attr . ',';
     868
     869                }
     870
     871                echo PHP_EOL;
     872
     873            }
     874           
     875            exit;
    843876
    844877        }
  • better-wp-security/trunk/inc/admin/construct.php

    r571459 r640296  
    2929       
    3030            add_action( 'admin_init', array( &$this, 'awaycheck' ) );
     31
     32            //Process 404 .csv file
     33            if ( isset( $_GET['bit51_404_csv'] ) ) {
     34
     35                add_action( 'init', array( &$this, 'log404csv' ) );
     36               
     37            }
    3138               
    3239        }
  • better-wp-security/trunk/inc/admin/content.php

    r640277 r640296  
    23312331            $log_content_4_table->prepare_items();
    23322332            $log_content_4_table->display();
    2333            
    2334             echo '<a href="admin.php?page=better-wp-security-logs&bit51_404_csv">' . __( 'Download 404 Log in .csv format', $this->hook ) . '</a>';
    2335 
    2336             //Process 404 .csv file
    2337             if ( isset( $_GET['bit51_404_csv'] ) ) {
    2338                  $this->log404csv();
    2339             }
     2333
     2334            ?>
     2335
     2336                <p><a href="<?php echo admin_url(); ?><?php echo is_multisite() ? 'network/' : ''; ?>admin.php?page=better-wp-security-logs&bit51_404_csv" target="_blank" ><?php _e( 'Download 404 Log in .csv format', $this->hook ); ?></a></p>
     2337
     2338            <?php
    23402339           
    23412340        }
     
    23872386                ?>
    23882387               
    2389                 <p><a href="<?php echo admin_url(); ?><?php echo is_multisite() ? 'network/' : ''; ?>admin.php?page=better-wp-security-logs#file-change"><?php _e( 'Return to Log', $this->hook ); ?></a></p>
     2388                <p><a href="<?php echo admin_url(); ?><?php echo is_multisite() ? 'network/' : ''; ?>admin.php?page=better-wp-security-logs#file-change" ><?php _e( 'Return to Log', $this->hook ); ?></a></p>
    23902389               
    23912390            <?php           
Note: See TracChangeset for help on using the changeset viewer.