Revision 3 (by ahitrov@rambler.ru, 2010/03/24 15:19:32) The CORE
% if ( @string ) {
%	$m->out( join($delimiter, @string) );
% }
<%args>

	$n	=> 10
	$p	=> 1
	$href	=> ''
	$found	=> undef
	$size	=> 8
	$params	=> {}
	$pname => 'p'
	$delimiter => ' | '

</%args>
<%init>

   $p = 1 if $p > 10000;

   my @string;
   my @params;
   while ( my ($key, $value) = each %$params ) {
	next		if $key eq $pname;
	if ( ref $value eq 'ARRAY' ) {
		push @params, ( map { "$key=$_" } @$value );
	} else {
		push @params, "$key=$value";
	}
   }

   my $delim = int( $size / 2 );
   my ($begin, $end);
   if ( $found < $n ) {
	$end = $p;
	$begin = $p >= $size ? $p - $size + 1 : 1;
   } elsif ( $p < $delim ) {
	$begin = 1;
	$end = $begin + $size - 1;
   } else {
	$begin = $p > $delim ? $p - $delim : 1;
	$end = $begin + $size - 1;
   }
   if ( $p > 1 ) {
	push @string, '<a href="'.$href.'?p='.($p - 1).(@params ? '&'.join('&', @params) : '' ).'">&larr; ����������</a>';
	if ( $begin > 1 ) {
		$string[-1] .= ' [<a href="'.$href.'?p=1'.(@params ? '&'.join('&', @params) : '' ).'">� ������</a>]';
	}
   }
   for ( $begin..$end ) {
	my $num = $_;
	if ( $num == $p ) {
		push @string, '<b>'.$num.'</b>';
	} else {
		push @string, '<a href="'.$href.'?p='.$num.( @params ? '&'.join('&', @params) : '' ).'">'.$num.'</a>';
	}
   }
   if ( defined $found && $found >= $n ) {
	push @string, '<a href="'.$href.'?p='.($p + 1).( @params ? '&'.join('&', @params) : '' ).'">��������� &rarr;</a>';
   }

</%init>