1 # Copyright (C) 2002 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19 package Torrus
::Renderer
::Frontpage
;
23 use Torrus
::ConfigTree
;
27 use URI
::Escape
qw( uri_escape );
32 # All our methods are imported by Torrus::Renderer;
38 my $cache = $self->{cache
};
40 $self->{'options'} = \
%new_options
43 my($t_render, $t_expires, $filename, $mime_type);
45 my $cachekey = 'LOGINSCREEN';
47 ($t_render, $t_expires, $filename, $mime_type) =
48 $cache->getCache( $cachekey, $self->{options
} );
51 $mime_type = $Torrus::Renderer
::LoginScreen
::mimeType
;
52 my $tmplfile = $Torrus::Renderer
::LoginScreen
::template
;
54 my $url = $Torrus::Renderer
::rendererURL
;
55 if( length( $self->{'options'}->{'urlPassTree'} ) > 0 )
57 $url .= '/' . $self->{'options'}->{'urlPassTree'};
63 'plainURL' => $Torrus::Renderer
::plainURL
,
64 'style' => sub { return $self->style($_[0]); },
65 'companyName'=> $Torrus::Renderer
::companyName
,
66 'companyLogo'=> $Torrus::Renderer
::companyLogo
,
67 'companyURL' => $Torrus::Renderer
::companyURL
,
68 'lostPasswordURL' => $Torrus::Renderer
::lostPasswordURL
,
69 'siteInfo' => $Torrus::Renderer
::siteInfo
,
70 'version' => $Torrus::Global
::version
,
71 'xmlnorm' => \
&Torrus
::Renderer
::xmlnormalize
75 # Pass the options from Torrus::Renderer::render() to Template
76 while( my( $opt, $val ) = each %{$self->{'options'}} )
78 $ttvars->{$opt} = $val;
82 my $result = $self->{'tt'}->process( $tmplfile, $ttvars, \
$content );
87 Error
('Error while rendering login screen: ' .
88 $self->{'tt'}->error());
92 $cache->setCache($cachekey, $self->{options
}, time(), $t_expires, $content, $mime_type);
93 @ret = ($content, $mime_type, $t_expires - time());
96 $self->{'options'} = undef;
103 sub renderTreeChooser
106 my %new_options = @_;
107 my $cache = $self->{cache
};
109 $self->{'options'} = \
%new_options
112 my($t_render, $t_expires, $content, $mime_type);
114 my $uid = $self->{'options'}->{'uid'} || '';
116 my $cachekey = $uid . ':' . 'TREECHOOSER';
118 ($t_render, $t_expires, $content, $mime_type) =
119 $cache->getCache( $cachekey, $self->{options
} );
121 if( defined( $content ) )
123 if( $t_expires >= time() )
125 return ($content,$mime_type, $t_expires - time());
127 # Else reuse the old filename
130 $t_expires = time() + $Torrus::Renderer
::Chooser
::expires
;
131 $mime_type = $Torrus::Renderer
::Chooser
::mimeType
;
134 if( defined( $self->{'options'}{'variables'}{'SEARCH'} ) and
135 $self->mayGlobalSearch() )
137 $tmplfile = $Torrus::Renderer
::Chooser
::searchTemplate
;
141 $tmplfile = $Torrus::Renderer
::Chooser
::template
;
146 'treeNames' => sub{ return Torrus
::SiteConfig
::listTreeNames
() },
147 'treeDescr' => sub{ return
148 Torrus
::SiteConfig
::treeDescription
($_[0]) }
150 'url' => sub { return $Torrus::Renderer
::rendererURL
. '/' . $_[0] },
151 'pathUrl' => sub { return $Torrus::Renderer
::rendererURL
. '/' .
152 $_[0] . '?path=' . $_[1] },
153 'plainURL' => $Torrus::Renderer
::plainURL
,
154 'clearVar' => sub { delete $self->{'options'}{'variables'}{$_[0]};
156 'style' => sub { return $self->style($_[0]); },
157 'companyName'=> $Torrus::Renderer
::companyName
,
158 'companyLogo'=> $Torrus::Renderer
::companyLogo
,
159 'companyURL' => $Torrus::Renderer
::companyURL
,
160 'siteInfo' => $Torrus::Renderer
::siteInfo
,
161 'version' => $Torrus::Global
::version
,
162 'xmlnorm' => \
&Torrus
::Renderer
::xmlnormalize
,
163 'userAuth' => $Torrus::CGI
::authorizeUsers
,
164 'uid' => $self->{'options'}->{'uid'},
165 'userAttr' => sub { return $self->userAttribute( $_[0] ) },
166 'mayDisplayTree' => sub { return $self->
167 hasPrivilege
( $_[0], 'DisplayTree' ) }
169 'mayGlobalSearch' => sub { return $self->mayGlobalSearch(); },
170 'searchResults' => sub { return $self->doGlobalSearch($_[0]); }
174 # Pass the options from Torrus::Renderer::render() to Template
175 while( my( $opt, $val ) = each( %{$self->{'options'}} ) )
177 $ttvars->{$opt} = $val;
180 my $result = $self->{'tt'}->process( $tmplfile, $ttvars, \
$content );
185 Error
('Error while rendering tree chooser: ' .
186 $self->{'tt'}->error());
190 $cache->setCache($cachekey, $self->{options
}, time(), $t_expires, $content, $mime_type);
191 @ret = ($content, $mime_type, $t_expires - time());
194 $self->{'options'} = undef;
204 return ( $Torrus::Renderer
::globalSearchEnabled
and
205 ( not $Torrus::CGI
::authorizeUsers
or
206 ( $self->hasPrivilege( '*', 'GlobalSearch' ) ) ) )
209 =head2 doGlobalSearch
211 Takes two arguments: I<$self> and I<$string>, the later being the search
212 string. This $string is then searched for and returns an array reference
222 my $sr = Torrus
::Search
->new();
224 my $result = $sr->searchPrefix( $string );
227 push( @
{$sorted}, sort {$a->[0] cmp $b->[0]} @
{$result} );
229 # remove duplicating entries
233 for my $element ( @
{$sorted} )
235 my $str = join( ':', $element->[0], $element->[1] );
236 if( not $seen{$str} )
239 push( @
{$ret}, $element );
255 # indent-tabs-mode: nil
256 # perl-indent-level: 4