/[webpac]/branches/humanistika/WebPac.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /branches/humanistika/WebPac.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/WebPac.pm revision 183 by dpavlin, Sat Nov 29 17:51:12 2003 UTC branches/humanistika/WebPac.pm revision 267 by dpavlin, Fri Mar 12 16:02:06 2004 UTC
# Line 29  my $ON_PAGE =$cfg_global->val('webpac', Line 29  my $ON_PAGE =$cfg_global->val('webpac',
29  my $MIN_WILDCARD =$cfg_global->val('webpac', 'min_wildcard') || 1;  my $MIN_WILDCARD =$cfg_global->val('webpac', 'min_wildcard') || 1;
30  my $TEMPLATE =$cfg_global->val('webpac', 'template');  my $TEMPLATE =$cfg_global->val('webpac', 'template');
31  my $UNAC_FILTER =$cfg_global->val('global', 'unac_filter');  my $UNAC_FILTER =$cfg_global->val('global', 'unac_filter');
32    my $BASE_PATH =$cfg_global->val('webpac', 'base_path');
33    
34  if ($UNAC_FILTER) {  if ($UNAC_FILTER) {
35          require $UNAC_FILTER;          require $UNAC_FILTER;
# Line 38  Text::Iconv->raise_error(0);     # Conve Line 39  Text::Iconv->raise_error(0);     # Conve
39    
40  my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);  my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
41    
42    # use path from cgi script to support templates in subdirs
43    sub url_ex {
44            my $q = shift || die "suff2file needs CGI object!";
45            my $tpl = shift || die "url_ex needs template name!";
46            return suff2file($BASE_PATH, $q->url(-path => 1),$TEMPLATE_PATH,$tpl);
47    }
48    
49    sub suff2file($$$$) {
50            my ($base_path, $p, $path, $tpl) = @_;
51    
52            return $tpl if (! $base_path);
53    
54            # strip everything to and including base path, leaving only
55            # additional (virtual) path
56            if ($p =~ s,^.*?$base_path,,) {
57                    $p =~ s,/*,,g;
58                    my ($name,$ext) = split(/\./,$tpl);
59                    $p = $name . $p . "." . $ext;
60            } else {
61                    # if unable reset it!
62                    $p = $tpl;
63            }
64    
65            if ( -e "$path/$p") {
66                    return $p;
67            } else {
68                    return $tpl;
69            }
70    
71    }
72    
73  sub setup {  sub setup {
74          my $self = shift;          my $self = shift;
# Line 55  sub setup { Line 86  sub setup {
86  }  }
87    
88  sub in_template {  sub in_template {
89          my $html = shift || "This page is left unintentionally blank";          my $q = shift || die "need CGI object!";
90            my $html = shift || die "This page is left unintentionally blank";
91          return $html if (! defined($TEMPLATE));          return $html if (! defined($TEMPLATE));
92          if (open(T, $TEMPLATE)) {  
93            my ($dir,$tpl);
94            if ($TEMPLATE =~ m,^(.*?/*)([^/]+)$,) {
95                    ($dir,$tpl) = ($1,$2);
96            } else {
97                    die "can't parse TEMPLATE path";
98            }
99    
100            my $master_tpl = suff2file($BASE_PATH, $q->url(-path => 1),$dir,$tpl);
101            if (open(T, $master_tpl)) {
102                  my $template_html = join("\n",<T>);                  my $template_html = join("\n",<T>);
103                  close(T);                  close(T);
104                  $template_html =~ s/##webpac##/$html/gsi;                  $template_html =~ s/##webpac##/$html/gsi;
105                  return $template_html;                  return $template_html;
106          } else {          } else {
107                  return "Can't read template '$TEMPLATE'";                  return "Can't read template '$master_tpl'";
108          }          }
109  }  }
110    
# Line 73  sub show_search_form { Line 114  sub show_search_form {
114          # Get the CGI.pm query object          # Get the CGI.pm query object
115          my $q = $self->query();          my $q = $self->query();
116    
117          my $tmpl = $self->load_tmpl('search.html');          my $tmpl = $self->load_tmpl(url_ex($q,'search.html'));
118          my $html = $tmpl->output;          my $html = $tmpl->output;
119    
120          my $fif = new HTML::FillInForm;          my $fif = new HTML::FillInForm;
121    
122          return in_template($fif->fill(scalarref => \$html, fobject => $q,          return in_template($q,$fif->fill(scalarref => \$html, fobject => $q,
123                  target => 'search'));                  target => 'search'));
124  }  }
125    
# Line 109  sub show_results_list { Line 150  sub show_results_list {
150    
151                  push @persist_vars, "f$i";                  push @persist_vars, "f$i";
152                  push @persist_vars, "v$i";                  push @persist_vars, "v$i";
153                    push @persist_vars, "e$i" if ($q->param("e$i"));
154    
155                  push @url_params,"f$i=".$q->url_param("f$i");                  push @url_params,"f$i=".$q->url_param("f$i");
156                  foreach my $v ($q->url_param("v$i")) {                  foreach my $v ($q->url_param("v$i")) {
# Line 141  sub show_results_list { Line 183  sub show_results_list {
183                          if ($q->param("e$i")) {                          if ($q->param("e$i")) {
184                                  $pre = '"' if (! $pre);                                  $pre = '"' if (! $pre);
185                                  $post = '"' if (! $post);                                  $post = '"' if (! $post);
186                                  $wc = '';       # don't use windcard in exact                                  # what about wildcards?
187                                    $wc = '';
188                                    $wc = '*' if ($q->param("e$i") & 4);
189                                  $exact = '_exact';                                  $exact = '_exact';
190                          }                          }
191    
# Line 168  sub show_results_list { Line 212  sub show_results_list {
212                  push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")";                  push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")";
213          }          }
214    
215          my $tmpl = $self->load_tmpl('results.html', global_vars => 1);          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1);
216    
217          sub esc_html {          sub esc_html {
218                  my $html = shift;                  my $html = shift;
# Line 177  sub show_results_list { Line 221  sub show_results_list {
221                  return $html;                  return $html;
222          }          }
223    
224            my $sort = 'swishrank';
225            if ($q->param("sort")) {
226                    $sort = 'headline';
227                    push @persist_vars, "sort";
228            }
229    
230          # call swish          # call swish
231          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
232                  prog     => $SWISH,                  prog     => $SWISH,
# Line 194  sub show_results_list { Line 244  sub show_results_list {
244    
245                  },                  },
246                  #startnum => 0,                  #startnum => 0,
247                  maxhits => $MAX_HITS                  maxhits => $MAX_HITS,
248                    sortorder => $sort,
249          );          );
250    
251          die $SWISH::errstr unless $sh;          die $SWISH::errstr unless $sh;
# Line 256  sub show_results_list { Line 307  sub show_results_list {
307    
308          my $html = $pager->output;          my $html = $pager->output;
309    
310          return in_template($html);          return in_template($q,$html);
311  }  }
312    
313  sub show_index {  sub show_index {
# Line 279  sub show_index { Line 330  sub show_index {
330    
331          my $total = $index->count($field,$limit);          my $total = $index->count($field,$limit);
332          if (! $total) {          if (! $total) {
333                  my $tmpl = $self->load_tmpl('no_index.html');                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
334                  $tmpl->param('field',$field);                  $tmpl->param('field',$field);
335                  $html = $tmpl->output;                  $html = $tmpl->output;
336                  return $html;                  return $html;
337          }          }
338    
339          my $tmpl = $self->load_tmpl('index_res.html', global_vars => 1);          my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1);
340          $tmpl->param('field',$field);          $tmpl->param('field',$field);
341          $tmpl->param('limit',$limit);          $tmpl->param('limit',$limit);
342          $tmpl->param('total',$total);          $tmpl->param('total',$total);
# Line 314  sub show_index { Line 365  sub show_index {
365                  template => $tmpl,                  template => $tmpl,
366          );          );
367    
368          return in_template($pager->output);          return in_template($q,$pager->output);
369  }  }
370    
371  1;  1;

Legend:
Removed from v.183  
changed lines
  Added in v.267

  ViewVC Help
Powered by ViewVC 1.1.26