1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
#=======================================================================
# Module for using Template-Toolkit for generating output
# $Id: TemplateToolkit.pm,v 1.1 2003/02/28 06:06:10 whmoseley Exp $
#
#=======================================================================
package SWISH::TemplateToolkit;
use strict;
use Template;
use vars '$Template';
sub show_template {
my ( $class, $template_params, $results ) = @_;
my $cgi = $results->CGI;
#/* Cached if running under mod_perl */
$Template ||= Template->new( $template_params->{options} );
die $Template->error() unless $Template;
print $cgi->header;
my $subclass = TemplateToolkit::Helpers->new( $results );
my $vars = {
search => $subclass,
CGI => $results->CGI,
};
$Template->process( $template_params->{file}, $vars )
|| die "Template process failed for page '$template_params->{file}' ", $Template->error(), "\n";
}
#==================================================================
# Form setup for sorts and metas
#
# This could be methods of $results object
# (and then available for Template-Toolkit)
# But that's too much HTML in the object, perhaps.
#
#
#==================================================================
package TemplateToolkit::Helpers;
use strict;
sub new {
my ( $class, $results ) = @_;
@TemplateToolkit::Helpers::ISA = ref $results; # that doesn't look right.
return bless $results, $class;
}
sub get_meta_name_limits {
my ( $results ) = @_;
my $metanames = $results->config('metanames');
return '' unless $metanames;
my $name_labels = $results->config('name_labels');
my $q = $results->CGI;
return join "\n",
'Limit search to:',
$q->radio_group(
-name =>'metaname',
-values => $metanames,
-default=>$metanames->[0],
-labels =>$name_labels
),
'<br>';
}
sub get_sort_select_list {
my ( $results ) = @_;
my $sort_metas = $results->config('sorts');
return '' unless $sort_metas;
my $name_labels = $results->config('name_labels');
my $q = $results->CGI;
return join "\n",
'Sort by:',
$q->popup_menu(
-name =>'sort',
-values => $sort_metas,
-default=>$sort_metas->[0],
-labels =>$name_labels
),
$q->checkbox(
-name => 'reverse',
-label => 'Reverse Sort'
);
}
sub get_index_select_list {
my ( $results ) = @_;
my $q = $results->CGI;
my $indexes = $results->config('swish_index');
return '' unless ref $indexes eq 'ARRAY';
my $select_config = $results->config('select_indexes');
return '' unless $select_config && ref $select_config eq 'HASH';
# Should return a warning, as this might be a likely mistake
# This jumps through hoops so that real index file name is not exposed
return '' unless exists $select_config->{labels}
&& ref $select_config->{labels} eq 'ARRAY'
&& @$indexes == @{$select_config->{labels}};
my @labels = @{$select_config->{labels}};
my %map;
for ( 0..$#labels ) {
$map{$_} = $labels[$_];
}
my $method = $select_config->{method} || 'checkbox_group';
my @cols = $select_config->{columns} ? ('-columns', $select_config->{columns}) : ();
return join "\n",
'<br>',
( $select_config->{description} || 'Select: '),
$q->$method(
-name => 'si',
-values => [0..$#labels],
-default=> 0,
-labels => \%map,
@cols );
}
sub get_limit_select {
my ( $results ) = @_;
my $q = $results->CGI;
my $limit = $results->config('select_by_meta');
return '' unless ref $limit eq 'HASH';
my $method = $limit->{method} || 'checkbox_group';
my @options = (
-name => 'sbm',
-values => $limit->{values},
-labels => $limit->{labels} || {},
);
push @options, ( -columns=> $limit->{columns} ) if $limit->{columns};
return join "\n",
'<br>',
( $limit->{description} || 'Select: '),
$q->$method( @options );
}
sub stopwords_removed {
my $results = shift;
my $swr = $results->header('removed stopwords');
my $stopwords = '';
if ( $swr && ref $swr eq 'ARRAY' ) {
$stopwords = @$swr > 1
? join( ', ', map { "<b>$_</b>" } @$swr ) . ' are very common words and were not included in your search'
: join( ', ', map { "<b>$_</b>" } @$swr ) . ' is a very common word and was not included in your search';
}
return $stopwords;
}
1;
|