' . 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[] = '