repository->counts(); $found = $this->log->counts(); $top = $this->unfixed( $this->log->top( 15 ), 5 ); printf( '
', esc_attr( AdminModule::appearance() ) ); echo ''; if ( [] === $top ) { printf( '

%s

', esc_html__( 'No broken links in the last week. Nicely done.', 'codebold-redirects' ) ); } else { printf( '

%s

', esc_html__( 'Most-visited pages that were not found', 'codebold-redirects' ) ); echo ''; foreach ( $top as $row ) { printf( '', esc_html( (string) $row['url'] ), esc_attr( sprintf( /* translators: %s: number of visits */ _n( '%s visit', '%s visits', (int) $row['hits'], 'codebold-redirects' ), number_format_i18n( (int) $row['hits'] ) ) ), esc_html( number_format_i18n( (int) $row['hits'] ) ), esc_url( AdminModule::url( [ 'add_source' => (string) $row['url'], 'tab' => '404s' ] ) ), /* translators: %s: an address */ esc_attr( sprintf( __( 'Fix %s', 'codebold-redirects' ), (string) $row['url'] ) ), esc_html__( 'Fix', 'codebold-redirects' ) ); } echo '
%1$s%3$s%6$s
'; } if ( $counts['broken'] > 0 ) { printf( '

%s

', esc_url( AdminModule::url( [ 'view' => 'broken' ] ) ), esc_html( sprintf( /* translators: %d: number of redirects */ _n( '%d redirect points at a page that is no longer published.', '%d redirects point at pages that are no longer published.', $counts['broken'], 'codebold-redirects' ), $counts['broken'] ) ) ); } printf( '', esc_url( AdminModule::url() ), esc_html__( 'Manage redirects', 'codebold-redirects' ) ); echo '
'; } /** * Leave out addresses a redirect already covers. They can still be in the list — a * redirect turned back on, or one added before the address was first seen — and a * "Fix" link for something already fixed sends somebody to a form that will refuse. * * @param list> $rows * @return list> */ private function unfixed( array $rows, int $limit ): array { $engine = new Engine( $this->repository ); $visitor = Validator::neutral(); $out = []; foreach ( $rows as $row ) { $address = Address::from_request( (string) $row['url'] ); if ( null !== $engine->resolve( $address, $visitor ) || null !== $engine->resolve( $address, $visitor->with( [ 'not_found' => true ] ), 'late' ) ) { continue; } $out[] = $row; if ( count( $out ) >= $limit ) { break; } } return $out; } private function stat( string $number, string $label, string $url ): void { printf( '
  • %s%s
  • ', esc_url( $url ), esc_html( $number ), esc_html( $label ) ); } }