collect(); $avg = $this->average_score( $rows ); echo '
'; echo '

' . esc_html__( 'AI Citations — Network', 'agentimus' ) . '

'; echo '

' . esc_html__( 'Latest citation-check results across every site on the network. Each site keeps its own data; open a site to configure its prompts and API keys (Visibility → Citations).', 'agentimus' ) . '

'; printf( '

%s %s

', esc_html( $avg . '%' ), esc_html__( 'average visibility score across sites with data', 'agentimus' ) ); echo ''; foreach ( array( __( 'Site', 'agentimus' ), __( 'Brand', 'agentimus' ), __( 'Visibility', 'agentimus' ), __( 'Citations', 'agentimus' ), __( 'Engines', 'agentimus' ), __( 'Last run', 'agentimus' ), '', ) as $col ) { echo ''; } echo ''; if ( empty( $rows ) ) { echo ''; } foreach ( $rows as $r ) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html( $col ) . '
' . esc_html__( 'No sites found.', 'agentimus' ) . '
' . esc_html( $r['name'] ) . '' . esc_html( $r['brand'] ?: '—' ) . '' . ( $r['hasData'] ? esc_html( $r['visibility'] . '%' ) : '—' ) . '' . ( $r['hasData'] ? esc_html( $r['citations'] . '%' ) : '—' ) . '' . esc_html( (string) $r['providers'] ) . '' . esc_html( $r['lastRun'] ) . '' . esc_html__( 'Open', 'agentimus' ) . '
'; } /** * Gather each site's latest numbers. * * @return array[] */ private function collect() { $site_ids = get_sites( array( 'fields' => 'ids', 'number' => self::MAX_SITES, ) ); $out = array(); foreach ( (array) $site_ids as $site_id ) { $site_id = (int) $site_id; switch_to_blog( $site_id ); $settings = new Settings(); $latest_id = Store::latest_run_id(); $summary = $latest_id ? Store::summarize( Store::rows_for_run( $latest_id ) ) : null; $last_ts = (int) get_option( Runner::LAST_RUN_OPTION, 0 ); $out[] = array( 'name' => get_bloginfo( 'name' ), 'brand' => implode( ', ', array_filter( array_map( static function ( $t ) { return is_array( $t ) ? trim( (string) ( $t['name'] ?? '' ) ) : ''; }, (array) $settings->get( 'targets', array() ) ) ) ), 'hasData' => (bool) $summary, 'visibility' => $summary ? (int) $summary['visibilityScore'] : 0, 'citations' => $summary ? (int) $summary['citationRate'] : 0, 'providers' => count( $settings->active_providers() ), 'lastRun' => $last_ts ? wp_date( 'M j, Y H:i', $last_ts ) : __( 'never', 'agentimus' ), 'adminUrl' => admin_url( 'admin.php?page=agentimus' ) . '#visibility', ); restore_current_blog(); } return $out; } /** * Average visibility score across the sites that have run at least once. * * @param array[] $rows Collected rows. * @return int */ private function average_score( array $rows ) { $scores = array(); foreach ( $rows as $r ) { if ( $r['hasData'] ) { $scores[] = (int) $r['visibility']; } } if ( empty( $scores ) ) { return 0; } return (int) round( array_sum( $scores ) / count( $scores ) ); } }