/[webpac]/trunk/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 /trunk/WebPac.pm

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

revision 641 by dpavlin, Sun Jan 23 02:02:10 2005 UTC revision 696 by dpavlin, Sun Mar 13 02:00:35 2005 UTC
# Line 10  use DBI; Line 10  use DBI;
10  use Config::IniFiles;  use Config::IniFiles;
11  use Text::Unaccent;  use Text::Unaccent;
12  use Data::Pageset;  use Data::Pageset;
13    use POSIX qw(locale_h);
14    
15  use lib '..';  use lib '..';
16  use index_DBI_tag;  use index_DBI_filter;
17  use back2html;  use back2html;
18    
19    
# Line 32  my $UNAC_FILTER =$cfg_global->val('globa Line 33  my $UNAC_FILTER =$cfg_global->val('globa
33  my $BASE_PATH =$cfg_global->val('webpac', 'base_path');  my $BASE_PATH =$cfg_global->val('webpac', 'base_path');
34  # for pager  # for pager
35  my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10;  my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10;
36    my $locale = $cfg_global->val('locale') || 'hr_HR';
37    
38  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
39    
40  my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);  my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
41    
42    setlocale(LC_CTYPE, $locale);
43    setlocale(LC_COLLATE, $locale);
44    
45  if ($UNAC_FILTER) {  if ($UNAC_FILTER) {
46          require $UNAC_FILTER;          require $UNAC_FILTER;
47  } else {  } else {
# Line 148  sub make_pager($$$) { Line 153  sub make_pager($$$) {
153    
154    
155          foreach my $p (@{$pager->pages_in_set()}) {          foreach my $p (@{$pager->pages_in_set()}) {
156                  next if ($p < 0);                  next if ($p <= 0);
157                  if($p == $pager->current_page()) {                  if($p == $pager->current_page()) {
158                          $pager_jump .= "<b>$p</b> ";                          $pager_jump .= "<b>$p</b> ";
159                  } else {                  } else {
# Line 182  sub make_pager_vars { Line 187  sub make_pager_vars {
187          my $tmpl = shift @_;          my $tmpl = shift @_;
188          my @persist_vars = @_;          my @persist_vars = @_;
189          my $hidden_vars = '';          my $hidden_vars = '';
190            my $hidden_search = '';
191          foreach my $v (@persist_vars) {          foreach my $v (@persist_vars) {
192                  foreach my $val ($q->param($v)) {                  foreach my $val ($q->param($v)) {
193                          next if (! $val || $val eq '');                          next if (! $val || $val eq '');
194                            $val =~ s/"/&quot;/g;
195                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
196                            $hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm");
197                  }                  }
198          }          }
199    
200          $tmpl->param('PAGER_HIDDEN', $hidden_vars);          $tmpl->param('PAGER_HIDDEN', $hidden_vars);
201            $tmpl->param('SEARCH_HIDDEN', $hidden_search);
202          $tmpl->param('PAGER_JAVASCRIPT', qq#          $tmpl->param('PAGER_JAVASCRIPT', qq#
203  <SCRIPT LANGUAGE="Javascript">  <SCRIPT LANGUAGE="Javascript">
204  <!-- Begin  <!-- Begin
# Line 224  sub show_results_list { Line 233  sub show_results_list {
233    
234          my $q = $self->query();          my $q = $self->query();
235    
236            # submit was reset?
237            if ($q->param('reset')) {
238                    $q->delete_all;
239                    return $self->show_search_form();
240            }
241    
242          # load template for this page          # load template for this page
243    
244          my @s_arr;      # all queries are located here          my @s_arr;      # all queries are located here
# Line 264  sub show_results_list { Line 279  sub show_results_list {
279                  push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);                  push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);
280    
281                  foreach my $v ($q->url_param("v$i")) {                  foreach my $v ($q->url_param("v$i")) {
282                            # escape quotes so that phrase search work
283                            $v =~ s/"/%22/g;
284                          push @url_params,"v$i=$v";                          push @url_params,"v$i=$v";
285                          push @url_params_persist,"v$i=$v" if ($persist);                          push @url_params_persist,"v$i=$v" if ($persist);
286                  }                  }
# Line 328  sub show_results_list { Line 345  sub show_results_list {
345                  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).")";
346          }          }
347    
348          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1);          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0);
349    
350          $tmpl->param('url_params',"?".join("&",@url_params));          $tmpl->param('url_params',"?".join("&",@url_params));
351    
# Line 345  sub show_results_list { Line 362  sub show_results_list {
362                  push @persist_vars, "sort";                  push @persist_vars, "sort";
363          }          }
364    
365            my $sortby = $q->param("sortby");
366            if ($sortby) {
367                    $sort = $sortby;
368                    push @persist_vars, "sortby";
369            }
370            $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
371    
372          # construct swish query          # construct swish query
373          my $sw_q = join(" and ",@s_arr);          my $sw_q = join(" and ",@s_arr);
374          if (@path_arr && $q->param('show_full')) {          if (@path_arr && $q->param('show_full')) {
# Line 359  sub show_results_list { Line 383  sub show_results_list {
383                  $tmpl->param('full',0);                  $tmpl->param('full',0);
384          }          }
385    
386            my $swish_msg = ' ';
387    
388          # create new swish instance          # create new swish instance
389          my $swish = SWISH::API->new($INDEX);          my $swish = SWISH::API->new($INDEX);
390          die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;          $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
391    
392          # execute query and get number of results from SWISH-E          # execute query and get number of results from SWISH-E
393          my $search = $swish->New_Search_Object;          my $search = $swish->New_Search_Object;
# Line 369  sub show_results_list { Line 395  sub show_results_list {
395          $search->SetSort($sort);          $search->SetSort($sort);
396    
397          my $results = $search->Execute($sw_q);          my $results = $search->Execute($sw_q);
398          die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;          $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
399    
400          my $hits = $results->Hits;          my $hits = $results->Hits;
401    
402          $tmpl->param('hits',$hits);          $tmpl->param('hits',$hits);
403          $tmpl->param('search',$sw_q);          my $search_msg = $sw_q;
404            $search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg);
405            $tmpl->param('search', $search_msg);
406    
407          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
408          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
# Line 438  sub show_index { Line 466  sub show_index {
466          my $field = $q->param("f$i");          my $field = $q->param("f$i");
467          my $limit = $q->param("v$i");          my $limit = $q->param("v$i");
468    
469            my $filter = $q->param("filter");
470    
471          my $html;          my $html;
472    
473          my $index = new index_DBI(          my $index = new index_DBI(
# Line 447  sub show_index { Line 477  sub show_index {
477                  $cfg_global->val('global', 'dbi_passwd') || ''                  $cfg_global->val('global', 'dbi_passwd') || ''
478          );          );
479    
480          my $total = $index->count($field,$limit);          my $total = $index->count($field,$limit,$filter);
481    
482          if (! $total) {          if (! defined($total)) {
483                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
484                  $tmpl->param('field',$field);                  $tmpl->param('field',$field);
485                  $html = $tmpl->output;                  $html = $tmpl->output;
486                  return $html;                  return $html;
487          }          }
488    
489          my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1);          my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1, die_on_bad_params => 0);
490          $tmpl->param('field',$field);          $tmpl->param('field',$field);
491          $tmpl->param('limit',$limit);          $tmpl->param('limit',$limit);
492          $tmpl->param('total',$total);          $tmpl->param('total',$total);
493            $tmpl->param('filter',$filter);
494    
495  # FIXME I should set offset and leave out limit from fetch!!  # FIXME I should set offset and leave out limit from fetch!!
496  #       if (! $q->param("PAGER_offset") {  #       if (! $q->param("PAGER_offset") {
# Line 482  sub show_index { Line 513  sub show_index {
513          make_pager($q, $tmpl, $pager);          make_pager($q, $tmpl, $pager);
514          make_pager_vars($q, $tmpl, @persist_vars);          make_pager_vars($q, $tmpl, @persist_vars);
515    
516          my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page);          my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page, $filter);
517          $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);          $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
518    
519          return in_template($q,$tmpl->output);          return in_template($q,$tmpl->output);

Legend:
Removed from v.641  
changed lines
  Added in v.696

  ViewVC Help
Powered by ViewVC 1.1.26