| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* 404 error logging. Extends the base log class with specifics for 404s |
| 5 |
*/ |
| 6 |
class Red_404_Log extends Red_Log { |
| 7 |
/** |
| 8 |
* Get's the table name for this log object |
| 9 |
* |
| 10 |
* @param Object $wpdb WPDB object. |
| 11 |
* @return String |
| 12 |
*/ |
| 13 |
protected static function get_table_name( $wpdb ) { |
| 14 |
return "{$wpdb->prefix}redirection_404"; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Create a 404 log entry |
| 19 |
* |
| 20 |
* @param string $domain Domain name of request. |
| 21 |
* @param string $url URL of request. |
| 22 |
* @param string $ip IP of client. |
| 23 |
* @param array $details Other log details. |
| 24 |
* @return integer|false Log ID, or false |
| 25 |
*/ |
| 26 |
public static function create( $domain, $url, $ip, $details ) { |
| 27 |
global $wpdb; |
| 28 |
|
| 29 |
$insert = static::sanitize_create( $domain, $url, $ip, $details ); |
| 30 |
$insert = apply_filters( 'redirection_404_data', $insert ); |
| 31 |
|
| 32 |
if ( $insert ) { |
| 33 |
do_action( 'redirection_404', $insert ); |
| 34 |
|
| 35 |
$wpdb->insert( $wpdb->prefix . 'redirection_404', $insert ); |
| 36 |
if ( $wpdb->insert_id ) { |
| 37 |
return $wpdb->insert_id; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get the CSV filename for this log object |
| 46 |
* |
| 47 |
* @return string |
| 48 |
*/ |
| 49 |
public static function get_csv_filename() { |
| 50 |
return 'redirection-404'; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Get the CSV headers for this log object |
| 55 |
* |
| 56 |
* @return array |
| 57 |
*/ |
| 58 |
public static function get_csv_header() { |
| 59 |
return [ 'date', 'source', 'ip', 'referrer', 'useragent' ]; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Get the CSV headers for this log object |
| 64 |
* |
| 65 |
* @param object $row Log row. |
| 66 |
* @return array |
| 67 |
*/ |
| 68 |
public static function get_csv_row( $row ) { |
| 69 |
return [ |
| 70 |
$row->created, |
| 71 |
$row->url, |
| 72 |
$row->ip, |
| 73 |
$row->referrer, |
| 74 |
$row->agent, |
| 75 |
]; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// phpcs:ignore |
| 80 |
class RE_404 { |
| 81 |
public static function create( $url, $agent, $ip, $referrer ) { |
| 82 |
_deprecated_function( __FUNCTION__, '4.6', 'Red_404_Log::create( $domain, $url, $ip, $details )' ); |
| 83 |
|
| 84 |
return Red_404_Log::create( Redirection_Request::get_server(), $url, $ip, [ |
| 85 |
'agent' => $agent, |
| 86 |
'referrer' => $referrer, |
| 87 |
'request_method' => Redirection_Request::get_request_method(), |
| 88 |
] ); |
| 89 |
} |
| 90 |
} |
| 91 |
|