File Coverage

blib/lib/WE_Frontend/Plugin/WE_Navigation/Object.pm
Criterion Covered Total %
statement 9 69 13.0
branch 0 30 0.0
condition 0 38 0.0
subroutine 3 15 20.0
pod 10 10 100.0
total 22 162 13.5


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 </td> </tr> <tr> <td class="h" > <a name="223">223</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> methods like C<lang_title>), C<url> (for methods like C<relurl>), or </td> </tr> <tr> <td class="h" > <a name="224">224</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> C<navigation>) (for C<include_in_navigation> and similar methods). If </td> </tr> <tr> <td class="h" > <a name="225">225</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> you need the real caller function name, then use the standard C<caller> </td> </tr> <tr> <td class="h" > <a name="226">226</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> function. </td> </tr> <tr> <td class="h" > <a name="227">227</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="228">228</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =cut </td> </tr> <tr> <td class="h" > <a name="229">229</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="230">230</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td class="c0" > <a href="blib-lib-WE_Frontend-Plugin-WE_Navigation-Object-pm--subroutine.html#230-1"> 0 </a> </td> <td class="c3" > <a href="blib-lib-WE_Frontend-Plugin-WE_Navigation-Object-pm--subroutine.html#230-1"> 1 </a> </td> <td >   </td> <td class="s"> sub obj_proxy { $_[0] } </td> </tr> <tr> <td class="h" > <a name="231">231</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="232">232</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =item version_proxy($caller) </td> </tr> <tr> <td class="h" > <a name="233">233</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="234">234</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> For a given object, determine which version of the object should be </td> </tr> <tr> <td class="h" > <a name="235">235</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> used. The default implementation of I<version_proxy> is to return the </td> </tr> <tr> <td class="h" > <a name="236">236</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> last released version (using I<get_released_object> from </td> </tr> <tr> <td class="h" > <a name="237">237</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> L<WE::DB::Obj>), or, if no object is released, the latest version. </td> </tr> <tr> <td class="h" > <a name="238">238</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> Subclasses are free to override this method. </td> </tr> <tr> <td class="h" > <a name="239">239</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="240">240</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =cut </td> </tr> <tr> <td class="h" > <a name="241">241</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="242">242</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> sub version_proxy { </td> </tr> <tr> <td class="h" > <a name="243">243</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td class="c0" > <a href="blib-lib-WE_Frontend-Plugin-WE_Navigation-Object-pm--subroutine.html#243-1"> 0 </a> </td> <td class="c3" > <a href="blib-lib-WE_Frontend-Plugin-WE_Navigation-Object-pm--subroutine.html#243-1"> 1 </a> </td> <td >   </td> <td class="s"> my($self, $caller) = @_; </td> </tr> <tr> <td class="h" > <a name="244">244</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> my $n = $self->Navigation; </td> </tr> <tr> <td class="h" > <a name="245">245</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> my $objdb = $n->{ObjDB}; </td> </tr> <tr> <td class="h" > <a name="246">246</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> my $relobj = $objdb->get_released_object($self->o->Id); </td> </tr> <tr> <td class="h" > <a name="247">247</a> </td> <td class="c0" > 0 </td> <td class="c0" > <a href="blib-lib-WE_Frontend-Plugin-WE_Navigation-Object-pm--branch.html#247-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> if (!defined $relobj) { </td> </tr> <tr> <td class="h" > <a name="248">248</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> return $self; </td> </tr> <tr> <td class="h" > <a name="249">249</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="250">250</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> my $ret = (ref $self)->new($relobj, $n); </td> </tr> <tr> <td class="h" > <a name="251">251</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $ret; </td> </tr> <tr> <td class="h" > <a name="252">252</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="253">253</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="254">254</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> # Call obj_proxy and version_proxy. Only for internal use. </td> </tr> <tr> <td class="h" > <a name="255">255</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> sub _obj_version_proxy { </td> </tr> <tr> <td class="h" > <a name="256">256</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td class="c0" > <a href="blib-lib-WE_Frontend-Plugin-WE_Navigation-Object-pm--subroutine.html#256-1"> 0 </a> </td> <td >   </td> <td >   </td> <td class="s"> my($self, $caller) = @_; </td> </tr> <tr> <td class="h" > <a name="257">257</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $self->obj_proxy($caller)->version_proxy($caller); </td> </tr> <tr> <td class="h" > <a name="258">258</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="259">259</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="260">260</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> __END__ </td> </tr> </table> </body> </html>