'atk-404-overview-' . get_current_blog_id() . '-' . get_current_user_id(), 'show' => __( 'Show overview', 'activity-track' ), 'hide' => __( 'Hide overview', 'activity-track' ), ] ); } private function authorize() { if ( ! current_user_can( 'manage_options' ) || ! ATKAI_404_Events::enabled() ) wp_die( esc_html__( 'You cannot access 404 logs.', 'activity-track' ) ); } private function input( $key, $source = null ) { $source = $source ?? $_GET; return isset( $source[ $key ] ) && is_string( $source[ $key ] ) ? sanitize_text_field( wp_unslash( $source[ $key ] ) ) : ''; } private function filters( $source = null ) { $search = substr( $this->input( 's', $source ), 0, 200 ); $days = absint( $this->input( 'days', $source ) ); return [ 's' => $search, 'days' => in_array( $days, [ 1, 7, 30 ], true ) ? $days : 0 ]; } private function where( $filters ) { global $wpdb; $where = '1=1'; if ( $filters['days'] ) $where .= $wpdb->prepare( ' AND captured_at >= %s', gmdate( 'Y-m-d H:i:s', time() - $filters['days'] * DAY_IN_SECONDS ) ); if ( $filters['s'] ) $where .= $wpdb->prepare( ' AND target_url LIKE %s', '%' . $wpdb->esc_like( $filters['s'] ) . '%' ); return $where; } private function url( $args = [] ) { return add_query_arg( array_merge( [ 'page' => 'activity-track-ai', 'tab' => '404' ], $args ), admin_url( 'admin.php' ) ); } public function delete() { $this->authorize(); check_admin_referer( 'atk_404_delete' ); global $wpdb; $ids = isset( $_POST['logs'] ) && is_array( $_POST['logs'] ) ? array_slice( array_filter( array_map( 'absint', $_POST['logs'] ) ), 0, 50 ) : []; if ( $ids ) $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE log_id IN (' . implode( ',', array_fill( 0, count( $ids ), '%d' ) ) . ')', array_merge( [ ATKAI_404_Events::table() ], $ids ) ) ); wp_safe_redirect( $this->url( $this->filters( $_POST ) ) ); exit; } public function export() { $this->authorize(); check_admin_referer( 'atk_404_export' ); global $wpdb; $where = $this->where( $this->filters() ); $snapshot = absint( $wpdb->get_var( $wpdb->prepare( 'SELECT MAX(log_id) FROM %i', ATKAI_404_Events::table() ) ) ); nocache_headers(); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename=activity-track-404.csv' ); $out = fopen( 'php://output', 'w' ); fputcsv( $out, [ 'Date & Time (UTC)', 'Target URL', 'User Device', 'User Location', 'IP Address', 'Referrer URL', 'Method', 'User Agent', 'User ID', 'Daily Visitor Fingerprint' ] ); $last = $snapshot + 1; for ( $batch = 0; $batch < 20; $batch++ ) { $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM %i WHERE $where AND log_id < %d ORDER BY log_id DESC LIMIT 500", ATKAI_404_Events::table(), $last ) ); foreach ( $rows as $row ) { $cells = [ $row->captured_at, $row->target_url, $row->device, $row->location, empty( \ATKAI_OPTIONS\Option::get( 'options' )['atk_no_ip'] ) ? $row->user_ip_address : '', $row->referrer_url, $row->request_method, $row->user_agent, $row->user_id, $row->visitor_hash ]; // Prevent request-derived values from becoming spreadsheet formulas. $cells = array_map( static function( $cell ) { return preg_match( '/^[=+@\-\t\r\n]/', (string) $cell ) ? "'" . $cell : $cell; }, $cells ); fputcsv( $out, $cells ); $last = $row->log_id; } if ( count( $rows ) < 500 ) break; } fclose( $out ); exit; } private function location_cell( $row ) { $options = \ATKAI_OPTIONS\Option::get( 'options' ); if ( ! empty( $options['atk_no_ip'] ) ) { echo esc_html__( 'IP Log', 'activity-track' ) . ' ' . esc_html__( 'Disabled', 'activity-track' ) . ''; return; } $ip = $row->user_ip_address ?? ''; $label = $ip ? AtkGeoLocation::readableIP( $ip ) : ( $row->location ?: __( 'Unknown', 'activity-track' ) ); $tooltip = $ip ? apply_filters( 'atkai_modify_user_ip_address', $ip ) : __( 'IP address was not recorded for this entry.', 'activity-track' ); if ( $row->location ) $tooltip .= ' · ' . $row->location; echo ''; if ( $ip && defined( 'ATKAI_PRO_PLUGIN_ACTIVE' ) && has_action( 'atkai_address_pro' ) ) { do_action( 'atkai_address_pro', $ip, $label, $row->country_code ?? '' ); } else { echo '' . esc_html( $label ?: __( 'Unknown', 'activity-track' ) ) . ''; } echo '' . esc_html( $tooltip ) . ''; $code = $row->country_code ?? ''; if ( ! defined( 'ATKAI_PRO_PLUGIN_ACTIVE' ) && preg_match( '/^[a-z]{2}$/', $code ) ) { echo ' | ' . esc_attr( $row->location ) . '' . esc_html( $row->location ) . ''; } } public function render() { $this->authorize(); ?>

' . esc_html__( '404 storage is unavailable. Visit Settings to retry installation.', 'activity-track' ) . '

'; return; } global $wpdb; $filters = $this->filters(); $page = max( 1, absint( $this->input( 'paged' ) ) ); $where = $this->where( $filters ); $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM %i WHERE $where ORDER BY log_id DESC LIMIT 51 OFFSET %d", ATKAI_404_Events::table(), ( $page - 1 ) * 50 ) ); $more = count( $rows ) > 50; $rows = array_slice( $rows, 0, 50 ); ?>
' . esc_html( $label ) . ''; ?>'; ?>
' . esc_html__( 'No 404 records in this view. New errors appear after tracking is enabled.', 'activity-track' ) . '
captured_at . ' UTC' ), time() ) . ' ' . __( 'ago', 'activity-track' ) ); ?>
captured_at, 'M j, Y H:i:s' ) . ' ' . wp_timezone_string() ); ?>
target_url ); ?>

request_method . ' · HTTP 404 · ' . ( $row->user_id ? sprintf( __( 'User ID %d', 'activity-track' ), $row->user_id ) : __( 'Guest', 'activity-track' ) ) ); ?>

user_agent ?: __( 'User agent not provided', 'activity-track' ) ); ?>

device ); ?>location_cell( $row ); ?> referrer_url, [ 'http', 'https' ] ); ?> referrer_url ); ?> atkai_log_source = '404'; echo wp_kses( apply_filters( 'atkai_render_logs_ai_column', '', $row ), [ 'button' => [ 'type' => true, 'class' => true, 'data-log-id' => true, 'data-log-source' => true ], 'svg' => [ 'class' => true, 'width' => true, 'height' => true, 'viewbox' => true, 'fill' => true, 'xmlns' => true ], 'path' => [ 'd' => true, 'fill-rule' => true, 'clip-rule' => true, 'fill' => true ], 'span' => [ 'class' => true ], ] ); ?>
1 ) : ?>