$raw_citations Raw citations from the API response. * * @return string[] Lowercase domain names (e.g. ['peptiderepo.com', 'examine.com']). */ public function parse_domains( array $raw_citations ): array { $domains = array(); foreach ( $raw_citations as $item ) { $url = ''; if ( is_string( $item ) ) { $url = $item; } elseif ( is_array( $item ) && isset( $item['url'] ) && is_string( $item['url'] ) ) { $url = $item['url']; } if ( '' === $url ) { continue; } $host = (string) wp_parse_url( $url, PHP_URL_HOST ); if ( '' !== $host ) { $bare = str_starts_with( $host, 'www.' ) ? substr( $host, 4 ) : $host; $domains[] = strtolower( $bare ); } } return array_values( array_unique( $domains ) ); } /** * Detect whether PRV_TARGET_DOMAIN appears in a domain list. * * @param string[] $domains Parsed domain list from parse_domains(). * * @return bool */ public function is_cited( array $domains ): bool { return in_array( PRV_TARGET_DOMAIN, $domains, true ); } /** * Find the 1-based position of PRV_TARGET_DOMAIN in a domain list. * * Returns null when the target domain is not found. * * @param string[] $domains Parsed domain list. * * @return int|null */ public function get_our_position( array $domains ): ?int { $pos = array_search( PRV_TARGET_DOMAIN, $domains, true ); if ( false === $pos ) { return null; } return (int) $pos + 1; // Convert 0-based index to 1-based position. } }