1 |
3 |
ahitrov@rambler.ru |
<% $LINE %> |
2 |
|
|
<%args> |
3 |
|
|
|
4 |
|
|
$p => 1 |
5 |
|
|
$n => 10 |
6 |
|
|
$size => 8 |
7 |
|
|
$total => undef |
8 |
|
|
$href => undef |
9 |
|
|
$params => {} |
10 |
|
|
$pname => 'p' |
11 |
|
|
$delimiter => ' | ' |
12 |
|
|
|
13 |
|
|
</%args> |
14 |
|
|
<%init> |
15 |
|
|
|
16 |
|
|
# ��� �����, ��� � ������... |
17 |
|
|
$p = 1 if $p > 10000; |
18 |
|
|
|
19 |
|
|
# ���� !$href � ���� �������� �� �������� DirectoryIndex, ����: |
20 |
|
|
# .../../gallery.html. � ������ � ��� �������������, ����: <a href="?param=1">, |
21 |
|
|
# �� IE �������� �� .../../gallery.html?param=1., � NN (4.x) �������� �� |
22 |
|
|
# .../../?param=1.., ��������� ���� ������� � ��������� ������ ��� �����. |
23 |
|
|
# |
24 |
|
|
if (!$href) |
25 |
|
|
{ |
26 |
|
|
$href = $r->uri(); |
27 |
|
|
$href =~ s/\/([\w]{1,}(\.[sp]?html?))//; |
28 |
|
|
$href = $1; |
29 |
|
|
if ($href =~ /(index|default|main)$2/ ){ |
30 |
|
|
$href = ''; |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
my @params; |
34 |
|
|
while ( my ($key, $value) = each %$params ) { |
35 |
|
|
next if $key eq $pname; |
36 |
|
|
if ( ref $value eq 'ARRAY' ) { |
37 |
|
|
push @params, ( map { "$key=$_" } @$value ); |
38 |
|
|
} else { |
39 |
|
|
push @params, "$key=$value"; |
40 |
|
|
} |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
my $parts = int($total/$n) + ($total % $n ? 1 : 0); |
44 |
|
|
return undef if ($parts <= 1); |
45 |
|
|
|
46 |
|
|
my @parts; |
47 |
|
|
|
48 |
|
|
my $mid_position = int($size/2); |
49 |
|
|
|
50 |
|
|
my $left_pushed_border = $mid_position; |
51 |
|
|
my $right_pushed_border = $parts - $mid_position; |
52 |
|
|
|
53 |
|
|
my $LINE = ''; |
54 |
|
|
my $left_border; |
55 |
|
|
my $right_border; |
56 |
|
|
|
57 |
|
|
if ($p >= $left_pushed_border) |
58 |
|
|
{ |
59 |
|
|
$left_border = $p-$mid_position+1; |
60 |
|
|
$right_border = $left_border+$size-1; |
61 |
|
|
} else { |
62 |
|
|
$left_border = 1; |
63 |
|
|
$right_border = $size; |
64 |
|
|
} |
65 |
|
|
if ($right_border > $parts) |
66 |
|
|
{ |
67 |
|
|
$left_border = $left_border-($right_border-$parts); |
68 |
|
|
$right_border = $parts; |
69 |
|
|
} |
70 |
|
|
$left_border = 1 if ($left_border < 1); |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
# � �� ���� �� �������� [� ������]... |
74 |
|
|
if ($left_border > 1) { |
75 |
|
|
$params->{$pname} = 1; |
76 |
|
|
$LINE .= "[<a href=\"$href?$pname=1".(@params ? '&'.join('&', @params) : '')."\">� ������</a>] "; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
# � ���� �� �������� [����.]... |
80 |
|
|
if ($p > 1) |
81 |
|
|
{ |
82 |
|
|
$params->{$pname} = $p-1; |
83 |
|
|
push(@parts, "<a title=\"���������� ��������\" href=\"$href?$pname=".($p-1).(@params ? '&'.join('&', @params) : '')."\"><<</a>"); |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
|
87 |
|
|
foreach my $pn ($left_border .. $right_border) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
$params->{$pname} = $pn; |
91 |
|
|
push @parts, ($pn == $p) ? "<b>$pn</b>" : "<a href=\"$href?$pname=$pn".(@params ? '&'.join('&', @params) : '')."\">$pn</a>"; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
# � ���� �� �������� [����.]... |
95 |
|
|
if ($p < $parts) |
96 |
|
|
{ |
97 |
|
|
$params->{$pname} = $p+1; |
98 |
|
|
push(@parts, "<a title=\"��������� ��������\" href=\"$href?$pname=".($p+1).(@params ? '&'.join('&', @params) : '')."\">>></a>"); |
99 |
|
|
} |
100 |
|
|
$LINE .= join($delimiter, @parts); |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
# � �� ���� �� �������� [� �����]... |
104 |
|
|
if ($right_border < $parts) |
105 |
|
|
{ |
106 |
|
|
$params->{$pname} = $parts; |
107 |
|
|
$LINE .= " [<a href=\"$href?$pname=$parts".(@params ? '&'.join('&', @params) : '')."\">� �����</a>]"; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
</%init> |
113 |
|
|
<%doc> |
114 |
|
|
|
115 |
|
|
����������� �������� |
116 |
|
|
|
117 |
|
|
</%doc> |