' . esc_html( $summary ) . '
' . self::offset( $page, $pages, $url ) . ''; } return '

' . esc_html( $summary ) . '

' . self::offset( $page, $pages, $url ) . '
'; } public static function clamp( int $requested, int $per_page, int $total ): int { return max( 1, min( max( 1, $requested ), (int) ceil( max( 0, $total ) / max( 1, $per_page ) ) ) ); } public static function offset( int $page, int $pages, callable $url ): string { $pages = max( 1, $pages ); $page = max( 1, min( $pages, $page ) ); if ( 1 === $pages ) { return ''; } if ( Ui::kit_markup() ) { return self::kit_offset( $page, $pages, $url ); } $items = array(); $items[] = self::step( '«', __( 'First page', 'rooster-lms' ), $page > 1 ? (string) $url( 1 ) : '' ); $items[] = self::step( '‹', __( 'Previous page', 'rooster-lms' ), $page > 1 ? (string) $url( $page - 1 ) : '' ); $shown = array_unique( array( 1, $page - 1, $page, $page + 1, $pages ) ); $shown = array_values( array_filter( $shown, static fn( int $n ): bool => $n >= 1 && $n <= $pages ) ); sort( $shown ); $last = 0; foreach ( $shown as $n ) { if ( $n - $last > 1 ) { $items[] = '
  • '; } $label = Format::number( $n ); if ( $n === $page ) { /* translators: %s: page number. */ $items[] = '
  • ' . esc_html( $label ) . '
  • '; } else { /* translators: %s: page number. */ $items[] = '
  • ' . esc_html( $label ) . '
  • '; } $last = $n; } $items[] = self::step( '›', __( 'Next page', 'rooster-lms' ), $page < $pages ? (string) $url( $page + 1 ) : '' ); $items[] = self::step( '»', __( 'Last page', 'rooster-lms' ), $page < $pages ? (string) $url( $pages ) : '' ); return self::nav( implode( '', $items ) ); } public static function steps( string $prev_url, string $next_url ): string { if ( '' === $prev_url && '' === $next_url ) { return ''; } if ( Ui::kit_markup() ) { return self::kit_links( array( array( __( 'Previous page', 'rooster-lms' ), $prev_url, 'prev', '' ), array( __( 'Next page', 'rooster-lms' ), $next_url, 'next', '' ), ) ); } return self::nav( self::step( '‹', __( 'Previous page', 'rooster-lms' ), $prev_url ) . self::step( '›', __( 'Next page', 'rooster-lms' ), $next_url ) ); } public static function keyset( string $first_url, string $more_url, string $first, string $more ): string { if ( Ui::kit_markup() ) { $links = array(); if ( '' !== $first_url ) { $links[] = array( $first, $first_url, 'first', 'first' ); } if ( '' !== $more_url ) { $links[] = array( $more, $more_url, 'more', 'more' ); } return array() === $links ? '' : self::kit_links( $links ); } $items = ''; if ( '' !== $first_url ) { $items .= '
  • ' . esc_html( $first ) . '
  • '; } if ( '' !== $more_url ) { $items .= '
  • ' . esc_html( $more ) . '
  • '; } return '' === $items ? '' : self::nav( $items ); } private static function step( string $glyph, string $label, string $url ): string { if ( '' === $url ) { return '
  • ' . esc_html( $glyph ) . '
  • '; } return '
  • ' . esc_html( $glyph ) . '
  • '; } private static function nav( string $items ): string { return ''; } private static function kit_offset( int $page, int $pages, callable $url ): string { $link = static fn( int $n, string $label, string $class = '', bool $current = false, string $name = '' ): string => '
  • ' . $label . '
  • '; $html = ''; } private static function kit_links( array $links ): string { $html = ''; } public static function chevron(): string { return ''; } }