line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: Object.pm,v 1.15 2004/11/03 21:56:19 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2002 Online Office Berlin. All rights reserved. |
8
|
|
|
|
|
|
|
# Copyright (C) 2002,2004 Slaven Rezic. |
9
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
10
|
|
|
|
|
|
|
# terms of the GNU General Public License, see the file COPYING. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
14
|
|
|
|
|
|
|
# WWW: http://we-framework.sourceforge.net |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package WE_Frontend::Plugin::WE_Navigation::Object; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use base qw(WE_Frontend::Plugin::Navigation::Object); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
22
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION $IGNORE_NAME_DB $DONT_USE_INDEXDOC); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
916
|
|
23
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
WE_Frontend::Plugin::WE_Navigation::Object - object for WE_Navigation plugin |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Normally not instantiated. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This is a specialization of |
36
|
|
|
|
|
|
|
L. This class has additional |
37
|
|
|
|
|
|
|
methods for retrieving language titles, relative and absolute urls. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over 4 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item ext |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Return default extension (by default ".html"). May be overwritten in a |
46
|
|
|
|
|
|
|
subclass. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
1
|
|
sub ext { ".html" } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _set_lang { |
53
|
0
|
|
|
0
|
|
|
my $self = shift; |
54
|
0
|
0
|
|
|
|
|
if (!defined $_[0]) { |
55
|
0
|
|
0
|
|
|
|
$_[0] = $self->Navigation->{Context}->stash->get("lang") || "en"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item lang_title([lang]) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
The language dependent title. C is optional. English will be |
62
|
|
|
|
|
|
|
used if other means to determine the language fail. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub lang_title { |
67
|
0
|
|
|
0
|
1
|
|
my($self, $lang) = @_; |
68
|
0
|
|
|
|
|
|
$self->_set_lang($lang); |
69
|
0
|
|
|
|
|
|
require WE::Util::LangString; |
70
|
0
|
|
|
|
|
|
WE::Util::LangString::get($self->_obj_version_proxy("title")->o->{Title}, $lang); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item lang_short_title([lang]) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Short title. (NYI) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub lang_short_title { |
80
|
0
|
|
|
0
|
1
|
|
shift->lang_title(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item relurl |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Return a relative URL to the object. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Use the name from NameDB if available. See also the C<$IGNORE_NAME_DB> |
88
|
|
|
|
|
|
|
variable to turn this feature of. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
If the object is an folder, then the C doc is used instead |
91
|
|
|
|
|
|
|
for the URL. If C is undefined, then the C |
92
|
|
|
|
|
|
|
feature handling fires. This feature may be turned off by |
93
|
|
|
|
|
|
|
C<$DONT_USE_INDEXDOC>. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub relurl { |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my $n = $self->Navigation; |
100
|
0
|
|
|
|
|
|
my $config = $n->{Config}; |
101
|
0
|
|
|
|
|
|
my $objdb = $n->{ObjDB}; |
102
|
0
|
|
|
|
|
|
my $o = $self->_obj_version_proxy("url")->o; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Resolve id for folders |
105
|
0
|
0
|
|
|
|
|
my $id = defined $o->Version_Parent ? $o->Version_Parent : $o->Id; |
106
|
0
|
0
|
0
|
|
|
|
if (!$DONT_USE_INDEXDOC && $o->can("IndexDoc")) { |
107
|
0
|
0
|
0
|
|
|
|
if (defined $o->IndexDoc && $o->IndexDoc ne "") { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$id = $o->IndexDoc; |
109
|
|
|
|
|
|
|
} elsif ($config && |
110
|
|
|
|
|
|
|
$config->project && |
111
|
|
|
|
|
|
|
$config->project->can("features") && |
112
|
|
|
|
|
|
|
$config->project->features && |
113
|
|
|
|
|
|
|
$config->project->features->{autoindexdoc} && |
114
|
|
|
|
|
|
|
$config->project->features->{autoindexdoc} eq 'first') { |
115
|
|
|
|
|
|
|
# XXX code doubled in WebEditor::OldController! |
116
|
0
|
|
|
|
|
|
my(@children_ids) = $objdb->get_released_children($id); |
117
|
0
|
0
|
|
|
|
|
if (@children_ids) { |
118
|
0
|
|
|
|
|
|
$id = $children_ids[0]->Id; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Prefer name over numerical id |
124
|
0
|
|
|
|
|
|
my $rootdb = $n->{RootDB}; |
125
|
0
|
0
|
0
|
|
|
|
if ($rootdb && !$IGNORE_NAME_DB) { |
126
|
0
|
|
|
|
|
|
my $namedb = $rootdb->NameDB; |
127
|
0
|
0
|
|
|
|
|
if ($namedb) { |
128
|
0
|
|
|
|
|
|
my @names = $namedb->get_names($id); |
129
|
0
|
0
|
|
|
|
|
if (@names) { |
130
|
0
|
|
|
|
|
|
return $names[0] . $self->ext; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if ($objdb->is_root_object($id)) { |
136
|
0
|
|
|
|
|
|
"index" . $self->ext; |
137
|
|
|
|
|
|
|
} else { |
138
|
0
|
|
|
|
|
|
$id . $self->ext; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item halfabsurl |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Return a half-absolute URL (without scheme, host and port part) to the |
145
|
|
|
|
|
|
|
object. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub halfabsurl { |
151
|
0
|
|
|
0
|
1
|
|
my($self, $lang) = @_; |
152
|
0
|
|
|
|
|
|
$self->_set_lang($lang); |
153
|
0
|
|
|
|
|
|
my $config = $self->Navigation->{Config}; |
154
|
0
|
|
|
|
|
|
$config->paths->rooturl . "/html/$lang/" . $self->relurl; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item absurl |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Return an absolute URL (with scheme, host and port part) to the |
160
|
|
|
|
|
|
|
object. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub absurl { |
165
|
0
|
|
|
0
|
1
|
|
my($self, $lang) = @_; |
166
|
0
|
|
|
|
|
|
$self->_set_lang($lang); |
167
|
0
|
|
|
|
|
|
my $config = $self->Navigation->{Config}; |
168
|
0
|
|
|
|
|
|
$config->paths->absoluteurl . "/html/$lang/" . $self->relurl; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item target |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Return the window target to the object. Currently this is always |
174
|
|
|
|
|
|
|
"_self". |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub target { |
179
|
0
|
|
|
0
|
1
|
|
"_self"; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item include_in_navigation |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Return true if the object should be included to the navigation. The |
185
|
|
|
|
|
|
|
following cases cause the object to be excluded from the navigation: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * The object's attribute C is not C |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * The object's attribute C is C |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * The object is not ready to be published as determined by |
194
|
|
|
|
|
|
|
C and C. The current date can be adjusted by |
195
|
|
|
|
|
|
|
setting the C template variable to a unix epoch time. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub include_in_navigation { |
202
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
203
|
0
|
|
|
|
|
|
my $o = $self->_obj_version_proxy("navigation")->o; |
204
|
0
|
0
|
0
|
|
|
|
return 0 if ((defined $o->{Navigation} && $o->{Navigation} eq 'hidden') || |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
205
|
|
|
|
|
|
|
(!defined $o->Release_State || $o->Release_State ne 'released')); |
206
|
0
|
0
|
0
|
|
|
|
if (defined $o->TimeOpen || defined $o->TimeExpire) { |
207
|
0
|
|
|
|
|
|
my $n = $self->Navigation; |
208
|
0
|
|
|
|
|
|
my $now = $n->{LocalConfig}{now}; |
209
|
0
|
0
|
|
|
|
|
$now = time if !defined $now; |
210
|
0
|
0
|
|
|
|
|
return 0 if $o->is_time_restricted($now); |
211
|
|
|
|
|
|
|
} |
212
|
0
|
|
|
|
|
|
1; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item obj_proxy($caller) |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Some objects may not have content of their own and use the first child |
218
|
|
|
|
|
|
|
in their collection instead for getting attributes like Title etc. By |
219
|
|
|
|
|
|
|
default, this method just returns the object itself, but may be |
220
|
|
|
|
|
|
|
overriden. See C for an example. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
C<$caller> will be set to a symbolic name of the caller: C (for |
223
|
|
|
|
|
|
|
methods like C), C (for methods like C), or |
224
|
|
|
|
|
|
|
C) (for C and similar methods). If |
225
|
|
|
|
|
|
|
you need the real caller function name, then use the standard C |
226
|
|
|
|
|
|
|
function. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
0
|
1
|
|
sub obj_proxy { $_[0] } |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item version_proxy($caller) |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
For a given object, determine which version of the object should be |
235
|
|
|
|
|
|
|
used. The default implementation of I is to return the |
236
|
|
|
|
|
|
|
last released version (using I from |
237
|
|
|
|
|
|
|
L), or, if no object is released, the latest version. |
238
|
|
|
|
|
|
|
Subclasses are free to override this method. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub version_proxy { |
243
|
0
|
|
|
0
|
1
|
|
my($self, $caller) = @_; |
244
|
0
|
|
|
|
|
|
my $n = $self->Navigation; |
245
|
0
|
|
|
|
|
|
my $objdb = $n->{ObjDB}; |
246
|
0
|
|
|
|
|
|
my $relobj = $objdb->get_released_object($self->o->Id); |
247
|
0
|
0
|
|
|
|
|
if (!defined $relobj) { |
248
|
0
|
|
|
|
|
|
return $self; |
249
|
|
|
|
|
|
|
} |
250
|
0
|
|
|
|
|
|
my $ret = (ref $self)->new($relobj, $n); |
251
|
0
|
|
|
|
|
|
$ret; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# Call obj_proxy and version_proxy. Only for internal use. |
255
|
|
|
|
|
|
|
sub _obj_version_proxy { |
256
|
0
|
|
|
0
|
|
|
my($self, $caller) = @_; |
257
|
0
|
|
|
|
|
|
$self->obj_proxy($caller)->version_proxy($caller); |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
__END__ |