' . Ailens_Admin::logo_html() . '

' . esc_html__( 'Crawler definitions could not be loaded.', 'ailys-lens' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- logo_html()は内部でesc_url/esc_html済み。 return; } try { $ranges = \AilysLens\Core\IpRangeRepository::fromFile( AILENS_PLUGIN_DIR . 'vendor-core/data/crawler-ip-ranges.json' ); } catch ( \Throwable $e ) { $ranges = null; } $period = isset( $_GET['period'] ) ? (int) $_GET['period'] : 30; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- 表示専用の読み取りパラメータ。 if ( ! in_array( $period, array( 7, 30, 90 ), true ) ) { $period = 30; } $today = Ailens_Dashboard_Data::today(); $to = $today->format( 'Y-m-d' ); $period_from = $today->modify( '-' . ( $period - 1 ) . ' days' )->format( 'Y-m-d' ); $hero_from = $today->modify( '-29 days' )->format( 'Y-m-d' ); $prev_from = $today->modify( '-59 days' )->format( 'Y-m-d' ); $prev_to = $today->modify( '-30 days' )->format( 'Y-m-d' ); $hero = Ailens_Dashboard_Data::totals( $hero_from, $to ); $previous = Ailens_Dashboard_Data::totals( $prev_from, $prev_to ); // 主役2数(訪問回数/本文ページが読まれた回数)。定義・語彙は週次レポートと // 完全に共用(単一定義)。期間はヒーローと同じ過去30日。 require_once AILENS_PLUGIN_DIR . 'includes/class-ailens-weekly-report.php'; $tz = wp_timezone(); $reading = Ailens_Weekly_Report::aggregate( new \DateTimeImmutable( $hero_from . ' 00:00:00', $tz ), ( new \DateTimeImmutable( $to . ' 00:00:00', $tz ) )->modify( '+1 day' ) ); $series = Ailens_Dashboard_Data::series( $period_from, $to ); $crawlers = Ailens_Dashboard_Data::crawler_rows( $period_from, $to ); $top_pages = Ailens_Dashboard_Data::top_pages( $period_from ); $robots = Ailens_Robots_Check::result( $repository ); echo '
'; self::render_header( $period ); // admin noticeの挿入位置マーカー(ヘッダー行のflexレイアウトを崩させない)。 echo '
'; self::render_hero( $robots, $reading ); self::render_category_cards( $hero['by_category'], $previous['by_category'] ); self::render_chart_section( $series, $period, $period_from, $to, $repository ); self::render_crawler_table( $crawlers, $repository, $ranges ); self::render_top_pages( $top_pages, $repository ); self::render_notes( $ranges ); self::render_footer(); echo '
'; } /** * 0. ヘッダー行(v0.1.7): ロゴ+週次レポートトグル+Doctor導線。 * * - トグルは設定画面の ailens_weekly_report_enabled と同一オプションの * 同期スイッチ(新しいoptionは作らない)。JSなしで動くよう、POSTフォームの * submitボタンをスイッチ型に描画し、ページ再描画で状態を反映する * - Doctor導線はリンクのみ(モーダルなし。2026-08-12 JD決定)。site パラメータは * 受信側フォームのプレフィル用で、送信されるのはユーザーがクリックしたときだけ。 * プラグイン自身は外部通信を一切行わない(恒久保証) * * @param int $period 表示中の期間(トグル往復後も期間選択を維持するため)。 */ private static function render_header( int $period ): void { $enabled = (int) get_option( 'ailens_weekly_report_enabled', 0 ); echo '
'; echo '

' . Ailens_Admin::logo_html() . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- logo_html()は内部でesc_url/esc_html済み。 echo '
'; echo ''; echo ''; wp_nonce_field( 'ailens_toggle_weekly' ); echo '' . esc_html__( 'Receive a weekly report', 'ailys-lens' ) . ''; echo ''; echo '
'; $doctor_url = 'https://ailys.app/doctor?src=lens-dash&site=' . rawurlencode( home_url() ); echo '

'; echo '' . esc_html__( 'Diagnosis and prescription →', 'ailys-lens' ) . ''; echo ''; echo 'AILYS Doctor'; echo ''; echo '

'; echo '
'; } /** * 週次レポートトグルのadmin_postハンドラ(v0.1.7)。 * * オプション更新は Ailens_Plugin::boot の add_option/update_option フックを * 経由して cron スケジュールに自動同期される(設定画面での変更と同一経路)。 */ public static function handle_toggle_weekly(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'ailys-lens' ) ); } check_admin_referer( 'ailens_toggle_weekly' ); $enabled = (int) get_option( 'ailens_weekly_report_enabled', 0 ); update_option( 'ailens_weekly_report_enabled', 1 === $enabled ? 0 : 1 ); $args = array( 'page' => 'ailys-lens' ); $period = isset( $_POST['period'] ) ? (int) $_POST['period'] : 30; if ( in_array( $period, array( 7, 30, 90 ), true ) && 30 !== $period ) { $args['period'] = $period; } wp_safe_redirect( add_query_arg( $args, admin_url( 'admin.php' ) ) ); exit; } /** * 1. ヒーロー数値。 * * {N} は本文実読数(content pages read)。「訪問≠実読」が製品テーゼであり、 * ヒーローは実読を見せる場所(readme.txtの記述とも一致させる。2026-07-30修正)。 * 空状態メッセージは来訪0回のときのみ。来訪>0かつ実読0のときは通常レイアウトで * 0を表示する(来訪があるのに「クローラーが来ていないかも」と案内するのは誤りのため)。 * * @param array $robots robots.txtチェック結果。 * @param array $reading 主役2数(週次レポートと共用の集計)。 */ private static function render_hero( array $robots, array $reading ): void { echo '
'; if ( (int) $reading['total'] > 0 ) { printf( /* translators: %s: number of content pages read by AI crawlers, wrapped in a large-figure span. */ esc_html__( 'In the last 30 days, your site was read by AI %s times.', 'ailys-lens' ), '' . esc_html( number_format_i18n( (int) $reading['content'] ) ) . '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 内部生成のspan+エスケープ済み数値。 ); } else { echo '' . esc_html__( 'Your site has not been read by AI yet.', 'ailys-lens' ) . ''; echo '

' . esc_html__( 'This can simply mean crawlers have not arrived yet — or that they are blocked. Check below.', 'ailys-lens' ) . '

'; } // 主役2数(語彙は週次レポートのメールと同一。定義も共用の単一定義)。 echo '

'; /* translators: %s: number of AI crawler visits. */ echo esc_html( sprintf( __( 'AI crawler visits: %s', 'ailys-lens' ), number_format_i18n( (int) $reading['total'] ) ) ) . '
'; /* translators: %s: number of content-page hits. */ echo esc_html( sprintf( __( 'Content pages read: %s', 'ailys-lens' ), number_format_i18n( (int) $reading['content'] ) ) ); echo '

'; self::render_robots_notice( $robots ); echo '
'; } /** * robots.txt簡易チェックの結果表示。 * * @param array $robots チェック結果。 */ private static function render_robots_notice( array $robots ): void { if ( 'blocked' === $robots['status'] ) { echo '
'; printf( /* translators: %s: comma-separated list of crawler tokens blocked in robots.txt. */ esc_html__( 'robots.txt fully blocks these AI crawlers: %s', 'ailys-lens' ), esc_html( implode( ', ', array_map( 'strval', (array) $robots['blocked'] ) ) ) ); echo '
'; } elseif ( 'unreachable' === $robots['status'] ) { echo '

' . esc_html__( 'robots.txt could not be checked (unreachable).', 'ailys-lens' ) . '

'; } } /** * 2. カテゴリ内訳カード3枚(過去30日+前期間比)。 * * @param array $current 今期(30日)。 * @param array $previous 前期(その前の30日)。 */ private static function render_category_cards( array $current, array $previous ): void { echo '
'; foreach ( self::category_labels() as $category => $meta ) { $cur = $current[ $category ] ?? 0; $prev = $previous[ $category ] ?? 0; echo '
'; echo '
' . esc_html( $meta['label'] ) . '
'; echo '
' . esc_html( $meta['desc'] ) . '
'; echo '
' . esc_html( number_format_i18n( $cur ) ) . '
'; echo wp_kses_post( self::delta_html( $cur, $prev ) ); echo '
'; } echo '
'; } /** * 前期間比の表示(上向き=良い方向)。 * * @param int $cur 今期値。 * @param int $prev 前期値。 */ private static function delta_html( int $cur, int $prev ): string { if ( 0 === $prev && 0 === $cur ) { return '
—
'; } if ( 0 === $prev ) { return '
' . esc_html__( 'New', 'ailys-lens' ) . '
'; } $pct = ( $cur - $prev ) / $prev * 100; $sign = $pct >= 0 ? '+' : ''; $cls = $pct >= 0 ? 'ailens-delta-up' : 'ailens-delta-down'; /* translators: %s: signed percentage vs the previous 30 days. */ $label = sprintf( __( '%s%% vs previous 30 days', 'ailys-lens' ), $sign . number_format_i18n( round( $pct ) ) ); return '
' . esc_html( $label ) . '
'; } /** * 3. 時系列グラフ(期間切替7/30/90)。 * * @param array> $series date => crawler_id => hits。 * @param int $period 選択中の期間。 * @param string $from Y-m-d。 * @param string $to Y-m-d。 * @param DefinitionRepository $repository 定義。 */ private static function render_chart_section( array $series, int $period, string $from, string $to, DefinitionRepository $repository ): void { echo '
'; echo '
'; echo '

' . esc_html__( 'Daily hits by crawler', 'ailys-lens' ) . '

'; echo '
'; // 対象期間の全日付(欠損日は0で埋める)。 $dates = array(); $cursor = new \DateTimeImmutable( $from, wp_timezone() ); $end = new \DateTimeImmutable( $to, wp_timezone() ); while ( $cursor <= $end ) { $dates[] = $cursor->format( 'Y-m-d' ); $cursor = $cursor->modify( '+1 day' ); } // 系列: 上位7クローラー+その他。色は定義ファイル順に固定順パレットを割り当て // (期間切替で生存系列の色が変わりにくいよう、割り当ては件数順でなく定義順)。 $totals = array(); foreach ( $series as $day ) { foreach ( $day as $crawler_id => $hits ) { $totals[ $crawler_id ] = ( $totals[ $crawler_id ] ?? 0 ) + $hits; } } if ( array() === $totals ) { echo '

' . esc_html__( 'No AI crawler hits in this period.', 'ailys-lens' ) . '

'; return; } arsort( $totals ); $top_ids = array_slice( array_keys( $totals ), 0, 7 ); $labels = array(); $colors = array(); $slot = 0; foreach ( $repository->crawlers() as $crawler ) { if ( in_array( $crawler->id, $top_ids, true ) ) { $labels[ $crawler->id ] = $crawler->uaPattern; $colors[ $crawler->id ] = Ailens_Chart::PALETTE[ $slot % count( Ailens_Chart::PALETTE ) ]; ++$slot; } } $has_other = count( $totals ) > count( $top_ids ); if ( $has_other ) { $labels['__other'] = __( 'Other', 'ailys-lens' ); $colors['__other'] = Ailens_Chart::OTHER_COLOR; } $chart_series = array(); foreach ( $dates as $date ) { $chart_series[ $date ] = array(); foreach ( ( $series[ $date ] ?? array() ) as $crawler_id => $hits ) { $key = isset( $labels[ $crawler_id ] ) ? $crawler_id : '__other'; $chart_series[ $date ][ $key ] = ( $chart_series[ $date ][ $key ] ?? 0 ) + $hits; } } echo Ailens_Chart::stacked_bars( $dates, $chart_series, $labels, $colors ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 内部でエスケープ済みのSVG。 // 凡例(2系列以上のとき常設)。 if ( count( $labels ) >= 2 ) { echo '
'; foreach ( $labels as $key => $label ) { echo '' . esc_html( $label ) . ''; } echo '
'; } echo ''; } /** * 4. クローラー別テーブル。 * * @param array $rows 集計行。 * @param DefinitionRepository $repository 定義。 * @param \AilysLens\Core\IpRangeRepository|null $ranges IPレンジスナップショット(読めない場合null)。 */ private static function render_crawler_table( array $rows, DefinitionRepository $repository, $ranges ): void { echo '
'; echo '

' . esc_html__( 'By crawler', 'ailys-lens' ) . '

'; if ( array() === $rows ) { echo '

' . esc_html__( 'No AI crawler hits in this period.', 'ailys-lens' ) . '

'; return; } $labels = self::category_labels(); $footnotes = array(); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ( $rows as $row ) { $crawler = $repository->findById( $row->crawler_id ); $name = $crawler ? $crawler->uaPattern : $row->crawler_id; $vendor = $crawler ? $crawler->vendor : '—'; $cat = $crawler && isset( $labels[ $crawler->category ] ) ? $labels[ $crawler->category ]['label'] : '—'; $mark = ''; if ( $crawler && null !== $crawler->note ) { // 翻訳可能な脚注(英語原文+ja.po訳)。未収載の新クローラーは // crawlers.json の note 原文をフォールバック表示する。 $footnote = self::footnote_text( $crawler->id ); $footnotes[ $crawler->id ] = null !== $footnote ? $footnote : $crawler->note; $mark = ' *'; } $has_means = $crawler && ( array() !== $crawler->verifyDomains() || ( null !== $ranges && $ranges->hasRanges( $crawler->id ) ) ); if ( $crawler && ! $has_means && CrawlerDefinition::VERIFY_NONE === $crawler->verifyMethod() ) { $verified = '' . esc_html__( 'n/a', 'ailys-lens' ) . ''; } elseif ( ! $has_means ) { // 公表形式が未対応等でレンジ未収載のベンダー(Amazon等)。0%と誤読させない。 $verified = '' . esc_html__( 'n/a', 'ailys-lens' ) . ''; } else { $verified = esc_html( $row->hits > 0 ? number_format_i18n( round( $row->verified_hits / $row->hits * 100 ) ) . '%' : '—' ); } echo ''; echo ''; echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- markは内部生成・エスケープ済み。 echo ''; echo ''; echo ''; echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 内部生成・エスケープ済み。 echo ''; } echo '
' . esc_html__( 'Vendor', 'ailys-lens' ) . '' . esc_html__( 'Crawler', 'ailys-lens' ) . '' . esc_html__( 'Category', 'ailys-lens' ) . '' . esc_html__( 'Hits', 'ailys-lens' ) . '' . esc_html__( 'Last visit', 'ailys-lens' ) . '' . esc_html__( 'Verified', 'ailys-lens' ) . '
' . esc_html( $vendor ) . '' . esc_html( $name ) . '' . $mark . '' . esc_html( $cat ) . '' . esc_html( number_format_i18n( $row->hits ) ) . '' . esc_html( $row->last_visit ? date_i18n( 'Y-m-d H:i', strtotime( $row->last_visit ) ) : '—' ) . '' . $verified . '
'; if ( array() !== $footnotes ) { echo '
    '; foreach ( $footnotes as $id => $note ) { echo '
  • * ' . esc_html( $note ) . '
  • '; } echo '
'; } echo ''; } /** * 5. 読まれたページTop10。 * * @param array $pages 集計行。 * @param DefinitionRepository $repository 定義。 */ private static function render_top_pages( array $pages, DefinitionRepository $repository ): void { echo '
'; echo '

' . esc_html__( 'Top pages read by AI', 'ailys-lens' ) . '

'; if ( array() === $pages ) { echo '

' . esc_html__( 'No AI crawler hits in this period.', 'ailys-lens' ) . '

'; return; } echo ''; echo ''; echo ''; echo ''; echo ''; foreach ( $pages as $page ) { $crawler = $repository->findById( $page->top_crawler ); echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html__( 'Path', 'ailys-lens' ) . '' . esc_html__( 'Hits', 'ailys-lens' ) . '' . esc_html__( 'Top crawler', 'ailys-lens' ) . '
' . esc_html( $page->url_path ) . '' . esc_html( number_format_i18n( $page->hits ) ) . '' . esc_html( $crawler ? $crawler->uaPattern : $page->top_crawler ) . '
'; } /** * 6. 注記(嘘をつかない計器の原則)。 * * @param \AilysLens\Core\IpRangeRepository|null $ranges IPレンジスナップショット(読めない場合null)。 */ private static function render_notes( $ranges ): void { echo '
'; echo '

' . esc_html__( 'Notes on measurement', 'ailys-lens' ) . '

    '; echo '
  • ' . esc_html__( 'If a full-page cache plugin (WP Super Cache, etc.) serves a request, PHP does not run and the hit cannot be counted. Counts shown here are a lower bound.', 'ailys-lens' ) . '
  • '; echo '
  • ' . esc_html__( '"Verified" means the visit was confirmed to originate from the claimed vendor, via its published IP ranges or reverse DNS. Unverified hits matched the user agent string only, which can be spoofed.', 'ailys-lens' ) . '
  • '; if ( null !== $ranges && '' !== $ranges->snapshotDate() ) { echo '
  • '; printf( /* translators: %s: date (YYYY-MM-DD) of the bundled IP-range snapshot. */ esc_html__( 'Verification IP ranges: snapshot as of %s, bundled with the plugin (no external fetching). Newer vendor ranges are picked up via plugin updates.', 'ailys-lens' ), esc_html( $ranges->snapshotDate() ) ); echo '
  • '; } echo '
  • ' . esc_html__( 'Only AI crawler visits are recorded. Human visitors are never tracked, and no data leaves your server.', 'ailys-lens' ) . '
  • '; echo '
'; } /** * 7. フッター(控えめなテキストリンク1本のみ)。 */ private static function render_footer(): void { echo ''; } /** * クローラー脚注の翻訳可能テキスト(英語原文・日本語はja.po訳)。 * * 内容は crawlers.json の note と技術的事実を一致させたもの(表示用の * i18nレイヤー。データ側のnoteは変更しない)。未収載IDはnullを返し、 * 呼び出し側が note 原文にフォールバックする。 * * @param string $crawler_id クローラーID。 */ private static function footnote_text( string $crawler_id ): ?string { $anthropic = __( 'Anthropic began publishing IP ranges on 2026-08-18. A single combined list covers all three of its crawlers, so a verified hit confirms the request came from Anthropic, not which crawler it was. No rDNS domains are published.', 'ailys-lens' ); $notes = array( 'claudebot' => $anthropic, 'claude-searchbot' => $anthropic, 'claude-user' => $anthropic, 'perplexity-user' => __( 'Perplexity officially states that user-initiated fetches generally ignore robots.txt.', 'ailys-lens' ), 'googleother' => __( 'A general-purpose Google crawler whose uses include research and development. AI training use is included but cannot be singled out. GoogleOther-Image and GoogleOther-Video also match this pattern.', 'ailys-lens' ), 'applebot' => __( 'Crawler for Siri, Spotlight, and other Apple search features. Whether fetched content may be used for AI training is controlled by the Applebot-Extended token in robots.txt.', 'ailys-lens' ), 'meta-externalagent' => __( 'Meta does not publish rDNS domains or IP ranges for verification.', 'ailys-lens' ), 'meta-webindexer' => __( 'Crawler used to improve the quality of Meta AI search results (confirmed in official documentation as of 2026).', 'ailys-lens' ), 'meta-externalfetcher' => __( 'User-initiated fetching, including agent-style task execution.', 'ailys-lens' ), 'amazonbot' => __( 'Amazon officially states it may be used to train Amazon AI models (search-only crawling is Amzn-SearchBot). The published IP list format is unconfirmed, so range data is not bundled.', 'ailys-lens' ), 'amzn-searchbot' => __( 'Officially stated to be for search indexing only (not used for generative AI training). A new crawler as of 2026; its verification method is still to be confirmed.', 'ailys-lens' ), 'amzn-user' => __( 'User-initiated real-time fetching. A new crawler as of 2026; its verification method is still to be confirmed.', 'ailys-lens' ), 'ccbot' => __( 'A non-profit web archive whose data is used by many AI companies for training. IP ranges have been published since 2026-08-11; Common Crawl also recommends forward-confirmed reverse DNS.', 'ailys-lens' ), 'bytespider' => __( 'No official documentation exists, and robots.txt compliance is widely reported as unreliable. No verification method.', 'ailys-lens' ), 'duckassistbot' => __( 'Real-time fetching for AI-assisted answers (DuckAssist). DuckDuckGo states the data is not used for training.', 'ailys-lens' ), 'mistralai-index' => __( 'Index crawler for Mistral search (officially stated not to be used for training).', 'ailys-lens' ), ); return $notes[ $crawler_id ] ?? null; } /** * カテゴリ表示ラベル(3分類はプロダクトの語り口の核、仕様書§3.3)。 * * @return array */ private static function category_labels(): array { return array( 'training' => array( 'label' => __( 'Training', 'ailys-lens' ), 'desc' => __( 'Collected to train AI models', 'ailys-lens' ), ), 'search_index' => array( 'label' => __( 'AI search index', 'ailys-lens' ), 'desc' => __( 'Indexed for AI search results', 'ailys-lens' ), ), 'user_fetch' => array( 'label' => __( 'User fetch', 'ailys-lens' ), 'desc' => __( 'Fetched live to answer a question', 'ailys-lens' ), ), ); } }