0 || $referrals > 0 || $access > 0 || $moved; } /** * Subject line. Leads with the single most interesting number. * * @param array $data Collected digest data. * @return string */ public static function subject( array $data ) { $agents = (int) ( $data['agents']['total'] ?? 0 ); $score = isset( $data['score']['now'] ) && null !== $data['score']['now'] ? (int) $data['score']['now'] : null; if ( $agents > 0 && null !== $score ) { return sprintf( /* translators: 1: number of AI agent requests this week, 2: readiness score. */ __( 'Your site’s AI week: %1$s agent reads, score %2$d', 'agentimus' ), number_format_i18n( $agents ), $score ); } if ( $agents > 0 ) { return sprintf( /* translators: %s: number of AI agent requests this week. */ __( 'Your site’s AI week: %s agent reads', 'agentimus' ), number_format_i18n( $agents ) ); } return __( 'Your site’s AI week', 'agentimus' ); } /** * The email body. * * @param array $data Collected digest data. * @return string HTML. */ public static function html( array $data ) { $out = self::open( $data ); $out .= self::section_agents( $data ); $out .= self::section_referrals( $data ); $out .= self::section_impostors( $data ); $out .= self::section_access( $data ); $out .= self::section_score( $data ); $out .= self::section_nudge( $data ); $out .= self::footer( $data ); return $out; } /* ------------------------------------------------------------------ */ /** Head + intro. On the first-ever digest, one line explains why it exists. */ private static function open( array $data ) { $site = (string) ( $data['site_name'] ?? '' ); $period = isset( $data['period'] ) && is_array( $data['period'] ) ? $data['period'] : array(); $range = isset( $period['label'] ) ? (string) $period['label'] : ''; $h = '
';
$h .= '
' . esc_html( sprintf( /* translators: %s: comma-separated list of AI assistants. */ __( 'Sent by: %s', 'agentimus' ), implode( ', ', $names ) ) ) . ' '; } return self::section( __( 'People from AI answers', 'agentimus' ), $body ); } /** Requests that claimed a known crawler and failed its operator's identity check. */ private static function section_impostors( array $data ) { $total = (int) ( $data['impostors']['total'] ?? 0 ); if ( 0 === $total ) { return ''; } $line = sprintf( /* translators: %s: number of requests that faked a known crawler. */ _n( '%s request pretended to be a known crawler and failed the identity check.', '%s requests pretended to be a known crawler and failed the identity check.', $total, 'agentimus' ), number_format_i18n( $total ) ); return self::section( __( 'Impostors', 'agentimus' ), self::stat_row( $line, '' ) ); } /** Authenticated agent activity. The store is event-keyed, so say "events", never "calls". */ private static function section_access( array $data ) { $events = (int) ( $data['access']['events'] ?? 0 ); if ( 0 === $events ) { return ''; } $line = sprintf( /* translators: %s: number of authenticated agent activity events. */ _n( 'Your connected agents were active this week: %s event.', 'Your connected agents were active this week: %s events.', $events, 'agentimus' ), number_format_i18n( $events ) ); return self::section( __( 'Connected agents', 'agentimus' ), self::stat_row( $line, '' ) ); } /** Readiness score + movement since the last digest. */ private static function section_score( array $data ) { $s = isset( $data['score'] ) && is_array( $data['score'] ) ? $data['score'] : array(); if ( ! isset( $s['now'] ) || null === $s['now'] ) { return ''; } $now = (int) $s['now']; $prev = isset( $s['prev'] ) && null !== $s['prev'] ? (int) $s['prev'] : null; $big = '' . esc_html( (string) $now ) . '' . ' / 100'; if ( null === $prev ) { $note = esc_html__( 'This is the first digest, so there is no earlier score to compare against yet. Next week this line shows the change.', 'agentimus' ); } elseif ( $now > $prev ) { /* translators: %d: the score in the previous digest. */ $note = esc_html( sprintf( __( 'Up from %d last week.', 'agentimus' ), $prev ) ); } elseif ( $now < $prev ) { /* translators: %d: the score in the previous digest. */ $note = esc_html( sprintf( __( 'Down from %d last week.', 'agentimus' ), $prev ) ); } else { $note = esc_html__( 'Unchanged since last week.', 'agentimus' ); } $body = '' . $big . ' ' . $note . ' '; return self::section( __( 'AI readiness score', 'agentimus' ), $body ); } /** One actionable nudge — the current top-ranked improvement, if any. */ private static function section_nudge( array $data ) { $n = isset( $data['nudge'] ) && is_array( $data['nudge'] ) ? $data['nudge'] : array(); if ( empty( $n['label'] ) ) { return ''; } $body = '' . esc_html( (string) $n['label'] ) . '';
if ( ! empty( $n['detail'] ) ) {
$body .= ' ';
if ( '' !== $dashboard ) {
$f .= ''
. esc_html__( 'Open the dashboard', 'agentimus' ) . '';
}
$f .= ' | ';
$f .= ' | ' . esc_html__( 'Agentimus sends this note once a week, built only from data stored on your own site. Nothing leaves your server except this email.', 'agentimus' ); if ( '' !== $stop ) { $f .= ' ' . esc_html__( 'Stop these emails', 'agentimus' ) . ''; } $f .= ' |
' . esc_html( $line ) . '
'; if ( '' !== $compare ) { $html .= '' . esc_html( $compare ) . '
'; } return $html; } /** * Plain-words comparison against the prior week. NULL prev = no full prior * week to compare against (first digest, or retention shorter than two * weeks) — say nothing rather than guess. * * @param int $now This week's count. * @param int|null $prev Prior week's count, or null when unknowable. * @return string */ private static function compare( $now, $prev ) { if ( null === $prev ) { return ''; } $prev = (int) $prev; if ( $now > $prev ) { /* translators: %s: the prior week's count. */ return sprintf( __( 'Up from %s the week before.', 'agentimus' ), number_format_i18n( $prev ) ); } if ( $now < $prev ) { /* translators: %s: the prior week's count. */ return sprintf( __( 'Down from %s the week before.', 'agentimus' ), number_format_i18n( $prev ) ); } return __( 'Same as the week before.', 'agentimus' ); } }