Changeset 3816103
- Timestamp:
- 11/22/2026 04:26:03 AM (less than one hour ago)
- Location:
- an10-ai-crawler-analytics
- Files:
-
- 10 edited
- 1 copied
-
tags/0.2.0 (copied) (copied from an10-ai-crawler-analytics/trunk )
-
tags/0.2.0/an10-ai-crawler-analytics.php (modified) (2 diffs)
-
tags/0.2.0/assets/admin/admin.css (modified) (1 diff)
-
tags/0.2.0/includes/admin/class-an10-admin.php (modified) (6 diffs)
-
tags/0.2.0/includes/class-an10-store.php (modified) (1 diff)
-
tags/0.2.0/readme.txt (modified) (2 diffs)
-
trunk/an10-ai-crawler-analytics.php (modified) (2 diffs)
-
trunk/assets/admin/admin.css (modified) (1 diff)
-
trunk/includes/admin/class-an10-admin.php (modified) (6 diffs)
-
trunk/includes/class-an10-store.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
an10-ai-crawler-analytics/tags/0.2.0/an10-ai-crawler-analytics.php
r3815816 r3816103 3 3 * Plugin Name: Agent Number 10 – AI Crawler Analytics 4 4 * Description: See which AI crawlers really visit, verified against each operator's published IP list; which pages they have never fetched; the visits AI answers send you; and what stands between your pages and an AI citation. Nothing phones home. 5 * Version: 0. 1.25 * Version: 0.2.0 6 6 * Requires at least: 6.5 7 7 * Requires PHP: 8.0 … … 17 17 defined( 'ABSPATH' ) || exit; 18 18 19 define( 'AN10_VERSION', '0. 1.2' );19 define( 'AN10_VERSION', '0.2.0' ); 20 20 // The plugin slug. It must equal this file's name, the folder name and the 21 21 // text domain; changing it is a search and replace across the plugin. -
an10-ai-crawler-analytics/tags/0.2.0/assets/admin/admin.css
r3805222 r3816103 281 281 gap: 16px; 282 282 margin: 16px 0 0; 283 } 284 285 /* Hero: the spoofed count leads the screen. */ 286 .an10 .an10-hero { 287 display: flex; 288 flex-wrap: wrap; 289 align-items: flex-end; 290 gap: 20px 56px; 291 margin: 0 0 16px; 292 } 293 294 .an10 .an10-hero__eyebrow { 295 flex-basis: 100%; 296 color: var(--an10-muted-foreground); 297 font-size: 13px; 298 font-weight: var(--an10-weight-ui); 299 } 300 301 .an10 .an10-hero__main { 302 display: flex; 303 flex-direction: column; 304 gap: 4px; 305 } 306 307 .an10 .an10-hero__label { 308 color: var(--an10-muted-foreground); 309 font-size: 13px; 310 font-weight: var(--an10-weight-ui); 311 } 312 313 .an10 .an10-hero__num { 314 color: var(--an10-destructive); 315 font-size: 56px; 316 font-variant-numeric: tabular-nums; 317 font-weight: var(--an10-weight-head); 318 letter-spacing: -0.03em; 319 line-height: 1.02; 320 } 321 322 .an10 .an10-hero__num--zero { 323 color: var(--an10-foreground); 324 } 325 326 .an10 .an10-hero__sub { 327 max-width: 46ch; 328 color: var(--an10-foreground-dim); 329 font-size: 13px; 330 } 331 332 .an10 .an10-hero__side { 333 display: flex; 334 gap: 40px; 335 padding-bottom: 6px; 336 } 337 338 .an10 .an10-export { 339 margin-top: 16px; 340 display: flex; 341 align-items: center; 342 gap: 12px; 343 flex-wrap: wrap; 283 344 } 284 345 -
an10-ai-crawler-analytics/tags/0.2.0/includes/admin/class-an10-admin.php
r3815816 r3816103 68 68 add_action( 'admin_enqueue_scripts', array( self::class, 'assets' ) ); 69 69 add_action( 'admin_notices', array( self::class, 'first_data_notice' ) ); 70 foreach ( array( 'apply', 'undo', 'rescan', 'settings', 'refresh_lists', 'dismiss', 'verification' ) as $action ) {70 foreach ( array( 'apply', 'undo', 'rescan', 'settings', 'refresh_lists', 'dismiss', 'verification', 'export' ) as $action ) { 71 71 add_action( "admin_post_an10_{$action}", array( self::class, "handle_{$action}" ) ); 72 72 } … … 227 227 self::render_verification_offer(); 228 228 } 229 230 // The one thing only this plugin does: catching spoofed crawlers. The 231 // verification split, spoofed as the headline. Verified is the AI-only 232 // figure ($fetches, search engines excluded) so it reconciles with the 233 // "Verified AI crawler fetches" number below. 234 self::hero( 235 (int) $fetches, 236 (int) array_sum( array_column( $summary, 'spoofed' ) ), 237 (int) array_sum( array_column( $summary, 'unverified' ) ) 238 ); 229 239 230 240 // Three numbers first. … … 430 440 ) . '</p>'; 431 441 } 442 if ( AN10_Store::has_rows() ) { 443 echo '<form method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '" class="an10-export">'; 444 wp_nonce_field( 'an10_export' ); 445 echo '<input type="hidden" name="action" value="an10_export">'; 446 echo '<button type="submit" class="button">' . esc_html__( 'Export CSV', 'an10-ai-crawler-analytics' ) . '</button> <span class="an10-muted">' . esc_html__( 'Every recorded visit, from your database only.', 'an10-ai-crawler-analytics' ) . '</span></form>'; 447 } 432 448 echo '</section></div>'; 433 449 … … 474 490 esc_html( number_format_i18n( $value ) ), 475 491 wp_kses( $sub, array( 'span' => array( 'class' => true ) ) ) 492 ); 493 } 494 495 /** 496 * The hero: the verification split of crawler hits over the last 30 days, 497 * with the spoofed count as the headline. It is the one thing no other 498 * plugin does, so it leads the screen. Reads the summary already queried. 499 * 500 * @param int $verified Verified crawler hits. 501 * @param int $spoofed Spoofed crawler hits. 502 * @param int $unverified Hits that could not be checked. 503 */ 504 private static function hero( int $verified, int $spoofed, int $unverified ): void { 505 $zero = 0 === $spoofed; 506 $sub = $zero 507 ? __( '0 spoofed so far. We check each crawler hit against the IP list its operator publishes.', 'an10-ai-crawler-analytics' ) 508 : __( 'Caught using a real crawler\'s name from an address its operator does not publish.', 'an10-ai-crawler-analytics' ); 509 printf( 510 '<section class="an10-card an10-hero"><span class="an10-hero__eyebrow">%s</span>' . 511 '<div class="an10-hero__main"><span class="an10-hero__label">%s</span>' . 512 '<span class="%s">%s</span><span class="an10-hero__sub">%s</span></div>' . 513 '<div class="an10-hero__side">' . 514 '<div class="an10-kpi"><span class="an10-kpi__label">%s</span><span class="an10-kpi__value">%s</span></div>' . 515 '<div class="an10-kpi"><span class="an10-kpi__label">%s</span><span class="an10-kpi__value">%s</span></div>' . 516 '</div></section>', 517 esc_html__( 'Crawler identity checks, last 30 days', 'an10-ai-crawler-analytics' ), 518 esc_html__( 'Spoofed crawler visits', 'an10-ai-crawler-analytics' ), 519 esc_attr( $zero ? 'an10-hero__num an10-hero__num--zero' : 'an10-hero__num' ), 520 esc_html( number_format_i18n( $spoofed ) ), 521 esc_html( $sub ), 522 esc_html__( 'Verified', 'an10-ai-crawler-analytics' ), 523 esc_html( number_format_i18n( $verified ) ), 524 esc_html__( 'Unverified', 'an10-ai-crawler-analytics' ), 525 esc_html( number_format_i18n( $unverified ) ) 476 526 ); 477 527 } … … 565 615 echo '<p class="description">' . esc_html__( 'Counts, not grades. "Words before the first h2" is shown without a verdict: there is no measured threshold for it.', 'an10-ai-crawler-analytics' ) . '</p>'; 566 616 echo '<table class="widefat an10-table"><thead><tr><th>' . esc_html__( 'Page', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num">' . esc_html__( 'Words', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num">' . esc_html__( 'Words before the first h2', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num">' . esc_html__( 'Question headings', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-mid">' . esc_html__( 'Structured data', 'an10-ai-crawler-analytics' ) . '</th><th>' . esc_html__( 'Findings', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num"><span class="screen-reader-text">' . esc_html__( 'Action', 'an10-ai-crawler-analytics' ) . '</span></th></tr></thead><tbody>'; 617 if ( ! $ids ) { 618 echo '<tr><td colspan="7" class="an10-muted">' . esc_html( 619 '' === $flag 620 ? __( 'No pages scanned yet. Page facts appear here after the scan runs, once you have a published page.', 'an10-ai-crawler-analytics' ) 621 : __( 'No page has this finding right now.', 'an10-ai-crawler-analytics' ) 622 ) . '</td></tr>'; 623 } 567 624 foreach ( $ids as $id ) { 568 625 $facts = AN10_Scanner::facts( $id ); … … 885 942 886 943 /** 944 * Stream the stored crawler-visit rows as a CSV download. Local database 945 * only, no external call. Columns match AN10_Store::csv_header(). 946 */ 947 public static function handle_export(): void { 948 check_admin_referer( 'an10_export' ); 949 if ( ! current_user_can( self::CAP ) ) { 950 wp_die( esc_html__( 'Not allowed.', 'an10-ai-crawler-analytics' ) ); 951 } 952 $rows = AN10_Store::export_rows(); 953 nocache_headers(); 954 header( 'Content-Type: text/csv; charset=utf-8' ); 955 header( 'Content-Disposition: attachment; filename="an10-crawler-visits-' . gmdate( 'Y-m-d' ) . '.csv"' ); 956 $out = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- streaming a download to the client, not writing a file. 957 fputcsv( $out, AN10_Store::csv_header() ); 958 foreach ( $rows as $row ) { 959 fputcsv( $out, AN10_Store::csv_row( $row ) ); 960 } 961 fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- php://output stream. 962 exit; 963 } 964 965 /** 887 966 * Save settings. 888 967 */ -
an10-ai-crawler-analytics/tags/0.2.0/includes/class-an10-store.php
r3805222 r3816103 311 311 return gmdate( 'Y-m-d H:i:s', $ts ); 312 312 } 313 314 /** 315 * Is there any stored event at all? 316 */ 317 public static function has_rows(): bool { 318 global $wpdb; 319 return (bool) $wpdb->get_var( 'SELECT 1 FROM ' . self::table() . ' LIMIT 1' ); // phpcs:ignore WordPress.DB 320 } 321 322 /** 323 * Stored events for CSV export, newest first. Local only, bounded. 324 * 325 * @param int $limit Maximum rows. 326 * @return array<int, array<string, mixed>> 327 */ 328 public static function export_rows( int $limit = 50000 ): array { 329 global $wpdb; 330 $limit = max( 1, min( 200000, $limit ) ); 331 return (array) $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery 332 $wpdb->prepare( 333 'SELECT created_at, kind, agent, verification, post_id, path, status FROM %i ORDER BY created_at DESC, id DESC LIMIT %d', 334 self::table(), 335 $limit 336 ), 337 ARRAY_A 338 ); 339 } 340 341 /** 342 * Human label for a kind. Pure. 343 * 344 * @param int $kind KIND_* constant. 345 */ 346 public static function kind_label( int $kind ): string { 347 return self::KIND_REFERRAL === $kind ? 'referral' : 'crawler'; 348 } 349 350 /** 351 * Human label for a verification state. Pure. Empty for not-applicable 352 * (a referral is never verified against an IP list). 353 * 354 * @param int $state VERIFIED / SPOOFED / UNVERIFIED / NOT_APPLICABLE. 355 */ 356 public static function verification_label( int $state ): string { 357 switch ( $state ) { 358 case self::VERIFIED: 359 return 'verified'; 360 case self::SPOOFED: 361 return 'spoofed'; 362 case self::UNVERIFIED: 363 return 'unverified'; 364 default: 365 return ''; 366 } 367 } 368 369 /** 370 * Shape one stored event row into CSV cells, in the export's column order: 371 * time, crawler, kind, status, path, http_status. Pure: no database, so it 372 * is unit-testable and the export handler only has to stream it. 373 * 374 * @param array<string, mixed> $row A row from export_rows(). 375 * @return array<int, string> 376 */ 377 public static function csv_row( array $row ): array { 378 return array( 379 (string) ( $row['created_at'] ?? '' ), 380 (string) ( $row['agent'] ?? '' ), 381 self::kind_label( (int) ( $row['kind'] ?? 0 ) ), 382 self::verification_label( (int) ( $row['verification'] ?? 0 ) ), 383 (string) ( $row['path'] ?? '' ), 384 (string) (int) ( $row['status'] ?? 0 ), 385 ); 386 } 387 388 /** 389 * The export CSV header row, matching csv_row(). 390 * 391 * @return array<int, string> 392 */ 393 public static function csv_header(): array { 394 return array( 'time', 'crawler', 'kind', 'status', 'path', 'http_status' ); 395 } 313 396 } -
an10-ai-crawler-analytics/tags/0.2.0/readme.txt
r3815816 r3816103 5 5 Tested up to: 7.1 6 6 Requires PHP: 8.0 7 Stable tag: 0. 1.27 Stable tag: 0.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 101 101 == Changelog == 102 102 103 = 0.2.0 = 104 * New: the Overview now leads with the number of spoofed crawler visits, the ones using a real crawler's name from an address its operator does not publish, so the one figure only this plugin can show is the first thing you see. 105 * New: export every recorded crawler visit as a CSV, straight from your own database, for your records or your own analysis. Nothing leaves your server. 106 * Improvement: a new install now shows what to expect before any crawler has arrived, with a clear control to turn verification on, instead of an empty screen. 107 103 108 = 0.1.2 = 104 109 * Fix: a real Claude visit could be labelled Spoofed. Anthropic's published list leaves out some of its own addresses, so the ranges Anthropic's own network announces now count too, read daily from RIPE NCC's public routing data while verification is on. -
an10-ai-crawler-analytics/trunk/an10-ai-crawler-analytics.php
r3815816 r3816103 3 3 * Plugin Name: Agent Number 10 – AI Crawler Analytics 4 4 * Description: See which AI crawlers really visit, verified against each operator's published IP list; which pages they have never fetched; the visits AI answers send you; and what stands between your pages and an AI citation. Nothing phones home. 5 * Version: 0. 1.25 * Version: 0.2.0 6 6 * Requires at least: 6.5 7 7 * Requires PHP: 8.0 … … 17 17 defined( 'ABSPATH' ) || exit; 18 18 19 define( 'AN10_VERSION', '0. 1.2' );19 define( 'AN10_VERSION', '0.2.0' ); 20 20 // The plugin slug. It must equal this file's name, the folder name and the 21 21 // text domain; changing it is a search and replace across the plugin. -
an10-ai-crawler-analytics/trunk/assets/admin/admin.css
r3805222 r3816103 281 281 gap: 16px; 282 282 margin: 16px 0 0; 283 } 284 285 /* Hero: the spoofed count leads the screen. */ 286 .an10 .an10-hero { 287 display: flex; 288 flex-wrap: wrap; 289 align-items: flex-end; 290 gap: 20px 56px; 291 margin: 0 0 16px; 292 } 293 294 .an10 .an10-hero__eyebrow { 295 flex-basis: 100%; 296 color: var(--an10-muted-foreground); 297 font-size: 13px; 298 font-weight: var(--an10-weight-ui); 299 } 300 301 .an10 .an10-hero__main { 302 display: flex; 303 flex-direction: column; 304 gap: 4px; 305 } 306 307 .an10 .an10-hero__label { 308 color: var(--an10-muted-foreground); 309 font-size: 13px; 310 font-weight: var(--an10-weight-ui); 311 } 312 313 .an10 .an10-hero__num { 314 color: var(--an10-destructive); 315 font-size: 56px; 316 font-variant-numeric: tabular-nums; 317 font-weight: var(--an10-weight-head); 318 letter-spacing: -0.03em; 319 line-height: 1.02; 320 } 321 322 .an10 .an10-hero__num--zero { 323 color: var(--an10-foreground); 324 } 325 326 .an10 .an10-hero__sub { 327 max-width: 46ch; 328 color: var(--an10-foreground-dim); 329 font-size: 13px; 330 } 331 332 .an10 .an10-hero__side { 333 display: flex; 334 gap: 40px; 335 padding-bottom: 6px; 336 } 337 338 .an10 .an10-export { 339 margin-top: 16px; 340 display: flex; 341 align-items: center; 342 gap: 12px; 343 flex-wrap: wrap; 283 344 } 284 345 -
an10-ai-crawler-analytics/trunk/includes/admin/class-an10-admin.php
r3815816 r3816103 68 68 add_action( 'admin_enqueue_scripts', array( self::class, 'assets' ) ); 69 69 add_action( 'admin_notices', array( self::class, 'first_data_notice' ) ); 70 foreach ( array( 'apply', 'undo', 'rescan', 'settings', 'refresh_lists', 'dismiss', 'verification' ) as $action ) {70 foreach ( array( 'apply', 'undo', 'rescan', 'settings', 'refresh_lists', 'dismiss', 'verification', 'export' ) as $action ) { 71 71 add_action( "admin_post_an10_{$action}", array( self::class, "handle_{$action}" ) ); 72 72 } … … 227 227 self::render_verification_offer(); 228 228 } 229 230 // The one thing only this plugin does: catching spoofed crawlers. The 231 // verification split, spoofed as the headline. Verified is the AI-only 232 // figure ($fetches, search engines excluded) so it reconciles with the 233 // "Verified AI crawler fetches" number below. 234 self::hero( 235 (int) $fetches, 236 (int) array_sum( array_column( $summary, 'spoofed' ) ), 237 (int) array_sum( array_column( $summary, 'unverified' ) ) 238 ); 229 239 230 240 // Three numbers first. … … 430 440 ) . '</p>'; 431 441 } 442 if ( AN10_Store::has_rows() ) { 443 echo '<form method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '" class="an10-export">'; 444 wp_nonce_field( 'an10_export' ); 445 echo '<input type="hidden" name="action" value="an10_export">'; 446 echo '<button type="submit" class="button">' . esc_html__( 'Export CSV', 'an10-ai-crawler-analytics' ) . '</button> <span class="an10-muted">' . esc_html__( 'Every recorded visit, from your database only.', 'an10-ai-crawler-analytics' ) . '</span></form>'; 447 } 432 448 echo '</section></div>'; 433 449 … … 474 490 esc_html( number_format_i18n( $value ) ), 475 491 wp_kses( $sub, array( 'span' => array( 'class' => true ) ) ) 492 ); 493 } 494 495 /** 496 * The hero: the verification split of crawler hits over the last 30 days, 497 * with the spoofed count as the headline. It is the one thing no other 498 * plugin does, so it leads the screen. Reads the summary already queried. 499 * 500 * @param int $verified Verified crawler hits. 501 * @param int $spoofed Spoofed crawler hits. 502 * @param int $unverified Hits that could not be checked. 503 */ 504 private static function hero( int $verified, int $spoofed, int $unverified ): void { 505 $zero = 0 === $spoofed; 506 $sub = $zero 507 ? __( '0 spoofed so far. We check each crawler hit against the IP list its operator publishes.', 'an10-ai-crawler-analytics' ) 508 : __( 'Caught using a real crawler\'s name from an address its operator does not publish.', 'an10-ai-crawler-analytics' ); 509 printf( 510 '<section class="an10-card an10-hero"><span class="an10-hero__eyebrow">%s</span>' . 511 '<div class="an10-hero__main"><span class="an10-hero__label">%s</span>' . 512 '<span class="%s">%s</span><span class="an10-hero__sub">%s</span></div>' . 513 '<div class="an10-hero__side">' . 514 '<div class="an10-kpi"><span class="an10-kpi__label">%s</span><span class="an10-kpi__value">%s</span></div>' . 515 '<div class="an10-kpi"><span class="an10-kpi__label">%s</span><span class="an10-kpi__value">%s</span></div>' . 516 '</div></section>', 517 esc_html__( 'Crawler identity checks, last 30 days', 'an10-ai-crawler-analytics' ), 518 esc_html__( 'Spoofed crawler visits', 'an10-ai-crawler-analytics' ), 519 esc_attr( $zero ? 'an10-hero__num an10-hero__num--zero' : 'an10-hero__num' ), 520 esc_html( number_format_i18n( $spoofed ) ), 521 esc_html( $sub ), 522 esc_html__( 'Verified', 'an10-ai-crawler-analytics' ), 523 esc_html( number_format_i18n( $verified ) ), 524 esc_html__( 'Unverified', 'an10-ai-crawler-analytics' ), 525 esc_html( number_format_i18n( $unverified ) ) 476 526 ); 477 527 } … … 565 615 echo '<p class="description">' . esc_html__( 'Counts, not grades. "Words before the first h2" is shown without a verdict: there is no measured threshold for it.', 'an10-ai-crawler-analytics' ) . '</p>'; 566 616 echo '<table class="widefat an10-table"><thead><tr><th>' . esc_html__( 'Page', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num">' . esc_html__( 'Words', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num">' . esc_html__( 'Words before the first h2', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num">' . esc_html__( 'Question headings', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-mid">' . esc_html__( 'Structured data', 'an10-ai-crawler-analytics' ) . '</th><th>' . esc_html__( 'Findings', 'an10-ai-crawler-analytics' ) . '</th><th class="an10-num"><span class="screen-reader-text">' . esc_html__( 'Action', 'an10-ai-crawler-analytics' ) . '</span></th></tr></thead><tbody>'; 617 if ( ! $ids ) { 618 echo '<tr><td colspan="7" class="an10-muted">' . esc_html( 619 '' === $flag 620 ? __( 'No pages scanned yet. Page facts appear here after the scan runs, once you have a published page.', 'an10-ai-crawler-analytics' ) 621 : __( 'No page has this finding right now.', 'an10-ai-crawler-analytics' ) 622 ) . '</td></tr>'; 623 } 567 624 foreach ( $ids as $id ) { 568 625 $facts = AN10_Scanner::facts( $id ); … … 885 942 886 943 /** 944 * Stream the stored crawler-visit rows as a CSV download. Local database 945 * only, no external call. Columns match AN10_Store::csv_header(). 946 */ 947 public static function handle_export(): void { 948 check_admin_referer( 'an10_export' ); 949 if ( ! current_user_can( self::CAP ) ) { 950 wp_die( esc_html__( 'Not allowed.', 'an10-ai-crawler-analytics' ) ); 951 } 952 $rows = AN10_Store::export_rows(); 953 nocache_headers(); 954 header( 'Content-Type: text/csv; charset=utf-8' ); 955 header( 'Content-Disposition: attachment; filename="an10-crawler-visits-' . gmdate( 'Y-m-d' ) . '.csv"' ); 956 $out = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- streaming a download to the client, not writing a file. 957 fputcsv( $out, AN10_Store::csv_header() ); 958 foreach ( $rows as $row ) { 959 fputcsv( $out, AN10_Store::csv_row( $row ) ); 960 } 961 fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- php://output stream. 962 exit; 963 } 964 965 /** 887 966 * Save settings. 888 967 */ -
an10-ai-crawler-analytics/trunk/includes/class-an10-store.php
r3805222 r3816103 311 311 return gmdate( 'Y-m-d H:i:s', $ts ); 312 312 } 313 314 /** 315 * Is there any stored event at all? 316 */ 317 public static function has_rows(): bool { 318 global $wpdb; 319 return (bool) $wpdb->get_var( 'SELECT 1 FROM ' . self::table() . ' LIMIT 1' ); // phpcs:ignore WordPress.DB 320 } 321 322 /** 323 * Stored events for CSV export, newest first. Local only, bounded. 324 * 325 * @param int $limit Maximum rows. 326 * @return array<int, array<string, mixed>> 327 */ 328 public static function export_rows( int $limit = 50000 ): array { 329 global $wpdb; 330 $limit = max( 1, min( 200000, $limit ) ); 331 return (array) $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery 332 $wpdb->prepare( 333 'SELECT created_at, kind, agent, verification, post_id, path, status FROM %i ORDER BY created_at DESC, id DESC LIMIT %d', 334 self::table(), 335 $limit 336 ), 337 ARRAY_A 338 ); 339 } 340 341 /** 342 * Human label for a kind. Pure. 343 * 344 * @param int $kind KIND_* constant. 345 */ 346 public static function kind_label( int $kind ): string { 347 return self::KIND_REFERRAL === $kind ? 'referral' : 'crawler'; 348 } 349 350 /** 351 * Human label for a verification state. Pure. Empty for not-applicable 352 * (a referral is never verified against an IP list). 353 * 354 * @param int $state VERIFIED / SPOOFED / UNVERIFIED / NOT_APPLICABLE. 355 */ 356 public static function verification_label( int $state ): string { 357 switch ( $state ) { 358 case self::VERIFIED: 359 return 'verified'; 360 case self::SPOOFED: 361 return 'spoofed'; 362 case self::UNVERIFIED: 363 return 'unverified'; 364 default: 365 return ''; 366 } 367 } 368 369 /** 370 * Shape one stored event row into CSV cells, in the export's column order: 371 * time, crawler, kind, status, path, http_status. Pure: no database, so it 372 * is unit-testable and the export handler only has to stream it. 373 * 374 * @param array<string, mixed> $row A row from export_rows(). 375 * @return array<int, string> 376 */ 377 public static function csv_row( array $row ): array { 378 return array( 379 (string) ( $row['created_at'] ?? '' ), 380 (string) ( $row['agent'] ?? '' ), 381 self::kind_label( (int) ( $row['kind'] ?? 0 ) ), 382 self::verification_label( (int) ( $row['verification'] ?? 0 ) ), 383 (string) ( $row['path'] ?? '' ), 384 (string) (int) ( $row['status'] ?? 0 ), 385 ); 386 } 387 388 /** 389 * The export CSV header row, matching csv_row(). 390 * 391 * @return array<int, string> 392 */ 393 public static function csv_header(): array { 394 return array( 'time', 'crawler', 'kind', 'status', 'path', 'http_status' ); 395 } 313 396 } -
an10-ai-crawler-analytics/trunk/readme.txt
r3815816 r3816103 5 5 Tested up to: 7.1 6 6 Requires PHP: 8.0 7 Stable tag: 0. 1.27 Stable tag: 0.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 101 101 == Changelog == 102 102 103 = 0.2.0 = 104 * New: the Overview now leads with the number of spoofed crawler visits, the ones using a real crawler's name from an address its operator does not publish, so the one figure only this plugin can show is the first thing you see. 105 * New: export every recorded crawler visit as a CSV, straight from your own database, for your records or your own analysis. Nothing leaves your server. 106 * Improvement: a new install now shows what to expect before any crawler has arrived, with a clear control to turn verification on, instead of an empty screen. 107 103 108 = 0.1.2 = 104 109 * Fix: a real Claude visit could be labelled Spoofed. Anthropic's published list leaves out some of its own addresses, so the ranges Anthropic's own network announces now count too, read daily from RIPE NCC's public routing data while verification is on.
Note:
See TracChangeset
for help on using the changeset viewer.