1 |
3 |
ahitrov@rambler.ru |
% if ( @string ) { |
2 |
|
|
% $m->out( join($delimiter, @string) ); |
3 |
|
|
% } |
4 |
|
|
<%args> |
5 |
|
|
|
6 |
|
|
$n => 10 |
7 |
|
|
$p => 1 |
8 |
|
|
$href => '' |
9 |
|
|
$found => undef |
10 |
|
|
$size => 8 |
11 |
|
|
$params => {} |
12 |
|
|
$pname => 'p' |
13 |
|
|
$delimiter => ' | ' |
14 |
|
|
|
15 |
|
|
</%args> |
16 |
|
|
<%init> |
17 |
|
|
|
18 |
|
|
$p = 1 if $p > 10000; |
19 |
|
|
|
20 |
|
|
my @string; |
21 |
|
|
my @params; |
22 |
|
|
while ( my ($key, $value) = each %$params ) { |
23 |
|
|
next if $key eq $pname; |
24 |
|
|
if ( ref $value eq 'ARRAY' ) { |
25 |
|
|
push @params, ( map { "$key=$_" } @$value ); |
26 |
|
|
} else { |
27 |
|
|
push @params, "$key=$value"; |
28 |
|
|
} |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
my $delim = int( $size / 2 ); |
32 |
|
|
my ($begin, $end); |
33 |
|
|
if ( $found < $n ) { |
34 |
|
|
$end = $p; |
35 |
|
|
$begin = $p >= $size ? $p - $size + 1 : 1; |
36 |
|
|
} elsif ( $p < $delim ) { |
37 |
|
|
$begin = 1; |
38 |
|
|
$end = $begin + $size - 1; |
39 |
|
|
} else { |
40 |
|
|
$begin = $p > $delim ? $p - $delim : 1; |
41 |
|
|
$end = $begin + $size - 1; |
42 |
|
|
} |
43 |
|
|
if ( $p > 1 ) { |
44 |
|
|
push @string, '<a href="'.$href.'?p='.($p - 1).(@params ? '&'.join('&', @params) : '' ).'">← ����������</a>'; |
45 |
|
|
if ( $begin > 1 ) { |
46 |
|
|
$string[-1] .= ' [<a href="'.$href.'?p=1'.(@params ? '&'.join('&', @params) : '' ).'">� ������</a>]'; |
47 |
|
|
} |
48 |
|
|
} |
49 |
|
|
for ( $begin..$end ) { |
50 |
|
|
my $num = $_; |
51 |
|
|
if ( $num == $p ) { |
52 |
|
|
push @string, '<b>'.$num.'</b>'; |
53 |
|
|
} else { |
54 |
|
|
push @string, '<a href="'.$href.'?p='.$num.( @params ? '&'.join('&', @params) : '' ).'">'.$num.'</a>'; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
if ( defined $found && $found >= $n ) { |
58 |
|
|
push @string, '<a href="'.$href.'?p='.($p + 1).( @params ? '&'.join('&', @params) : '' ).'">��������� →</a>'; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
</%init> |