id() ] = $s; } } return self::$sources; } public static function get( $id ) { $all = self::all(); $id = (string) $id; return isset( $all[ $id ] ) ? $all[ $id ] : null; } public static function detected() { static $memo = null; if ( null !== $memo ) { return $memo; } $out = array(); foreach ( self::all() as $s ) { if ( ! $s->available() ) { continue; } $out[] = array( 'id' => $s->id(), 'label' => $s->label(), 'counts' => $s->counts(), 'redirects' => (bool) $s->has_redirects(), ); } $memo = $out; return $out; } public static function best() { $best = ''; $score = -1; foreach ( self::detected() as $d ) { $n = (int) $d['counts']['posts'] + (int) $d['counts']['terms']; if ( $n > $score ) { $score = $n; $best = $d['id']; } } return $best; } }