line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: Linear.pm,v 1.7 2005/02/03 00:06:29 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2003 Slaven Rezic. |
8
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
9
|
|
|
|
|
|
|
# terms of the GNU General Public License, see the file COPYING. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
13
|
|
|
|
|
|
|
# WWW: http://we-framework.sourceforge.net |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package WE_Frontend::Plugin::Linear; |
17
|
1
|
|
|
1
|
|
1434
|
use base qw(Template::Plugin); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use HTML::Entities; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
72
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use WE_Frontend::Plugin::WE_Navigation; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
24
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION $DEBUG); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
754
|
|
25
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
WE_Frontend::Plugin::Linear - assume hierarchy as a "linear" list |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $t = Template->new({PLUGIN_BASE => "WE_Frontend::Plugin"}); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
[% USE Linear %] |
36
|
|
|
|
|
|
|
[% SET o = Linear.prev() %] |
37
|
|
|
|
|
|
|
[% SET o = Linear.next() %] |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This plugin assumes web.editor objects like linear pages as in books. |
42
|
|
|
|
|
|
|
The returned objects are L |
43
|
|
|
|
|
|
|
objects. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 METHODS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
0
|
|
|
0
|
1
|
|
my($class, $context, $params) = @_; |
53
|
0
|
|
|
|
|
|
my $n = WE_Frontend::Plugin::WE_Navigation->new($context, $params); |
54
|
0
|
|
|
|
|
|
my $self = { WE_Navigation => $n }; |
55
|
0
|
|
|
|
|
|
bless $self, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub restrict_code { |
59
|
|
|
|
|
|
|
return sub { |
60
|
0
|
|
|
0
|
|
|
my $o = shift; |
61
|
0
|
|
|
|
|
|
return $o->o->{VisibleToMenu}; |
62
|
0
|
|
|
0
|
0
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _prev_next { |
66
|
0
|
|
|
0
|
|
|
my($self, $dir, $nav_obj) = @_; |
67
|
0
|
|
|
|
|
|
my $wen = $self->{WE_Navigation}; |
68
|
0
|
|
|
|
|
|
my $restrict = $self->restrict_code; |
69
|
0
|
|
|
|
|
|
my $objid = $nav_obj->o->Id; |
70
|
0
|
|
|
|
|
|
my %std_args = (objid => $objid, |
71
|
|
|
|
|
|
|
restrict => $restrict); |
72
|
0
|
|
|
|
|
|
my $siblings = $wen->siblings(\%std_args); |
73
|
0
|
|
|
|
|
|
for my $i (0 .. $#$siblings) { |
74
|
0
|
|
|
|
|
|
my $o = $siblings->[$i]; |
75
|
0
|
0
|
|
|
|
|
if ($o->o->Id eq $objid) { |
76
|
0
|
0
|
0
|
|
|
|
if (($dir > 0 && $i == $#$siblings) || |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
77
|
|
|
|
|
|
|
($dir < 0 && $i == 0)) { |
78
|
0
|
|
|
|
|
|
my $level = $wen->level(\%std_args); |
79
|
0
|
0
|
|
|
|
|
if ($level == 0) { |
80
|
0
|
|
|
|
|
|
return undef; # we're already at the top (home of the site) |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
my $upper_siblings = $wen->siblings({ %std_args, |
83
|
|
|
|
|
|
|
level => $level - 1}); |
84
|
0
|
|
|
|
|
|
my $parent = $wen->parent(\%std_args); |
85
|
0
|
0
|
|
|
|
|
if ($dir > 0) { |
86
|
0
|
|
|
|
|
|
return $self->_next($parent); |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
|
my $p = $self->_prev($parent); |
89
|
0
|
|
|
|
|
|
return $self->last($p); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
0
|
0
|
0
|
|
|
|
if ($dir < 0 && $siblings->[$i + $dir]) { |
93
|
0
|
|
|
|
|
|
return $self->last($siblings->[$i + $dir]); |
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
|
return $siblings->[$i + $dir]; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
0
|
0
|
|
|
|
|
warn "Object id $objid: Can't find myself --- this may happen if the page is not included in the navigation" if $DEBUG; |
100
|
0
|
|
|
|
|
|
undef; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item prev() |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Get the previous object (or undef). |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
0
|
|
|
sub _prev { shift->_prev_next(-1, @_) } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub prev { |
112
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
113
|
0
|
|
|
|
|
|
my $wen = $self->{WE_Navigation}; |
114
|
0
|
|
|
|
|
|
$self->_prev($wen->self); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item next() |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Get the next object (or undef). |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
0
|
|
|
sub _next { shift->_prev_next(+1, @_) } |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub next { |
126
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
127
|
0
|
|
|
|
|
|
my $wen = $self->{WE_Navigation}; |
128
|
0
|
|
|
|
|
|
$self->_next($wen->self); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item last() |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Get the last object, probably by recursing into subdirectories. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub last { |
138
|
0
|
|
|
0
|
1
|
|
my($self, $nav_obj) = @_; |
139
|
0
|
|
|
|
|
|
my $wen = $self->{WE_Navigation}; |
140
|
0
|
|
|
|
|
|
my $restrict = $self->restrict_code; |
141
|
0
|
|
|
|
|
|
my %std_args = (objid => $nav_obj->o->Id, |
142
|
|
|
|
|
|
|
restrict => $restrict); |
143
|
0
|
|
|
|
|
|
my $children = $wen->children(\%std_args); |
144
|
0
|
0
|
|
|
|
|
if (!@$children) { |
145
|
|
|
|
|
|
|
# no children - return object itself |
146
|
0
|
|
|
|
|
|
return $nav_obj; |
147
|
|
|
|
|
|
|
} |
148
|
0
|
|
|
|
|
|
$self->last($children->[-1]); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__END__ |